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

Commit

Permalink
Add controller capability flag for 6DOF.
Browse files Browse the repository at this point in the history
  • Loading branch information
daoshengmu committed Dec 21, 2018
1 parent 90bcdb1 commit 2ac34bd
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/src/googlevr/cpp/DeviceDelegateGoogleVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ struct DeviceDelegateGoogleVR::State {
controller.enabled = true;
controllerDelegate->SetEnabled(index, true);
controllerDelegate->SetVisible(index, true);
controllerDelegate->SetCapabilityFlags(index, device::Orientation);
}

recentered = recentered || gvr_controller_state_get_recentered(controllerState);
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/cpp/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define VRBROWSER_CONTROLLER_H

#include "ControllerDelegate.h"
#include "Device.h"
#include "vrb/Forward.h"
#include "vrb/Matrix.h"

Expand Down Expand Up @@ -47,6 +48,7 @@ struct Controller {
bool leftHanded;
bool inDeadZone;
double lastHoverEvent;
device::CapabilityFlags deviceCapabilities;

Controller();
Controller(const Controller& aController);
Expand Down
11 changes: 9 additions & 2 deletions app/src/main/cpp/ControllerContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,11 @@ ControllerContainer::Create(vrb::CreationContextPtr& aContext, const vrb::GroupP
return result;
}


TogglePtr
ControllerContainer::GetRoot() const {
return m.root;
}


void
ControllerContainer::LoadControllerModel(const int32_t aModelIndex, const ModelLoaderAndroidPtr& aLoader, const std::string& aFileName) {
m.SetUpModelsGroup(aModelIndex);
Expand Down Expand Up @@ -200,6 +198,15 @@ ControllerContainer::DestroyController(const int32_t aControllerIndex) {
}
}

void
ControllerContainer::SetCapabilityFlags(const int32_t aControllerIndex, const device::CapabilityFlags aFlags) {
if (!m.Contains(aControllerIndex)) {
return;
}

m.list[aControllerIndex].deviceCapabilities = aFlags;
}

void
ControllerContainer::SetEnabled(const int32_t aControllerIndex, const bool aEnabled) {
if (!m.Contains(aControllerIndex)) {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/cpp/ControllerContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ControllerContainer : public crow::ControllerDelegate {
// crow::ControllerDelegate interface
void CreateController(const int32_t aControllerIndex, const int32_t aModelIndex, const std::string& aImmersiveName) override;
void DestroyController(const int32_t aControllerIndex) override;
void SetCapabilityFlags(const int32_t aControllerIndex, const device::CapabilityFlags aFlags) override;
void SetEnabled(const int32_t aControllerIndex, const bool aEnabled) override;
void SetVisible(const int32_t aControllerIndex, const bool aVisible) override;
void SetTransform(const int32_t aControllerIndex, const vrb::Matrix& aTransform) override;
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/cpp/ControllerDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "vrb/MacroUtils.h"
#include "vrb/Forward.h"
#include "Device.h"
#include "GestureDelegate.h"

#include <memory>
Expand All @@ -27,6 +28,7 @@ class ControllerDelegate {

virtual void CreateController(const int32_t aControllerIndex, const int32_t aModelIndex, const std::string& aImmersiveName) = 0;
virtual void DestroyController(const int32_t aControllerIndex) = 0;
virtual void SetCapabilityFlags(const int32_t aControllerIndex, const device::CapabilityFlags aFlags) = 0;
virtual void SetEnabled(const int32_t aControllerIndex, const bool aEnabled) = 0;
virtual void SetVisible(const int32_t aControllerIndex, const bool aVisible) = 0;
virtual void SetTransform(const int32_t aControllerIndex, const vrb::Matrix& aTransform) = 0;
Expand Down
44 changes: 39 additions & 5 deletions app/src/main/cpp/ExternalVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,25 @@ ExternalVR::IsPresenting() const {
return m.IsPresenting();
}

uint16_t
ExternalVR::GetControllerCapabilityFlags(device::CapabilityFlags aFlags) {
uint16_t result = 0;
if (device::Position & aFlags) {
result |= static_cast<uint16_t>(mozilla::gfx::ControllerCapabilityFlags::Cap_Position);
}
if (device::Orientation & aFlags) {
result |= static_cast<uint16_t>(mozilla::gfx::ControllerCapabilityFlags::Cap_Orientation);
}
if (device::AngularAcceleration & aFlags) {
result |= static_cast<uint16_t>(mozilla::gfx::ControllerCapabilityFlags::Cap_AngularAcceleration);
}
if (device::LinearAcceleration & aFlags) {
result |= static_cast<uint16_t>(mozilla::gfx::ControllerCapabilityFlags::Cap_LinearAcceleration);
}

return result;
}

ExternalVR::VRState
ExternalVR::GetVRState() const {
if (!IsPresenting()) {
Expand Down Expand Up @@ -367,11 +386,26 @@ ExternalVR::PushFramePoses(const vrb::Matrix& aHeadTransform, const std::vector<
}
immersiveController.hand = controller.leftHanded ? mozilla::gfx::ControllerHand::Left : mozilla::gfx::ControllerHand::Right;

immersiveController.flags = 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));
const uint16_t flags = GetControllerCapabilityFlags(controller.deviceCapabilities);
immersiveController.flags = static_cast<mozilla::gfx::ControllerCapabilityFlags>(flags);

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));
}
if (flags & static_cast<uint16_t>(mozilla::gfx::ControllerCapabilityFlags::Cap_Position)) {
immersiveController.isPositionValid = true;

// For 6 DOF controllers, we added this kAverageHeight in order to have the same height with 3 DOF controllers.
// So, we need to decrease it to provide the proper position data to the immersive controllers.
const vrb::Vector kAverageHeight(0.0f, 1.7f, 0.0f);
vrb::Vector position(controller.transformMatrix.GetTranslation());
position -= kAverageHeight;
memcpy(&(immersiveController.pose.position), position.Data(), sizeof(immersiveController.pose.position));
}
}

PushSystemState();
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/cpp/ExternalVR.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class ExternalVR : public ImmersiveDisplay {
struct State;
ExternalVR();
private:
uint16_t GetControllerCapabilityFlags(device::CapabilityFlags aFlags);

State& m;
VRB_NO_DEFAULTS(ExternalVR)
};
Expand Down
1 change: 1 addition & 0 deletions app/src/svr/cpp/DeviceDelegateSVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ struct DeviceDelegateSVR::State {
}
controller->SetEnabled(kControllerId, true);
controller->SetVisible(kControllerId, true);
controller->SetCapabilityFlags(kControllerId, device::Orientation);
usingHeadTrackingInput = false;
}
const svrQuaternion& rotation = controllerState.rotation;
Expand Down
1 change: 1 addition & 0 deletions app/src/wavevr/cpp/DeviceDelegateWaveVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ struct DeviceDelegateWaveVR::State {
controller.enabled = true;
delegate->SetEnabled(index, true);
delegate->SetVisible(index, true);
delegate->SetCapabilityFlags(index, device::Orientation);
}

const bool bumperPressed = WVR_GetInputButtonState(controller.type, WVR_InputId_Alias1_Digital_Trigger);
Expand Down

0 comments on commit 2ac34bd

Please sign in to comment.