Skip to content

Commit

Permalink
fix 360 goto /set home 2
Browse files Browse the repository at this point in the history
  • Loading branch information
di57mec committed Sep 21, 2019
1 parent 7c07799 commit cf482b9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
20 changes: 10 additions & 10 deletions app/src/main/cpp/Other/MatricesManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -63,24 +64,23 @@ 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();
}

/*if(TEST()){
LOGD("SUCCESS");
}else{
LOGD("FAIL");
}*/
//Reset tracking resets the rotation around the y axis, leaving everything else untouched
}*/
15 changes: 5 additions & 10 deletions app/src/main/cpp/Other/MatrixHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@

#include "vr/gvr/capi/include/gvr.h"
#include "vr/gvr/capi/include/gvr_types.h"

#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/quaternion.hpp>
#include <glm/ext.hpp>
#include <glm/gtx/matrix_decompose.hpp>
#include "include_glm.h"
#include <sstream>


Expand All @@ -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<const float*>(&gvrMatrix.m));
glm::mat4 ret=glm::make_mat4(reinterpret_cast<const float*>(&gvrMatrix.m));
ret=glm::transpose(ret);
return ret;
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/cpp/Other/include_glm.h
Original file line number Diff line number Diff line change
@@ -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 <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/quaternion.hpp>
//#include <glm/gtx/quaternion.hpp>
#include <glm/ext.hpp>
#include <glm/gtx/matrix_decompose.hpp>

#endif //FPV_VR_2018_INCLUDE_GLM_H

0 comments on commit cf482b9

Please sign in to comment.