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

Commit f6930db

Browse files
keianhzobluemarvin
authored andcommitted
Adds support for the home long press to recenter event
1 parent 25bc08b commit f6930db

4 files changed

Lines changed: 43 additions & 3 deletions

File tree

app/src/picovr/cpp/DeviceDelegatePicoVR.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
55

66
#include "DeviceDelegatePicoVR.h"
7+
#include "DeviceUtils.h"
78
#include "ElbowModel.h"
89
#include "VRBrowserPico.h"
910

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

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

287289
void
288290
DeviceDelegatePicoVR::SetReorientTransform(const vrb::Matrix& aMatrix) {
289-
// Until we can get the new heading don't reset it on the Neo 2
290-
if (m.type != kTypeNeo2) {
291-
// m.reorientMatrix = aMatrix;
291+
if (m.type == kTypeNeo2) {
292+
m.reorientMatrix = aMatrix;
292293
}
293294
}
294295

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

364365
if (m.renderMode == device::RenderMode::StandAlone) {
366+
if (m.recentered) {
367+
m.reorientMatrix = DeviceUtils::CalculateReorientationMatrix(head, kAverageHeight);
368+
}
365369
head.TranslateInPlace(m.headOffset);
366370
}
367371

372+
m.recentered = false;
373+
368374
m.cameras[0]->SetHeadTransform(head);
369375
m.cameras[1]->SetHeadTransform(head);
370376
m.UpdateControllers();
@@ -470,6 +476,10 @@ DeviceDelegatePicoVR::UpdateControllerButtons(const int aIndex, const int32_t aB
470476
m.controllers[aIndex].touched = touched;
471477
}
472478

479+
void
480+
DeviceDelegatePicoVR:: Recenter() {
481+
m.recentered = true;
482+
}
473483

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

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
@@ -139,6 +139,14 @@ JNI_METHOD(void, nativeUpdateControllerState)
139139
sDevice->UpdateControllerButtons(index, buttons, grip, axisX, axisY, touched);
140140
}
141141

142+
JNI_METHOD(void, nativeRecenter)
143+
(JNIEnv* env, jobject) {
144+
if (gDestroyed) {
145+
return;
146+
}
147+
sDevice->Recenter();
148+
}
149+
142150
JNI_METHOD(void, queueRunnable)
143151
(JNIEnv* aEnv, jobject, jobject aRunnable) {
144152
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

@@ -29,6 +33,7 @@
2933
import com.psmart.vrlib.VrActivity;
3034
import com.psmart.vrlib.PicovrSDK;
3135

36+
import org.mozilla.vrbrowser.utils.DeviceType;
3237
import org.mozilla.vrbrowser.utils.SystemUtils;
3338

3439

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

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

78+
IntentFilter filter = new IntentFilter();
79+
filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
80+
registerReceiver(mKeysReceiver, filter);
81+
6382
if (ControllerClient.isControllerServiceExisted(this)) {
6483
mControllerManager = new CVControllerManager(this);
6584
mControllerManager.setListener(this);
@@ -122,6 +141,7 @@ protected void onDestroy() {
122141
if (mControllerManager != null) {
123142
mControllerManager.setListener(null);
124143
}
144+
unregisterReceiver(mKeysReceiver);
125145
}
126146

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

0 commit comments

Comments
 (0)