Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Fixes 3DOF controller positionEmulated.
Browse files Browse the repository at this point in the history
  • Loading branch information
daoshengmu committed Apr 21, 2020
1 parent 929c0e2 commit aeb3361
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 19 deletions.
1 change: 1 addition & 0 deletions app/src/main/cpp/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const CapabilityFlags PositionEmulated = 1u << 9u;
const CapabilityFlags InlineSession = 1u << 10u;
const CapabilityFlags ImmersiveVRSession = 1u << 11u;
const CapabilityFlags ImmersiveARSession = 1u << 12u;
const CapabilityFlags GripSpacePosition = 1u << 13u;
enum class Eye { Left, Right };
enum class RenderMode { StandAlone, Immersive };
enum class CPULevel { Normal = 0, High };
Expand Down
33 changes: 22 additions & 11 deletions app/src/main/cpp/ExternalVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,12 @@ ExternalVR::GetControllerCapabilityFlags(device::CapabilityFlags aFlags) {
if (device::LinearAcceleration & aFlags) {
result |= static_cast<uint16_t>(mozilla::gfx::ControllerCapabilityFlags::Cap_LinearAcceleration);
}
if (device::PositionEmulated & aFlags) {
result |= static_cast<uint16_t>(mozilla::gfx::ControllerCapabilityFlags::Cap_PositionEmulated);
}
if (device::GripSpacePosition & aFlags) {
result |= static_cast<uint16_t>(mozilla::gfx::ControllerCapabilityFlags::Cap_GripSpacePosition);
}

return result;
}
Expand Down Expand Up @@ -476,20 +482,25 @@ ExternalVR::PushFramePoses(const vrb::Matrix& aHeadTransform, const std::vector<
if (flags & static_cast<uint16_t>(mozilla::gfx::ControllerCapabilityFlags::Cap_Orientation)) {
immersiveController.isOrientationValid = true;

vrb::Quaternion quaternion(controller.transformMatrix);
quaternion = quaternion.Inverse();
memcpy(&(immersiveController.pose.orientation), quaternion.Data(), sizeof(immersiveController.pose.orientation));

quaternion.SetFromRotationMatrix(beamTransform);
quaternion = quaternion.Inverse();
memcpy(&(immersiveController.targetRayPose.orientation), quaternion.Data(), sizeof(immersiveController.targetRayPose.orientation));
vrb::Quaternion rotate;
if (flags & static_cast<uint16_t>(mozilla::gfx::ControllerCapabilityFlags::Cap_GripSpacePosition)) {
rotate = controller.transformMatrix;
rotate = rotate.Inverse();
memcpy(&(immersiveController.pose.orientation), rotate.Data(), sizeof(immersiveController.pose.orientation));
}
rotate.SetFromRotationMatrix(beamTransform);
rotate = rotate.Inverse();
memcpy(&(immersiveController.targetRayPose.orientation), rotate.Data(), sizeof(immersiveController.targetRayPose.orientation));
}
if (flags & static_cast<uint16_t>(mozilla::gfx::ControllerCapabilityFlags::Cap_Position)) {
if (flags & static_cast<uint16_t>(mozilla::gfx::ControllerCapabilityFlags::Cap_Position) ||
flags & static_cast<uint16_t>(mozilla::gfx::ControllerCapabilityFlags::Cap_PositionEmulated)) {
immersiveController.isPositionValid = true;

vrb::Vector position(controller.transformMatrix.GetTranslation());
memcpy(&(immersiveController.pose.position), position.Data(), sizeof(immersiveController.pose.position));

vrb::Vector position;
if (flags & static_cast<uint16_t>(mozilla::gfx::ControllerCapabilityFlags::Cap_GripSpacePosition)) {
position = controller.transformMatrix.GetTranslation();
memcpy(&(immersiveController.pose.position), position.Data(), sizeof(immersiveController.pose.position));
}
position = beamTransform.GetTranslation();
memcpy(&(immersiveController.targetRayPose.position), position.Data(), sizeof(immersiveController.targetRayPose.position));
}
Expand Down
12 changes: 9 additions & 3 deletions app/src/main/cpp/moz_external_vr.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,19 @@ enum class ControllerCapabilityFlags : uint16_t {
*/
Cap_LinearAcceleration = 1 << 4,
/**
* Cap_TargetRaySpacePosition is set if the Gamepad has a target ray space position.
* Cap_TargetRaySpacePosition is set if the Gamepad has a grip space position.
*/
Cap_TargetRaySpacePosition = 1 << 5,
Cap_GripSpacePosition = 1 << 5,
/**
* Cap_PositionEmulated is set if the XRInputSoruce is capable of setting a
* emulated position (e.g. neck model) even if still doesn't support 6DOF
* tracking.
*/
Cap_PositionEmulated = 1 << 6,
/**
* Cap_All used for validity checking during IPC serialization
*/
Cap_All = (1 << 6) - 1
Cap_All = (1 << 7) - 1
};

#endif // ifndef MOZILLA_INTERNAL_API
Expand Down
6 changes: 4 additions & 2 deletions app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,10 @@ struct DeviceDelegateOculusVR::State {
flags |= device::Position;
} else {
controllerState.transform = elbow->GetTransform(controllerState.hand, head, controllerState.transform);
flags |= device::PositionEmulated;
}

flags |= device::GripSpacePosition;
controller->SetCapabilityFlags(controllerState.index, flags);
if (renderMode == device::RenderMode::Immersive && controllerState.Is6DOF()) {
static vrb::Matrix transform(vrb::Matrix::Identity());
Expand Down Expand Up @@ -963,10 +965,10 @@ DeviceDelegateOculusVR::StartFrame(const FramePrediction aPrediction) {
if (m.immersiveDisplay) {
m.immersiveDisplay->SetEyeOffset(device::Eye::Left, -ipd * 0.5f, 0.f, 0.f);
m.immersiveDisplay->SetEyeOffset(device::Eye::Right, ipd * 0.5f, 0.f, 0.f);
device::CapabilityFlags caps = device::Orientation | device::Present | device::StageParameters |
device::CapabilityFlags caps = device::Orientation | device::Present |
device::InlineSession | device::ImmersiveVRSession;
if (m.predictedTracking.Status & VRAPI_TRACKING_STATUS_POSITION_TRACKED) {
caps |= device::Position;
caps |= device::Position | device::StageParameters;
auto standing = vrapi_LocateTrackingSpace(m.ovr, VRAPI_TRACKING_SPACE_LOCAL_FLOOR);
vrb::Vector translation(-standing.Position.x, -standing.Position.y, -standing.Position.z);
m.immersiveDisplay->SetSittingToStandingTransform(vrb::Matrix::Translation(translation));
Expand Down
4 changes: 4 additions & 0 deletions app/src/picovr/cpp/DeviceDelegatePicoVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ struct DeviceDelegatePicoVR::State {
device::CapabilityFlags flags = device::Orientation;
if (controller.is6DoF) {
flags |= device::Position;
} else {
flags |= device::PositionEmulated;
}
flags |= device::GripSpacePosition;
controllerDelegate->SetCapabilityFlags(i, flags);
const bool appPressed = (controller.buttonsState & kButtonApp) > 0;
const bool triggerPressed = (controller.buttonsState & kButtonTrigger) > 0;
Expand Down Expand Up @@ -295,6 +298,7 @@ DeviceDelegatePicoVR::RegisterImmersiveDisplay(ImmersiveDisplayPtr aDisplay) {
flags |= device::Position | device::StageParameters;
m.immersiveDisplay->SetSittingToStandingTransform(vrb::Matrix::Translation(kAverageSittingToStanding));
} else {
flags |= device::PositionEmulated;
m.immersiveDisplay->SetSittingToStandingTransform(vrb::Matrix::Translation(kAverageHeight));
}
m.immersiveDisplay->SetCapabilityFlags(flags);
Expand Down
8 changes: 5 additions & 3 deletions app/src/wavevr/cpp/DeviceDelegateWaveVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,11 @@ struct DeviceDelegateWaveVR::State {
}
continue;
} else if (!controller.enabled) {
device::CapabilityFlags flags = device::Orientation;
device::CapabilityFlags flags = device::Orientation | device::GripSpacePosition;
if (controller.is6DoF) {
flags |= device::Position;
} else {
flags |= device::PositionEmulated;
}
controller.enabled = true;
delegate->SetEnabled(controller.index, true);
Expand Down Expand Up @@ -488,11 +490,11 @@ DeviceDelegateWaveVR::RegisterImmersiveDisplay(ImmersiveDisplayPtr aDisplay) {
}

m.immersiveDisplay->SetDeviceName("Wave");
device::CapabilityFlags flags = device::Orientation | device::Present | device::StageParameters |
device::CapabilityFlags flags = device::Orientation | device::Present |
device::InlineSession | device::ImmersiveVRSession;

if (WVR_GetDegreeOfFreedom(WVR_DeviceType_HMD) == WVR_NumDoF_6DoF) {
flags |= device::Position;
flags |= device::Position | device::StageParameters;
} else {
flags |= device::PositionEmulated;
}
Expand Down

0 comments on commit aeb3361

Please sign in to comment.