X-Git-Url: http://gitweb.pgornicz.com/gitweb.cgi?a=blobdiff_plain;f=src%2FEntities%2FPhysicsEntity.cpp;h=fba6a898dedb3f60fffec4629fe8e8ac9fcb6a18;hb=f206d19d6b5baa4cb25ba77726f1fd4fcd7492e3;hp=2eadc345d3a4a0d0b94ab9b1a49d589409b8b4cf;hpb=ad9f1fb6bdfc51df61a7fb52d607ca0c0bceca4c;p=physics.git diff --git a/src/Entities/PhysicsEntity.cpp b/src/Entities/PhysicsEntity.cpp index 2eadc34..fba6a89 100644 --- a/src/Entities/PhysicsEntity.cpp +++ b/src/Entities/PhysicsEntity.cpp @@ -1,15 +1,16 @@ #include "PhysicsEntity.h" +#include "../debug.h" + #include "../Vector2.h" +#include "../effectManager.h" /// ***** Public Class Methods ***** -PhysicsEntity::PhysicsEntity(Vector2 pos) - : Entity(pos) +PhysicsEntity::PhysicsEntity(const Vector2& pos) + : Entity(pos), force(0,0), mass(1), CoR(1) { - } PhysicsEntity::~PhysicsEntity() { - } void PhysicsEntity::update(float time_step) @@ -22,12 +23,26 @@ void PhysicsEntity::update(float time_step) Vector2 PhysicsEntity::positionAt(float time_step) const { - return force/mass / 2 * time_step * time_step + velocity * time_step + position; + Vector2 newPosition = position; + Vector2 newVelocity = velocity; + Vector2 newForce = force; + + newPosition += effect::positionDelta(this, time_step); + newVelocity += effect::velocityDelta(this, time_step); + newForce += effect::forceDelta(this, time_step); + + return newForce/mass / 2 * time_step * time_step + newVelocity * time_step + newPosition; } Vector2 PhysicsEntity::velocityAt(float time_step) const { - return force/mass / 2 * time_step + velocity; + Vector2 newForce = force; + Vector2 newVelocity = velocity; + + newForce += effect::forceDelta(this, time_step); + newVelocity += effect::velocityDelta(this, time_step); + + return newForce/mass / 2 * time_step + newVelocity; } void PhysicsEntity::applyForce(const Vector2& force)