Add full motion to cemu hook

This commit is contained in:
german
2020-08-29 17:51:41 -05:00
parent 39319f09d8
commit 4a6fa559c4
4 changed files with 38 additions and 11 deletions

View File

@@ -135,6 +135,8 @@ Client::Client(std::shared_ptr<DeviceStatus> status, const std::string& host, u1
u8 pad_index, u32 client_id)
: status(std::move(status)) {
StartCommunication(host, port, pad_index, client_id);
motion = new InputCommon::MotionInput(0.3f, 0.005f, 0.0f);
motion->SetGyroThreshold(0.0006f);
}
Client::~Client() {
@@ -168,12 +170,22 @@ void Client::OnPadData(Response::PadData data) {
packet_sequence = data.packet_counter;
// TODO: Check how the Switch handles motions and how the CemuhookUDP motion
// directions correspond to the ones of the Switch
Common::Vec3f accel = Common::MakeVec<float>(data.accel.x, data.accel.y, data.accel.z);
Common::Vec3f gyro = Common::MakeVec<float>(data.gyro.pitch, data.gyro.yaw, data.gyro.roll);
const auto now = std::chrono::system_clock::now();
u64 time_difference =
std::chrono::duration_cast<std::chrono::microseconds>(now - last_motion_update).count();
last_motion_update = now;
Common::Vec3f rawgyroscope = {data.gyro.pitch, data.gyro.roll, -data.gyro.yaw};
motion->SetAcceleration({data.accel.x, -data.accel.z, data.accel.y});
motion->SetGyroscope(rawgyroscope / 312.0f);
motion->UpdateRotation(time_difference);
motion->UpdateOrientation(time_difference);
Common::Vec3f gyroscope = motion->GetGyroscope();
Common::Vec3f accelerometer = motion->GetAcceleration();
Common::Vec3f rotation = motion->GetRotations();
std::array<Common::Vec3f, 3> orientation = motion->GetOrientation();
{
std::lock_guard guard(status->update_mutex);
status->motion_status = {accel, gyro};
status->motion_status = {accelerometer, gyroscope, rotation, orientation};
// TODO: add a setting for "click" touch. Click touch refers to a device that differentiates
// between a simple "tap" and a hard press that causes the touch screen to click.