Skip to content

Commit cf482b9

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

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ void MatricesManager::calculateProjectionAndDefaultView(float fov, float ratio)
3030

3131
void MatricesManager::calculateProjectionAndDefaultView360(float fov360Video,float ratio) {
3232
worldMatrices.projection360=glm::perspective(glm::radians(fov360Video), ratio, 0.1f, MAX_Z_DISTANCE+5);
33-
worldMatrices.monoViewTracked360=glm::mat4();
34-
worldMatrices.monoForward360=glm::mat4();
33+
worldMatrices.monoViewTracked360=glm::mat4(1.0f);
34+
worldMatrices.monoForward360=glm::mat4(1.0f);
35+
//worldMatrices.monoForward360 = glm::rotate(glm::mat4(1.0f),glm::radians(90.0f), glm::vec3(0,1,0));
3536
}
3637

3738
void MatricesManager::calculateNewHeadPoseIfNeeded(gvr::GvrApi *gvr_api, const int predictMS) {
@@ -63,24 +64,23 @@ void MatricesManager::calculateNewHeadPose360(gvr::GvrApi *gvr_api, const int pr
6364
gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow();
6465
target_time.monotonic_system_time_nanos+=predictMS*NANO_TO_MS;
6566
gvr::Mat4f tmpHeadPose = gvr_api->GetHeadSpaceFromStartSpaceRotation(target_time); //we only want rotation, screw the mirage solo
66-
tmpHeadPose = MatrixMul(worldMatrices.monoForward360, tmpHeadPose);
67-
//gvr_api->ApplyNeckModel(tmpHeadPose,1);
68-
worldMatrices.monoViewTracked360=toGLM(tmpHeadPose);
67+
gvr_api->ApplyNeckModel(tmpHeadPose,1);
68+
const glm::mat4 tmpHeadPoseGLM=toGLM(tmpHeadPose);
69+
worldMatrices.monoViewTracked360=tmpHeadPoseGLM*worldMatrices.monoForward360; //multiplication order is important
6970
}
7071

7172
void MatricesManager::setHomeOrientation360(gvr::GvrApi *gvr_api) {
72-
// Get the current start->head transformation
7373
gvr::Mat4f tmpHeadPose=gvr_api->GetHeadSpaceFromStartSpaceRotation(gvr::GvrApi::GetTimePointNow());
74-
//gvr_api->ApplyNeckModel(tmpHeadPose,1); We do not want to apply the neck model here,else the world shifts
74+
gvr_api->ApplyNeckModel(tmpHeadPose,1);
7575
glm::mat4 headView=toGLM(tmpHeadPose);
76-
headView=glm::toMat4(glm::quat_cast(headView));
76+
//headView=glm::toMat4(glm::quat_cast(headView));
7777
worldMatrices.monoForward360=worldMatrices.monoForward360*headView;
78+
//Reset tracking resets the rotation around the y axis, leaving everything else untouched
7879
gvr_api->RecenterTracking();
7980
}
8081

8182
/*if(TEST()){
8283
LOGD("SUCCESS");
8384
}else{
8485
LOGD("FAIL");
85-
}*/
86-
//Reset tracking resets the rotation around the y axis, leaving everything else untouched
86+
}*/

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@
77

88
#include "vr/gvr/capi/include/gvr.h"
99
#include "vr/gvr/capi/include/gvr_types.h"
10-
11-
#include <glm/glm.hpp>
12-
#include <glm/gtc/matrix_transform.hpp>
13-
#include <glm/gtc/quaternion.hpp>
14-
#include <glm/ext.hpp>
15-
#include <glm/gtx/matrix_decompose.hpp>
10+
#include "include_glm.h"
1611
#include <sstream>
1712

1813

@@ -23,7 +18,7 @@
2318
//2)glm matrices are stored in column major order (glm manual,section 4.11), as well as OpenGL matrices
2419

2520
static glm::mat4 toGLM(const gvr::Mat4f &gvrMatrix){
26-
glm::mat4x4 ret=glm::make_mat4(reinterpret_cast<const float*>(&gvrMatrix.m));
21+
glm::mat4 ret=glm::make_mat4(reinterpret_cast<const float*>(&gvrMatrix.m));
2722
ret=glm::transpose(ret);
2823
return ret;
2924
}
@@ -35,7 +30,7 @@ static gvr::Mat4f toGVR(const glm::mat4 &glmMatrix){
3530
return ret;
3631
}
3732

38-
static gvr::Mat4f MatrixMul(const glm::mat4x4 &m1, const gvr::Mat4f &m2){
33+
static gvr::Mat4f MatrixMul(const glm::mat4 &m1, const gvr::Mat4f &m2){
3934
glm::mat4 m2AsGLM=toGLM(m2);
4035
return toGVR(m1*m2AsGLM);
4136
}
@@ -84,11 +79,11 @@ static glm::mat4 removeRotationAroundSpecificAxes(const glm::mat4 mat,const bool
8479
euler.z=0;
8580
}
8681
glm::quat quat=glm::quat(euler);
87-
glm::mat4x4 RotationMatrix = glm::toMat4(quat);
82+
glm::mat4 RotationMatrix = glm::toMat4(quat);
8883
return mat*RotationMatrix;
8984
}
9085

91-
static const std::string toString(const glm::mat4x4 matrix){
86+
static const std::string toString(const glm::mat4 matrix){
9287
std::stringstream ss;
9388
ss<<"\n";
9489
for (int i = 0; i < 4; ++i) {

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// Created by Consti10 on 21/09/2019.
3+
//
4+
5+
#ifndef FPV_VR_2018_INCLUDE_GLM_H
6+
#define FPV_VR_2018_INCLUDE_GLM_H
7+
8+
#include <glm/glm.hpp>
9+
#include <glm/gtc/matrix_transform.hpp>
10+
#include <glm/gtc/quaternion.hpp>
11+
//#include <glm/gtx/quaternion.hpp>
12+
#include <glm/ext.hpp>
13+
#include <glm/gtx/matrix_decompose.hpp>
14+
15+
#endif //FPV_VR_2018_INCLUDE_GLM_H

0 commit comments

Comments
 (0)