summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerInterface
diff options
context:
space:
mode:
authorAdmiral H. Curtiss <pikachu025@gmail.com>2024-03-12 03:27:07 +0100
committerGitHub <noreply@github.com>2024-03-12 03:27:07 +0100
commit72bcdadc160255338f83b15587270a46974fc5a8 (patch)
tree587b475308c9633fa1bb042f8b4f2b3d9c7154bb /Source/Core/InputCommon/ControllerInterface
parentcda008bd10e9fa8774926986b706c3b9c2681aa6 (diff)
parentf6f435e6240421d170d2f79f46d8b70489663795 (diff)
Merge pull request #12492 from AdmiralCurtiss/wiimote-ir-passthrough
Implement IR passthrough for emulated Wiimotes
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface')
-rw-r--r--Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp60
-rw-r--r--Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.h5
2 files changed, 57 insertions, 8 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp b/Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp
index bc2db53328..c4e5fe028f 100644
--- a/Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp
+++ b/Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.cpp
@@ -201,6 +201,17 @@ Device::Device(std::unique_ptr<WiimoteReal::Wiimote> wiimote) : m_wiimote(std::m
AddInput(new UndetectableAnalogInput<float>(&m_ir_state.distance, "IR Distance", 1));
+ // Raw IR Objects.
+ for (std::size_t i = 0; i < 4; ++i)
+ {
+ AddInput(new UndetectableAnalogInput<float>(&m_ir_state.raw_ir_object_position[i].x,
+ fmt::format("IR Object {} X", i + 1), 1));
+ AddInput(new UndetectableAnalogInput<float>(&m_ir_state.raw_ir_object_position[i].y,
+ fmt::format("IR Object {} Y", i + 1), 1));
+ AddInput(new UndetectableAnalogInput<float>(&m_ir_state.raw_ir_object_size[i],
+ fmt::format("IR Object {} Size", i + 1), 1));
+ }
+
// Raw gyroscope.
static constexpr std::array<std::array<const char*, 2>, 3> gyro_names = {{
{"Gyro Pitch Down", "Gyro Pitch Up"},
@@ -1178,8 +1189,7 @@ void Device::ProcessInputReport(WiimoteReal::Report& report)
// Process IR data.
if (manipulator->HasIR() && m_ir_state.IsFullyConfigured())
{
- m_ir_state.ProcessData(
- Common::BitCastPtr<std::array<WiimoteEmu::IRBasic, 2>>(manipulator->GetIRDataPtr()));
+ m_ir_state.ProcessData(*manipulator);
}
// Process extension data.
@@ -1251,7 +1261,7 @@ void Device::UpdateOrientation()
float(MathUtil::PI);
}
-void Device::IRState::ProcessData(const std::array<WiimoteEmu::IRBasic, 2>& data)
+void Device::IRState::ProcessData(const DataReportManipulator& manipulator)
{
// A better implementation might extrapolate points when they fall out of camera view.
// But just averaging visible points actually seems to work very well.
@@ -1263,18 +1273,54 @@ void Device::IRState::ProcessData(const std::array<WiimoteEmu::IRBasic, 2>& data
const auto camera_max = IRObject(WiimoteEmu::CameraLogic::CAMERA_RES_X - 1,
WiimoteEmu::CameraLogic::CAMERA_RES_Y - 1);
- const auto add_point = [&](IRObject point) {
+ const auto add_point = [&](IRObject point, u8 size, size_t idx) {
// Non-visible points are 0xFF-filled.
if (point.y > camera_max.y)
+ {
+ raw_ir_object_position[idx].x = 0.0f;
+ raw_ir_object_position[idx].y = 0.0f;
+ raw_ir_object_size[idx] = 0.0f;
return;
+ }
+
+ raw_ir_object_position[idx].x = static_cast<float>(point.x) / camera_max.x;
+ raw_ir_object_position[idx].y = static_cast<float>(point.y) / camera_max.y;
+ raw_ir_object_size[idx] = static_cast<float>(size) / 15.0f;
points.Push(Common::Vec2(point));
};
- for (auto& block : data)
+ size_t object_index = 0;
+ switch (manipulator.GetIRReportFormat())
+ {
+ case IRReportFormat::Basic:
+ {
+ const std::array<WiimoteEmu::IRBasic, 2> data =
+ Common::BitCastPtr<std::array<WiimoteEmu::IRBasic, 2>>(manipulator.GetIRDataPtr());
+ for (const auto& block : data)
+ {
+ // size is not reported by IRBasic, just assume a typical size
+ add_point(block.GetObject1(), 2, object_index);
+ ++object_index;
+ add_point(block.GetObject2(), 2, object_index);
+ ++object_index;
+ }
+ break;
+ }
+ case IRReportFormat::Extended:
{
- add_point(block.GetObject1());
- add_point(block.GetObject2());
+ const std::array<WiimoteEmu::IRExtended, 4> data =
+ Common::BitCastPtr<std::array<WiimoteEmu::IRExtended, 4>>(manipulator.GetIRDataPtr());
+ for (const auto& object : data)
+ {
+ add_point(object.GetPosition(), object.size, object_index);
+ ++object_index;
+ }
+ break;
+ }
+ default:
+ // unsupported format
+ return;
}
is_hidden = !points.Count();
diff --git a/Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.h b/Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.h
index bbc07e58be..bc60a1405e 100644
--- a/Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.h
+++ b/Source/Core/InputCommon/ControllerInterface/Wiimote/WiimoteController.h
@@ -126,7 +126,7 @@ private:
{
static u32 GetDesiredIRSensitivity();
- void ProcessData(const std::array<WiimoteEmu::IRBasic, 2>&);
+ void ProcessData(const DataReportManipulator& manipulator);
bool IsFullyConfigured() const;
u32 current_sensitivity = u32(-1);
@@ -139,6 +139,9 @@ private:
float distance = 0;
bool is_hidden = true;
+
+ std::array<Common::Vec2, 4> raw_ir_object_position;
+ std::array<float, 4> raw_ir_object_size;
};
class ReportHandler