From: Patrik Gornicz Date: Sat, 2 Aug 2008 19:48:55 +0000 (-0400) Subject: Effect methods changed from pure virtual to defaulting to a 0,0 vector X-Git-Tag: physics-premerge~173 X-Git-Url: http://gitweb.pgornicz.com/gitweb.cgi?a=commitdiff_plain;h=094a13b85bb8ab6011907cdea75216cc1040b1c4;p=libbear.git Effect methods changed from pure virtual to defaulting to a 0,0 vector --- diff --git a/src/Effects/Effect.cpp b/src/Effects/Effect.cpp index 8ea3880..f6bf921 100644 --- a/src/Effects/Effect.cpp +++ b/src/Effects/Effect.cpp @@ -9,3 +9,16 @@ Effect::~Effect() { } + +Vector2 Effect::positionDelta(const PhysicsEntity*, float) const +{ + return Vector2(0,0); +} +Vector2 Effect::velocityDelta(const PhysicsEntity*, float) const +{ + return Vector2(0,0); +} +Vector2 Effect::forceDelta(const PhysicsEntity*, float) const +{ + return Vector2(0,0); +} diff --git a/src/Effects/Effect.h b/src/Effects/Effect.h index 963ecb2..5d0f1f9 100644 --- a/src/Effects/Effect.h +++ b/src/Effects/Effect.h @@ -15,9 +15,9 @@ class Effect public: virtual ~Effect(); - virtual Vector2 positionDelta(const PhysicsEntity*, float) const = 0; - virtual Vector2 velocityDelta(const PhysicsEntity*, float) const = 0; - virtual Vector2 forceDelta(const PhysicsEntity*, float) const = 0; + virtual Vector2 positionDelta(const PhysicsEntity*, float) const; + virtual Vector2 velocityDelta(const PhysicsEntity*, float) const; + virtual Vector2 forceDelta(const PhysicsEntity*, float) const; }; #endif // EFFECT_H diff --git a/src/Effects/Gravity.cpp b/src/Effects/Gravity.cpp index c8394b4..9d0ac65 100644 --- a/src/Effects/Gravity.cpp +++ b/src/Effects/Gravity.cpp @@ -9,16 +9,6 @@ Gravity::~Gravity() } -Vector2 Gravity::positionDelta(const PhysicsEntity*, float) const -{ - return Vector2(0, 0); -} - -Vector2 Gravity::velocityDelta(const PhysicsEntity*, float) const -{ - return Vector2(0, 0); -} - Vector2 Gravity::forceDelta(const PhysicsEntity*, float) const { return Vector2(0, 0.001); diff --git a/src/Effects/Gravity.h b/src/Effects/Gravity.h index ac20d49..1675a6c 100644 --- a/src/Effects/Gravity.h +++ b/src/Effects/Gravity.h @@ -11,8 +11,6 @@ class Gravity: public Effect Gravity(); ~Gravity(); - Vector2 positionDelta(const PhysicsEntity*, float) const; - Vector2 velocityDelta(const PhysicsEntity*, float) const; Vector2 forceDelta(const PhysicsEntity*, float) const; }; diff --git a/src/Effects/Screen.cpp b/src/Effects/Screen.cpp index bbae5bb..9d81238 100644 --- a/src/Effects/Screen.cpp +++ b/src/Effects/Screen.cpp @@ -2,6 +2,7 @@ #include "../debug.h" #include "../Entities/PhysicsEntity.h" +#include "../Entities/Ball.h" Screen::Screen() { @@ -12,11 +13,6 @@ Screen::~Screen() } -Vector2 Screen::positionDelta(const PhysicsEntity*, float) const -{ - return Vector2(0,0); -} - Vector2 Screen::velocityDelta(const PhysicsEntity* e, float time_step) const { const Vector2& pos = e->positionRaw(); @@ -24,30 +20,23 @@ Vector2 Screen::velocityDelta(const PhysicsEntity* e, float time_step) const Vector2 acc(0,0); - if(pos.y > 600 && velo.y > 0) - { + float radius = 0; + const Ball* b = dynamic_cast(e); + if( b != NULL ) + radius = b->getRadius(); + + + if(pos.y > 600-radius && velo.y > 0) acc.y += velo.y * -2; - } - if(pos.y < 0 && velo.y < 0) - { + if(pos.y < 0+radius && velo.y < 0) acc.y += velo.y * -2; - } - if(pos.x > 800 && velo.x > 0) - { + if(pos.x > 800-radius && velo.x > 0) acc.x += velo.x * -2; - } - if(pos.x < 0 && velo.x < 0) - { + if(pos.x < 0+radius && velo.x < 0) acc.x += velo.x * -2; - } return acc; } - -Vector2 Screen::forceDelta(const PhysicsEntity*, float) const -{ - return Vector2(0,0); -} diff --git a/src/Effects/Screen.h b/src/Effects/Screen.h index 9403687..2e32e95 100644 --- a/src/Effects/Screen.h +++ b/src/Effects/Screen.h @@ -11,9 +11,7 @@ class Screen: public Effect Screen(); ~Screen(); - Vector2 positionDelta(const PhysicsEntity*, float) const; Vector2 velocityDelta(const PhysicsEntity*, float) const; - Vector2 forceDelta(const PhysicsEntity*, float) const; }; #endif // SCREEN_H diff --git a/src/Entities/Ball.cpp b/src/Entities/Ball.cpp index 37a37c7..23180f0 100644 --- a/src/Entities/Ball.cpp +++ b/src/Entities/Ball.cpp @@ -19,3 +19,8 @@ void Ball::draw() const { glDrawCircle(radius, position, color); } + +float Ball::getRadius() const +{ + return radius; +} diff --git a/src/Entities/Ball.h b/src/Entities/Ball.h index 8312c95..5dcffaa 100644 --- a/src/Entities/Ball.h +++ b/src/Entities/Ball.h @@ -13,6 +13,8 @@ class Ball: public PhysicsEntity virtual void draw() const; + float getRadius() const; + protected: float radius; const float* color; diff --git a/src/entityCreator.cpp b/src/entityCreator.cpp index 078e40f..a183d87 100644 --- a/src/entityCreator.cpp +++ b/src/entityCreator.cpp @@ -43,7 +43,7 @@ void creator::init() ball = new Ball(Vector2(100, 100), 20, cGreen); - ball->applyImpulse(Vector2(-0.15,0.05)), + ball->applyImpulse(Vector2(-0.15,0.55)), Balls.push(ball); manager::add(ball);