ControllerEmu: Remove focus-checking code from the rest of ControllerEmu
This commit is contained in:
parent
74f3083381
commit
e4eec2002b
|
@ -89,43 +89,31 @@ std::string GCPad::GetName() const
|
|||
|
||||
void GCPad::GetInput(GCPadStatus* const pad)
|
||||
{
|
||||
// if window has focus or background input enabled
|
||||
if (Host_RendererHasFocus() || m_options[0].settings[0]->value)
|
||||
{
|
||||
double x, y, triggers[2];
|
||||
double x, y, triggers[2];
|
||||
|
||||
// buttons
|
||||
m_buttons->GetState(&pad->button, button_bitmasks);
|
||||
// buttons
|
||||
m_buttons->GetState(&pad->button, button_bitmasks);
|
||||
|
||||
// set analog A/B analog to full or w/e, prolly not needed
|
||||
if (pad->button & PAD_BUTTON_A) pad->analogA = 0xFF;
|
||||
if (pad->button & PAD_BUTTON_B) pad->analogB = 0xFF;
|
||||
// set analog A/B analog to full or w/e, prolly not needed
|
||||
if (pad->button & PAD_BUTTON_A) pad->analogA = 0xFF;
|
||||
if (pad->button & PAD_BUTTON_B) pad->analogB = 0xFF;
|
||||
|
||||
// dpad
|
||||
m_dpad->GetState(&pad->button, dpad_bitmasks);
|
||||
// dpad
|
||||
m_dpad->GetState(&pad->button, dpad_bitmasks);
|
||||
|
||||
// sticks
|
||||
m_main_stick->GetState(&x, &y);
|
||||
pad->stickX = 0x7F + (x * 0x80);
|
||||
pad->stickY = 0x7F + (y * 0x80);
|
||||
// sticks
|
||||
m_main_stick->GetState(&x, &y);
|
||||
pad->stickX = 0x7F + (x * 0x80);
|
||||
pad->stickY = 0x7F + (y * 0x80);
|
||||
|
||||
m_c_stick->GetState(&x, &y);
|
||||
pad->substickX = 0x7F + (x * 0x80);
|
||||
pad->substickY = 0x7F + (y * 0x80);
|
||||
m_c_stick->GetState(&x, &y);
|
||||
pad->substickX = 0x7F + (x * 0x80);
|
||||
pad->substickY = 0x7F + (y * 0x80);
|
||||
|
||||
// triggers
|
||||
m_triggers->GetState(&pad->button, trigger_bitmasks, triggers);
|
||||
pad->triggerLeft = triggers[0] * 0xFF;
|
||||
pad->triggerRight = triggers[1] * 0xFF;
|
||||
}
|
||||
else
|
||||
{
|
||||
// center sticks
|
||||
pad->stickX = 0x80;
|
||||
pad->stickY = 0x80;
|
||||
pad->substickX = 0x80;
|
||||
pad->substickY = 0x80;
|
||||
}
|
||||
// triggers
|
||||
m_triggers->GetState(&pad->button, trigger_bitmasks, triggers);
|
||||
pad->triggerLeft = triggers[0] * 0xFF;
|
||||
pad->triggerRight = triggers[1] * 0xFF;
|
||||
}
|
||||
|
||||
void GCPad::SetMotor(const u8 on)
|
||||
|
@ -135,17 +123,12 @@ void GCPad::SetMotor(const u8 on)
|
|||
if (state < 0.5)
|
||||
force = -force;
|
||||
|
||||
// only rumble if window has focus or background input is enabled
|
||||
if (Host_RendererHasFocus() || m_options[0].settings[0]->value)
|
||||
m_rumble->controls[0]->control_ref->State(force);
|
||||
else
|
||||
m_rumble->controls[0]->control_ref->State(0);
|
||||
m_rumble->controls[0]->control_ref->State(force);
|
||||
}
|
||||
|
||||
void GCPad::SetOutput(const u8 on)
|
||||
{
|
||||
// only rumble if window has focus or background input is enabled
|
||||
m_rumble->controls[0]->control_ref->State(on && (Host_RendererHasFocus() || m_options[0].settings[0]->value));
|
||||
m_rumble->controls[0]->control_ref->State(on);
|
||||
}
|
||||
|
||||
void GCPad::LoadDefaults(const ControllerInterface& ciface)
|
||||
|
|
|
@ -42,7 +42,7 @@ void Attachment::Reset()
|
|||
|
||||
}
|
||||
|
||||
void ControllerEmu::Extension::GetState(u8* const data, const bool focus)
|
||||
void ControllerEmu::Extension::GetState(u8* const data)
|
||||
{
|
||||
((WiimoteEmu::Attachment*)attachments[active_extension].get())->GetState(data, focus);
|
||||
((WiimoteEmu::Attachment*)attachments[active_extension].get())->GetState(data);
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ class Attachment : public ControllerEmu
|
|||
public:
|
||||
Attachment(const char* const _name, WiimoteEmu::ExtensionReg& _reg);
|
||||
|
||||
virtual void GetState(u8* const data, const bool focus = true) {}
|
||||
virtual void GetState(u8* const data) {}
|
||||
void Reset();
|
||||
std::string GetName() const override;
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ Classic::Classic(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Classic"),
|
|||
memcpy(&id, classic_id, sizeof(classic_id));
|
||||
}
|
||||
|
||||
void Classic::GetState(u8* const data, const bool focus)
|
||||
void Classic::GetState(u8* const data)
|
||||
{
|
||||
wm_classic_extension* const ccdata = (wm_classic_extension*)data;
|
||||
ccdata->bt = 0;
|
||||
|
@ -90,15 +90,7 @@ void Classic::GetState(u8* const data, const bool focus)
|
|||
// left stick
|
||||
{
|
||||
double x, y;
|
||||
if (focus)
|
||||
{
|
||||
m_left_stick->GetState(&x, &y);
|
||||
}
|
||||
else
|
||||
{
|
||||
x = 0.0;
|
||||
y = 0.0;
|
||||
}
|
||||
m_left_stick->GetState(&x, &y);
|
||||
|
||||
ccdata->lx = (x * 0x1F) + 0x20;
|
||||
ccdata->ly = (y * 0x1F) + 0x20;
|
||||
|
@ -108,15 +100,7 @@ void Classic::GetState(u8* const data, const bool focus)
|
|||
{
|
||||
double x, y;
|
||||
u8 x_, y_;
|
||||
if (focus)
|
||||
{
|
||||
m_right_stick->GetState(&x, &y);
|
||||
}
|
||||
else
|
||||
{
|
||||
x = 0.0;
|
||||
y = 0.0;
|
||||
}
|
||||
m_right_stick->GetState(&x, &y);
|
||||
|
||||
x_ = (x * 0x1F) + 0x20;
|
||||
y_ = (y * 0x1F) + 0x20;
|
||||
|
@ -141,13 +125,10 @@ void Classic::GetState(u8* const data, const bool focus)
|
|||
ccdata->rt = rt;
|
||||
}
|
||||
|
||||
if (focus)
|
||||
{
|
||||
// buttons
|
||||
m_buttons->GetState(&ccdata->bt, classic_button_bitmasks);
|
||||
// dpad
|
||||
m_dpad->GetState(&ccdata->bt, classic_dpad_bitmasks);
|
||||
}
|
||||
// buttons
|
||||
m_buttons->GetState(&ccdata->bt, classic_button_bitmasks);
|
||||
// dpad
|
||||
m_dpad->GetState(&ccdata->bt, classic_dpad_bitmasks);
|
||||
|
||||
// flip button bits
|
||||
ccdata->bt ^= 0xFFFF;
|
||||
|
|
|
@ -13,7 +13,7 @@ class Classic : public Attachment
|
|||
{
|
||||
public:
|
||||
Classic(WiimoteEmu::ExtensionReg& _reg);
|
||||
void GetState(u8* const data, const bool focus) override;
|
||||
void GetState(u8* const data) override;
|
||||
|
||||
enum
|
||||
{
|
||||
|
|
|
@ -51,7 +51,7 @@ Drums::Drums(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Drums"), _reg)
|
|||
memcpy(&id, drums_id, sizeof(drums_id));
|
||||
}
|
||||
|
||||
void Drums::GetState(u8* const data, const bool focus)
|
||||
void Drums::GetState(u8* const data)
|
||||
{
|
||||
wm_drums_extension* const ddata = (wm_drums_extension*)data;
|
||||
ddata->bt = 0;
|
||||
|
@ -61,15 +61,7 @@ void Drums::GetState(u8* const data, const bool focus)
|
|||
// stick
|
||||
{
|
||||
double x, y;
|
||||
if (focus)
|
||||
{
|
||||
m_stick->GetState(&x, &y);
|
||||
}
|
||||
else
|
||||
{
|
||||
x = 0.0;
|
||||
y = 0.0;
|
||||
}
|
||||
m_stick->GetState(&x, &y);
|
||||
|
||||
ddata->sx = (x * 0x1F) + 0x20;
|
||||
ddata->sx = (y * 0x1F) + 0x20;
|
||||
|
@ -79,13 +71,10 @@ void Drums::GetState(u8* const data, const bool focus)
|
|||
data[2] = 0xFF;
|
||||
data[3] = 0xFF;
|
||||
|
||||
if (focus)
|
||||
{
|
||||
// buttons
|
||||
m_buttons->GetState(&ddata->bt, drum_button_bitmasks);
|
||||
// pads
|
||||
m_pads->GetState(&ddata->bt, drum_pad_bitmasks);
|
||||
}
|
||||
// buttons
|
||||
m_buttons->GetState(&ddata->bt, drum_button_bitmasks);
|
||||
// pads
|
||||
m_pads->GetState(&ddata->bt, drum_pad_bitmasks);
|
||||
|
||||
// flip button bits
|
||||
ddata->bt ^= 0xFFFF;
|
||||
|
|
|
@ -13,7 +13,7 @@ class Drums : public Attachment
|
|||
{
|
||||
public:
|
||||
Drums(WiimoteEmu::ExtensionReg& _reg);
|
||||
void GetState(u8* const data, const bool focus) override;
|
||||
void GetState(u8* const data) override;
|
||||
|
||||
enum
|
||||
{
|
||||
|
|
|
@ -64,7 +64,7 @@ Guitar::Guitar(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Guitar"), _r
|
|||
memcpy(&id, guitar_id, sizeof(guitar_id));
|
||||
}
|
||||
|
||||
void Guitar::GetState(u8* const data, const bool focus)
|
||||
void Guitar::GetState(u8* const data)
|
||||
{
|
||||
wm_guitar_extension* const gdata = (wm_guitar_extension*)data;
|
||||
gdata->bt = 0;
|
||||
|
@ -74,15 +74,7 @@ void Guitar::GetState(u8* const data, const bool focus)
|
|||
// stick
|
||||
{
|
||||
double x, y;
|
||||
if (focus)
|
||||
{
|
||||
m_stick->GetState(&x, &y);
|
||||
}
|
||||
else
|
||||
{
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
m_stick->GetState(&x, &y);
|
||||
|
||||
gdata->sx = (x * 0x1F) + 0x20;
|
||||
gdata->sy = (y * 0x1F) + 0x20;
|
||||
|
@ -96,15 +88,12 @@ void Guitar::GetState(u8* const data, const bool focus)
|
|||
m_whammy->GetState(&whammy);
|
||||
gdata->whammy = whammy * 0x1F;
|
||||
|
||||
if (focus)
|
||||
{
|
||||
// buttons
|
||||
m_buttons->GetState(&gdata->bt, guitar_button_bitmasks);
|
||||
// frets
|
||||
m_frets->GetState(&gdata->bt, guitar_fret_bitmasks);
|
||||
// strum
|
||||
m_strum->GetState(&gdata->bt, guitar_strum_bitmasks);
|
||||
}
|
||||
// buttons
|
||||
m_buttons->GetState(&gdata->bt, guitar_button_bitmasks);
|
||||
// frets
|
||||
m_frets->GetState(&gdata->bt, guitar_fret_bitmasks);
|
||||
// strum
|
||||
m_strum->GetState(&gdata->bt, guitar_strum_bitmasks);
|
||||
|
||||
// flip button bits
|
||||
gdata->bt ^= 0xFFFF;
|
||||
|
|
|
@ -13,7 +13,7 @@ class Guitar : public Attachment
|
|||
{
|
||||
public:
|
||||
Guitar(WiimoteEmu::ExtensionReg& _reg);
|
||||
void GetState(u8* const data, const bool focus) override;
|
||||
void GetState(u8* const data) override;
|
||||
|
||||
enum
|
||||
{
|
||||
|
|
|
@ -60,7 +60,7 @@ Nunchuk::Nunchuk(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Nunchuk"),
|
|||
memset(m_shake_step, 0, sizeof(m_shake_step));
|
||||
}
|
||||
|
||||
void Nunchuk::GetState(u8* const data, const bool focus)
|
||||
void Nunchuk::GetState(u8* const data)
|
||||
{
|
||||
wm_extension* const ncdata = (wm_extension*)data;
|
||||
ncdata->bt = 0;
|
||||
|
@ -96,26 +96,17 @@ void Nunchuk::GetState(u8* const data, const bool focus)
|
|||
ncdata->jx = cal.jx.center + 1;
|
||||
}
|
||||
|
||||
if (!focus)
|
||||
{
|
||||
ncdata->jx = cal.jx.center;
|
||||
ncdata->jy = cal.jy.center;
|
||||
}
|
||||
|
||||
AccelData accel;
|
||||
|
||||
// tilt
|
||||
EmulateTilt(&accel, m_tilt, focus);
|
||||
EmulateTilt(&accel, m_tilt);
|
||||
|
||||
if (focus)
|
||||
{
|
||||
// swing
|
||||
EmulateSwing(&accel, m_swing);
|
||||
// shake
|
||||
EmulateShake(&accel, m_shake, m_shake_step);
|
||||
// buttons
|
||||
m_buttons->GetState(&ncdata->bt, nunchuk_button_bitmasks);
|
||||
}
|
||||
// swing
|
||||
EmulateSwing(&accel, m_swing);
|
||||
// shake
|
||||
EmulateShake(&accel, m_shake, m_shake_step);
|
||||
// buttons
|
||||
m_buttons->GetState(&ncdata->bt, nunchuk_button_bitmasks);
|
||||
|
||||
// flip the button bits :/
|
||||
ncdata->bt ^= 0x03;
|
||||
|
|
|
@ -14,7 +14,7 @@ class Nunchuk : public Attachment
|
|||
public:
|
||||
Nunchuk(WiimoteEmu::ExtensionReg& _reg);
|
||||
|
||||
virtual void GetState(u8* const data, const bool focus) override;
|
||||
virtual void GetState(u8* const data) override;
|
||||
|
||||
enum
|
||||
{
|
||||
|
|
|
@ -55,7 +55,7 @@ Turntable::Turntable(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Turnta
|
|||
memcpy(&id, turntable_id, sizeof(turntable_id));
|
||||
}
|
||||
|
||||
void Turntable::GetState(u8* const data, const bool focus)
|
||||
void Turntable::GetState(u8* const data)
|
||||
{
|
||||
wm_turntable_extension* const ttdata = (wm_turntable_extension*)data;
|
||||
ttdata->bt = 0;
|
||||
|
@ -63,15 +63,7 @@ void Turntable::GetState(u8* const data, const bool focus)
|
|||
// stick
|
||||
{
|
||||
double x, y;
|
||||
if (focus)
|
||||
{
|
||||
m_stick->GetState(&x, &y);
|
||||
}
|
||||
else
|
||||
{
|
||||
x = 0.0;
|
||||
y = 0.0;
|
||||
}
|
||||
m_stick->GetState(&x, &y);
|
||||
|
||||
ttdata->sx = (x * 0x1F) + 0x20;
|
||||
ttdata->sy = (y * 0x1F) + 0x20;
|
||||
|
@ -81,14 +73,7 @@ void Turntable::GetState(u8* const data, const bool focus)
|
|||
{
|
||||
double tt;
|
||||
s8 tt_;
|
||||
if (focus)
|
||||
{
|
||||
m_left_table->GetState(&tt);
|
||||
}
|
||||
else
|
||||
{
|
||||
tt = 0.0;
|
||||
}
|
||||
m_left_table->GetState(&tt);
|
||||
|
||||
tt_ = tt * 0x1F;
|
||||
|
||||
|
@ -100,14 +85,7 @@ void Turntable::GetState(u8* const data, const bool focus)
|
|||
{
|
||||
double tt;
|
||||
s8 tt_;
|
||||
if (focus)
|
||||
{
|
||||
m_right_table->GetState(&tt);
|
||||
}
|
||||
else
|
||||
{
|
||||
tt = 0.0;
|
||||
}
|
||||
m_right_table->GetState(&tt);
|
||||
|
||||
tt_ = tt * 0x1F;
|
||||
|
||||
|
@ -121,14 +99,7 @@ void Turntable::GetState(u8* const data, const bool focus)
|
|||
{
|
||||
double dial;
|
||||
u8 dial_;
|
||||
if (focus)
|
||||
{
|
||||
m_effect_dial->GetState(&dial);
|
||||
}
|
||||
else
|
||||
{
|
||||
dial = 0;
|
||||
}
|
||||
m_effect_dial->GetState(&dial);
|
||||
|
||||
dial_ = dial * 0x0F;
|
||||
|
||||
|
@ -139,23 +110,13 @@ void Turntable::GetState(u8* const data, const bool focus)
|
|||
// crossfade slider
|
||||
{
|
||||
double cfs;
|
||||
if (focus)
|
||||
{
|
||||
m_crossfade->GetState(&cfs);
|
||||
}
|
||||
else
|
||||
{
|
||||
cfs = 0;
|
||||
}
|
||||
m_crossfade->GetState(&cfs);
|
||||
|
||||
ttdata->slider = (cfs * 0x07) + 0x08;
|
||||
}
|
||||
|
||||
if (focus)
|
||||
{
|
||||
// buttons
|
||||
m_buttons->GetState(&ttdata->bt, turntable_button_bitmasks);
|
||||
}
|
||||
// buttons
|
||||
m_buttons->GetState(&ttdata->bt, turntable_button_bitmasks);
|
||||
|
||||
// flip button bits :/
|
||||
ttdata->bt ^= (
|
||||
|
|
|
@ -13,7 +13,7 @@ class Turntable : public Attachment
|
|||
{
|
||||
public:
|
||||
Turntable(WiimoteEmu::ExtensionReg& _reg);
|
||||
void GetState(u8* const data, const bool focus) override;
|
||||
void GetState(u8* const data) override;
|
||||
|
||||
enum
|
||||
{
|
||||
|
|
|
@ -118,19 +118,11 @@ void EmulateShake(AccelData* const accel
|
|||
|
||||
void EmulateTilt(AccelData* const accel
|
||||
, ControllerEmu::Tilt* const tilt_group
|
||||
, const bool focus, const bool sideways, const bool upright)
|
||||
, const bool sideways, const bool upright)
|
||||
{
|
||||
double roll, pitch;
|
||||
// 180 degrees
|
||||
if (focus)
|
||||
{
|
||||
tilt_group->GetState(&roll, &pitch);
|
||||
}
|
||||
else
|
||||
{
|
||||
roll = 0.0;
|
||||
pitch = 0.0;
|
||||
}
|
||||
tilt_group->GetState(&roll, &pitch);
|
||||
|
||||
roll *= PI;
|
||||
pitch *= PI;
|
||||
|
@ -329,26 +321,17 @@ std::string Wiimote::GetName() const
|
|||
return std::string("Wiimote") + char('1'+m_index);
|
||||
}
|
||||
|
||||
// if windows is focused or background input is enabled
|
||||
#define HAS_FOCUS (Host_RendererHasFocus() || (m_options->settings[0]->value != 0))
|
||||
|
||||
bool Wiimote::Step()
|
||||
{
|
||||
const bool has_focus = HAS_FOCUS;
|
||||
|
||||
// TODO: change this a bit
|
||||
m_motion_plus_present = m_extension->settings[0]->value != 0;
|
||||
|
||||
// no rumble if no focus
|
||||
if (false == has_focus)
|
||||
m_rumble_on = false;
|
||||
|
||||
m_rumble->controls[0]->control_ref->State(m_rumble_on);
|
||||
|
||||
// when a movie is active, this button status update is disabled (moved), because movies only record data reports.
|
||||
if (!(Movie::IsPlayingInput() || Movie::IsRecordingInput()) || NetPlay::IsNetPlayRunning())
|
||||
{
|
||||
UpdateButtonsStatus(has_focus);
|
||||
UpdateButtonsStatus();
|
||||
}
|
||||
|
||||
// check if there is a read data request
|
||||
|
@ -388,16 +371,13 @@ bool Wiimote::Step()
|
|||
return false;
|
||||
}
|
||||
|
||||
void Wiimote::UpdateButtonsStatus(bool has_focus)
|
||||
void Wiimote::UpdateButtonsStatus()
|
||||
{
|
||||
// update buttons in status struct
|
||||
m_status.buttons = 0;
|
||||
if (has_focus)
|
||||
{
|
||||
const bool is_sideways = m_options->settings[1]->value != 0;
|
||||
m_buttons->GetState(&m_status.buttons, button_bitmasks);
|
||||
m_dpad->GetState(&m_status.buttons, is_sideways ? dpad_sideways_bitmasks : dpad_bitmasks);
|
||||
}
|
||||
const bool is_sideways = m_options->settings[1]->value != 0;
|
||||
m_buttons->GetState(&m_status.buttons, button_bitmasks);
|
||||
m_dpad->GetState(&m_status.buttons, is_sideways ? dpad_sideways_bitmasks : dpad_bitmasks);
|
||||
}
|
||||
|
||||
void Wiimote::GetCoreData(u8* const data)
|
||||
|
@ -405,7 +385,7 @@ void Wiimote::GetCoreData(u8* const data)
|
|||
// when a movie is active, the button update happens here instead of Wiimote::Step, to avoid potential desync issues.
|
||||
if (Movie::IsPlayingInput() || Movie::IsRecordingInput() || NetPlay::IsNetPlayRunning())
|
||||
{
|
||||
UpdateButtonsStatus(HAS_FOCUS);
|
||||
UpdateButtonsStatus();
|
||||
}
|
||||
|
||||
*(wm_core*)data |= m_status.buttons;
|
||||
|
@ -413,20 +393,16 @@ void Wiimote::GetCoreData(u8* const data)
|
|||
|
||||
void Wiimote::GetAccelData(u8* const data)
|
||||
{
|
||||
const bool has_focus = HAS_FOCUS;
|
||||
const bool is_sideways = m_options->settings[1]->value != 0;
|
||||
const bool is_upright = m_options->settings[2]->value != 0;
|
||||
|
||||
// ----TILT----
|
||||
EmulateTilt(&m_accel, m_tilt, has_focus, is_sideways, is_upright);
|
||||
EmulateTilt(&m_accel, m_tilt, is_sideways, is_upright);
|
||||
|
||||
// ----SWING----
|
||||
// ----SHAKE----
|
||||
if (has_focus)
|
||||
{
|
||||
EmulateSwing(&m_accel, m_swing, is_sideways, is_upright);
|
||||
EmulateShake(&m_accel, m_shake, m_shake_step);
|
||||
}
|
||||
EmulateSwing(&m_accel, m_swing, is_sideways, is_upright);
|
||||
EmulateShake(&m_accel, m_shake, m_shake_step);
|
||||
|
||||
FillRawAccelFromGForceData(*(wm_accel*)data, *(accel_cal*)&m_eeprom[0x16], m_accel);
|
||||
}
|
||||
|
@ -440,93 +416,89 @@ inline void LowPassFilter(double & var, double newval, double period)
|
|||
|
||||
void Wiimote::GetIRData(u8* const data, bool use_accel)
|
||||
{
|
||||
const bool has_focus = HAS_FOCUS;
|
||||
|
||||
u16 x[4], y[4];
|
||||
memset(x, 0xFF, sizeof(x));
|
||||
|
||||
if (has_focus)
|
||||
{
|
||||
double xx = 10000, yy = 0, zz = 0;
|
||||
double nsin,ncos;
|
||||
double xx = 10000, yy = 0, zz = 0;
|
||||
double nsin,ncos;
|
||||
|
||||
if (use_accel)
|
||||
if (use_accel)
|
||||
{
|
||||
double ax,az,len;
|
||||
ax=m_accel.x;
|
||||
az=m_accel.z;
|
||||
len=sqrt(ax*ax+az*az);
|
||||
if (len)
|
||||
{
|
||||
double ax,az,len;
|
||||
ax=m_accel.x;
|
||||
az=m_accel.z;
|
||||
len=sqrt(ax*ax+az*az);
|
||||
if (len)
|
||||
{
|
||||
ax/=len;
|
||||
az/=len; //normalizing the vector
|
||||
nsin=ax;
|
||||
ncos=az;
|
||||
}
|
||||
else
|
||||
{
|
||||
nsin=0;
|
||||
ncos=1;
|
||||
}
|
||||
// PanicAlert("%d %d %d\nx:%f\nz:%f\nsin:%f\ncos:%f",accel->x,accel->y,accel->z,ax,az,sin,cos);
|
||||
// PanicAlert("%d %d %d\n%d %d %d\n%d %d %d",accel->x,accel->y,accel->z,calib->zero_g.x,calib->zero_g.y,calib->zero_g.z, calib->one_g.x,calib->one_g.y,calib->one_g.z);
|
||||
ax/=len;
|
||||
az/=len; //normalizing the vector
|
||||
nsin=ax;
|
||||
ncos=az;
|
||||
}
|
||||
else
|
||||
{
|
||||
nsin=0; //m_tilt stuff here (can't figure it out yet....)
|
||||
nsin=0;
|
||||
ncos=1;
|
||||
}
|
||||
// PanicAlert("%d %d %d\nx:%f\nz:%f\nsin:%f\ncos:%f",accel->x,accel->y,accel->z,ax,az,sin,cos);
|
||||
// PanicAlert("%d %d %d\n%d %d %d\n%d %d %d",accel->x,accel->y,accel->z,calib->zero_g.x,calib->zero_g.y,calib->zero_g.z, calib->one_g.x,calib->one_g.y,calib->one_g.z);
|
||||
}
|
||||
else
|
||||
{
|
||||
nsin=0; //m_tilt stuff here (can't figure it out yet....)
|
||||
ncos=1;
|
||||
}
|
||||
|
||||
LowPassFilter(ir_sin,nsin,1.0f/60);
|
||||
LowPassFilter(ir_cos,ncos,1.0f/60);
|
||||
LowPassFilter(ir_sin,nsin,1.0f/60);
|
||||
LowPassFilter(ir_cos,ncos,1.0f/60);
|
||||
|
||||
m_ir->GetState(&xx, &yy, &zz, true);
|
||||
m_ir->GetState(&xx, &yy, &zz, true);
|
||||
|
||||
Vertex v[4];
|
||||
Vertex v[4];
|
||||
|
||||
static const int camWidth=1024;
|
||||
static const int camHeight=768;
|
||||
static const double bndup=-0.315447;
|
||||
static const double bnddown=0.85;
|
||||
static const double bndleft=0.443364;
|
||||
static const double bndright=-0.443364;
|
||||
static const double dist1=100.f/camWidth; //this seems the optimal distance for zelda
|
||||
static const double dist2=1.2f*dist1;
|
||||
static const int camWidth=1024;
|
||||
static const int camHeight=768;
|
||||
static const double bndup=-0.315447;
|
||||
static const double bnddown=0.85;
|
||||
static const double bndleft=0.443364;
|
||||
static const double bndright=-0.443364;
|
||||
static const double dist1=100.f/camWidth; //this seems the optimal distance for zelda
|
||||
static const double dist2=1.2f*dist1;
|
||||
|
||||
for (auto& vtx : v)
|
||||
{
|
||||
vtx.x=xx*(bndright-bndleft)/2+(bndleft+bndright)/2;
|
||||
if (m_sensor_bar_on_top) vtx.y=yy*(bndup-bnddown)/2+(bndup+bnddown)/2;
|
||||
else vtx.y=yy*(bndup-bnddown)/2-(bndup+bnddown)/2;
|
||||
vtx.z=0;
|
||||
}
|
||||
for (auto& vtx : v)
|
||||
{
|
||||
vtx.x=xx*(bndright-bndleft)/2+(bndleft+bndright)/2;
|
||||
if (m_sensor_bar_on_top) vtx.y=yy*(bndup-bnddown)/2+(bndup+bnddown)/2;
|
||||
else vtx.y=yy*(bndup-bnddown)/2-(bndup+bnddown)/2;
|
||||
vtx.z=0;
|
||||
}
|
||||
|
||||
v[0].x-=(zz*0.5+1)*dist1;
|
||||
v[1].x+=(zz*0.5+1)*dist1;
|
||||
v[2].x-=(zz*0.5+1)*dist2;
|
||||
v[3].x+=(zz*0.5+1)*dist2;
|
||||
v[0].x-=(zz*0.5+1)*dist1;
|
||||
v[1].x+=(zz*0.5+1)*dist1;
|
||||
v[2].x-=(zz*0.5+1)*dist2;
|
||||
v[3].x+=(zz*0.5+1)*dist2;
|
||||
|
||||
#define printmatrix(m) PanicAlert("%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n",m[0][0],m[0][1],m[0][2],m[0][3],m[1][0],m[1][1],m[1][2],m[1][3],m[2][0],m[2][1],m[2][2],m[2][3],m[3][0],m[3][1],m[3][2],m[3][3])
|
||||
Matrix rot,tot;
|
||||
static Matrix scale;
|
||||
MatrixScale(scale,1,camWidth/camHeight,1);
|
||||
//MatrixIdentity(scale);
|
||||
MatrixRotationByZ(rot,ir_sin,ir_cos);
|
||||
//MatrixIdentity(rot);
|
||||
MatrixMultiply(tot,scale,rot);
|
||||
Matrix rot,tot;
|
||||
static Matrix scale;
|
||||
MatrixScale(scale,1,camWidth/camHeight,1);
|
||||
//MatrixIdentity(scale);
|
||||
MatrixRotationByZ(rot,ir_sin,ir_cos);
|
||||
//MatrixIdentity(rot);
|
||||
MatrixMultiply(tot,scale,rot);
|
||||
|
||||
for (int i=0; i<4; i++)
|
||||
{
|
||||
MatrixTransformVertex(tot,v[i]);
|
||||
if ((v[i].x<-1)||(v[i].x>1)||(v[i].y<-1)||(v[i].y>1))
|
||||
continue;
|
||||
x[i] = (u16)lround((v[i].x+1)/2*(camWidth-1));
|
||||
y[i] = (u16)lround((v[i].y+1)/2*(camHeight-1));
|
||||
}
|
||||
// PanicAlert("%f %f\n%f %f\n%f %f\n%f %f\n%d %d\n%d %d\n%d %d\n%d %d",
|
||||
// v[0].x,v[0].y,v[1].x,v[1].y,v[2].x,v[2].y,v[3].x,v[3].y,
|
||||
// x[0],y[0],x[1],y[1],x[2],y[2],x[3],y[38]);
|
||||
for (int i=0; i<4; i++)
|
||||
{
|
||||
MatrixTransformVertex(tot,v[i]);
|
||||
if ((v[i].x<-1)||(v[i].x>1)||(v[i].y<-1)||(v[i].y>1))
|
||||
continue;
|
||||
x[i] = (u16)lround((v[i].x+1)/2*(camWidth-1));
|
||||
y[i] = (u16)lround((v[i].y+1)/2*(camHeight-1));
|
||||
}
|
||||
// PanicAlert("%f %f\n%f %f\n%f %f\n%f %f\n%d %d\n%d %d\n%d %d\n%d %d",
|
||||
// v[0].x,v[0].y,v[1].x,v[1].y,v[2].x,v[2].y,v[3].x,v[3].y,
|
||||
// x[0],y[0],x[1],y[1],x[2],y[2],x[3],y[38]);
|
||||
|
||||
// Fill report with valid data when full handshake was done
|
||||
if (m_reg_ir.data[0x30])
|
||||
// ir mode
|
||||
|
@ -586,7 +558,7 @@ void Wiimote::GetIRData(u8* const data, bool use_accel)
|
|||
|
||||
void Wiimote::GetExtData(u8* const data)
|
||||
{
|
||||
m_extension->GetState(data, HAS_FOCUS);
|
||||
m_extension->GetState(data);
|
||||
|
||||
// i dont think anything accesses the extension data like this, but ill support it. Indeed, commercial games don't do this.
|
||||
// i think it should be unencrpyted in the register, encrypted when read.
|
||||
|
|
|
@ -77,7 +77,7 @@ void EmulateShake(AccelData* const accel_data
|
|||
|
||||
void EmulateTilt(AccelData* const accel
|
||||
, ControllerEmu::Tilt* const tilt_group
|
||||
, const bool focus, const bool sideways = false, const bool upright = false);
|
||||
, const bool sideways = false, const bool upright = false);
|
||||
|
||||
void EmulateSwing(AccelData* const accel
|
||||
, ControllerEmu::Force* const tilt_group
|
||||
|
@ -128,7 +128,7 @@ protected:
|
|||
bool Step();
|
||||
void HidOutputReport(const wm_report* const sr, const bool send_ack = true);
|
||||
void HandleExtensionSwap();
|
||||
void UpdateButtonsStatus(bool has_focus);
|
||||
void UpdateButtonsStatus();
|
||||
|
||||
void GetCoreData(u8* const data);
|
||||
void GetAccelData(u8* const data);
|
||||
|
|
|
@ -411,7 +411,7 @@ public:
|
|||
|
||||
~Extension() {}
|
||||
|
||||
void GetState(u8* const data, const bool focus = true);
|
||||
void GetState(u8* const data);
|
||||
|
||||
std::vector<std::unique_ptr<ControllerEmu>> attachments;
|
||||
|
||||
|
|
Loading…
Reference in New Issue