src/Collision.h

Go to the documentation of this file.
00001 #ifndef COLLISION_H
00002 #define COLLISION_H
00003 
00004 
00005 #include <cassert>
00006 #include <string>
00007 
00008 
00009 #include "TableBorder.h"
00010 
00011 
00017 struct Collision
00018 {
00019 public:
00021     float       time;
00022 
00024     Object *    first;
00025 
00027     Object *    second;
00028 
00029 
00032     Collision(float t, Object * o1, Object * o2)
00033         : time(t),
00034             first(o1),
00035             second(o2)
00036     {
00037         assert(o1);
00038         assert(o2);
00039     }
00040 
00043     virtual ~Collision()
00044     {
00045     }
00046 
00049     static bool compare(const Collision * c1, const Collision * c2)
00050     {
00051         if (!c1 || !c2)
00052             return c1 < c2;
00053         return c1->time < c2->time && c1 != c2;
00054     }
00055 
00058     static bool ucompare(const Collision * c1, const Collision * c2)
00059     {
00060         if (!c1 || !c2)
00061             return c1 < c2;
00062         return c1 != c2 && (c1->first < c2->first
00063                             || (c1->first == c2->first && c1->second < c2->second));
00064     }
00065 
00068     static bool predicate(const Collision * c1, const Collision * c2)
00069     {
00070         return (c1 == c2) || (c1 && c2 && c1->first == c2->first && c1->second == c2->second);
00071     }
00072 
00075     virtual void collide() = 0;
00076 
00081     bool isAffected(Collision * another)
00082     {
00083         return another
00084 //                && another->time <= time
00085                 && (another->first == first
00086                     || another->first == second
00087                     || another->second == first
00088                     || another->second == second);
00089     }
00090 
00091 
00094     std::string dump() const;
00095 };
00096 
00097 
00102 struct BallCollision : public Collision
00103 {
00104 public:
00107     BallCollision(float t, Object * o1, Object * o2)
00108         : Collision(t, o1, o2)
00109     {
00110         LOG("BALL COLLISION " << dump());
00111     }
00112 
00115     virtual void collide();
00116 };
00117 
00118 
00123 struct BorderCollision : public Collision
00124 {
00125 public:
00128     BorderCollision(float t, Object * obj, TableBorder * border)
00129         : Collision(t, obj, border)
00130     {
00131         LOG("BORDER COLLISION " << dump());
00132     }
00133 
00136     virtual void collide();
00137 };
00138 
00139 
00140 #endif
00141 

Generated on Fri Feb 1 00:01:42 2008 for Grayfall by  doxygen 1.5.1