From c3903fcc7e281a488a26b7e6d7d739c794fa4676 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Wed, 10 Jan 2024 05:10:21 +0100 Subject: [PATCH] InputCommon/WiimoteController: Add inputs that report the raw IR objects seen by the Wiimote. --- .../Wiimote/WiimoteController.cpp | 60 ++++++++++++++++--- .../Wiimote/WiimoteController.h | 5 +- 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 wiimote) : m_wiimote(std::m AddInput(new UndetectableAnalogInput(&m_ir_state.distance, "IR Distance", 1)); + // Raw IR Objects. + for (std::size_t i = 0; i < 4; ++i) + { + AddInput(new UndetectableAnalogInput(&m_ir_state.raw_ir_object_position[i].x, + fmt::format("IR Object {} X", i + 1), 1)); + AddInput(new UndetectableAnalogInput(&m_ir_state.raw_ir_object_position[i].y, + fmt::format("IR Object {} Y", i + 1), 1)); + AddInput(new UndetectableAnalogInput(&m_ir_state.raw_ir_object_size[i], + fmt::format("IR Object {} Size", i + 1), 1)); + } + // Raw gyroscope. static constexpr std::array, 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>(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& 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& 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(point.x) / camera_max.x; + raw_ir_object_position[idx].y = static_cast(point.y) / camera_max.y; + raw_ir_object_size[idx] = static_cast(size) / 15.0f; points.Push(Common::Vec2(point)); }; - for (auto& block : data) + size_t object_index = 0; + switch (manipulator.GetIRReportFormat()) { - add_point(block.GetObject1()); - add_point(block.GetObject2()); + case IRReportFormat::Basic: + { + const std::array data = + Common::BitCastPtr>(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: + { + const std::array data = + Common::BitCastPtr>(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&); + 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 raw_ir_object_position; + std::array raw_ir_object_size; }; class ReportHandler