diff --git a/app/src/main/cpp/Other/MatricesManager.cpp b/app/src/main/cpp/Other/MatricesManager.cpp index 4277b6c6..1d4cf702 100644 --- a/app/src/main/cpp/Other/MatricesManager.cpp +++ b/app/src/main/cpp/Other/MatricesManager.cpp @@ -30,8 +30,9 @@ void MatricesManager::calculateProjectionAndDefaultView(float fov, float ratio) void MatricesManager::calculateProjectionAndDefaultView360(float fov360Video,float ratio) { worldMatrices.projection360=glm::perspective(glm::radians(fov360Video), ratio, 0.1f, MAX_Z_DISTANCE+5); - worldMatrices.monoViewTracked360=glm::mat4(); - worldMatrices.monoForward360=glm::mat4(); + worldMatrices.monoViewTracked360=glm::mat4(1.0f); + worldMatrices.monoForward360=glm::mat4(1.0f); + //worldMatrices.monoForward360 = glm::rotate(glm::mat4(1.0f),glm::radians(90.0f), glm::vec3(0,1,0)); } void MatricesManager::calculateNewHeadPoseIfNeeded(gvr::GvrApi *gvr_api, const int predictMS) { @@ -63,18 +64,18 @@ void MatricesManager::calculateNewHeadPose360(gvr::GvrApi *gvr_api, const int pr gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); 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); - worldMatrices.monoViewTracked360=toGLM(tmpHeadPose); + gvr_api->ApplyNeckModel(tmpHeadPose,1); + const glm::mat4 tmpHeadPoseGLM=toGLM(tmpHeadPose); + worldMatrices.monoViewTracked360=tmpHeadPoseGLM*worldMatrices.monoForward360; //multiplication order is important } 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); We do not want to apply the neck model here,else the world shifts + gvr_api->ApplyNeckModel(tmpHeadPose,1); glm::mat4 headView=toGLM(tmpHeadPose); - headView=glm::toMat4(glm::quat_cast(headView)); + //headView=glm::toMat4(glm::quat_cast(headView)); worldMatrices.monoForward360=worldMatrices.monoForward360*headView; + //Reset tracking resets the rotation around the y axis, leaving everything else untouched gvr_api->RecenterTracking(); } @@ -82,5 +83,4 @@ void MatricesManager::setHomeOrientation360(gvr::GvrApi *gvr_api) { LOGD("SUCCESS"); }else{ LOGD("FAIL"); - }*/ -//Reset tracking resets the rotation around the y axis, leaving everything else untouched \ No newline at end of file + }*/ \ No newline at end of file diff --git a/app/src/main/cpp/Other/MatrixHelper.h b/app/src/main/cpp/Other/MatrixHelper.h index 54202b4a..bed7b987 100644 --- a/app/src/main/cpp/Other/MatrixHelper.h +++ b/app/src/main/cpp/Other/MatrixHelper.h @@ -7,12 +7,7 @@ #include "vr/gvr/capi/include/gvr.h" #include "vr/gvr/capi/include/gvr_types.h" - -#include -#include -#include -#include -#include +#include "include_glm.h" #include @@ -23,7 +18,7 @@ //2)glm matrices are stored in column major order (glm manual,section 4.11), as well as OpenGL matrices static glm::mat4 toGLM(const gvr::Mat4f &gvrMatrix){ - glm::mat4x4 ret=glm::make_mat4(reinterpret_cast(&gvrMatrix.m)); + glm::mat4 ret=glm::make_mat4(reinterpret_cast(&gvrMatrix.m)); ret=glm::transpose(ret); return ret; } @@ -35,7 +30,7 @@ static gvr::Mat4f toGVR(const glm::mat4 &glmMatrix){ return ret; } -static gvr::Mat4f MatrixMul(const glm::mat4x4 &m1, const gvr::Mat4f &m2){ +static gvr::Mat4f MatrixMul(const glm::mat4 &m1, const gvr::Mat4f &m2){ glm::mat4 m2AsGLM=toGLM(m2); return toGVR(m1*m2AsGLM); } @@ -84,11 +79,11 @@ static glm::mat4 removeRotationAroundSpecificAxes(const glm::mat4 mat,const bool euler.z=0; } glm::quat quat=glm::quat(euler); - glm::mat4x4 RotationMatrix = glm::toMat4(quat); + glm::mat4 RotationMatrix = glm::toMat4(quat); return mat*RotationMatrix; } -static const std::string toString(const glm::mat4x4 matrix){ +static const std::string toString(const glm::mat4 matrix){ std::stringstream ss; ss<<"\n"; for (int i = 0; i < 4; ++i) { diff --git a/app/src/main/cpp/Other/include_glm.h b/app/src/main/cpp/Other/include_glm.h new file mode 100644 index 00000000..a2aeb7d0 --- /dev/null +++ b/app/src/main/cpp/Other/include_glm.h @@ -0,0 +1,15 @@ +// +// Created by Consti10 on 21/09/2019. +// + +#ifndef FPV_VR_2018_INCLUDE_GLM_H +#define FPV_VR_2018_INCLUDE_GLM_H + +#include +#include +#include +//#include +#include +#include + +#endif //FPV_VR_2018_INCLUDE_GLM_H