From 263f59f000dd403b7d58e5b8d0bb4203d64bc1e7 Mon Sep 17 00:00:00 2001 From: Jasper Date: Fri, 21 Nov 2014 12:31:29 +0100 Subject: [PATCH] Normalized body movement (still has float strength to change magnitude) --- physics.cc | 35 +++++++++++++---------------------- physics.hh | 1 + 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/physics.cc b/physics.cc index c7cadaf..ecb3326 100644 --- a/physics.cc +++ b/physics.cc @@ -31,8 +31,7 @@ void Physics::init() } void Physics::takeUpdateStep(float timeDiff) -{ - +{ world->stepSimulation(timeDiff); } @@ -52,11 +51,6 @@ void Physics::addTerrain(int width, int length, float** heightData) } highest++; - /* - heightfield[j*length+i] = heightData[i][j]; - if (heightData[i][j] > highest) - highest = heightData[i][j]; - */ btHeightfieldTerrainShape* terrianShape = new btHeightfieldTerrainShape(length,width,heightfield,highest,1,true,false); @@ -69,21 +63,6 @@ void Physics::addTerrain(int width, int length, float** heightData) terrainBody = tBody; world->addRigidBody(terrainBody); - -/* - terrianShape->setLocalScaling(btVector3(1,1,1)); - btCollisionShape* trimeshShape = terrianShape; - - float mass = 0.f; - btTransform startTransform; - startTransform.setIdentity(); - startTransform.setOrigin(btVector3(0,highest/2,0));//not 100% sure maybe (0,0,0) or (0,-highest/2,0) - - btRigidBody* groundBody = localCreateRigidBody(mass, startTransform,trimeshShape); - - world->addRigidBody(terrainBody); - */ - } void Physics::addStaticGroundPlane() @@ -126,6 +105,10 @@ void Physics::addPlayer(float rad, float x, float y, float z, float mass, unsign } +void Physics::addBox() +{ + +} void Physics::addSphere(float rad, float x, float y, float z, float mass, unsigned indice) { @@ -178,26 +161,34 @@ glm::mat4 Physics::getRotation(int i) void Physics::rollForward(glm::vec3 camPos,float strength) { btVector3 pos(camPos.x,0,camPos.z); + pos.normalize(); pos = btCross(pos,btVector3(0,1,0)); + pos *= strength; playerBall->applyTorque(pos); } void Physics::rollBack(glm::vec3 camPos,float strength) { btVector3 pos(camPos.x,0,camPos.z); + pos.normalize(); pos = btCross(btVector3(0,1,0),pos); + pos *= strength; playerBall->applyTorque(pos); } void Physics::rollLeft(glm::vec3 camPos,float strength) { btVector3 pos(camPos.x,0,camPos.z); + pos.normalize(); + pos *= strength; playerBall->applyTorque(pos); } void Physics::rollRight(glm::vec3 camPos,float strength) { btVector3 pos(camPos.x,0,camPos.z); + pos.normalize(); + pos *= strength; playerBall->applyTorque(-pos); } diff --git a/physics.hh b/physics.hh index 42abad2..10a0a8f 100644 --- a/physics.hh +++ b/physics.hh @@ -47,6 +47,7 @@ class Physics { void addTerrain(int width, int length, float** heightData); void addPlayer(float rad, float x, float y, float z, float mass, unsigned indice); void addSphere(float rad, float x, float y, float z, float mass, unsigned indice); + void addBox(); private: btRigidBody* playerBody;