Commit | Line | Data |
---|---|---|
ad9f1fb6 | 1 | #include "PhysicsEntity.h" |
89ca62b2 PG |
2 | #include "../debug.h" |
3 | ||
ad9f1fb6 PG |
4 | #include "../Vector2.h" |
5 | ||
6 | /// ***** Public Class Methods ***** | |
5f1f55d1 | 7 | PhysicsEntity::PhysicsEntity(const Vector2& pos) |
c58ffbb1 | 8 | : Entity(pos), force(0,0), mass(1), CoR(1) |
ad9f1fb6 PG |
9 | { |
10 | ||
11 | } | |
12 | PhysicsEntity::~PhysicsEntity() | |
13 | { | |
14 | ||
15 | } | |
16 | ||
17 | void PhysicsEntity::update(float time_step) | |
18 | { | |
19 | position = positionAt(time_step); | |
20 | velocity = velocityAt(time_step); | |
21 | ||
22 | force *= 0; | |
23 | } | |
24 | ||
25 | Vector2 PhysicsEntity::positionAt(float time_step) const | |
26 | { | |
27 | return force/mass / 2 * time_step * time_step + velocity * time_step + position; | |
28 | } | |
29 | ||
30 | Vector2 PhysicsEntity::velocityAt(float time_step) const | |
31 | { | |
32 | return force/mass / 2 * time_step + velocity; | |
33 | } | |
34 | ||
35 | void PhysicsEntity::applyForce(const Vector2& force) | |
36 | { | |
37 | this->force += force; | |
38 | } | |
39 | ||
40 | void PhysicsEntity::applyImpulse(const Vector2& impluse) | |
41 | { | |
42 | velocity += impluse; | |
43 | } |