From 3fcd677dd5e2c15a8fe304bf747a6084c6ffe8cf Mon Sep 17 00:00:00 2001 From: Jasper Date: Fri, 28 Nov 2014 16:46:35 +0100 Subject: [PATCH] Added basic Triangle Mesh, pending reading out of .obj and then testing. --- physics.cc | 34 ++++++++++++++++++++++++++++------ physics.hh | 3 +++ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/physics.cc b/physics.cc index c9cc895..0da8d65 100644 --- a/physics.cc +++ b/physics.cc @@ -118,11 +118,7 @@ void Physics::addBox(float width, float height, float length, Entity entity, flo world->addRigidBody(body); bodies.push_back(body); - - if(mass != 0) - body->setSleepingThresholds(0,0); - - + if(bodies.size() != indice) throw std::invalid_argument( "Bodies out of Sync" ); } @@ -159,6 +155,32 @@ void Physics::addSphere(float rad, Entity entity, float mass, unsigned indice) } +void Physics::addTriangleMeshBody(Entity entity, float mass, float dampningL, float dampningA,unsigned indice) +{ + btTriangleMesh* trimesh = new btTriangleMesh(); + + btVector3* v0 = new btVector3( 0, 0, 0); + btVector3* v1 = new btVector3( 1, 1, 1); + btVector3* v2 = new btVector3( 2, 2, 2); + + trimesh->addTriangle( *v0, *v1, *v2 ); + + btTriangleMeshShape* shape = new btBvhTriangleMeshShape(trimesh,true); + btVector3 inertia(0,0,0); + if(mass != 0.0) + { + shape->calculateLocalInertia((btScalar)mass,inertia); + } + + btDefaultMotionState* motion = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(entity.getPosition().x,entity.getPosition().y,entity.getPosition().z))); + + btRigidBody::btRigidBodyConstructionInfo info(mass,motion,shape,inertia); + btRigidBody* body = new btRigidBody(info); + + body->setDamping(dampningL,dampningA); + +} + void Physics::addCamera(float rad, float distance) { btSphereShape* sphere = new btSphereShape(rad); @@ -170,7 +192,7 @@ void Physics::addCamera(float rad, float distance) cameraBody = new btRigidBody(info); - cameraBody->setDamping(0.2f,0.4f); + cameraBody->setDamping(0.9f,1.0f); world->addRigidBody(cameraBody); diff --git a/physics.hh b/physics.hh index 8ba675d..9eff59c 100644 --- a/physics.hh +++ b/physics.hh @@ -15,6 +15,8 @@ #include "extern/bullet/src/BulletCollision/CollisionShapes/btBoxShape.h" #include "extern/bullet/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h" #include "extern/bullet/src/BulletCollision/CollisionShapes/btStaticPlaneShape.h" +#include "extern/bullet/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h" +#include "extern/bullet/src/BulletCollision/CollisionShapes/btTriangleMesh.h" #include "extern/bullet/src/BulletDynamics/ConstraintSolver/btConstraintSolver.h" #include "extern/bullet/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h"//YAY! @@ -49,6 +51,7 @@ class Physics { void addStaticGroundPlane(); void addCamera(float rad,float distance); //Do NOT impliment before Player has been created; glm::vec3 getCameraPosition(); + void addTriangleMeshBody(Entity entity, float mass, float dampningL, float dampningA,unsigned indice); void addTerrain(int width, int length, float** heightData); void addPlayer(float rad, Entity entity, float mass, unsigned indice); //use these AFTER physicObjects.push_back(object)! if mass == 0 then the object is unmoveable void addSphere(float rad, Entity entity, float mass, unsigned indice); //The Indice should be set to physicObjects.size()