-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathPhysics.h
73 lines (55 loc) · 2.81 KB
/
Physics.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// +------------------------------------------------------------+
// | University Racer |
// | Projekt do PGR a GMU, FIT VUT v Brne, 2011 |
// +------------------------------------------------------------+
// | Autori: Tomáš Kimer, [email protected] |
// | Tomáš Sychra, [email protected] |
// | David Šabata, [email protected] |
// +------------------------------------------------------------+
#ifndef PHYSICS_H
#define PHYSICS_H
#include <btBulletDynamicsCommon.h>
#include <glm/gtc/type_ptr.hpp>
#include "PhysicsUtils.h"
#include "PhysicsCar.h"
#include "PhysicsCheckpoint.h"
#include "PhysicsDebugDraw.h"
#include "BaseModel.h"
#define FIXED_SIMULATION_TIMESTEP 1/120.f /// pevny simulacni krok
#define MAX_SIMULATION_SUBSTEPS 10 /// maximum simulacnich podkroku
/**
* Zapouzdruje veskerou praci s fyzikalni simulaci pomoci knihovny Bullet Physics (http://bulletphysics.org/).
* Cerpano z Bullet 2.79 Physics SDK Manual a Bullet demos, konkretne VehicleDemo.
* Oboji lze nalezt v archivu http://code.google.com/p/bullet/downloads/detail?name=bullet-2.79-rev2440.zip
* Dale vyuzity stranky knihovny, konkretne wiki a fora.
*/
class Physics
{
public:
Physics(void);
~Physics(void);
void Initialize();
void Deinitialize();
void StepSimulation(btScalar timeStep);
btRigidBody * AddRigidBody(float mass, const btTransform & startTransform, btCollisionShape * shape);
void DebugDrawWorld() { m_dynamicsWorld->debugDrawWorld(); }
static btCollisionShape * CreateStaticCollisionShape(Mesh * mesh, const btVector3 & scale = btVector3(1,1,1));
static std::vector<btCollisionShape *> CreateStaticCollisionShapes(BaseModel * model, const btVector3 & scale);
static std::vector<btCollisionShape *> CreateStaticCollisionShapes(BaseModel * model, float scale = 1.f);
void AddStaticModel(std::vector<btCollisionShape *> & collisionShapes, const btTransform & trans, bool debugDraw = true, const btVector3 & scale = btVector3(1,1,1));
PhysicsCar * GetCar() { return m_car; }
PhysicsCheckpoint & Checkpoint() { return m_checkpoint; }
PhysicsDebugDraw *GetDebugDrawer() { return m_debugDraw; }
btDiscreteDynamicsWorld * GetDynamicsWorld() { return m_dynamicsWorld; }
void AddCar(const btTransform & trans) { (m_car = new PhysicsCar())->Initialize(m_dynamicsWorld, trans); }
private:
btCollisionDispatcher* m_dispatcher;
btBroadphaseInterface* m_overlappingPairCache;
btSequentialImpulseConstraintSolver* m_constraintSolver;
btDefaultCollisionConfiguration* m_collisionConfiguration;
btDiscreteDynamicsWorld *m_dynamicsWorld;
PhysicsCar *m_car;
PhysicsCheckpoint m_checkpoint;
PhysicsDebugDraw *m_debugDraw;
};
#endif