Made Roll & Pitch independent from each other, you can set one to free swing while keeping the other in degrees.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4685 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
fad1fa4e3d
commit
d476048359
|
@ -89,44 +89,26 @@ void AdjustAngles(int &Roll, int &Pitch)
|
||||||
|
|
||||||
|
|
||||||
// Angles to accelerometer values
|
// Angles to accelerometer values
|
||||||
void PitchDegreeToAccelerometer(int Roll, int Pitch, int &_x, int &_y, int &_z)
|
void PitchDegreeToAccelerometer(int _Roll, int _Pitch, int &_x, int &_y, int &_z)
|
||||||
{
|
{
|
||||||
// Direct mapping for swing, from analog stick to accelerometer
|
|
||||||
if (g_Config.Tilt.Range.Roll == 0 && g_Config.Tilt.Range.Pitch == 0)
|
|
||||||
{
|
|
||||||
if (!g_Config.bUpright)
|
|
||||||
{
|
|
||||||
_x -= Roll;
|
|
||||||
_z -= Pitch;
|
|
||||||
}
|
|
||||||
else // Upright wiimote
|
|
||||||
{
|
|
||||||
_x -= Roll;
|
|
||||||
_y += Pitch;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We need radiands for the math functions
|
// We need radiands for the math functions
|
||||||
float _Roll = InputCommon::Deg2Rad((float)Roll);
|
float Roll = InputCommon::Deg2Rad((float)_Roll);
|
||||||
float _Pitch = InputCommon::Deg2Rad((float)Pitch);
|
float Pitch = InputCommon::Deg2Rad((float)_Pitch);
|
||||||
// We need decimal values
|
// We need float values
|
||||||
float x, y, z;
|
float x = 0.0f, y = 0.0f, z = 0.0f;
|
||||||
|
|
||||||
// In these cases we can use the simple and accurate formula
|
// In these cases we can use the simple and accurate formula
|
||||||
if(g_Config.Tilt.Range.Pitch == 0)
|
if(g_Config.Tilt.Range.Roll && g_Config.Tilt.Range.Pitch == 0)
|
||||||
{
|
{
|
||||||
x = sin(_Roll);
|
x = sin(Roll);
|
||||||
y = 0.0f;
|
z = cos(Roll);
|
||||||
z = cos(_Roll);
|
|
||||||
}
|
}
|
||||||
else if (g_Config.Tilt.Range.Roll == 0)
|
else if (g_Config.Tilt.Range.Pitch && g_Config.Tilt.Range.Roll == 0)
|
||||||
{
|
{
|
||||||
x = 0.0f;
|
y = sin(Pitch);
|
||||||
y = sin(_Pitch);
|
z = cos(Pitch);
|
||||||
z = cos(_Pitch);
|
|
||||||
}
|
}
|
||||||
else
|
else if(g_Config.Tilt.Range.Roll && g_Config.Tilt.Range.Pitch)
|
||||||
{
|
{
|
||||||
// ====================================================
|
// ====================================================
|
||||||
/* This seems to always produce the exact same combination of x, y, z
|
/* This seems to always produce the exact same combination of x, y, z
|
||||||
|
@ -135,17 +117,17 @@ void PitchDegreeToAccelerometer(int Roll, int Pitch, int &_x, int &_y, int &_z)
|
||||||
and Pitch. But if we select a Z from the smallest of the absolute
|
and Pitch. But if we select a Z from the smallest of the absolute
|
||||||
value of cos(Roll) and cos (Pitch) we get the right values. */
|
value of cos(Roll) and cos (Pitch) we get the right values. */
|
||||||
// ---------
|
// ---------
|
||||||
if (abs(cos(_Roll)) < abs(cos(_Pitch)))
|
if (abs(cos(Roll)) < abs(cos(Pitch)))
|
||||||
z = cos(_Roll);
|
z = cos(Roll);
|
||||||
else
|
else
|
||||||
z = cos(_Pitch);
|
z = cos(Pitch);
|
||||||
/* I got these from reversing the calculation in
|
/* I got these from reversing the calculation in
|
||||||
PitchAccelerometerToDegree() in a math program. */
|
PitchAccelerometerToDegree() in a math program. */
|
||||||
float x_num = 2 * tanf(0.5f * _Roll) * z;
|
float x_num = 2 * tanf(0.5f * Roll) * z;
|
||||||
float x_den = pow2f(tanf(0.5f * _Roll)) - 1;
|
float x_den = pow2f(tanf(0.5f * Roll)) - 1;
|
||||||
x = - (x_num / x_den);
|
x = - (x_num / x_den);
|
||||||
float y_num = 2 * tanf(0.5f * _Pitch) * z;
|
float y_num = 2 * tanf(0.5f * Pitch) * z;
|
||||||
float y_den = pow2f(tanf(0.5f * _Pitch)) - 1;
|
float y_den = pow2f(tanf(0.5f * Pitch)) - 1;
|
||||||
y = - (y_num / y_den);
|
y = - (y_num / y_den);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,6 +151,19 @@ void PitchDegreeToAccelerometer(int Roll, int Pitch, int &_x, int &_y, int &_z)
|
||||||
if(g_Config.Tilt.Range.Pitch != 0) _z = iy;
|
if(g_Config.Tilt.Range.Pitch != 0) _z = iy;
|
||||||
_y = 0xFF - iz;
|
_y = 0xFF - iz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Direct mapping for swing, from analog stick to accelerometer
|
||||||
|
if (g_Config.Tilt.Range.Roll == 0)
|
||||||
|
{
|
||||||
|
_x -= _Roll;
|
||||||
|
}
|
||||||
|
if (g_Config.Tilt.Range.Pitch == 0)
|
||||||
|
{
|
||||||
|
if (!g_Config.bUpright)
|
||||||
|
_z -= _Pitch;
|
||||||
|
else // Upright wiimote
|
||||||
|
_y += _Pitch;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Accelerometer to roll and pitch angles
|
// Accelerometer to roll and pitch angles
|
||||||
|
|
|
@ -507,7 +507,7 @@ void TiltWiimoteGamepad(int &Roll, int &Pitch)
|
||||||
int &RollRange = g_Config.Tilt.Range.Roll;
|
int &RollRange = g_Config.Tilt.Range.Roll;
|
||||||
int &PitchRange = g_Config.Tilt.Range.Pitch;
|
int &PitchRange = g_Config.Tilt.Range.Pitch;
|
||||||
|
|
||||||
// The trigger currently only controls pitch
|
// The trigger currently only controls pitch, no roll, no free swing
|
||||||
if (g_Config.Tilt.Type == g_Config.Tilt.TRIGGER)
|
if (g_Config.Tilt.Type == g_Config.Tilt.TRIGGER)
|
||||||
{
|
{
|
||||||
// Make the range the same dimension as the analog stick
|
// Make the range the same dimension as the analog stick
|
||||||
|
@ -553,53 +553,63 @@ void TiltWiimoteGamepad(int &Roll, int &Pitch)
|
||||||
// Tilting Wiimote with keyboard
|
// Tilting Wiimote with keyboard
|
||||||
void TiltWiimoteKeyboard(int &Roll, int &Pitch)
|
void TiltWiimoteKeyboard(int &Roll, int &Pitch)
|
||||||
{
|
{
|
||||||
// Direct map roll/pitch to swing
|
// Do roll/pitch or free swing
|
||||||
if (g_Config.Tilt.Range.Roll == 0 && g_Config.Tilt.Range.Pitch == 0)
|
if (IsKey(g_Wiimote_kbd.ROLL_L))
|
||||||
{
|
{
|
||||||
if (IsKey(g_Wiimote_kbd.ROLL_L))
|
if (g_Config.Tilt.Range.Roll)
|
||||||
Roll = -0x80 / 2;
|
|
||||||
else if (IsKey(g_Wiimote_kbd.ROLL_R))
|
|
||||||
Roll = 0x80 / 2;
|
|
||||||
else
|
|
||||||
Roll = 0;
|
|
||||||
if (IsKey(g_Wiimote_kbd.PITCH_U))
|
|
||||||
Pitch = -0x80 / 2;
|
|
||||||
else if (IsKey(g_Wiimote_kbd.PITCH_D))
|
|
||||||
Pitch = 0x80 / 2;
|
|
||||||
else
|
|
||||||
Pitch = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise do roll/pitch
|
|
||||||
if (IsKey(g_Wiimote_kbd.ROLL_L))
|
|
||||||
{
|
{
|
||||||
// Stop at the upper end of the range
|
// Stop at the upper end of the range
|
||||||
if (Roll < g_Config.Tilt.Range.Roll)
|
if (Roll < g_Config.Tilt.Range.Roll)
|
||||||
Roll += 3; // aim left
|
Roll += 3; // aim left
|
||||||
}
|
}
|
||||||
|
else // Free swing
|
||||||
|
{
|
||||||
|
Roll = -0x80 / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (IsKey(g_Wiimote_kbd.ROLL_R))
|
else if (IsKey(g_Wiimote_kbd.ROLL_R))
|
||||||
|
{
|
||||||
|
if (g_Config.Tilt.Range.Roll)
|
||||||
{
|
{
|
||||||
// Stop at the lower end of the range
|
// Stop at the lower end of the range
|
||||||
if (Roll > -g_Config.Tilt.Range.Roll)
|
if (Roll > -g_Config.Tilt.Range.Roll)
|
||||||
Roll -= 3; // aim right
|
Roll -= 3; // aim right
|
||||||
}
|
}
|
||||||
|
else // Free swing
|
||||||
|
{
|
||||||
|
Roll = 0x80 / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Roll = 0;
|
Roll = 0;
|
||||||
}
|
}
|
||||||
if (IsKey(g_Wiimote_kbd.PITCH_U))
|
if (IsKey(g_Wiimote_kbd.PITCH_U))
|
||||||
|
{
|
||||||
|
if (g_Config.Tilt.Range.Pitch)
|
||||||
{
|
{
|
||||||
// Stop at the upper end of the range
|
// Stop at the upper end of the range
|
||||||
if (Pitch < g_Config.Tilt.Range.Pitch)
|
if (Pitch < g_Config.Tilt.Range.Pitch)
|
||||||
Pitch += 3; // aim up
|
Pitch += 3; // aim up
|
||||||
}
|
}
|
||||||
|
else // Free swing
|
||||||
|
{
|
||||||
|
Pitch = -0x80 / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (IsKey(g_Wiimote_kbd.PITCH_D))
|
else if (IsKey(g_Wiimote_kbd.PITCH_D))
|
||||||
|
{
|
||||||
|
if (g_Config.Tilt.Range.Pitch)
|
||||||
{
|
{
|
||||||
// Stop at the lower end of the range
|
// Stop at the lower end of the range
|
||||||
if (Pitch > -g_Config.Tilt.Range.Pitch)
|
if (Pitch > -g_Config.Tilt.Range.Pitch)
|
||||||
Pitch -= 3; // aim down
|
Pitch -= 3; // aim down
|
||||||
}
|
}
|
||||||
|
else // Free swing
|
||||||
|
{
|
||||||
|
Pitch = 0x80 / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Pitch = 0;
|
Pitch = 0;
|
||||||
|
|
Loading…
Reference in New Issue