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

Adds support for the home long press to recenter event #2888

Merged
merged 1 commit into from
Mar 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions app/src/picovr/cpp/DeviceDelegatePicoVR.cpp
Original file line number Diff line number Diff line change
@@ -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"

@@ -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();
@@ -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;
}
Comment on lines -289 to 293
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just disabled it for the G2 and I think it all works as expected.

}

@@ -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();
@@ -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) {}

1 change: 1 addition & 0 deletions app/src/picovr/cpp/DeviceDelegatePicoVR.h
Original file line number Diff line number Diff line change
@@ -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);
8 changes: 8 additions & 0 deletions app/src/picovr/cpp/native-lib.cpp
Original file line number Diff line number Diff line change
@@ -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) {
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
@@ -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;

@@ -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;


@@ -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;
@@ -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);
@@ -122,6 +141,7 @@ protected void onDestroy() {
if (mControllerManager != null) {
mControllerManager.setListener(null);
}
unregisterReceiver(mKeysReceiver);
}

@Override
@@ -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);
}