massive cleaning of file section headers
[physics.git] / src / Entities / PhysicsEntity.cpp
CommitLineData
ad9f1fb6 1#include "PhysicsEntity.h"
89ca62b2
PG
2#include "../debug.h"
3
f206d19d 4#include "../effectManager.h"
617dcc71
PG
5#include "../Vector2.h"
6
7
8/// ***** Constructors/Destructors *****
ad9f1fb6 9
5f1f55d1 10PhysicsEntity::PhysicsEntity(const Vector2& pos)
c58ffbb1 11 : Entity(pos), force(0,0), mass(1), CoR(1)
ad9f1fb6 12{
617dcc71 13
ad9f1fb6
PG
14}
15PhysicsEntity::~PhysicsEntity()
16{
617dcc71 17
ad9f1fb6
PG
18}
19
617dcc71
PG
20/// ***** Public Class Methods *****
21
ad9f1fb6
PG
22void PhysicsEntity::update(float time_step)
23{
24 position = positionAt(time_step);
25 velocity = velocityAt(time_step);
26
27 force *= 0;
28}
29
30Vector2 PhysicsEntity::positionAt(float time_step) const
31{
6aad402a
PG
32 Vector2 newPosition = position;
33 Vector2 newVelocity = velocity;
34 Vector2 newForce = force;
35
f206d19d
PG
36 newPosition += effect::positionDelta(this, time_step);
37 newVelocity += effect::velocityDelta(this, time_step);
38 newForce += effect::forceDelta(this, time_step);
6aad402a
PG
39
40 return newForce/mass / 2 * time_step * time_step + newVelocity * time_step + newPosition;
ad9f1fb6
PG
41}
42
43Vector2 PhysicsEntity::velocityAt(float time_step) const
44{
6aad402a
PG
45 Vector2 newForce = force;
46 Vector2 newVelocity = velocity;
47
f206d19d
PG
48 newForce += effect::forceDelta(this, time_step);
49 newVelocity += effect::velocityDelta(this, time_step);
6aad402a
PG
50
51 return newForce/mass / 2 * time_step + newVelocity;
ad9f1fb6
PG
52}
53
54void PhysicsEntity::applyForce(const Vector2& force)
55{
56 this->force += force;
57}
58
59void PhysicsEntity::applyImpulse(const Vector2& impluse)
60{
61 velocity += impluse;
62}