Skip to content

Commit

Permalink
Merge pull request #989 from daoshengmu/oculus6ofController
Browse files Browse the repository at this point in the history
Fixed the second controller doesn't show up problem
  • Loading branch information
daoshengmu committed Mar 9, 2019
2 parents 6205fac + b5702f7 commit 38c334e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/src/main/cpp/ControllerContainer.cpp
Expand Up @@ -44,7 +44,7 @@ struct ControllerContainer::State {
}

void SetUpModelsGroup(const int32_t aModelIndex) {
if (models.size() >= aModelIndex) {
if (aModelIndex >= models.size()) {
models.resize((size_t)(aModelIndex + 1));
}
if (!models[aModelIndex]) {
Expand Down
31 changes: 21 additions & 10 deletions app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp
Expand Up @@ -580,7 +580,13 @@ struct DeviceDelegateOculusVR::State {
vrb::Matrix controllerTransform = vrb::Matrix::Identity();
ovrInputStateTrackedRemote controllerState = {};
ElbowModel::HandEnum hand = ElbowModel::HandEnum::Right;

bool Is6DOF() const {
return (controllerCapabilities.ControllerCapabilities & ovrControllerCaps_HasPositionTracking) &&
(controllerCapabilities.ControllerCapabilities & ovrControllerCaps_HasOrientationTracking);
}
};

vrb::RenderContextWeak context;
android_app* app = nullptr;
bool initialized = false;
Expand Down Expand Up @@ -709,10 +715,16 @@ struct DeviceDelegateOculusVR::State {
aHeight = scale * (uint32_t)(vrapi_GetSystemPropertyInt(&java, VRAPI_SYS_PROP_SUGGESTED_EYE_TEXTURE_HEIGHT));
}

bool Is6DOF() const {
bool IsOculusQuest() const {
return deviceType >= VRAPI_DEVICE_TYPE_OCULUSQUEST_START && deviceType <= VRAPI_DEVICE_TYPE_OCULUSQUEST_END;
}

bool Is6DOF() const {
// ovrInputHeadsetCapabilities is unavailable in Oculus mobile SDK,
// the current workaround is checking if it is Quest.
return IsOculusQuest();
}

void SetRenderSize(device::RenderMode aRenderMode) {
if (renderMode == device::RenderMode::StandAlone) {
GetStandaloneRenderSize(renderWidth, renderHeight);
Expand Down Expand Up @@ -747,15 +759,14 @@ struct DeviceDelegateOculusVR::State {
ovrInputCapabilityHeader capsHeader = {};
if (vrapi_EnumerateInputDevices(ovr, index++, &capsHeader) < 0) {
// No more input devices to enumerate
controller->SetEnabled(index-1, false);
controller->SetEnabled(index - 1, false);
break;
}

if (state.size() <= count) {
state.push_back(ControllerState());
}

if (capsHeader.Type == ovrControllerType_TrackedRemote) {
if (state.size() <= count) {
state.push_back(ControllerState());
}
// We are only interested in the remote controller input device
state[count].controllerCapabilities.Header = capsHeader;
ovrResult result = vrapi_GetInputDeviceCapabilities(ovr, &state[count].controllerCapabilities.Header);
Expand All @@ -772,7 +783,7 @@ struct DeviceDelegateOculusVR::State {

// We need to call CreateController() to update the model index to avoid some cases that
// the controller index is changed.
if (Is6DOF()) {
if (state[count].controllerCapabilities.ControllerCapabilities & ovrControllerCaps_ModelOculusTouch) {
std::string controllerID;
if (state[count].hand == ElbowModel::HandEnum::Left) {
controllerID = "Oculus Touch (Left)";
Expand Down Expand Up @@ -839,7 +850,7 @@ struct DeviceDelegateOculusVR::State {
bool trackpadPressed = false, trackpadTouched = false;
float axes[kNumAxes];
float trackpadX, trackpadY = 0.0f;
if (Is6DOF()) {
if (state[i].Is6DOF()) {
triggerPressed = (state[i].controllerState.Buttons & ovrButton_Trigger) != 0;
triggerTouched = (state[i].controllerState.Touches & ovrTouch_IndexTrigger) != 0;
trackpadPressed = (state[i].controllerState.Buttons & ovrButton_Joystick) != 0;
Expand Down Expand Up @@ -1032,7 +1043,7 @@ DeviceDelegateOculusVR::ReleaseControllerDelegate() {

int32_t
DeviceDelegateOculusVR::GetControllerModelCount() const {
if (m.Is6DOF()) {
if (m.IsOculusQuest()) {
return 2;
} else {
return 1;
Expand All @@ -1043,7 +1054,7 @@ const std::string
DeviceDelegateOculusVR::GetControllerModelName(const int32_t aModelIndex) const {
static std::string name = "";

if (m.Is6DOF()) {
if (m.IsOculusQuest()) {
switch (aModelIndex) {
case 0:
name = "vr_controller_oculusquest_left.obj";
Expand Down

0 comments on commit 38c334e

Please sign in to comment.