-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModulePhysics3D.h
97 lines (76 loc) · 2.57 KB
/
ModulePhysics3D.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#pragma once
#include "Module.h"
#include "Globals.h"
#include "p2List.h"
#include "Primitive.h"
#include "Bullet/include/btBulletDynamicsCommon.h"
// Recommended scale is 1.0f == 1 meter, no less than 0.2 objects
#define GRAVITY btVector3(0.0f, -10.0f, 0.0f)
class DebugDrawer;
struct PhysBody3D;
struct PhysVehicle3D;
struct VehicleInfo;
class ModulePhysics3D : public Module
{
public:
ModulePhysics3D(Application* app, bool start_enabled = true);
~ModulePhysics3D();
bool Init();
bool Start();
update_status PreUpdate(float dt);
update_status Update(float dt);
update_status PostUpdate(float dt);
bool CleanUp();
PhysBody3D* AddBody(const Sphere& sphere, float mass = 1.0f);
PhysBody3D* AddBody(const Cube& cube, float mass = 1.0f, bool sensor = false);
PhysBody3D* AddBody(const Cylinder& cylinder, float mass = 1.0f);
PhysVehicle3D* AddVehicle(const VehicleInfo& info);
void AddConstraintP2P(PhysBody3D& bodyA, PhysBody3D& bodyB, const vec3& anchorA, const vec3& anchorB);
void AddConstraintHinge(PhysBody3D& bodyA, PhysBody3D& bodyB, const vec3& anchorA, const vec3& anchorB, const vec3& axisS, const vec3& axisB, bool disable_collision = false);
p2List<PhysBody3D*> GetPhysBodyList() { return this->bodies; }
p2List<PhysVehicle3D*>* GetPhysVehicles() { return &this->vehicles; }
private:
btDefaultCollisionConfiguration* collision_conf;
btCollisionDispatcher* dispatcher;
btBroadphaseInterface* broad_phase;
btSequentialImpulseConstraintSolver* solver;
btDiscreteDynamicsWorld* world;
btDefaultVehicleRaycaster* vehicle_raycaster;
DebugDrawer* debug_draw;
p2List<btCollisionShape*> shapes;
p2List<PhysBody3D*> bodies;
p2List<btDefaultMotionState*> motions;
p2List<btTypedConstraint*> constraints;
p2List<PhysVehicle3D*> vehicles;
public:
//flags/debug
bool debug;
bool drawWorld;
bool freeCamera;
btVector3 gravity;
bool gravityON;
btScalar bodyMass;
float clayDragForce;
float coeficientDragClay;
bool dragOn;
float aeroLiftForce;
float coeficientLiftAero;
bool liftOn;
int goalcount;
bool goal;
};
class DebugDrawer : public btIDebugDraw
{
public:
DebugDrawer() : line(0,0,0)
{}
void drawLine(const btVector3& from, const btVector3& to, const btVector3& color);
void drawContactPoint(const btVector3& PointOnB, const btVector3& normalOnB, btScalar distance, int lifeTime, const btVector3& color);
void reportErrorWarning(const char* warningString);
void draw3dText(const btVector3& location, const char* textString);
void setDebugMode(int debugMode);
int getDebugMode() const;
DebugDrawModes mode;
Line line;
Primitive point;
};