Skip to content

Commit

Permalink
Fix 6DoF controllers rotation in WebXR
Browse files Browse the repository at this point in the history
For the Quest2 devices, controllers used to show some abnormal rotation
to the top inside WebXR sessions. The problem was that we were applying
a 45º rotation to the controller transform instead of to the immersive
beam transform.
  • Loading branch information
svillar committed May 26, 2022
1 parent 6b0e1b2 commit 4b03f97
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,11 @@ struct DeviceDelegateOculusVR::State {

float offsetX = controllerState.hand == ElbowModel::HandEnum::Left ? 0.011f : -0.011f;
const vrb::Matrix trans = vrb::Matrix::Position(vrb::Vector(offsetX, 0.025f, 0.05f));
controller->SetImmersiveBeamTransform(controllerState.index, trans);

// Apply a 45º rotation to controller in immersive mode.
vrb::Matrix transform = vrb::Matrix::Rotation(vrb::Vector(1.0f, 0.0f, 0.0f), M_PI_4);
transform = transform.PostMultiply(trans);
controller->SetImmersiveBeamTransform(controllerState.index, transform);
} else {
// Oculus Go only has one kind of controller model.
controller->CreateController(controllerState.index, 0, "Oculus Go Controller");
Expand Down Expand Up @@ -474,16 +478,10 @@ struct DeviceDelegateOculusVR::State {
controller->SetCapabilityFlags(controllerState.index, flags);
if (renderMode == device::RenderMode::Immersive) {
static vrb::Matrix transform(vrb::Matrix::Identity());
if (transform.IsIdentity()) {
if (controllerState.Is6DOF()) {
transform = vrb::Matrix::Rotation(vrb::Vector(1.0f, 0.0f, 0.0f), 0.77f);
const vrb::Matrix trans = vrb::Matrix::Position(vrb::Vector(0.0f, 0.0f, 0.025f));
transform = transform.PostMultiply(trans);
} else {
transform = vrb::Matrix::Rotation(vrb::Vector(1.0f, 0.0f, 0.0f), 0.60f);
}
if (transform.IsIdentity() && !controllerState.Is6DOF()) {
transform = vrb::Matrix::Rotation(vrb::Vector(1.0f, 0.0f, 0.0f), 0.60f);
controllerState.transform = controllerState.transform.PostMultiply(transform);
}
controllerState.transform = controllerState.transform.PostMultiply(transform);
}
controller->SetTransform(controllerState.index, controllerState.transform);

Expand Down

0 comments on commit 4b03f97

Please sign in to comment.