diff --git a/app/src/main/cpp/GLRenderer/GLRMono360.cpp b/app/src/main/cpp/GLRenderer/GLRMono360.cpp index 0ba98181..d5faace4 100644 --- a/app/src/main/cpp/GLRenderer/GLRMono360.cpp +++ b/app/src/main/cpp/GLRenderer/GLRMono360.cpp @@ -49,6 +49,7 @@ void GLRMono360::onSurfaceChanged(int width, int height) { void GLRMono360::onDrawFrame() { glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); cpuFrameTime.start(); + mMatricesM.calculateNewHeadPoseIfNeeded(gvr_api_.get(),0); mMatricesM.calculateNewHeadPose360(gvr_api_.get(),0); Matrices& worldMatrices=mMatricesM.getWorldMatrices(); mVideoRenderer->drawVideoCanvas360(worldMatrices.monoViewTracked,worldMatrices.projection360); diff --git a/app/src/main/cpp/Other/MatricesManager.cpp b/app/src/main/cpp/Other/MatricesManager.cpp index 83befaa5..efe3fb2d 100644 --- a/app/src/main/cpp/Other/MatricesManager.cpp +++ b/app/src/main/cpp/Other/MatricesManager.cpp @@ -16,7 +16,7 @@ //#define TAG "HeadTrackerExtended" //#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__) - +constexpr auto NANO_TO_MS=1000*1000; static glm::mat4 toGLM(const gvr::Mat4f &matrix) { glm::mat4 result; @@ -35,12 +35,13 @@ gvr::Mat4f MatrixMul(const glm::mat4x4 &m1, const gvr::Mat4f &m2) { memcpy(reinterpret_cast(&ret.m), reinterpret_cast(&tm2[0]), 16 * sizeof(float)); return ret; } + static const std::string toString(const glm::mat4x4 matrix){ std::stringstream ss; ss<<"\n"; for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; ++j) { - ss<GetHeadSpaceFromStartSpaceRotation(target_time); //we only apply the neck model when we calculate the view M for 1PP if(settingsVR.GHT_MODE==MODE_1PP){ @@ -112,21 +113,44 @@ void MatricesManager::calculateNewHeadPoseIfNeeded(gvr::GvrApi *gvr_api, const i }*/ worldMatrices.leftEyeViewTracked=glm::translate(headView,glm::vec3(-settingsVR.VR_InterpupilaryDistance/2.0f,0,0)); worldMatrices.rightEyeViewTracked=glm::translate(headView,glm::vec3(settingsVR.VR_InterpupilaryDistance/2.0f,0,0)); + + //LOGD("%s",toString(worldMatrices.leftEyeViewTracked).c_str()); } //The 360 degree mono renderer only uses the last known head translation as 'view' matrix void MatricesManager::calculateNewHeadPose360(gvr::GvrApi *gvr_api, const int predictMS) { gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); - target_time.monotonic_system_time_nanos+=predictMS*1000*1000; + target_time.monotonic_system_time_nanos+=predictMS*NANO_TO_MS; const gvr::Mat4f tmpHeadPose = gvr_api->GetHeadSpaceFromStartSpaceTransform(target_time); + gvr_api->ApplyNeckModel(tmpHeadPose,1); worldMatrices.monoViewTracked=toGLM(tmpHeadPose); - //glm::mat4 tmpM2=toGLM(tmpM); - //tmpM = MatrixMul(worldMatrices.monoForward360, tmpM); - //glm::mat4x4 headView=glm::make_mat4(reinterpret_cast(&tmpM.m)); - //headView=glm::transpose(headView); - //worldMatrices.monoViewTracked=headView; + worldMatrices.monoViewTracked=glm::transpose(worldMatrices.monoViewTracked); + + worldMatrices.monoViewTracked=worldMatrices.leftEyeViewTracked; + + //float aaa[16]={1,-1.94429e-07,5.55111e-17,0, + // 1.94429e-07,1,1.66533e-16,0, + // -5.55112e-17,-1.66533e-16,1,0, + // -0.1,1.94429e-08,-5.55111e-18,1,}; + //worldMatrices.monoViewTracked=glm::make_mat4x4(aaa); } +/*float rot=0; +void MatricesManager::calculateNewHeadPose360_fixRot(gvr::GvrApi *gvr_api, const int predictMS) { + gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); + target_time.monotonic_system_time_nanos+=predictMS*NANO_TO_MS; + gvr::Mat4f tmpM = gvr_api->GetHeadSpaceFromStartSpaceTransform(target_time); + tmpM = MatrixMul(worldMatrices.monoForward360, tmpM); + gvr_api->ApplyNeckModel(tmpM,1); + glm::mat4x4 headView=glm::make_mat4(reinterpret_cast(&tmpM.m)); + headView=glm::transpose(headView); + worldMatrices.monoViewTracked=glm::translate(headView,glm::vec3(0,0,0.0)); + //worldMatrices.monoViewTracked=glm::mat4(); + //worldMatrices.monoViewTracked=glm::rotate(worldMatrices.monoViewTracked,rot,glm::vec3(0,0,1)); + //rot+=0.02f; + +}*/ + /*fov=100; float left=fov/2.0f; float right=fov/2.0f; diff --git a/app/src/main/java/constantin/fpv_vr/APlay/AMono360.java b/app/src/main/java/constantin/fpv_vr/APlay/AMono360.java index c6b68745..c8cabfa8 100644 --- a/app/src/main/java/constantin/fpv_vr/APlay/AMono360.java +++ b/app/src/main/java/constantin/fpv_vr/APlay/AMono360.java @@ -9,6 +9,7 @@ import com.google.vr.cardboard.DisplaySynchronizer; import com.google.vr.ndk.base.GvrApi; +import com.google.vr.ndk.base.GvrLayout; import constantin.fpv_vr.AirHeadTrackingSender; import constantin.fpv_vr.GLRenderer.GLRMono360; @@ -21,30 +22,42 @@ public class AMono360 extends AppCompatActivity { private Context mContext; private GLSurfaceView mGLView; - private GvrApi gvrApi; private GLRMono360 mGLRenderer; - private AirHeadTrackingSender airHeadTrackingSender; private TelemetryReceiver telemetryReceiver; + //either create gvr api directly or use gvr layout as wrapper - first one introduces bug, e.g. "wrong 360° video orientation" + private static final boolean useGvrLayout=true; + private GvrApi gvrApi; + private GvrLayout gvrLayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext=this; + PerformanceHelper.enableSustainedPerformanceIfPossible(this); mGLView = new GLSurfaceView(this); mGLView.setEGLContextClientVersion(2); mGLView.setEGLConfigChooser(new MyEGLConfigChooser(false, SJ.MultiSampleAntiAliasing(this),true)); mGLView.setEGLWindowSurfaceFactory(new MyEGLWindowSurfaceFactory()); - - //mGLView.getHolder().setFormat(PixelFormat.TRANSLUCENT); mGLView.setPreserveEGLContextOnPause(true); - gvrApi = new GvrApi(this, new DisplaySynchronizer(this,getWindowManager().getDefaultDisplay())); - if(SJ.EnableAHT(mContext)){ - airHeadTrackingSender=new AirHeadTrackingSender(this,gvrApi); + if(useGvrLayout){ + gvrLayout=new GvrLayout(this); + gvrLayout.setAsyncReprojectionEnabled(false); + gvrLayout.setStereoModeEnabled(false); + gvrLayout.setPresentationView(mGLView); + }else{ + gvrApi = new GvrApi(this, new DisplaySynchronizer(this,getWindowManager().getDefaultDisplay())); + gvrApi.reconnectSensors(); + gvrApi.clearError(); + gvrApi.recenterTracking(); } telemetryReceiver=new TelemetryReceiver(this); - mGLRenderer =new GLRMono360(mContext,telemetryReceiver,gvrApi); + mGLRenderer =new GLRMono360(mContext,telemetryReceiver,useGvrLayout ? gvrLayout.getGvrApi() : gvrApi); mGLView.setRenderer(mGLRenderer); - setContentView(mGLView); + if(useGvrLayout){ + setContentView(gvrLayout); + }else{ + setContentView(mGLView); + } } @@ -56,33 +69,32 @@ protected void onResume() { getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); telemetryReceiver.startReceiving(); mGLView.onResume(); - if(gvrApi!=null){ + if(useGvrLayout){ + gvrLayout.onResume(); + }else{ gvrApi.resumeTracking(); } - if(airHeadTrackingSender!=null){ - airHeadTrackingSender.startSendingDataIfEnabled(); - } } @Override protected void onPause() { super.onPause(); - //Log.d(TAG, "onPause"); - if(gvrApi!=null){ - gvrApi.pauseTracking(); - } - if(airHeadTrackingSender!=null){ - airHeadTrackingSender.stopSendingDataIfEnabled(); - } telemetryReceiver.stopReceiving(); mGLRenderer.onPause(); mGLView.onPause(); + if(useGvrLayout){ + gvrLayout.onPause(); + }else{ + gvrApi.pauseTracking(); + } } @Override protected void onDestroy() { super.onDestroy(); - if(gvrApi!=null){ + if(useGvrLayout){ + gvrLayout.shutdown(); + }else{ gvrApi.shutdown(); } mGLView=null; diff --git a/build.gradle b/build.gradle index 4ce9c5df..59136ba9 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:3.5.0' - classpath 'com.google.gms:google-services:4.3.1' + classpath 'com.google.gms:google-services:4.3.2' classpath 'io.fabric.tools:gradle:1.31.0' classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' } @@ -35,7 +35,7 @@ allprojects { materialVersion = '1.1.0-alpha10' constraintlayoutVersion='1.1.3' androidxpreferenceVersion='1.1.0' - mGvrVersion = '1.190.0' + mGvrVersion = '1.180.0' } }