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

Commit 2768159

Browse files
committed
Adds support for the home long press to recenter event
1 parent 61931dc commit 2768159

4 files changed

Lines changed: 42 additions & 4 deletions

File tree

app/src/picovr/cpp/DeviceDelegatePicoVR.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "DeviceDelegatePicoVR.h"
77
#include "ElbowModel.h"
88
#include "BrowserEGLContext.h"
9+
#include "DeviceUtils.h"
910

1011
#include <EGL/egl.h>
1112
#include "vrb/CameraEye.h"
@@ -90,6 +91,7 @@ struct DeviceDelegatePicoVR::State {
9091
float ipd = 0.064f;
9192
float fov = (float) (51.0 * M_PI / 180.0);
9293
int32_t focusIndex = 0;
94+
bool recentered = false;
9395

9496
void Initialize() {
9597
vrb::RenderContextPtr localContext = context.lock();
@@ -269,10 +271,7 @@ DeviceDelegatePicoVR::GetReorientTransform() const {
269271

270272
void
271273
DeviceDelegatePicoVR::SetReorientTransform(const vrb::Matrix& aMatrix) {
272-
// Until we can get the new heading don't reset it on the Neo 2
273-
if (m.type != kTypeNeo2) {
274-
// m.reorientMatrix = aMatrix;
275-
}
274+
m.reorientMatrix = aMatrix;
276275
}
277276

278277
void
@@ -345,9 +344,14 @@ DeviceDelegatePicoVR::StartFrame() {
345344
head.TranslateInPlace(m.position);
346345

347346
if (m.renderMode == device::RenderMode::StandAlone) {
347+
if (m.recentered) {
348+
m.reorientMatrix = DeviceUtils::CalculateReorientationMatrix(head, kAverageHeight);
349+
}
348350
head.TranslateInPlace(m.headOffset);
349351
}
350352

353+
m.recentered = false;
354+
351355
m.cameras[0]->SetHeadTransform(head);
352356
m.cameras[1]->SetHeadTransform(head);
353357
m.UpdateControllers();
@@ -453,6 +457,10 @@ DeviceDelegatePicoVR::UpdateControllerButtons(const int aIndex, const int32_t aB
453457
m.controllers[aIndex].touched = touched;
454458
}
455459

460+
void
461+
DeviceDelegatePicoVR:: Recenter() {
462+
m.recentered = true;
463+
}
456464

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

app/src/picovr/cpp/DeviceDelegatePicoVR.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class DeviceDelegatePicoVR : public DeviceDelegate {
5353
void UpdateControllerConnected(const int aIndex, const bool aConnected);
5454
void UpdateControllerPose(const int aIndex, const bool a6Dof, const vrb::Vector& aPosition, const vrb::Quaternion& aRotation);
5555
void UpdateControllerButtons(const int aIndex, const int32_t aButtonsState, const float aGrip, const float axisX, const float axisY, const bool touched);
56+
void Recenter();
5657
protected:
5758
struct State;
5859
DeviceDelegatePicoVR(State& aState);

app/src/picovr/cpp/native-lib.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ JNI_METHOD(void, nativeUpdateControllerState)
136136
sDevice->UpdateControllerButtons(index, buttons, grip, axisX, axisY, touched);
137137
}
138138

139+
JNI_METHOD(void, nativeRecenter)
140+
(JNIEnv* env, jobject) {
141+
if (gDestroyed) {
142+
return;
143+
}
144+
sDevice->Recenter();
145+
}
146+
139147
JNI_METHOD(void, queueRunnable)
140148
(JNIEnv* aEnv, jobject, jobject aRunnable) {
141149
if (gDestroyed) {

app/src/picovr/java/org/mozilla/vrbrowser/PlatformActivity.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
package org.mozilla.vrbrowser;
77

88
import android.Manifest;
9+
import android.content.BroadcastReceiver;
10+
import android.content.Context;
11+
import android.content.Intent;
12+
import android.content.IntentFilter;
913
import android.os.Bundle;
1014
import android.util.Log;
1115

@@ -28,6 +32,7 @@
2832
import com.psmart.vrlib.VrActivity;
2933
import com.psmart.vrlib.PicovrSDK;
3034

35+
import org.mozilla.vrbrowser.utils.DeviceType;
3136
import org.mozilla.vrbrowser.utils.SystemUtils;
3237

3338

@@ -41,6 +46,16 @@ public static boolean filterPermission(final String aPermission) {
4146
return false;
4247
}
4348

49+
private BroadcastReceiver mKeysReceiver = new BroadcastReceiver() {
50+
@Override
51+
public void onReceive(Context context, Intent intent) {
52+
String s = intent.getStringExtra("reason");
53+
if (s.equalsIgnoreCase("recenter")) {
54+
nativeRecenter();
55+
}
56+
}
57+
};
58+
4459
CVControllerManager mControllerManager;
4560
HbManager mHbManager;
4661
private boolean mControllersReady;
@@ -59,6 +74,10 @@ protected void onCreate(Bundle bundle) {
5974
nativeOnCreate();
6075
super.onCreate(bundle);
6176

77+
IntentFilter filter = new IntentFilter();
78+
filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
79+
registerReceiver(mKeysReceiver, filter);
80+
6281
if (ControllerClient.isControllerServiceExisted(this)) {
6382
mControllerManager = new CVControllerManager(this);
6483
mControllerManager.setListener(this);
@@ -118,6 +137,7 @@ protected void onDestroy() {
118137
if (mControllerManager != null) {
119138
mControllerManager.setListener(null);
120139
}
140+
unregisterReceiver(mKeysReceiver);
121141
}
122142

123143
@Override
@@ -330,5 +350,6 @@ public void onChannelChanged(int var1, int var2) {
330350
protected native void nativeSetFocusedController(int index);
331351
protected native void nativeUpdateControllerState(int index, boolean connected, int buttons, float grip, float axisX, float axisY, boolean touched);
332352
protected native void nativeUpdateControllerPose(int index, boolean dof6, float px, float py, float pz, float qx, float qy, float qz, float qw);
353+
protected native void nativeRecenter();
333354
protected native void queueRunnable(Runnable aRunnable);
334355
}

0 commit comments

Comments
 (0)