Skip to content

Commit

Permalink
Remove example code
Browse files Browse the repository at this point in the history
  • Loading branch information
Eirenliel committed Feb 3, 2022
1 parent a29fc71 commit 04b6dab
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 120 deletions.
51 changes: 0 additions & 51 deletions src/ControllerDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<IVRDevice>& 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<float, 3> hmd_position{ (float)hmd_pose.vecPosition[0], (float)hmd_pose.vecPosition[1], (float)hmd_pose.vecPosition[2] };
linalg::vec<float, 4> 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<float, 3> hmd_pose_offset = { controller_x, controller_y, -0.5f };

hmd_pose_offset = linalg::qrot(hmd_rotation, hmd_pose_offset);

linalg::vec<float, 3> 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()
Expand Down
42 changes: 0 additions & 42 deletions src/HMDDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float, 4> y_quat{ 0, std::sin(this->rot_y_ / 2), 0, std::cos(this->rot_y_ / 2) };

linalg::vec<float, 4> x_quat{ std::sin(this->rot_x_ / 2), 0, 0, std::cos(this->rot_x_ / 2) };

linalg::vec<float, 4> 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<float, 3> forward_vec{-1.0f * (GetAsyncKeyState(0x44) == 0) + 1.0f * (GetAsyncKeyState(0x41) == 0), 0, 0};
linalg::vec<float, 3> right_vec{0, 0, 1.0f * (GetAsyncKeyState(0x57) == 0) - 1.0f * (GetAsyncKeyState(0x53) == 0) };
linalg::vec<float, 3> 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)
Expand Down
27 changes: 0 additions & 27 deletions src/TrackingReferenceDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float, 3> device_position{ 0.f, 1.f, 1.f };

linalg::vec<float, 4> 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<float, 4> 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<float, 4> 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()
Expand Down

0 comments on commit 04b6dab

Please sign in to comment.