#define EFFECT_H
#include "../Vector2.h"
-#include "../Entities/PhysicsEntity.h"
+
+//#include "../Entities/PhysicsEntity.h"
+class PhysicsEntity;
/// ***** Header Class *****
class Effect
}
-Vector2 Gravity::positionDelta(const PhysicsEntity*, float)
+Vector2 Gravity::positionDelta(const PhysicsEntity*, float) const
{
return Vector2(0, 0);
}
-Vector2 Gravity::velocityDelta(const PhysicsEntity*, float)
+Vector2 Gravity::velocityDelta(const PhysicsEntity*, float) const
{
return Vector2(0, 0);
}
-Vector2 Gravity::forceDelta(const PhysicsEntity*, float)
+Vector2 Gravity::forceDelta(const PhysicsEntity*, float) const
{
- return Vector2(0, 0.000001);
+ return Vector2(0, 0.001);
}
{
public:
Gravity();
- ~Gravity();
+ virtual ~Gravity();
- Vector2 positionDelta(const PhysicsEntity*, float);
- Vector2 velocityDelta(const PhysicsEntity*, float);
- Vector2 forceDelta(const PhysicsEntity*, float);
+ Vector2 positionDelta(const PhysicsEntity*, float) const;
+ Vector2 velocityDelta(const PhysicsEntity*, float) const;
+ Vector2 forceDelta(const PhysicsEntity*, float) const;
};
#endif // GRAVITY_H
#include "../debug.h"
#include "../Vector2.h"
+#include "../Effects/Effect.h"
+#include "../Effects/Gravity.h"
/// ***** Public Class Methods *****
PhysicsEntity::PhysicsEntity(const Vector2& pos)
: Entity(pos), force(0,0), mass(1), CoR(1)
{
-
+ g = new Gravity();
}
PhysicsEntity::~PhysicsEntity()
{
-
+ delete g;
}
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 += g->positionDelta(this, time_step);
+ newVelocity += g->velocityDelta(this, time_step);
+ newForce += g->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 += g->forceDelta(this, time_step);
+ newVelocity += g->velocityDelta(this, time_step);
+
+ return newForce/mass / 2 * time_step + newVelocity;
}
void PhysicsEntity::applyForce(const Vector2& force)
#define PHYSICS_H
#include "Entity.h"
+#include "../Effects/Effect.h"
#include "../Vector2.h"
/// ***** Header Class *****
class PhysicsEntity: public Entity
{
- protected:
- PhysicsEntity(const Vector2&);
+ protected:
+ PhysicsEntity(const Vector2&);
- public:
- virtual ~PhysicsEntity();
+ public:
+ virtual ~PhysicsEntity();
- virtual void update(float);
+ virtual void update(float);
- virtual Vector2 positionAt(float) const;
- virtual Vector2 velocityAt(float) const;
+ virtual Vector2 positionAt(float) const;
+ virtual Vector2 velocityAt(float) const;
- virtual void applyForce(const Vector2&);
- virtual void applyImpulse(const Vector2&);
+ virtual void applyForce(const Vector2&);
+ virtual void applyImpulse(const Vector2&);
- protected:
- Vector2 force;
+ protected:
+ Vector2 force;
- float mass;
+ float mass;
- // Coefficient of Restitution
- float CoR;
+ // Coefficient of Restitution
+ float CoR;
+
+ Effect* g;
};
#endif // PHYSICS_H
run: all
${TARGET}
+.PHONY: gdb
+gdb: all
+ gdb ${TARGET}
+
.PHONY: val
val: all
valgrind --leak-check=full ${TARGET}