-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForceMotion.h
More file actions
60 lines (45 loc) · 1.18 KB
/
Copy pathForceMotion.h
File metadata and controls
60 lines (45 loc) · 1.18 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
#pragma once
#include "Vector2D.h"
class ForceMotion {
private:
float m_mass; // object's mass
Vector2D m_velocity; // object's velocity
Vector2D m_force; // force applied to the object
Vector2D* m_pPosition;
public:
// constructor
ForceMotion(float m, Vector2D* position) {
m_mass = m;
m_velocity = Vector2D(0, 0);
m_force = Vector2D(0, 0);
m_pPosition = position;
}
// method to clear force - do this each frame
void clearForce() {
m_force = Vector2D(0,0);
}
// method to apply force
void applyForce(Vector2D f) {
m_force = (f);
}
// method to accummulate force
void accummulateForce(Vector2D f) {
m_force += (f);
}
void update(double dt) {
updateVelocity(dt);
updatePosition(dt);
}
// method to update object's velocity
void updateVelocity(double dt) {
m_velocity = (m_force / m_mass) * dt;
}
// method to update object's position
void updatePosition(double dt) {
*m_pPosition += m_velocity * dt;
}
// getter for velocity
Vector2D getVelocity() {
return m_velocity;
}
};