-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRockPhysicsComponent.cpp
More file actions
51 lines (38 loc) · 1.74 KB
/
RockPhysicsComponent.cpp
File metadata and controls
51 lines (38 loc) · 1.74 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
#ifndef ROCKPHYSICSCOMPONENT_CPP
#define ROCKPHYSICSCOMPONENT_CPP
#include <math.h>
#include <GL/gl.h>
#include "RockPhysicsComponent.hpp"
#define PI 3.1415926535898
void RockPhysicsComponent::propagate(double const dt)
// Do basic propagation (integration of speed and spin)
{
// attenuate the speeds with the decay
GLfloat spinspeed_size = fabs(_spinspeed);
GLfloat spinspeed_sign = (_spinspeed >= 0.0) ? 1.0 : -1.0;
spinspeed_size -= decceleration_spin* dt; // decay the rotational speed
if (spinspeed_size <= state0)
spinspeed_size = state0; // make sure that the spin is really in the state
_spinspeed = spinspeed_sign * spinspeed_size;
_movespeed -= decceleration_move* dt;
if (_movespeed <= state0)
_movespeed = state0;
// integrate the spin over dt
_orientation += _spinspeed * dt;
if (_orientation > 360.0)
_orientation -= 360.0;
// adjust position according to orientation and speed
_pos_x += _movespeed * sin(2*PI*(_orientation/360.0)) * dt;
_pos_y += _movespeed * cos(2*PI*(_orientation/360.0)) * dt;
}
// constructors
RockPhysicsComponent::RockPhysicsComponent() :
base_class(), _radius(MAX_RADIUS) {};
RockPhysicsComponent::RockPhysicsComponent(GLfloat const radius) :
base_class(), _radius(radius) {};
RockPhysicsComponent::RockPhysicsComponent( GLfloat const pos_x, GLfloat const pos_y,
GLfloat const orientation,
GLfloat const movespeed, GLfloat const spinspeed,
GLfloat const radius) :
base_class(pos_x, pos_y, orientation, movespeed, spinspeed), _radius(radius) {};
#endif /* RockPhysicsComponent class implementation */