From e579fe1d75a239a7836d3bc9048dcb9473fa8dfa Mon Sep 17 00:00:00 2001 From: Jasper Date: Mon, 17 Nov 2014 13:12:51 +0100 Subject: [PATCH] added wasd recognition, prepared roll forward to accept vec3 pos instead of mat3 rot --- level.cc | 5 +++++ level.hh | 2 +- physics.cc | 12 ++++++++---- physics.hh | 2 +- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/level.cc b/level.cc index fda5982..721e5f7 100644 --- a/level.cc +++ b/level.cc @@ -76,6 +76,11 @@ void Level::update(float runTime, glm::vec2 mouseDelta, bool wPressed, bool aPre camera.updateRotation(mouseDelta/100.0f); } + if(wPressed) + { + //physics.rollForward(camera.getRotation); + } + physics.takeUpdateStep(runTime); objects[0].setPosition(physics.getPos(0)); diff --git a/level.hh b/level.hh index 784b4e2..db6ab73 100644 --- a/level.hh +++ b/level.hh @@ -16,7 +16,7 @@ class Level { Level(); ~Level(); void load(ACGL::OpenGL::SharedShaderProgram shader); // Shader is necessary for correct texture assigning - void update(float runTime, glm::vec2 mouseDelta,bool wPressed, bool aPressed, bool dPressed, bool sPressed); + void update(float runTime, glm::vec2 mouseDelta,bool wPressed, bool aPressed,bool sPressed, bool dPressed); void render(); glm::vec3 getAmbientLight(); std::vector getLights(); diff --git a/physics.cc b/physics.cc index d270266..11ede4a 100644 --- a/physics.cc +++ b/physics.cc @@ -14,7 +14,6 @@ btRigidBody* staticGroundBody; Physics::Physics() { - //init(); } Physics::~Physics() { @@ -159,11 +158,16 @@ glm::mat4 Physics::getRotation(int i) return matrix; } -void Physics::rollForward(glm::mat3 rotCamera) +void Physics::rollForward(glm::vec3 camPos) { - glm::vec3 saveVector= glm::vec3(1,0,0) * rotCamera; + btVector3 pos(camPos.x,camPos.y,camPos.z); + pos -= playerBody->getCentreOfMassPosition(); + pos.cross(btVector3(0,1,0); + playerBall->applyTorque(pos); + +/* glm::vec3 saveVector= glm::vec3(1,0,0) * rotCamera; saveVector = glm::cross(glm::vec3(0,1,0),saveVector); - playerBall->applyTorque(btVector3(saveVector[0],saveVector[1],saveVector[2])); + playerBall->applyTorque(btVector3(saveVector[0],saveVector[1],saveVector[2]));*/ } /* diff --git a/physics.hh b/physics.hh index c3cbaca..c2d7774 100644 --- a/physics.hh +++ b/physics.hh @@ -39,7 +39,7 @@ class Physics { void rollForward(glm::vec3 camPos, float strength); glm::vec3 getPos(int i); glm::mat4 getRotation(int i); - void rollForward(glm::mat3 rotCamera); + void rollForward(glm::vec3 camPos); void addStaticGroundPlane(); void addTerrain(int width, int length, float** heightData); void addPlayer(float rad, float x, float y, float z, float mass, unsigned indice);