Added basic Triangle Mesh, pending reading out of .obj and then testing.
This commit is contained in:
parent
594f336204
commit
ad61969176
32
physics.cc
32
physics.cc
@ -119,10 +119,6 @@ void Physics::addBox(float width, float height, float length, Entity entity, flo
|
|||||||
|
|
||||||
bodies.push_back(body);
|
bodies.push_back(body);
|
||||||
|
|
||||||
if(mass != 0)
|
|
||||||
body->setSleepingThresholds(0,0);
|
|
||||||
|
|
||||||
|
|
||||||
if(bodies.size() != indice)
|
if(bodies.size() != indice)
|
||||||
throw std::invalid_argument( "Bodies out of Sync" );
|
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)
|
void Physics::addCamera(float rad, float distance)
|
||||||
{
|
{
|
||||||
btSphereShape* sphere = new btSphereShape(rad);
|
btSphereShape* sphere = new btSphereShape(rad);
|
||||||
@ -170,7 +192,7 @@ void Physics::addCamera(float rad, float distance)
|
|||||||
|
|
||||||
cameraBody = new btRigidBody(info);
|
cameraBody = new btRigidBody(info);
|
||||||
|
|
||||||
cameraBody->setDamping(0.2f,0.4f);
|
cameraBody->setDamping(0.9f,1.0f);
|
||||||
|
|
||||||
world->addRigidBody(cameraBody);
|
world->addRigidBody(cameraBody);
|
||||||
|
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
#include "extern/bullet/src/BulletCollision/CollisionShapes/btBoxShape.h"
|
#include "extern/bullet/src/BulletCollision/CollisionShapes/btBoxShape.h"
|
||||||
#include "extern/bullet/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h"
|
#include "extern/bullet/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h"
|
||||||
#include "extern/bullet/src/BulletCollision/CollisionShapes/btStaticPlaneShape.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/btConstraintSolver.h"
|
||||||
#include "extern/bullet/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h"//YAY!
|
#include "extern/bullet/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h"//YAY!
|
||||||
@ -49,6 +51,7 @@ class Physics {
|
|||||||
void addStaticGroundPlane();
|
void addStaticGroundPlane();
|
||||||
void addCamera(float rad,float distance); //Do NOT impliment before Player has been created;
|
void addCamera(float rad,float distance); //Do NOT impliment before Player has been created;
|
||||||
glm::vec3 getCameraPosition();
|
glm::vec3 getCameraPosition();
|
||||||
|
void addTriangleMeshBody(Entity entity, float mass, float dampningL, float dampningA,unsigned indice);
|
||||||
void addTerrain(int width, int length, float** heightData);
|
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 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()
|
void addSphere(float rad, Entity entity, float mass, unsigned indice); //The Indice should be set to physicObjects.size()
|
||||||
|
Loading…
Reference in New Issue
Block a user