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
|
||||
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
|
||||
float _Roll = InputCommon::Deg2Rad((float)Roll);
|
||||
float _Pitch = InputCommon::Deg2Rad((float)Pitch);
|
||||
// We need decimal values
|
||||
float x, y, z;
|
||||
float Roll = InputCommon::Deg2Rad((float)_Roll);
|
||||
float Pitch = InputCommon::Deg2Rad((float)_Pitch);
|
||||
// We need float values
|
||||
float x = 0.0f, y = 0.0f, z = 0.0f;
|
||||
|
||||
// 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);
|
||||
y = 0.0f;
|
||||
z = cos(_Roll);
|
||||
x = sin(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);
|
||||
z = cos(_Pitch);
|
||||
y = sin(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
|
||||
|
@ -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
|
||||
value of cos(Roll) and cos (Pitch) we get the right values. */
|
||||
// ---------
|
||||
if (abs(cos(_Roll)) < abs(cos(_Pitch)))
|
||||
z = cos(_Roll);
|
||||
if (abs(cos(Roll)) < abs(cos(Pitch)))
|
||||
z = cos(Roll);
|
||||
else
|
||||
z = cos(_Pitch);
|
||||
z = cos(Pitch);
|
||||
/* I got these from reversing the calculation in
|
||||
PitchAccelerometerToDegree() in a math program. */
|
||||
float x_num = 2 * tanf(0.5f * _Roll) * z;
|
||||
float x_den = pow2f(tanf(0.5f * _Roll)) - 1;
|
||||
float x_num = 2 * tanf(0.5f * Roll) * z;
|
||||
float x_den = pow2f(tanf(0.5f * Roll)) - 1;
|
||||
x = - (x_num / x_den);
|
||||
float y_num = 2 * tanf(0.5f * _Pitch) * z;
|
||||
float y_den = pow2f(tanf(0.5f * _Pitch)) - 1;
|
||||
float y_num = 2 * tanf(0.5f * Pitch) * z;
|
||||
float y_den = pow2f(tanf(0.5f * Pitch)) - 1;
|
||||
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;
|
||||
_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
|
||||
|
|
|
@ -507,7 +507,7 @@ void TiltWiimoteGamepad(int &Roll, int &Pitch)
|
|||
int &RollRange = g_Config.Tilt.Range.Roll;
|
||||
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)
|
||||
{
|
||||
// Make the range the same dimension as the analog stick
|
||||
|
@ -553,36 +553,32 @@ void TiltWiimoteGamepad(int &Roll, int &Pitch)
|
|||
// Tilting Wiimote with keyboard
|
||||
void TiltWiimoteKeyboard(int &Roll, int &Pitch)
|
||||
{
|
||||
// Direct map roll/pitch to swing
|
||||
if (g_Config.Tilt.Range.Roll == 0 && g_Config.Tilt.Range.Pitch == 0)
|
||||
{
|
||||
if (IsKey(g_Wiimote_kbd.ROLL_L))
|
||||
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
|
||||
// Do roll/pitch or free swing
|
||||
if (IsKey(g_Wiimote_kbd.ROLL_L))
|
||||
{
|
||||
// Stop at the upper end of the range
|
||||
if (Roll < g_Config.Tilt.Range.Roll)
|
||||
Roll += 3; // aim left
|
||||
if (g_Config.Tilt.Range.Roll)
|
||||
{
|
||||
// Stop at the upper end of the range
|
||||
if (Roll < g_Config.Tilt.Range.Roll)
|
||||
Roll += 3; // aim left
|
||||
}
|
||||
else // Free swing
|
||||
{
|
||||
Roll = -0x80 / 2;
|
||||
}
|
||||
}
|
||||
else if (IsKey(g_Wiimote_kbd.ROLL_R))
|
||||
{
|
||||
// Stop at the lower end of the range
|
||||
if (Roll > -g_Config.Tilt.Range.Roll)
|
||||
Roll -= 3; // aim right
|
||||
if (g_Config.Tilt.Range.Roll)
|
||||
{
|
||||
// Stop at the lower end of the range
|
||||
if (Roll > -g_Config.Tilt.Range.Roll)
|
||||
Roll -= 3; // aim right
|
||||
}
|
||||
else // Free swing
|
||||
{
|
||||
Roll = 0x80 / 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -590,15 +586,29 @@ void TiltWiimoteKeyboard(int &Roll, int &Pitch)
|
|||
}
|
||||
if (IsKey(g_Wiimote_kbd.PITCH_U))
|
||||
{
|
||||
// Stop at the upper end of the range
|
||||
if (Pitch < g_Config.Tilt.Range.Pitch)
|
||||
Pitch += 3; // aim up
|
||||
if (g_Config.Tilt.Range.Pitch)
|
||||
{
|
||||
// Stop at the upper end of the range
|
||||
if (Pitch < g_Config.Tilt.Range.Pitch)
|
||||
Pitch += 3; // aim up
|
||||
}
|
||||
else // Free swing
|
||||
{
|
||||
Pitch = -0x80 / 2;
|
||||
}
|
||||
}
|
||||
else if (IsKey(g_Wiimote_kbd.PITCH_D))
|
||||
{
|
||||
// Stop at the lower end of the range
|
||||
if (Pitch > -g_Config.Tilt.Range.Pitch)
|
||||
Pitch -= 3; // aim down
|
||||
if (g_Config.Tilt.Range.Pitch)
|
||||
{
|
||||
// Stop at the lower end of the range
|
||||
if (Pitch > -g_Config.Tilt.Range.Pitch)
|
||||
Pitch -= 3; // aim down
|
||||
}
|
||||
else // Free swing
|
||||
{
|
||||
Pitch = 0x80 / 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue