added collision masks and button creator
This commit is contained in:
parent
ba14a492f1
commit
c2634543dc
40
physics.cc
40
physics.cc
@ -87,7 +87,7 @@ void Physics::addTerrainTriangles(int width, int length, float** heightData)
|
|||||||
|
|
||||||
terrainBody = tBody;
|
terrainBody = tBody;
|
||||||
|
|
||||||
world->addRigidBody(tBody);
|
world->addRigidBody(tBody,COL_TERRAIN,COL_OBJECTS);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +145,7 @@ void Physics::addPlayer(float friction, float rad, Entity entity, float mass, fl
|
|||||||
|
|
||||||
playerBall->setDamping(dampningL, dampningA);
|
playerBall->setDamping(dampningL, dampningA);
|
||||||
|
|
||||||
world->addRigidBody(playerBall);
|
world->addRigidBody(playerBall,COL_OBJECTS,COL_OBJECTS|COL_OBJECTS_NO_TERRAIN|COL_TERRAIN);
|
||||||
|
|
||||||
bodies.push_back(playerBall);
|
bodies.push_back(playerBall);
|
||||||
|
|
||||||
@ -202,7 +202,7 @@ void Physics::addTriangleMeshBody(Entity entity, std::string path, float mass, f
|
|||||||
}
|
}
|
||||||
|
|
||||||
btBvhTriangleMeshShape* shape = new btBvhTriangleMeshShape(triMesh,true);
|
btBvhTriangleMeshShape* shape = new btBvhTriangleMeshShape(triMesh,true);
|
||||||
|
shape->setLocalScaling(btVector3(0.5f,0.5f,0.5f));
|
||||||
btDefaultMotionState* motion = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(entity.getPosition().x,entity.getPosition().y,entity.getPosition().z)));
|
btDefaultMotionState* motion = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(entity.getPosition().x,entity.getPosition().y,entity.getPosition().z)));
|
||||||
|
|
||||||
btVector3 inertia(0,0,0);
|
btVector3 inertia(0,0,0);
|
||||||
@ -226,6 +226,34 @@ void Physics::addTriangleMeshBody(Entity entity, std::string path, float mass, f
|
|||||||
throw std::invalid_argument( "Bodies out of Sync" );
|
throw std::invalid_argument( "Bodies out of Sync" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Physics::addButton(float radius, float height, Entity entity, float mass, float dampningL, float dampningA, unsigned indice)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(bodies.size() == indice)
|
||||||
|
throw std::invalid_argument( "Bodies out of Sync" );
|
||||||
|
btCylinderShape* shape = new btCylinderShape(btVector3(height/2, radius,radius));
|
||||||
|
btDefaultMotionState* motion = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(entity.getPosition().x,entity.getPosition().y,entity.getPosition().z)));
|
||||||
|
|
||||||
|
btVector3 inertia(0,0,0);
|
||||||
|
if(mass != 0.0)
|
||||||
|
{
|
||||||
|
shape->calculateLocalInertia((btScalar)mass,inertia);
|
||||||
|
}
|
||||||
|
|
||||||
|
btRigidBody::btRigidBodyConstructionInfo info(mass,motion,shape,inertia);
|
||||||
|
|
||||||
|
btRigidBody* body = new btRigidBody(info);
|
||||||
|
|
||||||
|
body->setDamping(dampningL, dampningA);
|
||||||
|
|
||||||
|
world->addRigidBody(body,COL_OBJECTS_NO_TERRAIN, specialPhysicsCollision);
|
||||||
|
|
||||||
|
bodies.push_back(body);
|
||||||
|
|
||||||
|
if(bodies.size() != indice)
|
||||||
|
throw std::invalid_argument( "Bodies out of Sync" );
|
||||||
|
}
|
||||||
|
|
||||||
void Physics::addBox(float width, float height, float length, Entity entity, float mass, float dampningL, float dampningA, unsigned indice)
|
void Physics::addBox(float width, float height, float length, Entity entity, float mass, float dampningL, float dampningA, unsigned indice)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -248,8 +276,8 @@ void Physics::addBox(float width, float height, float length, Entity entity, flo
|
|||||||
|
|
||||||
body->setDamping(dampningL, dampningA);
|
body->setDamping(dampningL, dampningA);
|
||||||
|
|
||||||
world->addRigidBody(body);
|
world->addRigidBody(body,COL_OBJECTS, objectsPhysicsCollision);
|
||||||
|
|
||||||
bodies.push_back(body);
|
bodies.push_back(body);
|
||||||
|
|
||||||
if(bodies.size() != indice)
|
if(bodies.size() != indice)
|
||||||
@ -277,7 +305,7 @@ void Physics::addSphere(float rad, Entity entity, float mass, float dampningL, f
|
|||||||
|
|
||||||
body->setDamping(dampningL, dampningA);
|
body->setDamping(dampningL, dampningA);
|
||||||
|
|
||||||
world->addRigidBody(body);
|
world->addRigidBody(body,COL_OBJECTS, objectsPhysicsCollision);
|
||||||
|
|
||||||
bodies.push_back(body);
|
bodies.push_back(body);
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "extern/bullet/src/BulletCollision/CollisionShapes/btTriangleMesh.h"
|
#include "extern/bullet/src/BulletCollision/CollisionShapes/btTriangleMesh.h"
|
||||||
#include "extern/bullet/src/BulletCollision/CollisionShapes/btCollisionShape.h"
|
#include "extern/bullet/src/BulletCollision/CollisionShapes/btCollisionShape.h"
|
||||||
#include "extern/bullet/src/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h"
|
#include "extern/bullet/src/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h"
|
||||||
|
#include "extern/bullet/src/BulletCollision/CollisionShapes/btCylinderShape.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!
|
||||||
@ -64,6 +65,7 @@ class Physics {
|
|||||||
void addBox(float width, float height, float length, Entity entity, float mass, float dampningL, float dampningA, unsigned indice); //this is used to ensuer that the system is synchronized
|
void addBox(float width, float height, float length, Entity entity, float mass, float dampningL, float dampningA, unsigned indice); //this is used to ensuer that the system is synchronized
|
||||||
void addPositionConstraint(int bodyIndice, float strength, glm::vec3 position);
|
void addPositionConstraint(int bodyIndice, float strength, glm::vec3 position);
|
||||||
void removePositionConstraint(int bodyIndice);
|
void removePositionConstraint(int bodyIndice);
|
||||||
|
void addButton(float radius, float height, Entity entity, float mass, float dampningL, float dampningA, unsigned indice);
|
||||||
|
|
||||||
struct positionConstraint{btRigidBody* body; float strength; btVector3 position;};
|
struct positionConstraint{btRigidBody* body; float strength; btVector3 position;};
|
||||||
|
|
||||||
@ -80,6 +82,10 @@ class Physics {
|
|||||||
btCollisionConfiguration* colConfig; //defines the type of collision detection.
|
btCollisionConfiguration* colConfig; //defines the type of collision detection.
|
||||||
btBroadphaseInterface* broadphase; //defines how objects are culled from collision detection.
|
btBroadphaseInterface* broadphase; //defines how objects are culled from collision detection.
|
||||||
btConstraintSolver* solver; //solver for forces and impulses.
|
btConstraintSolver* solver; //solver for forces and impulses.
|
||||||
|
int objectsPhysicsCollision = 1 | 2 | 4;
|
||||||
|
int specialPhysicsCollision = 2 | 4;
|
||||||
|
int terrainPhysicsCollision = 2;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum collisionTypes{
|
enum collisionTypes{
|
||||||
@ -89,6 +95,7 @@ enum collisionTypes{
|
|||||||
COL_OBJECTS_NO_TERRAIN = 4
|
COL_OBJECTS_NO_TERRAIN = 4
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//world->addRigidBody(playerBall,COL_OBJECTS_NO_TERRAIN, COL_OBJECTS);
|
||||||
class btDistanceConstraint : public btPoint2PointConstraint
|
class btDistanceConstraint : public btPoint2PointConstraint
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
Loading…
Reference in New Issue
Block a user