change Vector2 param to a const Vector2&
[physics.git] / src / Entities / PhysicsEntity.cpp
CommitLineData
ad9f1fb6
PG
1#include "PhysicsEntity.h"
2#include "../Vector2.h"
3
4/// ***** Public Class Methods *****
5f1f55d1 5PhysicsEntity::PhysicsEntity(const Vector2& pos)
ad9f1fb6
PG
6 : Entity(pos)
7{
8
9}
10PhysicsEntity::~PhysicsEntity()
11{
12
13}
14
15void PhysicsEntity::update(float time_step)
16{
17 position = positionAt(time_step);
18 velocity = velocityAt(time_step);
19
20 force *= 0;
21}
22
23Vector2 PhysicsEntity::positionAt(float time_step) const
24{
25 return force/mass / 2 * time_step * time_step + velocity * time_step + position;
26}
27
28Vector2 PhysicsEntity::velocityAt(float time_step) const
29{
30 return force/mass / 2 * time_step + velocity;
31}
32
33void PhysicsEntity::applyForce(const Vector2& force)
34{
35 this->force += force;
36}
37
38void PhysicsEntity::applyImpulse(const Vector2& impluse)
39{
40 velocity += impluse;
41}