00001
00002
00003
00004
00005
00006 #ifndef COLLISIONHULL_H
00007 #define COLLISIONHULL_H
00008
00009 #include<AABoundingBox.h>
00010 #include<Vertex3.h>
00011
00012 #include<vector>
00013
00014 class RenderContext;
00015 class Mesh;
00016 class World;
00017 class PolygonalModel;
00018
00021 class CollisionHull
00022 {
00023 public:
00024 static const real inf;
00025 static const real epsilon;
00026
00027 CollisionHull(float r, float y);
00028
00029 const AABoundingBox &getBound() const {
00030 return bound;
00031 }
00032 void operator +=(const Vertex3 &v) {
00033 position += v;
00034 }
00035 Vertex3 &getVelocity() {
00036 return velocity;
00037 }
00038 void setVelocity(const Vertex3 &v) {
00039 velocity = v;
00040 }
00041 const Vertex3 &getPosition() const {
00042 return position;
00043 }
00044 void setPosition(const Vertex3 &p) {
00045 position = p;
00046 }
00047 const Vertex3 &getNormVelocity() const {
00048 return normalizedVelocity;
00049 }
00050 real getYScale() const {
00051 return yScale;
00052 }
00053 real getRadius() const {
00054 return radius;
00055 }
00056 real getDistanceToTravel() const {
00057 return distanceToTravel;
00058 }
00059 bool update(World &world);
00060 bool collide(const AABoundingBox &box) const {
00061 return bound.intersect(box);
00062 }
00063
00064 protected:
00065 void recursiveCollide(World &world);
00066 void calculateBound();
00067
00068 AABoundingBox bound;
00069
00070 Vertex3 position;
00071 Vertex3 velocity;
00072 float radius;
00073 float yScale;
00074
00075
00076 Vertex3 normalizedVelocity;
00077 real distanceToTravel;
00078 };
00079
00080 template<typename T>
00081 inline real collide( vector<T> &array, Vertex3 &nearestIntersection)
00082 {
00083 real nearest = inf;
00084 vector<T>::iterator i = array.begin();
00085 for (;i<array.end;++i) {
00086 Vertex3 intersection;
00087 real d = collide(*i, intersection);
00088 if ((d >= 0.0) && (d < nearest)) {
00089 nearest = d;
00090 nearestIntersection = intersection;
00091 }
00092 }
00093 return nearest;
00094 }
00095
00096 #endif