motion
This commit is contained in:
@ -5,6 +5,8 @@
|
||||
#include <random>
|
||||
|
||||
#include "common/input.h"
|
||||
#include "common/math_util.h"
|
||||
#include "common/quaternion.h"
|
||||
#include "core/hid/input_converter.h"
|
||||
|
||||
namespace Core::HID {
|
||||
@ -81,7 +83,7 @@ Common::Input::MotionStatus TransformToMotion(const Common::Input::CallbackStatu
|
||||
Common::Input::MotionStatus status{};
|
||||
switch (callback.type) {
|
||||
case Common::Input::InputType::Button: {
|
||||
Common::Input::AnalogProperties properties{
|
||||
const Common::Input::AnalogProperties properties{
|
||||
.deadzone = 0.0f,
|
||||
.range = 1.0f,
|
||||
.offset = 0.0f,
|
||||
@ -93,31 +95,18 @@ Common::Input::MotionStatus TransformToMotion(const Common::Input::CallbackStatu
|
||||
.raw_value = 0.0f,
|
||||
.properties = properties,
|
||||
};
|
||||
status.accel.y = {
|
||||
.value = 0.0f,
|
||||
.raw_value = 0.0f,
|
||||
.properties = properties,
|
||||
};
|
||||
status.delta_timestamp = 5000;
|
||||
status.force_update = true;
|
||||
status.accel.x = default_analog_status;
|
||||
status.accel.y = default_analog_status;
|
||||
status.accel.z = {
|
||||
.value = 0.0f,
|
||||
.raw_value = -1.0f,
|
||||
.properties = properties,
|
||||
};
|
||||
status.gyro.x = {
|
||||
.value = 0.0f,
|
||||
.raw_value = 0.0f,
|
||||
.properties = properties,
|
||||
};
|
||||
status.gyro.y = {
|
||||
.value = 0.0f,
|
||||
.raw_value = 0.0f,
|
||||
.properties = properties,
|
||||
};
|
||||
status.gyro.z = {
|
||||
.value = 0.0f,
|
||||
.raw_value = 0.0f,
|
||||
.properties = properties,
|
||||
};
|
||||
status.gyro.x = default_analog_status;
|
||||
status.gyro.y = default_analog_status;
|
||||
status.gyro.z = default_analog_status;
|
||||
if (TransformToButton(callback).value) {
|
||||
std::random_device device;
|
||||
std::mt19937 gen(device());
|
||||
@ -134,6 +123,9 @@ Common::Input::MotionStatus TransformToMotion(const Common::Input::CallbackStatu
|
||||
case Common::Input::InputType::Motion:
|
||||
status = callback.motion_status;
|
||||
break;
|
||||
case Common::Input::InputType::VirtualMotion:
|
||||
status = GetVirtualMotion(callback.motion_status);
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR(Input, "Conversion from type {} to motion not implemented", callback.type);
|
||||
break;
|
||||
@ -437,4 +429,32 @@ void SanitizeStick(Common::Input::AnalogStatus& analog_x, Common::Input::AnalogS
|
||||
}
|
||||
}
|
||||
|
||||
Common::Input::MotionStatus GetVirtualMotion(Common::Input::MotionStatus input_data,
|
||||
Common::Vec3f last_giro) {
|
||||
Common::Input::MotionStatus motion_status = input_data;
|
||||
|
||||
// Axis data is stored in the gyro value
|
||||
float wx = input_data.gyro.x.raw_value;
|
||||
float wy = input_data.gyro.y.raw_value;
|
||||
|
||||
float rotX = (wy * 2 - 1.0f) * 135.0f; // up/down best
|
||||
float rotY = (wx * 2 - 1.0f) * -180.0f; // left/right
|
||||
float rotZ = input_data.gyro.y.raw_value * 14.0f + m_lastGyroRotation.z;
|
||||
|
||||
Common::Vec3f rotation(rotX - m_lastGyroRotation.x, (rotY - m_lastGyroRotation.y) * 15.0f,
|
||||
rotZ - m_lastGyroRotation.z);
|
||||
|
||||
rotation.x = std::min(1.0f, std::max(-1.0f, rotation.x / 360.0f));
|
||||
rotation.y = std::min(1.0f, std::max(-1.0f, rotation.y / 360.0f));
|
||||
rotation.z = std::min(1.0f, std::max(-1.0f, rotation.z / 360.0f));
|
||||
|
||||
motion_status.gyro.x.raw_value = rotation.x;
|
||||
motion_status.gyro.y.raw_value = rotation.y;
|
||||
motion_status.gyro.z.raw_value = rotation.z;
|
||||
|
||||
motion_status.accel.x.raw_value = 0.0f;
|
||||
motion_status.accel.y.raw_value = 0.0f;
|
||||
motion_status.accel.z.raw_value = -1.0f;
|
||||
}
|
||||
|
||||
} // namespace Core::HID
|
||||
|
Reference in New Issue
Block a user