WiimoteEmu: Add user-accessible controls that report the desired state of the IR camera objects.

This commit is contained in:
Admiral H. Curtiss
2024-01-10 05:26:29 +01:00
parent c3903fcc7e
commit 617fcc3cf8
8 changed files with 123 additions and 2 deletions

View File

@ -49,6 +49,7 @@
#include "InputCommon/ControllerEmu/ControlGroup/IMUAccelerometer.h"
#include "InputCommon/ControllerEmu/ControlGroup/IMUCursor.h"
#include "InputCommon/ControllerEmu/ControlGroup/IMUGyroscope.h"
#include "InputCommon/ControllerEmu/ControlGroup/IRPassthrough.h"
#include "InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.h"
#include "InputCommon/ControllerEmu/ControlGroup/Tilt.h"
@ -250,6 +251,8 @@ Wiimote::Wiimote(const unsigned int index) : m_index(index), m_bt_device_index(i
_trans("Camera field of view (affects sensitivity of pointing).")},
fov_default.y, 0.01, 180);
groups.emplace_back(m_ir_passthrough = new ControllerEmu::IRPassthrough(
IR_PASSTHROUGH_GROUP, _trans("Point (Passthrough)")));
groups.emplace_back(m_imu_accelerometer = new ControllerEmu::IMUAccelerometer(
ACCELEROMETER_GROUP, _trans("Accelerometer")));
groups.emplace_back(m_imu_gyroscope =
@ -360,6 +363,8 @@ ControllerEmu::ControlGroup* Wiimote::GetWiimoteGroup(WiimoteGroup group) const
return m_imu_gyroscope;
case WiimoteGroup::IMUPoint:
return m_imu_ir;
case WiimoteGroup::IRPassthrough:
return m_ir_passthrough;
default:
ASSERT(false);
return nullptr;
@ -447,6 +452,33 @@ void Wiimote::UpdateButtonsStatus(const DesiredWiimoteState& target_state)
m_status.buttons.hex = target_state.buttons.hex & ButtonData::BUTTON_MASK;
}
static std::array<CameraPoint, CameraLogic::NUM_POINTS>
GetPassthroughCameraPoints(ControllerEmu::IRPassthrough* ir_passthrough)
{
std::array<CameraPoint, CameraLogic::NUM_POINTS> camera_points;
for (size_t i = 0; i < camera_points.size(); ++i)
{
const ControlState size = ir_passthrough->GetObjectSize(i);
if (size <= 0.0f)
continue;
const ControlState x = ir_passthrough->GetObjectPositionX(i);
const ControlState y = ir_passthrough->GetObjectPositionY(i);
camera_points[i].position.x =
std::clamp(std::lround(x * ControlState(CameraLogic::CAMERA_RES_X - 1)), long(0),
long(CameraLogic::CAMERA_RES_X - 1));
camera_points[i].position.y =
std::clamp(std::lround(y * ControlState(CameraLogic::CAMERA_RES_Y - 1)), long(0),
long(CameraLogic::CAMERA_RES_Y - 1));
camera_points[i].size =
std::clamp(std::lround(size * ControlState(CameraLogic::MAX_POINT_SIZE)), long(0),
long(CameraLogic::MAX_POINT_SIZE));
}
return camera_points;
}
void Wiimote::BuildDesiredWiimoteState(DesiredWiimoteState* target_state,
SensorBarState sensor_bar_state)
{
@ -470,7 +502,11 @@ void Wiimote::BuildDesiredWiimoteState(DesiredWiimoteState* target_state,
ConvertAccelData(GetTotalAcceleration(), ACCEL_ZERO_G << 2, ACCEL_ONE_G << 2);
// Calculate IR camera state.
if (sensor_bar_state == SensorBarState::Enabled)
if (m_ir_passthrough->enabled)
{
target_state->camera_points = GetPassthroughCameraPoints(m_ir_passthrough);
}
else if (sensor_bar_state == SensorBarState::Enabled)
{
target_state->camera_points = CameraLogic::GetCameraPoints(
GetTotalTransformation(),

View File

@ -34,6 +34,7 @@ class Force;
class IMUAccelerometer;
class IMUGyroscope;
class IMUCursor;
class IRPassthrough;
class ModifySettingsButton;
class Output;
class Tilt;
@ -59,6 +60,7 @@ enum class WiimoteGroup
IMUAccelerometer,
IMUGyroscope,
IMUPoint,
IRPassthrough,
};
enum class NunchukGroup;
@ -121,6 +123,7 @@ public:
static constexpr const char* ACCELEROMETER_GROUP = "IMUAccelerometer";
static constexpr const char* GYROSCOPE_GROUP = "IMUGyroscope";
static constexpr const char* IR_GROUP = "IR";
static constexpr const char* IR_PASSTHROUGH_GROUP = "IRPassthrough";
static constexpr const char* A_BUTTON = "A";
static constexpr const char* B_BUTTON = "B";
@ -300,6 +303,7 @@ private:
ControllerEmu::IMUAccelerometer* m_imu_accelerometer;
ControllerEmu::IMUGyroscope* m_imu_gyroscope;
ControllerEmu::IMUCursor* m_imu_ir;
ControllerEmu::IRPassthrough* m_ir_passthrough;
ControllerEmu::SettingValue<bool> m_sideways_setting;
ControllerEmu::SettingValue<bool> m_upright_setting;