Skip to content

Commit

Permalink
fix 360 goto /set home
Browse files Browse the repository at this point in the history
  • Loading branch information
di57mec committed Sep 21, 2019
1 parent e222c79 commit 7c07799
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ dependencies {
implementation project(path: ':preferences')

implementation project(':VideoCore')
//implementation 'com.github.Consti10:LiveVideo10ms:v1.2'
//implementation 'com.github.Consti10:LiveVideo10ms:v1.3'
implementation project(':TelemetryCore')
implementation project(':RenderingXCore')

Expand Down
11 changes: 7 additions & 4 deletions app/src/main/cpp/GLRenderer/GLRMono360.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ void GLRMono360::onSurfaceCreated360(JNIEnv* env,jobject androidContext,jint vid
mVideoRenderer=std::make_unique<VideoRenderer>(mBasicGLPrograms->vc, nullptr,mSettingsVR.DEV_3D_VIDEO,mGLProgramSpherical.get());
}

void GLRMono360::onSurfaceChanged360(int width, int height) {
void GLRMono360::onSurfaceChanged360(int width, int height,float video360FOV) {
screenW=width;
screenH=height;
GLRMono::onSurfaceChanged(width,height);
const float displayRatio=(float) width/(float)height;
mMatricesM.calculateProjectionAndDefaultView360(40.0f,displayRatio);
mMatricesM.calculateProjectionAndDefaultView360(video360FOV,displayRatio);
cpuFrameTimeVidOSD.reset();
}

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


//----------------------------------------------------JAVA bindings---------------------------------------------------------------

#define JNI_METHOD(return_type, method_name) \
Expand Down Expand Up @@ -74,8 +77,8 @@ JNI_METHOD(void, nativeOnSurfaceCreated)
native(glRendererMono)->onSurfaceCreated360(env,androidContext,videoTexture);
}
JNI_METHOD(void, nativeOnSurfaceChanged)
(JNIEnv *env, jobject obj, jlong glRendererMono,jint w,jint h) {
native(glRendererMono)->onSurfaceChanged360(w, h);
(JNIEnv *env, jobject obj, jlong glRendererMono,jint w,jint h,jfloat video360FOV) {
native(glRendererMono)->onSurfaceChanged360(w, h,video360FOV);
}
JNI_METHOD(void, nativeOnDrawFrame)
(JNIEnv *env, jobject obj, jlong glRendererMono) {
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/cpp/GLRenderer/GLRMono360.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ class GLRMono360 : private GLRMono{
explicit GLRMono360(JNIEnv* env,jobject androidContext,TelemetryReceiver& telemetryReceiver,gvr_context* gvr_context,bool renderOSD);
public:
void onSurfaceCreated360(JNIEnv * env,jobject obj,jint videoTexture);
void onSurfaceChanged360(int width, int height);
void onSurfaceChanged360(int width, int height,float video360FOV);
//Draw the 360° video, optionally also the OSD as overlay
void onDrawFrame360();
void setHomeOrientation();
private:
const int renderOSD;
int screenW,screenH;
std::unique_ptr<GLProgramSpherical> mGLProgramSpherical=nullptr;
std::unique_ptr<VideoRenderer> mVideoRenderer= nullptr;
std::unique_ptr<gvr::GvrApi> gvr_api_;
Expand Down
19 changes: 14 additions & 5 deletions app/src/main/cpp/Other/MatricesManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
// Created by Constantin on 12.12.2017.
//

#include <android/log.h>
#include "MatricesManager.h"
#include "MatrixHelper.h"
#include "SettingsVR.h"

//#define TAG "HeadTrackerExtended"
//#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)
constexpr auto TAG="HeadTrackerExtended";
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)
constexpr auto NANO_TO_MS=1000*1000;

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

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

/*if(TEST()){
LOGD("SUCCESS");
}else{
LOGD("FAIL");
}*/
//Reset tracking resets the rotation around the y axis, leaving everything else untouched
24 changes: 24 additions & 0 deletions app/src/main/cpp/Other/MatrixHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,30 @@ static gvr::Mat4f MatrixMul(const glm::mat4x4 &m1, const gvr::Mat4f &m2){
return toGVR(m1*m2AsGLM);
}


static bool TEST(){
float aaa[16];
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
int idx=i*4+j;
aaa[idx]=idx;
}
}
{
glm::mat4 glmMat=glm::make_mat4x4(aaa);
gvr::Mat4f gvrMat=toGVR(glmMat);
glm::mat4 glmMat2=toGLM(gvrMat);
if(glmMat != glmMat2) {
return false;
}
}
glm::mat4 glmMat=glm::make_mat4x4(aaa);
glm::mat4 glmMat2=glm::make_mat4x4(aaa);
glm::mat4 multiplyGLM=glmMat*glmMat2;
glm::mat4 multiplyGVR=toGLM(MatrixMul(glmMat,toGVR(glmMat2)));
return multiplyGLM==multiplyGVR;
}

//remove rotation around specific axes, but leaves
//all other axes & translations intact
//We can lock head tracking on specific axises. Therefore, we first calculate the inverse quaternion from the headView (rotation) matrix.
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/constantin/fpv_vr/APlay/AMono360.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ protected void onPause() {
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("Options");
getMenuInflater().inflate(R.menu.video_context_menu, menu);
getMenuInflater().inflate(R.menu.video360_context_menu, menu);
}

@Override
Expand Down
25 changes: 25 additions & 0 deletions app/src/main/java/constantin/fpv_vr/APlay/AStereoNormal.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;

import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;

import com.google.vr.ndk.base.GvrLayout;
import com.google.vr.ndk.base.GvrUiLayout;

import constantin.fpv_vr.AirHeadTrackingSender;
import constantin.fpv_vr.GLRenderer.GLRStereoNormal;
import constantin.fpv_vr.R;
import constantin.fpv_vr.Settings.SJ;
import constantin.fpv_vr.Toaster;
import constantin.renderingX.MyEGLConfigChooser;
Expand Down Expand Up @@ -65,6 +70,8 @@ public void run() {
mGvrLayout.setPresentationView(mGLViewStereo);
setContentView(mGvrLayout);
airHeadTrackingSender=new AirHeadTrackingSender(this,mGvrLayout.getGvrApi());

registerForContextMenu(mGvrLayout);
}


Expand Down Expand Up @@ -106,5 +113,23 @@ protected void onDestroy(){
telemetryReceiver.delete();
}

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("Options");
getMenuInflater().inflate(R.menu.videovr_context_menu, menu);
}

