From d5198ff4f5334791d3cfac0e313d289f5aa3b0d1 Mon Sep 17 00:00:00 2001 From: Jasper Date: Fri, 14 Nov 2014 15:15:29 +0100 Subject: [PATCH] Added getRotation in physics to give rotation of object back as 4x4Matrix --- physics.cc | 10 ++++++++-- physics.hh | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/physics.cc b/physics.cc index cf030ff..f092a1d 100644 --- a/physics.cc +++ b/physics.cc @@ -100,9 +100,15 @@ glm::vec3 getPos(int i) return save; } -void getRotation(int i) +glm::mat4 getRotation(int i) { - btQuaternion rotQuantrino = bodies[i]->getOrientation(); //TODO return orientation in gl format + btQuaternion quat = bodies[i]->getOrientation(); + + glm::mat4 matrix = glm::rotate( + matrix, + quat.getAngle(), + glm::vec3(quat.getAxis().getX(), quat.getAxis().getY(), quat.getAxis().getZ()) + ); } void rollForward() diff --git a/physics.hh b/physics.hh index a52e646..97a56ca 100644 --- a/physics.hh +++ b/physics.hh @@ -26,6 +26,8 @@ #include "extern/bullet/src/LinearMath/btMotionState.h" #include "extern/bullet/src/LinearMath/btDefaultMotionState.h" #include "extern/bullet/src/LinearMath/btQuaternion.h" +#include "extern/bullet/src/LinearMath/btVector3.h" +#include "extern/bullet/src/LinearMath/btMatrix3x3.h" class Physics { public: @@ -35,7 +37,7 @@ class Physics { void takeUpdateStep(float timeDiff); void rollForward(glm::vec3 camPos, float strength); glm::vec3 getPos(int i); - void getRotation(int i); + glm::mat4 getRotation(int i); void rollForward(); void addTerrain(int width, int length, float** heightData); void addSphere(float rad, float x, float y, float z, float mass, int indice);