1 #include "PhysicsEntity.h"
4 #include "../Vector2.h"
5 #include "../Effects/Effect.h"
6 #include "../Effects/Gravity.h"
8 /// ***** Public Class Methods *****
9 PhysicsEntity::PhysicsEntity(const Vector2& pos)
10 : Entity(pos), force(0,0), mass(1), CoR(1)
14 PhysicsEntity::~PhysicsEntity()
19 void PhysicsEntity::update(float time_step)
21 position = positionAt(time_step);
22 velocity = velocityAt(time_step);
27 Vector2 PhysicsEntity::positionAt(float time_step) const
29 Vector2 newPosition = position;
30 Vector2 newVelocity = velocity;
31 Vector2 newForce = force;
33 newPosition += g->positionDelta(this, time_step);
34 newVelocity += g->velocityDelta(this, time_step);
35 newForce += g->forceDelta(this, time_step);
37 return newForce/mass / 2 * time_step * time_step + newVelocity * time_step + newPosition;
40 Vector2 PhysicsEntity::velocityAt(float time_step) const
42 Vector2 newForce = force;
43 Vector2 newVelocity = velocity;
45 newForce += g->forceDelta(this, time_step);
46 newVelocity += g->velocityDelta(this, time_step);
48 return newForce/mass / 2 * time_step + newVelocity;
51 void PhysicsEntity::applyForce(const Vector2& force)
56 void PhysicsEntity::applyImpulse(const Vector2& impluse)