From 04b6dabcfe3cdd81dda09f8c20602a2f14e015df Mon Sep 17 00:00:00 2001 From: Eiren Rain Date: Thu, 3 Feb 2022 20:18:04 +0200 Subject: [PATCH] Remove example code --- src/ControllerDevice.cpp | 51 --------------------------------- src/HMDDevice.cpp | 42 --------------------------- src/TrackingReferenceDevice.cpp | 27 ----------------- 3 files changed, 120 deletions(-) diff --git a/src/ControllerDevice.cpp b/src/ControllerDevice.cpp index 07d093b..8fd9147 100644 --- a/src/ControllerDevice.cpp +++ b/src/ControllerDevice.cpp @@ -37,57 +37,6 @@ void SlimeVRDriver::ControllerDevice::Update() this->vibrate_anim_state_ = 0.0f; } } - - // Setup pose for this frame - auto pose = IVRDevice::MakeDefaultPose(); - - // Find a HMD - auto devices = GetDriver()->GetDevices(); - auto hmd = std::find_if(devices.begin(), devices.end(), [](const std::shared_ptr& device_ptr) {return device_ptr->GetDeviceType() == DeviceType::HMD; }); - if (hmd != devices.end()) { - // Found a HMD - vr::DriverPose_t hmd_pose = (*hmd)->GetPose(); - - // Here we setup some transforms so our controllers are offset from the headset by a small amount so we can see them - linalg::vec hmd_position{ (float)hmd_pose.vecPosition[0], (float)hmd_pose.vecPosition[1], (float)hmd_pose.vecPosition[2] }; - linalg::vec hmd_rotation{ (float)hmd_pose.qRotation.x, (float)hmd_pose.qRotation.y, (float)hmd_pose.qRotation.z, (float)hmd_pose.qRotation.w }; - - // Do shaking animation if haptic vibration was requested - float controller_y = -0.2f + 0.01f * std::sin(8 * 3.1415f * vibrate_anim_state_); - - // Left hand controller on the left, right hand controller on the right, any other handedness sticks to the middle - float controller_x = this->handedness_ == Handedness::LEFT ? -0.2f : (this->handedness_ == Handedness::RIGHT ? 0.2f : 0.f); - - linalg::vec hmd_pose_offset = { controller_x, controller_y, -0.5f }; - - hmd_pose_offset = linalg::qrot(hmd_rotation, hmd_pose_offset); - - linalg::vec final_pose = hmd_pose_offset + hmd_position; - - pose.vecPosition[0] = final_pose.x; - pose.vecPosition[1] = final_pose.y; - pose.vecPosition[2] = final_pose.z; - - pose.qRotation.w = hmd_rotation.w; - pose.qRotation.x = hmd_rotation.x; - pose.qRotation.y = hmd_rotation.y; - pose.qRotation.z = hmd_rotation.z; - } - - // Check if we need to press any buttons (I am only hooking up the A button here but the process is the same for the others) - // You will still need to go into the games button bindings and hook up each one (ie. a to left click, b to right click, etc.) for them to work properly - if (GetAsyncKeyState(0x45 /* E */) != 0) { - GetDriver()->GetInput()->UpdateBooleanComponent(this->a_button_click_component_, true, 0); - GetDriver()->GetInput()->UpdateBooleanComponent(this->a_button_touch_component_, true, 0); - } - else { - GetDriver()->GetInput()->UpdateBooleanComponent(this->a_button_click_component_, false, 0); - GetDriver()->GetInput()->UpdateBooleanComponent(this->a_button_touch_component_, false, 0); - } - - // Post pose - GetDriver()->GetDriverHost()->TrackedDevicePoseUpdated(this->device_index_, pose, sizeof(vr::DriverPose_t)); - this->last_pose_ = pose; } DeviceType SlimeVRDriver::ControllerDevice::GetDeviceType() diff --git a/src/HMDDevice.cpp b/src/HMDDevice.cpp index 0695ff4..67a5245 100644 --- a/src/HMDDevice.cpp +++ b/src/HMDDevice.cpp @@ -15,48 +15,6 @@ void SlimeVRDriver::HMDDevice::Update() { if (this->device_index_ == vr::k_unTrackedDeviceIndexInvalid) return; - - // Setup pose for this frame - auto pose = IVRDevice::MakeDefaultPose(); - - float delta_seconds = GetDriver()->GetLastFrameTime().count() / 1000.0f; - - // Get orientation - this->rot_y_ += (1.0f * (GetAsyncKeyState(VK_RIGHT) == 0) - 1.0f * (GetAsyncKeyState(VK_LEFT) == 0)) * delta_seconds; - this->rot_x_ += (-1.0f * (GetAsyncKeyState(VK_UP) == 0) + 1.0f * (GetAsyncKeyState(VK_DOWN) == 0)) * delta_seconds; - this->rot_x_ = std::fmax(this->rot_x_, -3.14159f/2); - this->rot_x_ = std::fmin(this->rot_x_, 3.14159f/2); - - linalg::vec y_quat{ 0, std::sin(this->rot_y_ / 2), 0, std::cos(this->rot_y_ / 2) }; - - linalg::vec x_quat{ std::sin(this->rot_x_ / 2), 0, 0, std::cos(this->rot_x_ / 2) }; - - linalg::vec pose_rot = linalg::qmul(y_quat, x_quat); - - pose.qRotation.w = (float) pose_rot.w; - pose.qRotation.x = (float) pose_rot.x; - pose.qRotation.y = (float) pose_rot.y; - pose.qRotation.z = (float) pose_rot.z; - - // Update position based on rotation - linalg::vec forward_vec{-1.0f * (GetAsyncKeyState(0x44) == 0) + 1.0f * (GetAsyncKeyState(0x41) == 0), 0, 0}; - linalg::vec right_vec{0, 0, 1.0f * (GetAsyncKeyState(0x57) == 0) - 1.0f * (GetAsyncKeyState(0x53) == 0) }; - linalg::vec final_dir = forward_vec + right_vec; - if (linalg::length(final_dir) > 0.01) { - final_dir = linalg::normalize(final_dir) * (float)delta_seconds; - final_dir = linalg::qrot(pose_rot, final_dir); - this->pos_x_ += final_dir.x; - this->pos_y_ += final_dir.y; - this->pos_z_ += final_dir.z; - } - - pose.vecPosition[0] = (float) this->pos_x_; - pose.vecPosition[1] = (float) this->pos_y_; - pose.vecPosition[2] = (float) this->pos_z_; - - // Post pose - GetDriver()->GetDriverHost()->TrackedDevicePoseUpdated(this->device_index_, pose, sizeof(vr::DriverPose_t)); - this->last_pose_ = pose; } void SlimeVRDriver::HMDDevice::PositionMessage(messages::Position &position) diff --git a/src/TrackingReferenceDevice.cpp b/src/TrackingReferenceDevice.cpp index e302eda..672cec2 100644 --- a/src/TrackingReferenceDevice.cpp +++ b/src/TrackingReferenceDevice.cpp @@ -17,33 +17,6 @@ void SlimeVRDriver::TrackingReferenceDevice::Update() { if (this->device_index_ == vr::k_unTrackedDeviceIndexInvalid) return; - - - // Setup pose for this frame - auto pose = IVRDevice::MakeDefaultPose(); - - linalg::vec device_position{ 0.f, 1.f, 1.f }; - - linalg::vec y_quat{ 0, std::sin(this->random_angle_rad_ / 2), 0, std::cos(this->random_angle_rad_ / 2) }; // Point inwards (z- is forward) - - linalg::vec x_look_down{ std::sin((-3.1415f/4) / 2), 0, 0, std::cos((-3.1415f / 4) / 2) }; // Tilt downwards to look at the centre - - linalg::vec device_rotation = linalg::qmul(y_quat, x_look_down); - - device_position = linalg::qrot(y_quat, device_position); - - pose.vecPosition[0] = device_position.x; - pose.vecPosition[1] = device_position.y; - pose.vecPosition[2] = device_position.z; - - pose.qRotation.w = device_rotation.w; - pose.qRotation.x = device_rotation.x; - pose.qRotation.y = device_rotation.y; - pose.qRotation.z = device_rotation.z; - - // Post pose - GetDriver()->GetDriverHost()->TrackedDevicePoseUpdated(this->device_index_, pose, sizeof(vr::DriverPose_t)); - this->last_pose_ = pose; } DeviceType SlimeVRDriver::TrackingReferenceDevice::GetDeviceType()