-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModulePhysics.h
86 lines (64 loc) · 2.03 KB
/
ModulePhysics.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
#pragma once
#include "Module.h"
#include "Globals.h"
#include "Box2D/Box2D/Box2D.h"
#define GRAVITY_X 0.0f
//#define GRAVITY_Y -7.0f
#define PIXELS_PER_METER 50.0f // if touched change METER_PER_PIXEL too
#define METER_PER_PIXEL 0.02f // this is 1 / PIXELS_PER_METER !
#define METERS_TO_PIXELS(m) ((int) floor(PIXELS_PER_METER * m))
#define PIXEL_TO_METERS(p) ((float) METER_PER_PIXEL * p)
// Small class to return to other modules to track position and rotation of physics bodies
class Prop;
class PhysBody
{
public:
PhysBody();
~PhysBody();
void GetPosition(int& x, int& y) const;
float GetRotation() const;
bool Contains(int x, int y) const;
int RayCast(int x1, int y1, int x2, int y2, float& normal_x, float& normal_y) const;
public:
int width, height;
b2Body* body;
Module* listener;
Prop* prop;
};
// Module --------------------------------------
class ModulePhysics : public Module, public b2ContactListener // TODO
{
public:
// Constructors & Destructors
ModulePhysics(Application* app, bool start_enabled = true);
~ModulePhysics();
// Main module steps
bool Start();
update_status PreUpdate();
update_status PostUpdate();
bool CleanUp();
// Create main ground
//void CreateScenarioGround();
// Create basic physics objects
PhysBody* CreateCircle(int x, int y, int radius);
PhysBody* CreateRectangle(int x, int y, int width, int height);
PhysBody* CreateRectangleSensor(int x, int y, int width, int height);
PhysBody* CreateChain(int x, int y, int* points, int size);
b2RevoluteJoint* CreateRevoluteJoint(PhysBody* pBody1, PhysBody* pBody2, float anchorX, float anchorY);
b2PrismaticJoint* CreatePrismaticJoint(PhysBody* pBody1, PhysBody* pBody2, float anchorX, float anchorY, b2Vec2 axis);
// b2ContactListener ---
void BeginContact(b2Contact* contact);
void EndContact(b2Contact* contact);
private:
// Debug mode
bool debug;
// Box2D World
b2World* world;
float GRAVITY_Y = 5.0f;
// Main ground
b2Body* worldBody;
// Mouse joint
b2MouseJoint* mouse_joint;
b2Body* mouse_body;
friend class ModuleDebug;
};