From: Patrik Gornicz Date: Thu, 21 Aug 2008 20:58:24 +0000 (-0400) Subject: gravity well now follows the mouse X-Git-Tag: physics-premerge~144 X-Git-Url: http://gitweb.pgornicz.com/gitweb.cgi?a=commitdiff_plain;h=a823a80039c6069bb7676433832d9f9413494860;p=libbear.git gravity well now follows the mouse --- diff --git a/src/Effects/GravityWell.cpp b/src/Effects/GravityWell.cpp index 4fcd446..68afa27 100644 --- a/src/Effects/GravityWell.cpp +++ b/src/Effects/GravityWell.cpp @@ -48,3 +48,8 @@ Vector2 GravityWell::forceDelta(const PhysicsEntity* e, float) const return acc; } + +void GravityWell::setPosition(const Vector2& pos) +{ + position = pos; +} diff --git a/src/Effects/GravityWell.h b/src/Effects/GravityWell.h index 36b9dec..d6165d3 100644 --- a/src/Effects/GravityWell.h +++ b/src/Effects/GravityWell.h @@ -27,11 +27,13 @@ class GravityWell: public Effect { public: - GravityWell(const Vector2& pos); + GravityWell(const Vector2&); ~GravityWell(); Vector2 forceDelta(const PhysicsEntity*, float) const; + void setPosition(const Vector2&); + private: Vector2 position; }; diff --git a/src/Effects/Screen.cpp b/src/Effects/Screen.cpp index 61108c4..f7bf80e 100644 --- a/src/Effects/Screen.cpp +++ b/src/Effects/Screen.cpp @@ -37,7 +37,6 @@ Screen::~Screen() Vector2 Screen::positionDelta(const PhysicsEntity* e, float time_step) const { const Vector2& pos = e->positionRaw(); - const Vector2& velo = e->velocityRaw(); Vector2 acc(0,0); diff --git a/src/effectManager.cpp b/src/effectManager.cpp index 6ebffdd..2e50c65 100644 --- a/src/effectManager.cpp +++ b/src/effectManager.cpp @@ -23,12 +23,15 @@ #include "Effects/Screen.h" #include "Vector2.h" +#include "input/inputManager.h" /// ***** Private Variables ***** Effect** effects; int numEffects; +GravityWell* mouseWell; + /// ***** Initializers/Cleaners ***** void effect::init() @@ -36,8 +39,10 @@ void effect::init() numEffects = 3; effects = new Effect*[numEffects](); - effects[0] = new Gravity(); - effects[1] = new GravityWell(Vector2(400,400)); + mouseWell = new GravityWell(input::mousePosition()); + + effects[0] = mouseWell; + effects[1] = new Gravity(); effects[2] = new Screen(); } void effect::clean() @@ -52,6 +57,15 @@ void effect::clean() /// ***** Public Methods ***** +void effect::update(float) +{ + +} +void effect::handleInput() +{ + mouseWell->setPosition(input::mousePosition()); +} + Vector2 effect::positionDelta(const PhysicsEntity* e, float time_step) { Vector2 acc(0,0); diff --git a/src/effectManager.h b/src/effectManager.h index 089c12a..f77e191 100644 --- a/src/effectManager.h +++ b/src/effectManager.h @@ -27,6 +27,9 @@ namespace effect void init(); void clean(); + void update(float); + void handleInput(); + Vector2 positionDelta(const PhysicsEntity*, float); Vector2 velocityDelta(const PhysicsEntity*, float); Vector2 forceDelta(const PhysicsEntity*, float); diff --git a/src/entityManager.cpp b/src/entityManager.cpp index c7fc78b..c78a7ce 100644 --- a/src/entityManager.cpp +++ b/src/entityManager.cpp @@ -25,6 +25,7 @@ #include "Entities/PhysicsEntity.h" #include "collisionHandler.h" +#include "effectManager.h" /// ***** Private Method Headers ***** @@ -107,10 +108,12 @@ void manager::remove(Entity* e) void manager::handleInput() { - // TODO + effect::handleInput(); } void manager::update(float time_step) { + effect::update(time_step); + updateParticles(time_step); updatePhysics(time_step); } diff --git a/src/input/inputManager.cpp b/src/input/inputManager.cpp index a8491b1..0df4baa 100644 --- a/src/input/inputManager.cpp +++ b/src/input/inputManager.cpp @@ -72,6 +72,16 @@ void input::update() } } +Vector2 input::mousePosition() +{ + int x; + int y; + + SDL_GetMouseState(&x, &y); + + return Vector2(x,y); +} + bool input::isPressed(Uint8 key) { return keyState[key] == isP || keyState[key] == wasP; diff --git a/src/input/inputManager.h b/src/input/inputManager.h index a117324..3e0e45d 100644 --- a/src/input/inputManager.h +++ b/src/input/inputManager.h @@ -19,6 +19,7 @@ #define INPUT_H #include +#include "../Vector2.h" /// ***** Header Methods ***** @@ -30,6 +31,8 @@ namespace input void update(); + Vector2 mousePosition(); + bool isPressed(Uint8); bool isReleased(Uint8);