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

Commit

Permalink
Adds support for the home long press to recenter event (#2888)
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo authored Mar 9, 2020
1 parent 25bc08b commit d659400
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
16 changes: 13 additions & 3 deletions app/src/picovr/cpp/DeviceDelegatePicoVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "DeviceDelegatePicoVR.h"
#include "DeviceUtils.h"
#include "ElbowModel.h"
#include "VRBrowserPico.h"

Expand Down Expand Up @@ -91,6 +92,7 @@ struct DeviceDelegatePicoVR::State {
float ipd = 0.064f;
float fov = (float) (51.0 * M_PI / 180.0);
int32_t focusIndex = 0;
bool recentered = false;

void Initialize() {
vrb::RenderContextPtr localContext = context.lock();
Expand Down Expand Up @@ -286,9 +288,8 @@ DeviceDelegatePicoVR::GetReorientTransform() const {

void
DeviceDelegatePicoVR::SetReorientTransform(const vrb::Matrix& aMatrix) {
// Until we can get the new heading don't reset it on the Neo 2
if (m.type != kTypeNeo2) {
// m.reorientMatrix = aMatrix;
if (m.type == kTypeNeo2) {
m.reorientMatrix = aMatrix;
}
}

Expand Down Expand Up @@ -362,9 +363,14 @@ DeviceDelegatePicoVR::StartFrame() {
head.TranslateInPlace(m.position);

if (m.renderMode == device::RenderMode::StandAlone) {
if (m.recentered) {
m.reorientMatrix = DeviceUtils::CalculateReorientationMatrix(head, kAverageHeight);
}
head.TranslateInPlace(m.headOffset);
}

m.recentered = false;

m.cameras[0]->SetHeadTransform(head);
m.cameras[1]->SetHeadTransform(head);
m.UpdateControllers();
Expand Down Expand Up @@ -470,6 +476,10 @@ DeviceDelegatePicoVR::UpdateControllerButtons(const int aIndex, const int32_t aB
m.controllers[aIndex].touched = touched;
}

void
DeviceDelegatePicoVR:: Recenter() {
m.recentered = true;
}

DeviceDelegatePicoVR::DeviceDelegatePicoVR(State &aState) : m(aState) {}

Expand Down
1 change: 1 addition & 0 deletions app/src/picovr/cpp/DeviceDelegatePicoVR.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class DeviceDelegatePicoVR : public DeviceDelegate {
void UpdateControllerConnected(const int aIndex, const bool aConnected);
void UpdateControllerPose(const int aIndex, const bool a6Dof, const vrb::Vector& aPosition, const vrb::Quaternion& aRotation);
void UpdateControllerButtons(const int aIndex, const int32_t aButtonsState, const float aGrip, const float axisX, const float axisY, const bool touched);
void Recenter();
protected:
struct State;
DeviceDelegatePicoVR(State& aState);
Expand Down
8 changes: 8 additions & 0 deletions app/src/picovr/cpp/native-lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ JNI_METHOD(void, nativeUpdateControllerState)
sDevice->UpdateControllerButtons(index, buttons, grip, axisX, axisY, touched);
}

JNI_METHOD(void, nativeRecenter)
(JNIEnv* env, jobject) {
if (gDestroyed) {
return;
}
sDevice->Recenter();
}

JNI_METHOD(void, queueRunnable)
(JNIEnv* aEnv, jobject, jobject aRunnable) {
if (gDestroyed) {
Expand Down
21 changes: 21 additions & 0 deletions app/src/picovr/java/org/mozilla/vrbrowser/PlatformActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
package org.mozilla.vrbrowser;

import android.Manifest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;

Expand All @@ -29,6 +33,7 @@
import com.psmart.vrlib.VrActivity;
import com.psmart.vrlib.PicovrSDK;

import org.mozilla.vrbrowser.utils.DeviceType;
import org.mozilla.vrbrowser.utils.SystemUtils;


Expand All @@ -42,6 +47,16 @@ public static boolean filterPermission(final String aPermission) {
return false;
}

private BroadcastReceiver mKeysReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String s = intent.getStringExtra("reason");
if (s.equalsIgnoreCase("recenter")) {
nativeRecenter();
}
}
};

CVControllerManager mControllerManager;
HbManager mHbManager;
private boolean mControllersReady;
Expand All @@ -60,6 +75,10 @@ protected void onCreate(Bundle bundle) {
nativeOnCreate();
super.onCreate(bundle);

IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
registerReceiver(mKeysReceiver, filter);

if (ControllerClient.isControllerServiceExisted(this)) {
mControllerManager = new CVControllerManager(this);
mControllerManager.setListener(this);
Expand Down Expand Up @@ -122,6 +141,7 @@ protected void onDestroy() {
if (mControllerManager != null) {
mControllerManager.setListener(null);
}
unregisterReceiver(mKeysReceiver);
}

@Override
Expand Down Expand Up @@ -354,5 +374,6 @@ private void cancelAllHaptics() {
protected native void nativeSetFocusedController(int index);
protected native void nativeUpdateControllerState(int index, boolean connected, int buttons, float grip, float axisX, float axisY, boolean touched);
protected native void nativeUpdateControllerPose(int index, boolean dof6, float px, float py, float pz, float qx, float qy, float qz, float qw);
protected native void nativeRecenter();
protected native void queueRunnable(Runnable aRunnable);
}

0 comments on commit d659400

Please sign in to comment.