mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-22 22:00:39 -06:00
nJoy:
1. Circumvent the IDirectInputDevice2::SetDataFormat() error when opening the configuration window to. 2. Fixed the Allow out of focus input option again 3. Allow changing of the mapped pads while a game is running 4. Prevented crashes or problems from any combination of having the configuration window open when a game is started or stopped 5. Fixed a crash that would occur after nJoy was started with a connected pad, then stopped, and all pads disconnected, then started again git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2215 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
@ -44,59 +44,84 @@
|
||||
namespace WiiMoteEmu
|
||||
{
|
||||
|
||||
void PitchDegreeToAccelerometer(float _Degree, u8 &_y, u8 &_z)
|
||||
void PitchDegreeToAccelerometer(float _Roll, float _Pitch, u8 &_x, u8 &_y, u8 &_z, bool RollOn, bool PitchOn)
|
||||
{
|
||||
// Then don't update z either
|
||||
if (!RollOn && ! PitchOn) return;
|
||||
|
||||
// Calculate the radian
|
||||
float d_rad = _Degree * M_PI / 180.0;
|
||||
float _RollRad = _Roll * M_PI / 180.0;
|
||||
float _PitchRad = _Pitch * M_PI / 180.0;
|
||||
|
||||
// Calculate a good set of y and z values for the degree
|
||||
float r = 1.0;
|
||||
float fy = r * sin(d_rad); // y
|
||||
float fz = r * cos(d_rad); // x
|
||||
float fx = r * sin(_RollRad); // y
|
||||
float fy = r * sin(_PitchRad); // y
|
||||
float fz = r * cos(_PitchRad); // x
|
||||
|
||||
// Multiple with the neutral of z and its g
|
||||
float xg = g_accel.cal_g.x;
|
||||
float yg = g_accel.cal_g.y;
|
||||
float zg = g_accel.cal_g.z;
|
||||
float x_zero = g_accel.cal_zero.x;
|
||||
float y_zero = g_accel.cal_zero.y;
|
||||
float z_zero = g_accel.cal_zero.z;
|
||||
fx = (int) (x_zero + xg * fx);
|
||||
fy = (int) (y_zero + yg * fy);
|
||||
fz = (int) (z_zero + zg * fz);
|
||||
|
||||
// Boundaries
|
||||
int ix = (int)fx;
|
||||
int iy = (int)fy;
|
||||
int iz = (int)fz;
|
||||
if (iy < 0) iy = 0;
|
||||
if (iy > 255) iy = 255;
|
||||
_y = iy;
|
||||
if (ix < 0) ix = 0; if (ix > 255) ix = 255;
|
||||
if (iy < 0) iy = 0; if (iy > 255) iy = 255;
|
||||
if (iz < 0) iz = 0; if (iz > 255) iz = 255;
|
||||
if (RollOn) _x = ix;
|
||||
if (PitchOn) _y = iy;
|
||||
_z = iz;
|
||||
}
|
||||
|
||||
|
||||
int PitchAccelerometerToDegree(u8 _y, u8 _z)
|
||||
// The pitch and roll in 360<36>
|
||||
void PitchAccelerometerToDegree(u8 _x, u8 _y, u8 _z, int &_Roll, int &_Pitch)
|
||||
{
|
||||
/* find out how much it has to move to be 1g */
|
||||
float xg = (float)g_accel.cal_g.x;
|
||||
float yg = (float)g_accel.cal_g.y;
|
||||
float zg = (float)g_accel.cal_g.z;
|
||||
float d = 0;
|
||||
float Pitch = 0, Roll = 0;
|
||||
|
||||
/* find out how much it actually moved and normalize to +/- 1g */
|
||||
float x = ((float)_x - (float)g_accel.cal_zero.x) / xg;
|
||||
float y = ((float)_y - (float)g_accel.cal_zero.y) / yg;
|
||||
float z = ((float)_z - (float)g_accel.cal_zero.z) / zg;
|
||||
|
||||
/* make sure x,y,z are between -1 and 1 for the tan function */
|
||||
if (x < -1.0) x = -1.0;
|
||||
else if (x > 1.0) x = 1.0;
|
||||
if (y < -1.0) y = -1.0;
|
||||
else if (y > 1.0) y = 1.0;
|
||||
if (z < -1.0) z = -1.0;
|
||||
else if (z > 1.0) z = 1.0;
|
||||
|
||||
// If it is over 1g then it is probably accelerating and may not reliable
|
||||
//if (abs(accel->x - ac->cal_zero.x) <= ac->cal_g.x)
|
||||
{
|
||||
// Calculate the radian
|
||||
Roll = atan2(x, z);
|
||||
// Calculate the degree
|
||||
Roll = (Roll * 180.0) / M_PI;
|
||||
}
|
||||
|
||||
//if (abs(_y - g_accel.cal_zero.y) <= g_accel.cal_g.y)
|
||||
{
|
||||
// Calculate the radian
|
||||
d = atan2(y, z);
|
||||
Pitch = atan2(y, z);
|
||||
// Calculate the degree
|
||||
d = (d * 180.0) / M_PI;
|
||||
Pitch = (Pitch * 180.0) / M_PI;
|
||||
}
|
||||
return (int)d;
|
||||
_Roll = Roll;
|
||||
_Pitch = Pitch;
|
||||
}
|
||||
|
||||
}
|
||||
} // WiiMoteEmu
|
Reference in New Issue
Block a user