New Feature: Free Swing for EMU WiiMote

How to: First bind Roll & Pitch to "Analog 1" or "Analog 2", then set Roll Degree and Pitch Degree both to: "Free Swing".

Now in games, you can swing your emulated wiimote to Up/Down/Left/Right by simply pushing your binding analog stick to Up/Down/Left/Right.

PS:The swing direction will automatically adjust itself when "Upright Wiimote" option is checked.

Now you can play "Mad World" with emulated wiimote. :)

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4641 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
ayuanx 2009-12-04 16:36:24 +00:00
parent d919a641c1
commit c71adffa80
5 changed files with 81 additions and 55 deletions

View File

@ -274,8 +274,8 @@ void Config::Load(bool ChangePad)
iniFile.Get(SectionName, "NoTriggerFilter", &bNoTriggerFilter, false);
iniFile.Get(SectionName, "TriggerType", &Trigger.Type, Trigger.TRIGGER_OFF);
iniFile.Get(SectionName, "TriggerUpright", &Trigger.Upright, false);
iniFile.Get(SectionName, "TriggerRollRange", &Trigger.Range.Roll, 50);
iniFile.Get(SectionName, "TriggerPitchRange", &Trigger.Range.Pitch, false);
iniFile.Get(SectionName, "TriggerRollRange", &Trigger.Range.Roll, 0);
iniFile.Get(SectionName, "TriggerPitchRange", &Trigger.Range.Pitch, 0);
// Wiimote
for (int x = 0; x < WM_CONTROLS; x++)

View File

@ -363,9 +363,11 @@ void WiimotePadConfigDialog::CreatePadGUIControls()
StrTilt.Add(wxString::FromAscii("Triggers"));
// The range is in degrees and are set at even 5 degrees values
wxArrayString StrTiltRangeRoll, StrTiltRangePitch;
for (int i = 0; i < 37; i++)
StrTiltRangeRoll.Add(wxString::Format(wxT("Free Swing")));
for (int i = 1; i < 37; i++)
StrTiltRangeRoll.Add(wxString::Format(wxT("%i"), i*5));
for (int i = 0; i < 37; i++)
StrTiltRangePitch.Add(wxString::Format(wxT("Free Swing")));
for (int i = 1; i < 37; i++)
StrTiltRangePitch.Add(wxString::Format(wxT("%i"), i*5));
// The Trigger type list
@ -1004,10 +1006,22 @@ void WiimotePadConfigDialog::GeneralSettingsChanged(wxCommandEvent& event)
g_Config.Trigger.Type = m_TiltComboInput[Page]->GetSelection();
break;
case ID_TILT_RANGE_ROLL:
m_TiltComboRangeRoll[Page]->GetValue().ToLong(&TmpValue); g_Config.Trigger.Range.Roll = TmpValue;
if (m_TiltComboRangeRoll[Page]->GetSelection() == 0)
g_Config.Trigger.Range.Roll = 0;
else
{
m_TiltComboRangeRoll[Page]->GetValue().ToLong(&TmpValue);
g_Config.Trigger.Range.Roll = TmpValue;
}
break;
case ID_TILT_RANGE_PITCH:
m_TiltComboRangePitch[Page]->GetValue().ToLong(&TmpValue); g_Config.Trigger.Range.Pitch = TmpValue;
if (m_TiltComboRangePitch[Page]->GetSelection() == 0)
g_Config.Trigger.Range.Pitch = 0;
else
{
m_TiltComboRangePitch[Page]->GetValue().ToLong(&TmpValue);
g_Config.Trigger.Range.Pitch = TmpValue;
}
break;
case IDC_JOYNAME:
DoChangeJoystick();

View File

