forked from PrototypeX29A/norbit
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathphysics.h
More file actions
135 lines (86 loc) · 2.61 KB
/
physics.h
File metadata and controls
135 lines (86 loc) · 2.61 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*----------------------------------------------------------------------------
2D Physics Test Program - a cheesy test harness for 2D physics
by Chris Hecker for my Game Developer Magazine articles. See my homepage
for more information.
NOTE: This is a hacked test program, not a nice example of Windows programming.
physics.cpp the only part of this you should look at!!!
This material is Copyright 1997 Chris Hecker, All Rights Reserved.
It's for you to read and learn from, not to put in your own articles
or books or on your website, etc. Thank you.
Chris Hecker
checker@d6.com
http://www.d6.com/users/checker
*/
/*----------------------------------------------------------------------------
physics.h - The header for the physics demo.
10/15/96 - checker
*/
#if !defined(PHYSICS_H)
#define PHYSICS_H
#include <vector>
#include "math2d.h"
/*----------------------------------------------------------------------------
Declarations for physics code.
*/
struct rigid_body
{
rigid_body ();
real OneOverMass, OneOverCMMomentOfInertia;
float Mass;
enum
{ NumberOfConfigurations = 2 };
struct configuration
{
vector_2 CMPosition;
real Orientation;
vector_2 CMVelocity;
real AngularVelocity;
vector_2 CMForce;
real Torque;
} aConfigurations[NumberOfConfigurations];
void apply_force (vector_2 const &F, vector_2 const &Pl);
void apply_force_G (vector_2 const &F, vector_2 const &Pl);
int SourceConfigurationIndex;
int TargetConfigurationIndex;
};
class simulation_world
{
public:
simulation_world ();
void Simulate (real DeltaTime);
void Render (void);
rigid_body *add_body (real Mass);
~simulation_world (void);
/*----------------------------------------------------------------------------
various forces you can add to the system
@todo need to figure out units here so these numbers mean something
*/
// World Spring
vector_2 WorldSpringAnchor;
static real const Kws = 3.0f; // Hooke's spring constant
static real const Kwd = 0.5f;
//BodySpring
static real const Kbs = 1.0f; // Hooke's spring constant
static real const Kbd = 0.5f; // damping constant
// Damping
static real const Kdl = 2.50f; // linear damping factor
static real const Kda = 140.0f; // angular damping factor
std::vector < rigid_body * >aBodies;
int NumberOfBodies ()
{
return aBodies.size ();
}
private:
enum collision_state
{
Penetrating,
Colliding,
Clear
} CollisionState;
vector_2 CollisionNormal;
int CollidingBodyIndex;
int CollidingCornerIndex;
void ResetForces ();
void Integrate (real DeltaTime);
};
#endif