mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2026-11-18 09:46:19 -06:00
MathUtil: C++20/23 modernisations
I've also created DegreesToRadians/RadiansToDegrees utility functions since there was a lot of repeated code
This commit is contained in:
@@ -574,7 +574,7 @@ Device::Device(std::string name, int index, std::string server_address, u16 serv
|
||||
AddInput(new AccelerometerInput("Accel Backward", m_pad_data.accelerometer_z_g, -accel_scale));
|
||||
|
||||
// Convert degrees per second to radians per second
|
||||
constexpr auto gyro_scale = 360.0 / MathUtil::TAU;
|
||||
constexpr auto gyro_scale = MathUtil::RadiansToDegrees(1.0);
|
||||
|
||||
AddInput(new GyroInput("Gyro Pitch Up", m_pad_data.gyro_pitch_deg_s, gyro_scale));
|
||||
AddInput(new GyroInput("Gyro Pitch Down", m_pad_data.gyro_pitch_deg_s, -gyro_scale));
|
||||
|
||||
@@ -189,7 +189,7 @@ bool ReshapableInputMapper::Update()
|
||||
|
||||
float ReshapableInputMapper::GetCurrentAngle() const
|
||||
{
|
||||
constexpr auto quarter_circle = float(MathUtil::TAU) * 0.25f;
|
||||
constexpr auto quarter_circle = MathUtil::TAU_v<float> * 0.25f;
|
||||
return quarter_circle - (float(m_input_detector.GetResults().size()) * quarter_circle);
|
||||
}
|
||||
|
||||
|
||||
@@ -257,7 +257,7 @@ Device::Device(hid_device* device) : m_device{device}
|
||||
|
||||
// 16.384 (?) LSBs = 1 deg / s
|
||||
// final output in rads / s
|
||||
constexpr auto gyro_scale = 16.384 * 360.0 / MathUtil::TAU;
|
||||
constexpr auto gyro_scale = MathUtil::RadiansToDegrees(16.384);
|
||||
AddInput(new MotionInput("Gyro Pitch Up", m_latest_input.gyro_pitch, gyro_scale));
|
||||
AddInput(new MotionInput("Gyro Pitch Down", m_latest_input.gyro_pitch, -gyro_scale));
|
||||
AddInput(new MotionInput("Gyro Roll Left", m_latest_input.gyro_roll, -gyro_scale));
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#include "InputCommon/ControllerInterface/Wiimote/WiimoteController.h"
|
||||
|
||||
#include <numbers>
|
||||
|
||||
#include "Common/BitUtils.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Common/MathUtil.h"
|
||||
@@ -1258,7 +1260,7 @@ void Device::UpdateOrientation()
|
||||
m_rotation_inputs =
|
||||
Common::Vec3{WiimoteEmu::GetPitch(m_orientation), WiimoteEmu::GetRoll(m_orientation),
|
||||
WiimoteEmu::GetYaw(m_orientation)} /
|
||||
float(MathUtil::PI);
|
||||
std::numbers::pi_v<float>;
|
||||
}
|
||||
|
||||
void Device::IRState::ProcessData(const DataReportManipulator& manipulator)
|
||||
|
||||
@@ -538,7 +538,7 @@ bool evdevDevice::AddNode(std::string devnode, int fd, libevdev* dev)
|
||||
// evdev resolution is specified in "g"s and deg/s.
|
||||
// Convert these to m/s/s and rad/s.
|
||||
constexpr ControlState accel_scale = MathUtil::GRAVITY_ACCELERATION;
|
||||
constexpr ControlState gyro_scale = MathUtil::TAU / 360;
|
||||
constexpr ControlState gyro_scale = MathUtil::DegreesToRadians(ControlState{1});
|
||||
|
||||
add_motion_inputs(ABS_X, accel_scale);
|
||||
add_motion_inputs(ABS_RX, gyro_scale);
|
||||
|
||||
Reference in New Issue
Block a user