-
Notifications
You must be signed in to change notification settings - Fork 0
/
RigidBody.hpp
54 lines (44 loc) · 1.1 KB
/
RigidBody.hpp
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
#ifndef RIGIDBODY
#define RIGIDBODY
#include "Transform.hpp"
#include <glm/glm.hpp>
#include "ODE.hpp"
#include "helpers.hpp"
using namespace glm;
typedef struct
{
vec3 x;
mat3 R;
vec3 P;
vec3 L;
} State;
class RigidBody
{
private:
// constants
float mass;
mat3 Ibody;
mat3 Ibodyinv;
// state variables
vec3 x; // displacement of CM from origin
mat3 R; // Orientation
vec3 P; // Linear momentum
vec3 L; // Angular momentum
// derived quantities
mat3 Iinv;
vec3 v; // linear velocity
vec3 omega; // angular velocity
vec3 force;
vec3 torque;
// for drawing (assuming rigid body is a cube)
float size;
public:
RigidBody();
void reset(); // reset to original state
void sim_step(float dt); // simulate one step forward
mat3 dRdt(float t, mat3 R);
vec3 dxdt(float t, vec3 M);
State getState();
mat4 getTransformation(); // returns the transformation matrix from origin
};
#endif