@ -44,7 +44,7 @@ namespace WiiMoteEmu
// Accelerometer functions
//******************************************************************************
/*
// Test the calculations
void TiltTest(u8 x, u8 y, u8 z)
{
@ -61,20 +61,20 @@ void TiltTest(u8 x, u8 y, u8 z)
(_Pitch >= 0) ? StringFromFormat(" %03i", (int)_Pitch).c_str() : StringFromFormat("%04i", (int)_Pitch).c_str());
NOTICE_LOG(CONSOLE, "\n%s", To.c_str());
}
*/
/* Angles adjustment for the upside down state when both roll and pitch is
used. When the absolute values of the angles go over 90 the Wiimote is
upside down and these adjustments are needed. */
void AdjustAngles(float &Roll, float &Pitch)
void AdjustAngles(int &Roll, int &Pitch)
{
float OldPitch = Pitch;
int OldPitch = Pitch;
if (abs(Roll) > 90)
{
if (Pitch >= 0)
Pitch = 180 - Pitch; // 15 to 165
else if (Pitch < 0)
else
Pitch = -180 - Pitch; // -15 to -165
}
@ -82,18 +82,44 @@ void AdjustAngles(float &Roll, float &Pitch)
{
if (Roll >= 0)
Roll = 180 - Roll; // 15 to 165
else if (Roll < 0)
else
Roll = -180 - Roll; // -15 to -165
}
}
// Angles to accelerometer values
void PitchDegreeToAccelerometer(float _Roll, float _Pitch, u8 &_x, u8 &_y, u8 &_z)
void PitchDegreeToAccelerometer(int Roll, int Pitch, u8 &_x, u8 &_y, u8 &_z)
{
// Direct mapping from analog stick to x/y accelerometer
if (g_Config.Trigger.Range.Pitch == 0 && g_Config.Trigger.Range.Roll == 0)
{
if (abs(Roll) <= abs(g_wm.cal_g.x))
Roll = 0;
if (abs(Pitch) <= abs(g_wm.cal_g.y))
Pitch = 0;
int ix = g_wm.cal_zero.x + Roll;
int iy = g_wm.cal_zero.y + Pitch;
if (ix > 0xFF) ix = 0xFF;
if (ix < 0x00) ix = 0x00;
if (iy > 0xFF) iy = 0xFF;
if (iy < 0x00) iy = 0x00;
if (!g_Config.Trigger.Upright)
{
_x = ix;
_y = iy;
}
else
{
_x = ix;
_z = iy;
}
return;
}
// We need radiands for the math functions
_Roll = InputCommon::Deg2Rad(_Roll);
_Pitch = InputCommon::Deg2Rad(_Pitch);
float _Roll = InputCommon::Deg2Rad((float)Roll);
float _Pitch = InputCommon::Deg2Rad((float)Pitch);
// We need decimal values
float x = (float)_x, y = (float)_y, z = (float)_z;

View File

@ -57,12 +57,12 @@ void GetJoyState(InputCommon::CONTROLLER_STATE_NEW &_PadState, InputCommon::CONT
void PadStateAdjustments(int &Lx, int &Ly, int &Rx, int &Ry, int &Tl, int &Tr);
// Accelerometer
void PitchDegreeToAccelerometer(float _Roll, float _Pitch, u8 &_x, u8 &_y, u8 &_z);
void PitchDegreeToAccelerometer(int _Roll, int _Pitch, u8 &_x, u8 &_y, u8 &_z);
void PitchAccelerometerToDegree(u8 _x, u8 _y, u8 _z, int &_Roll, int &_Pitch, int&, int&);
float AccelerometerToG(float Current, float Neutral, float G);
void TiltTest(u8 x, u8 y, u8 z);
//void TiltTest(u8 x, u8 y, u8 z);
void Tilt(u8 &_x, u8 &_y, u8 &_z);
void AdjustAngles(float &Roll, float &Pitch);
void AdjustAngles(int &Roll, int &Pitch);
// IR data
void IRData2Dots(u8 *Data);

View File

@ -428,7 +428,8 @@ u8 g_x, g_y, g_z, g_X, g_Y, g_Z;
int Shake[] = {0, 0};
// For the tilt function, the size of this list determines how fast Y returns to its neutral value
std::vector<u8> yhist(15, 0); float KbDegree;
std::vector<u8> yhist(15, 0);
int KbDegree;
// Single shake of all three directions
@ -485,7 +486,7 @@ void SingleShake(u8 &_x, u8 &_y, u8 &_z, int wm)
/* Tilting Wiimote with gamepad. We can guess that the game will calculate a
Wiimote pitch and use it as a measure of the tilting of the Wiimote. We are
interested in this tilting range 90 to -90*/
void TiltWiimoteGamepad(float &Roll, float &Pitch)
void TiltWiimoteGamepad(int &Roll, int &Pitch)
{
// Return if we have no pads
if (NumGoodPads == 0) return;
@ -499,18 +500,12 @@ void TiltWiimoteGamepad(float &Roll, float &Pitch)
lose any precision by doing this we could consider not doing this
adjustment. And instead for example upsize the XInput trigger from 0x80
to 0x8000. */
int _Lx, _Ly, _Rx, _Ry, _Tl, _Tr;
PadStateAdjustments(_Lx, _Ly, _Rx, _Ry, _Tl, _Tr);
float Lx = (float)_Lx;
float Ly = (float)_Ly;
float Rx = (float)_Rx;
float Ry = (float)_Ry;
float Tl = (float)_Tl;
float Tr = (float)_Tr;
int Lx, Ly, Rx, Ry, Tl, Tr;
PadStateAdjustments(Lx, Ly, Rx, Ry, Tl, Tr);;
// Save the Range in degrees, 45 and 90 are good values in some games
float RollRange = (float)g_Config.Trigger.Range.Roll;
float PitchRange = (float)g_Config.Trigger.Range.Pitch;
int RollRange = g_Config.Trigger.Range.Roll;
int PitchRange = g_Config.Trigger.Range.Pitch;
// The trigger currently only controls pitch
if (g_Config.Trigger.Type == g_Config.Trigger.TRIGGER)
@ -521,47 +516,43 @@ void TiltWiimoteGamepad(float &Roll, float &Pitch)
// Invert
if (PadMapping[Page].bPitchInvert) { Tl = -Tl; Tr = -Tr; }
// The final value
Pitch = Tl * (PitchRange / 128.0)
- Tr * (PitchRange / 128.0);
Pitch = Tl * ((float)PitchRange / 128.0)
- Tr * ((float)PitchRange / 128.0);
}
/* For the analog stick roll us by default set to the X-axis, pitch is by
/* For the analog stick roll is by default set to the X-axis, pitch is by
default set to the Y-axis. By changing the axis mapping and the invert
options this can be altered in any way */
else if (g_Config.Trigger.Type == g_Config.Trigger.ANALOG1)
{
// Adjust the trigger to go between negative and positive values
Lx = Lx - 128.0;
Ly = Ly - 128.0;
Lx = Lx - 128;
Ly = Ly - 128;
// Invert
if (PadMapping[Page].bRollInvert) Lx = -Lx; // else Tr = -Tr;
if (PadMapping[Page].bPitchInvert) Ly = -Ly; // else Tr = -Tr;
// Produce the final value
Roll = Lx * (RollRange / 128.0);
Pitch = Ly * (PitchRange / 128.0);
Roll = (RollRange) ? RollRange * ((float)Lx / 128.0) : Lx;
Pitch = (PitchRange) ? PitchRange * ((float)Ly / 128.0) : Ly;
}
// Otherwise we are using ANALOG2
else
{
// Adjust the trigger to go between negative and positive values
Rx = Rx - 128.0;
Ry = Ry - 128.0;
Rx = Rx - 128;
Ry = Ry - 128;
// Invert
if (PadMapping[Page].bRollInvert) Rx = -Rx; // else Tr = -Tr;
if (PadMapping[Page].bPitchInvert) Ry = -Ry; // else Tr = -Tr;
// Produce the final value
Roll = Rx * (RollRange / 128.0);
Pitch = Ry * (PitchRange / 128.0);
Roll = (RollRange) ? RollRange * ((float)Rx / 128.0) : Rx;
Pitch = (PitchRange) ? PitchRange * ((float)Ry / 128.0) : Ry;
}
// Adjustment to prevent a slightly to high angle
if (Pitch >= PitchRange) Pitch = PitchRange - 0.1;
if (Roll >= RollRange) Roll = RollRange - 0.1;
}
// Tilting Wiimote with keyboard
void TiltWiimoteKeyboard(float &Roll, float &Pitch)
void TiltWiimoteKeyboard(int &Roll, int &Pitch)
{
#ifdef _WIN32
if(IsKey(g_Wiimote_kbd.PITCH_L))
@ -599,7 +590,7 @@ void TiltWiimoteKeyboard(float &Roll, float &Pitch)
else
{
Pitch = KbDegree;
//DEBUG_LOG(WIIMOTE, "Degree: %2.1f", KbDegree);
//DEBUG_LOG(WIIMOTE, "Degree: %i", KbDegree);
}
#endif
}
@ -607,11 +598,11 @@ void TiltWiimoteKeyboard(float &Roll, float &Pitch)
// Tilting Wiimote (Wario Land aiming, Mario Kart steering and other things)
void Tilt(u8 &_x, u8 &_y, u8 &_z)
{
// Ceck if it's on
// Check if it's on
if (g_Config.Trigger.Type == g_Config.Trigger.TRIGGER_OFF) return;
// Set to zero
float Roll = 0, Pitch = 0;
int Roll = 0, Pitch = 0;
// Select input method and return the x, y, x values
if (g_Config.Trigger.Type == g_Config.Trigger.KEYBOARD)
@ -626,12 +617,7 @@ void Tilt(u8 &_x, u8 &_y, u8 &_z)
//PitchDegreeToAccelerometer(Roll, Pitch, _x, _y, _z, g_Config.Trigger.Roll, g_Config.Trigger.Pitch);
PitchDegreeToAccelerometer(Roll, Pitch, _x, _y, _z);
if (g_DebugData)
{
/*DEBUG_LOG(WIIMOTE, "L:%2.1f R:%2.1f Lx:%2.1f Range:%2.1f Degree:%2.1f L:%i R:%i",
Tl, Tr, Lx, Range, Degree, PadState[Page].Axis.Tl, PadState[Page].Axis.Tr);*/
/*DEBUG_LOG(WIIMOTE, "Roll:%2.1f Pitch:%2.1f", Roll, Pitch);*/
}
//DEBUG_LOG(WIIMOTE, "Roll:%i, Pitch:%i, _x:%i, _y:%i, _z:%i", Roll, Pitch, _x, _y, _z);
}
void FillReportAcc(wm_accel& _acc)