Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9142 from jordan-woyak/expose-fov
WiimoteEmu: Expose IR camera FOV to adjust IMU pointing sensitivity.
  • Loading branch information
leoetlino committed Oct 20, 2020
2 parents b2709b8 + 1dae834 commit f653bd7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
8 changes: 4 additions & 4 deletions Source/Core/Core/HW/WiimoteEmu/Camera.cpp
Expand Up @@ -53,7 +53,7 @@ int CameraLogic::BusWrite(u8 slave_addr, u8 addr, int count, const u8* data_in)
return RawWrite(&m_reg_data, addr, count, data_in);
}

void CameraLogic::Update(const Common::Matrix44& transform)
void CameraLogic::Update(const Common::Matrix44& transform, Common::Vec2 field_of_view)
{
// IR data is read from offset 0x37 on real hardware.
auto& data = m_reg_data.camera_data;
Expand Down Expand Up @@ -88,9 +88,9 @@ void CameraLogic::Update(const Common::Matrix44& transform)
Vec3{SENSOR_BAR_LED_SEPARATION / 2, 0, 0},
};

const auto camera_view = Matrix44::Perspective(CAMERA_FOV_Y, CAMERA_AR, 0.001f, 1000) *
Matrix44::FromMatrix33(Matrix33::RotateX(float(MathUtil::TAU / 4))) *
transform;
const auto camera_view =
Matrix44::Perspective(field_of_view.y, field_of_view.x / field_of_view.y, 0.001f, 1000) *
Matrix44::FromMatrix33(Matrix33::RotateX(float(MathUtil::TAU / 4))) * transform;

struct CameraPoint
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/HW/WiimoteEmu/Camera.h
Expand Up @@ -112,7 +112,7 @@ class CameraLogic : public I2CSlave

void Reset();
void DoState(PointerWrap& p);
void Update(const Common::Matrix44& transform);
void Update(const Common::Matrix44& transform, Common::Vec2 field_of_view);
void SetEnabled(bool is_enabled);

static constexpr u8 I2C_ADDR = 0x58;
Expand Down
25 changes: 24 additions & 1 deletion Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp
Expand Up @@ -217,6 +217,27 @@ Wiimote::Wiimote(const unsigned int index) : m_index(index)
new ControllerEmu::IMUGyroscope("IMUGyroscope", _trans("Gyroscope")));
groups.emplace_back(m_imu_ir = new ControllerEmu::IMUCursor("IMUIR", _trans("Point")));

const auto fov_default =
Common::DVec2(CameraLogic::CAMERA_FOV_X, CameraLogic::CAMERA_FOV_Y) / MathUtil::TAU * 360;

m_imu_ir->AddSetting(&m_fov_x_setting,
// i18n: FOV stands for "Field of view".
{_trans("Horizontal FOV"),
// i18n: The symbol/abbreviation for degrees (unit of angular measure).
_trans("°"),
// i18n: Refers to emulated wii remote camera properties.
_trans("Camera field of view (affects sensitivity of pointing).")},
fov_default.x, 0.01, 180);

m_imu_ir->AddSetting(&m_fov_y_setting,
// i18n: FOV stands for "Field of view".
{_trans("Vertical FOV"),
// i18n: The symbol/abbreviation for degrees (unit of angular measure).
_trans("°"),
// i18n: Refers to emulated wii remote camera properties.
_trans("Camera field of view (affects sensitivity of pointing).")},
fov_default.y, 0.01, 180);

// Extension
groups.emplace_back(m_attachments = new ControllerEmu::Attachments(_trans("Extension")));
m_attachments->AddAttachment(std::make_unique<WiimoteEmu::None>());
Expand Down Expand Up @@ -505,7 +526,9 @@ void Wiimote::SendDataReport()
{
// Note: Camera logic currently contains no changing state so we can just update it here.
// If that changes this should be moved to Wiimote::Update();
m_camera_logic.Update(GetTotalTransformation());
m_camera_logic.Update(GetTotalTransformation(),
Common::Vec2(m_fov_x_setting.GetValue(), m_fov_y_setting.GetValue()) /
360 * float(MathUtil::TAU));

// The real wiimote reads camera data from the i2c bus starting at offset 0x37:
const u8 camera_data_offset =
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h
Expand Up @@ -262,6 +262,8 @@ class Wiimote : public ControllerEmu::EmulatedController, public WiimoteCommon::
ControllerEmu::SettingValue<bool> m_upright_setting;
ControllerEmu::SettingValue<double> m_battery_setting;
ControllerEmu::SettingValue<bool> m_motion_plus_setting;
ControllerEmu::SettingValue<double> m_fov_x_setting;
ControllerEmu::SettingValue<double> m_fov_y_setting;

SpeakerLogic m_speaker_logic;
MotionPlus m_motion_plus;
Expand Down
Expand Up @@ -37,7 +37,7 @@ IMUCursor::IMUCursor(std::string name_, std::string ui_name_)
// i18n: The symbol/abbreviation for degrees (unit of angular measure).
_trans("°"),
// i18n: Refers to emulated wii remote movements.
_trans("Total rotation about the yaw axis.")},
_trans("Clamping of rotation about the yaw axis.")},
25, 0, 360);
}

Expand Down

0 comments on commit f653bd7

Please sign in to comment.