Skip to content

Commit 7c07799

Browse files
author
di57mec
committed
fix 360 goto /set home
1 parent e222c79 commit 7c07799

File tree

10 files changed

+94
-15
lines changed

10 files changed

+94
-15
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ dependencies {
5656
implementation project(path: ':preferences')
5757

5858
implementation project(':VideoCore')
59-
//implementation 'com.github.Consti10:LiveVideo10ms:v1.2'
59+
//implementation 'com.github.Consti10:LiveVideo10ms:v1.3'
6060
implementation project(':TelemetryCore')
6161
implementation project(':RenderingXCore')
6262

app/src/main/cpp/GLRenderer/GLRMono360.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ void GLRMono360::onSurfaceCreated360(JNIEnv* env,jobject androidContext,jint vid
2121
mVideoRenderer=std::make_unique<VideoRenderer>(mBasicGLPrograms->vc, nullptr,mSettingsVR.DEV_3D_VIDEO,mGLProgramSpherical.get());
2222
}
2323

24-
void GLRMono360::onSurfaceChanged360(int width, int height) {
24+
void GLRMono360::onSurfaceChanged360(int width, int height,float video360FOV) {
25+
screenW=width;
26+
screenH=height;
2527
GLRMono::onSurfaceChanged(width,height);
2628
const float displayRatio=(float) width/(float)height;
27-
mMatricesM.calculateProjectionAndDefaultView360(40.0f,displayRatio);
29+
mMatricesM.calculateProjectionAndDefaultView360(video360FOV,displayRatio);
2830
cpuFrameTimeVidOSD.reset();
2931
}
3032

@@ -46,6 +48,7 @@ void GLRMono360::setHomeOrientation() {
4648
mMatricesM.setHomeOrientation360(gvr_api_.get());
4749
}
4850

51+
4952
//----------------------------------------------------JAVA bindings---------------------------------------------------------------
5053

5154
#define JNI_METHOD(return_type, method_name) \
@@ -74,8 +77,8 @@ JNI_METHOD(void, nativeOnSurfaceCreated)
7477
native(glRendererMono)->onSurfaceCreated360(env,androidContext,videoTexture);
7578
}
7679
JNI_METHOD(void, nativeOnSurfaceChanged)
77-
(JNIEnv *env, jobject obj, jlong glRendererMono,jint w,jint h) {
78-
native(glRendererMono)->onSurfaceChanged360(w, h);
80+
(JNIEnv *env, jobject obj, jlong glRendererMono,jint w,jint h,jfloat video360FOV) {
81+
native(glRendererMono)->onSurfaceChanged360(w, h,video360FOV);
7982
}
8083
JNI_METHOD(void, nativeOnDrawFrame)
8184
(JNIEnv *env, jobject obj, jlong glRendererMono) {

app/src/main/cpp/GLRenderer/GLRMono360.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ class GLRMono360 : private GLRMono{
1515
explicit GLRMono360(JNIEnv* env,jobject androidContext,TelemetryReceiver& telemetryReceiver,gvr_context* gvr_context,bool renderOSD);
1616
public:
1717
void onSurfaceCreated360(JNIEnv * env,jobject obj,jint videoTexture);
18-
void onSurfaceChanged360(int width, int height);
18+
void onSurfaceChanged360(int width, int height,float video360FOV);
1919
//Draw the 360° video, optionally also the OSD as overlay
2020
void onDrawFrame360();
2121
void setHomeOrientation();
2222
private:
2323
const int renderOSD;
24+
int screenW,screenH;
2425
std::unique_ptr<GLProgramSpherical> mGLProgramSpherical=nullptr;
2526
std::unique_ptr<VideoRenderer> mVideoRenderer= nullptr;
2627
std::unique_ptr<gvr::GvrApi> gvr_api_;

app/src/main/cpp/Other/MatricesManager.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
// Created by Constantin on 12.12.2017.
33
//
44

5+
#include <android/log.h>
56
#include "MatricesManager.h"
67
#include "MatrixHelper.h"
78
#include "SettingsVR.h"
89

9-
//#define TAG "HeadTrackerExtended"
10-
//#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)
10+
constexpr auto TAG="HeadTrackerExtended";
11+
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)
1112
constexpr auto NANO_TO_MS=1000*1000;
1213

1314
MatricesManager::MatricesManager(const SettingsVR& settingsVR):
@@ -63,15 +64,23 @@ void MatricesManager::calculateNewHeadPose360(gvr::GvrApi *gvr_api, const int pr
6364
target_time.monotonic_system_time_nanos+=predictMS*NANO_TO_MS;
6465
gvr::Mat4f tmpHeadPose = gvr_api->GetHeadSpaceFromStartSpaceRotation(target_time); //we only want rotation, screw the mirage solo
6566
tmpHeadPose = MatrixMul(worldMatrices.monoForward360, tmpHeadPose);
66-
gvr_api->ApplyNeckModel(tmpHeadPose,1);
67+
//gvr_api->ApplyNeckModel(tmpHeadPose,1);
6768
worldMatrices.monoViewTracked360=toGLM(tmpHeadPose);
6869
}
6970

7071
void MatricesManager::setHomeOrientation360(gvr::GvrApi *gvr_api) {
7172
// Get the current start->head transformation
7273
gvr::Mat4f tmpHeadPose=gvr_api->GetHeadSpaceFromStartSpaceRotation(gvr::GvrApi::GetTimePointNow());
73-
gvr_api->ApplyNeckModel(tmpHeadPose,1);
74+
//gvr_api->ApplyNeckModel(tmpHeadPose,1); We do not want to apply the neck model here,else the world shifts
7475
glm::mat4 headView=toGLM(tmpHeadPose);
75-
worldMatrices.monoForward360*=headView;
76+
headView=glm::toMat4(glm::quat_cast(headView));
77+
worldMatrices.monoForward360=worldMatrices.monoForward360*headView;
78+
gvr_api->RecenterTracking();
7679
}
7780

81+
/*if(TEST()){
82+
LOGD("SUCCESS");
83+
}else{
84+
LOGD("FAIL");
85+
}*/
86+
//Reset tracking resets the rotation around the y axis, leaving everything else untouched

app/src/main/cpp/Other/MatrixHelper.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,30 @@ static gvr::Mat4f MatrixMul(const glm::mat4x4 &m1, const gvr::Mat4f &m2){
4040
return toGVR(m1*m2AsGLM);
4141
}
4242

43+
44+
static bool TEST(){
45+
float aaa[16];
46+
for(int i=0;i<4;i++){
47+
for(int j=0;j<4;j++){
48+
int idx=i*4+j;
49+
aaa[idx]=idx;
50+
}
51+
}
52+
{
53+
glm::mat4 glmMat=glm::make_mat4x4(aaa);
54+
gvr::Mat4f gvrMat=toGVR(glmMat);
55+
glm::mat4 glmMat2=toGLM(gvrMat);
56+
if(glmMat != glmMat2) {
57+
return false;
58+
}
59+
}
60+
glm::mat4 glmMat=glm::make_mat4x4(aaa);
61+
glm::mat4 glmMat2=glm::make_mat4x4(aaa);
62+
glm::mat4 multiplyGLM=glmMat*glmMat2;
63+
glm::mat4 multiplyGVR=toGLM(MatrixMul(glmMat,toGVR(glmMat2)));
64+
return multiplyGLM==multiplyGVR;
65+
}
66+
4367
//remove rotation around specific axes, but leaves
4468
//all other axes & translations intact
4569
//We can lock head tracking on specific axises. Therefore, we first calculate the inverse quaternion from the headView (rotation) matrix.

app/src/main/java/constantin/fpv_vr/APlay/AMono360.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ protected void onPause() {
108108
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
109109
super.onCreateContextMenu(menu, v, menuInfo);
110110
menu.setHeaderTitle("Options");
111-
getMenuInflater().inflate(R.menu.video_context_menu, menu);
111+
getMenuInflater().inflate(R.menu.video360_context_menu, menu);
112112
}
113113

114114
@Override

app/src/main/java/constantin/fpv_vr/APlay/AStereoNormal.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@
99
import android.opengl.GLSurfaceView;
1010
import android.os.Bundle;
1111
import androidx.appcompat.app.AppCompatActivity;
12+
13+
import android.view.ContextMenu;
14+
import android.view.MenuItem;
15+
import android.view.View;
1216
import android.view.WindowManager;
1317

1418
import com.google.vr.ndk.base.GvrLayout;
1519
import com.google.vr.ndk.base.GvrUiLayout;
1620

1721
import constantin.fpv_vr.AirHeadTrackingSender;
1822
import constantin.fpv_vr.GLRenderer.GLRStereoNormal;
23+
import constantin.fpv_vr.R;
1924
import constantin.fpv_vr.Settings.SJ;
2025
import constantin.fpv_vr.Toaster;
2126
import constantin.renderingX.MyEGLConfigChooser;
@@ -65,6 +70,8 @@ public void run() {
6570
mGvrLayout.setPresentationView(mGLViewStereo);
6671
setContentView(mGvrLayout);
6772
airHeadTrackingSender=new AirHeadTrackingSender(this,mGvrLayout.getGvrApi());
73+
74+
registerForContextMenu(mGvrLayout);
6875
}
6976

7077

@@ -106,5 +113,23 @@ protected void onDestroy(){
106113
telemetryReceiver.delete();
107114
}
108115

116+
@Override
117+
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
118+
super.onCreateContextMenu(menu, v, menuInfo);
119+
menu.setHeaderTitle("Options");
120+
getMenuInflater().inflate(R.menu.videovr_context_menu, menu);
121+
}
122+
123+
@Override
124+
public boolean onContextItemSelected(MenuItem item) {
125+
switch (item.getItemId()) {
126+
case R.id.option_reset_tracking:
127+
mGvrLayout.getGvrApi().recenterTracking();
128+
return true;
129+
default:
130+
return super.onContextItemSelected(item);
131+
}
132+
}
133+
109134

110135
}

app/src/main/java/constantin/fpv_vr/GLRenderer/GLRMono360.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import javax.microedition.khronos.opengles.GL10;
1313

1414
import constantin.fpv_vr.MVideoPlayer;
15+
import constantin.fpv_vr.R;
1516
import constantin.telemetry.core.TelemetryReceiver;
1617
import constantin.video.core.DecodingInfo;
1718
import constantin.video.core.IVideoParamsChanged;
@@ -27,17 +28,19 @@ public class GLRMono360 implements GLSurfaceView.Renderer, IVideoParamsChanged {
2728
private native long nativeConstruct(Context context,long telemetryReceiver,long nativeGvrContext,boolean renderOSD);
2829
private native void nativeDelete(long glRendererMonoP);
2930
private native void nativeOnSurfaceCreated(long glRendererP,int videoTexture,Context androidContext);
30-
private native void nativeOnSurfaceChanged(long glRendererMonoP,int width,int height);
31+
private native void nativeOnSurfaceChanged(long glRendererMonoP,int width,int height,float video360FOV);
3132
private native void nativeOnDrawFrame(long glRendererMonoP);
3233
private native void nativeSetHomeOrientation(long glRendererMonoP);
3334

3435
private final long nativeGLRendererMono;
3536
private final Context mContext;
3637
private SurfaceTexture mSurfaceTexture;
3738
private MVideoPlayer mVideoPlayer;
39+
private final TelemetryReceiver telemetryReceiver;
3840

3941
public GLRMono360(final Context context, final TelemetryReceiver telemetryReceiver, GvrApi gvrApi,final boolean renderOSD){
4042
mContext=context;
43+
this.telemetryReceiver=telemetryReceiver;
4144
nativeGLRendererMono=nativeConstruct(context,telemetryReceiver.getNativeInstance(),gvrApi.getNativeGvrContext(),renderOSD);
4245
}
4346

@@ -52,7 +55,8 @@ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
5255

5356
@Override
5457
public void onSurfaceChanged(GL10 gl, int width, int height) {
55-
nativeOnSurfaceChanged(nativeGLRendererMono,width,height);
58+
final float video360FOV=mContext.getSharedPreferences("pref_video",Context.MODE_PRIVATE).getFloat(mContext.getString(R.string.VS_360_VIDEO_FOV),50);
59+
nativeOnSurfaceChanged(nativeGLRendererMono,width,height,video360FOV);
5660
//MyEGLConfigChooser.setEglSurfaceAttrib(EGL14.EGL_RENDER_BUFFER,EGL14.EGL_SINGLE_BUFFER);
5761
}
5862

@@ -97,7 +101,10 @@ public void onVideoRatioChanged(int videoW, int videoH) {
97101

98102
@Override
99103
public void onDecodingInfoChanged(DecodingInfo decodingInfo) {
100-
104+
if(telemetryReceiver!=null){
105+
telemetryReceiver.setDecodingInfo(decodingInfo.currentFPS,decodingInfo.currentKiloBitsPerSecond,decodingInfo.avgParsingTime_ms,decodingInfo.avgWaitForInputBTime_ms,
106+
decodingInfo.avgHWDecodingTime_ms);
107+
}
101108
}
102109

103110
public void setHomeOrientation(){
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<menu xmlns:tools="http://schemas.android.com/tools"
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
tools:ignore="HardcodedText">
5+
<item
6+
android:id="@+id/option_reset_tracking"
7+
android:title="Reset tracking"
8+
/>
9+
10+
</menu>

0 commit comments

Comments
 (0)