@Override
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.option_reset_tracking:
mGvrLayout.getGvrApi().recenterTracking();
return true;
default:
return super.onContextItemSelected(item);
}
}


}
13 changes: 10 additions & 3 deletions app/src/main/java/constantin/fpv_vr/GLRenderer/GLRMono360.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import javax.microedition.khronos.opengles.GL10;

import constantin.fpv_vr.MVideoPlayer;
import constantin.fpv_vr.R;
import constantin.telemetry.core.TelemetryReceiver;
import constantin.video.core.DecodingInfo;
import constantin.video.core.IVideoParamsChanged;
Expand All @@ -27,17 +28,19 @@ public class GLRMono360 implements GLSurfaceView.Renderer, IVideoParamsChanged {
private native long nativeConstruct(Context context,long telemetryReceiver,long nativeGvrContext,boolean renderOSD);
private native void nativeDelete(long glRendererMonoP);
private native void nativeOnSurfaceCreated(long glRendererP,int videoTexture,Context androidContext);
private native void nativeOnSurfaceChanged(long glRendererMonoP,int width,int height);
private native void nativeOnSurfaceChanged(long glRendererMonoP,int width,int height,float video360FOV);
private native void nativeOnDrawFrame(long glRendererMonoP);
private native void nativeSetHomeOrientation(long glRendererMonoP);

private final long nativeGLRendererMono;
private final Context mContext;
private SurfaceTexture mSurfaceTexture;
private MVideoPlayer mVideoPlayer;
private final TelemetryReceiver telemetryReceiver;

public GLRMono360(final Context context, final TelemetryReceiver telemetryReceiver, GvrApi gvrApi,final boolean renderOSD){
mContext=context;
this.telemetryReceiver=telemetryReceiver;
nativeGLRendererMono=nativeConstruct(context,telemetryReceiver.getNativeInstance(),gvrApi.getNativeGvrContext(),renderOSD);
}

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

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

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

@Override
public void onDecodingInfoChanged(DecodingInfo decodingInfo) {

if(telemetryReceiver!=null){
telemetryReceiver.setDecodingInfo(decodingInfo.currentFPS,decodingInfo.currentKiloBitsPerSecond,decodingInfo.avgParsingTime_ms,decodingInfo.avgWaitForInputBTime_ms,
decodingInfo.avgHWDecodingTime_ms);
}
}

public void setHomeOrientation(){
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/menu/videovr_context_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:ignore="HardcodedText">
<item
android:id="@+id/option_reset_tracking"
android:title="Reset tracking"
/>

</menu>

0 comments on commit 7c07799

Please sign in to comment.