X-Git-Url: http://gitweb.pgornicz.com/gitweb.cgi?a=blobdiff_plain;f=src%2FEntities%2FPhysicsEntity.cpp;h=752d5eb63a8069fbe47b9dc7447574bdeb49a867;hb=389bf8fdd7e1b8f4fe21e5a9fdb477d40d03d829;hp=9daff3a0bb58ca788651eca2186d0af6743ec261;hpb=3d1f081343dc603a3292538eeb9bd794b255deb6;p=physics.git diff --git a/src/Entities/PhysicsEntity.cpp b/src/Entities/PhysicsEntity.cpp index 9daff3a..752d5eb 100644 --- a/src/Entities/PhysicsEntity.cpp +++ b/src/Entities/PhysicsEntity.cpp @@ -16,16 +16,18 @@ */ #include "PhysicsEntity.h" -#include "debug.h" + +#include +#include +using namespace bear; #include "effectManager.h" -#include "Vector2.h" /// ***** Constructors/Destructors ***** PhysicsEntity::PhysicsEntity(const Vector2& pos) - : Entity(pos), force(0,0), mass(1), CoR(0.8) + : Entity(pos), m_force(0,0), m_mass(1), m_CoR(0.8) { } @@ -38,50 +40,55 @@ PhysicsEntity::~PhysicsEntity() void PhysicsEntity::update(float time_step) { - position = positionAt(time_step); - velocity = velocityAt(time_step); + m_position = positionAt(time_step); + m_velocity = velocityAt(time_step); - force *= 0; + m_force *= 0; } Vector2 PhysicsEntity::positionAt(float time_step) const { - Vector2 newPosition = position; - Vector2 newVelocity = velocity; - Vector2 newForce = force; + Vector2 newPosition = m_position; + Vector2 newVelocity = m_velocity; + Vector2 newForce = m_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; + return newForce/m_mass / 2 * time_step * time_step + newVelocity * time_step + newPosition; } Vector2 PhysicsEntity::velocityAt(float time_step) const { - Vector2 newForce = force; - Vector2 newVelocity = velocity; + Vector2 newForce = m_force; + Vector2 newVelocity = m_velocity; newForce += effect::forceDelta(this, time_step); newVelocity += effect::velocityDelta(this, time_step); - return newForce/mass / 2 * time_step + newVelocity; + return newForce/m_mass / 2 * time_step + newVelocity; } void PhysicsEntity::applyForce(const Vector2& force) { - applyForce(force, position); + applyForce(force, m_position); } -void PhysicsEntity::applyForce(const Vector2& force, const Vector2& at) +void PhysicsEntity::applyForce(const Vector2& force, const Vector2& /*at*/) { - this->force += force; + this->m_force += force; } void PhysicsEntity::applyImpulse(const Vector2& impulse) { - applyImpulse(impulse, position); + applyImpulse(impulse, m_position); +} +void PhysicsEntity::applyImpulse(const Vector2& impulse, const Vector2& /*at*/) +{ + m_velocity += impulse; } -void PhysicsEntity::applyImpulse(const Vector2& impulse, const Vector2& at) + +void PhysicsEntity::applyNudge(const Vector2& vecPush) { - velocity += impulse; + m_position += vecPush; }