Sion Tower (demo técnica) 0.1

/home/david/programacion/iberogre-siontower/siontower/trunk/src/include/shape.h

00001 /*
00002  * This file is part of SionTower.
00003  *
00004  * 
00005  * David Saltares Márquez (C) 2011
00006  * <david.saltares@gmail.com>
00007  *
00008  * 
00009  * SionTower examples are free software: you can redistribute it and/or
00010  * modify it under the terms of the GNU General Public License ad
00011  * published by the Free Software Foundation, either version 3 of the
00012  * License, or (at your option) ant later version.
00013  *
00014  * SionTower examples are distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with SionTower examples.  If not, see <http://www.gnu.org/licenses/>.
00021  */
00022  
00023 #ifndef SIONTOWER_TRUNK_SRC_INCLUDE_SHAPE_H_
00024 #define SIONTOWER_TRUNK_SRC_INCLUDE_SHAPE_H_
00025 
00026 #include <OGRE/Ogre.h>
00027 #include <boost/unordered_map.hpp>
00028 #include <boost/function.hpp>
00029 
00030 class Plane;
00031 class Sphere;
00032 class AxisAlignedBox;
00033 class OrientedBox;
00034 
00036 
00110 class Shape {
00111     public:
00115         enum Type {SPHERE = 1, AABB = 2, PLANE = 3, OBB = 4};
00116         
00121         typedef boost::function<bool(Shape*, Shape*)> CollisionCheckFunction;
00122 
00131         Shape(const Ogre::String& name = "");
00132 
00136         virtual ~Shape();
00137 
00141         const Ogre::String& getName() const;
00142 
00149         virtual int getType() const = 0;
00150 
00164         virtual void applyTransform(Shape* localShape,
00165                                     const Ogre::Vector3& traslation = Ogre::Vector3::ZERO,
00166                                     const Ogre::Vector3& scale = Ogre::Vector3::UNIT_SCALE,
00167                                     const Ogre::Quaternion& orientation = Ogre::Quaternion::IDENTITY) = 0;
00168 
00169 
00170 
00180         virtual Shape* getTransformedCopy(const Ogre::Vector3& traslation = Ogre::Vector3::ZERO,
00181                                           const Ogre::Vector3& scale = Ogre::Vector3::UNIT_SCALE,
00182                                           const Ogre::Quaternion& orientation = Ogre::Quaternion::IDENTITY) = 0;
00183 
00190         static void configureCollisionDispatching();
00191 
00203         static void addCollisionTest(CollisionCheckFunction test, int typeA, int typeB);
00204 
00216         static bool getCollision(Shape* shapeA, Shape* shapeB);
00217 
00218     protected:
00219         Ogre::String _name;
00220 
00221     private:
00222         typedef boost::unordered_map<int, boost::unordered_map<int, CollisionCheckFunction> > CollisionDispatchTable;
00223 
00224         static CollisionDispatchTable  _collisionDispatcher;
00225         
00226         static bool getCollisionSphereSphere(Shape* shapeA, Shape* shapeB);
00227         static bool getCollisionAABBAABB(Shape* shapeA, Shape* shapeB);
00228         static bool getCollisionPlanePlane(Shape* shapeA, Shape* shapeB);
00229         static bool getCollisionOBBOBB(Shape* shapeA, Shape* shapeB);
00230         static bool getCollisionSphereAABB(Shape* shapeA, Shape* shapeB);
00231         static bool getCollisionSphereOBB(Shape* shapeA, Shape* shapeB);
00232         static bool getCollisionPlaneSphere(Shape* shapeA, Shape* shapeB);
00233         static bool getCollisionPlaneAABB(Shape* shapeA, Shape* shapeB);
00234         static bool getCollisionOBBPlane(Shape* shapeA, Shape* shapeB);
00235         static bool getCollisionOBBAABB(Shape* shapeA, Shape* shapeB);
00236 };
00237 
00238 
00240 
00248 class Sphere: public Shape {
00249     public:
00257         Sphere(const Ogre::String& name,
00258                const Ogre::Vector3& center = Ogre::Vector3::ZERO,
00259                Ogre::Real radius = 1.0);
00260 
00264         ~Sphere();
00265 
00269         int getType() const;
00270         
00271         void applyTransform(Shape* localShape,
00272                             const Ogre::Vector3& traslation = Ogre::Vector3::ZERO,
00273                             const Ogre::Vector3& scale = Ogre::Vector3::UNIT_SCALE,
00274                             const Ogre::Quaternion& orientation = Ogre::Quaternion::IDENTITY);
00275 
00276         Shape* getTransformedCopy(const Ogre::Vector3& traslation = Ogre::Vector3::ZERO,
00277                                   const Ogre::Vector3& scale = Ogre::Vector3::UNIT_SCALE,
00278                                   const Ogre::Quaternion& orientation = Ogre::Quaternion::IDENTITY);
00282         Ogre::Real getRadius() const;
00283 
00287         void setRadius(Ogre::Real radius);
00288 
00292         const Ogre::Vector3& getCenter() const;
00293 
00297         void setCenter(const Ogre::Vector3& center);
00298     private:
00299         Ogre::Vector3 _center;
00300         Ogre::Real _radius;
00301 };
00302 
00303 
00304 
00306 
00314 class AxisAlignedBox: public Shape {
00315     public:
00323         AxisAlignedBox(const Ogre::String& name,
00324                        const Ogre::Vector3& minPos,
00325                        const Ogre::Vector3& maxPos);
00326 
00330         ~AxisAlignedBox();
00331 
00336         int getType() const;
00337         
00338         void applyTransform(Shape* localShape,
00339                             const Ogre::Vector3& traslation = Ogre::Vector3::ZERO,
00340                             const Ogre::Vector3& scale = Ogre::Vector3::UNIT_SCALE,
00341                             const Ogre::Quaternion& orientation = Ogre::Quaternion::IDENTITY);
00342 
00343         Shape* getTransformedCopy(const Ogre::Vector3& traslation = Ogre::Vector3::ZERO,
00344                                   const Ogre::Vector3& scale = Ogre::Vector3::UNIT_SCALE,
00345                                   const Ogre::Quaternion& orientation = Ogre::Quaternion::IDENTITY);
00346 
00350         const Ogre::Vector3& getMinPos() const;
00351 
00355         void setMinPos(const Ogre::Vector3& minPos);
00356         
00360         const Ogre::Vector3& getMaxPos() const;
00361 
00365         void setMaxPos(const Ogre::Vector3& maxPos);
00366 
00367     private:
00368         Ogre::Vector3 _minPos;
00369         Ogre::Vector3 _maxPos;
00370 };
00371 
00372 
00373 
00375 
00383 class Plane: public Shape {
00384     public:
00392         Plane(const Ogre::String& name,
00393               const Ogre::Vector3& position,
00394               const Ogre::Vector3& normal);
00395 
00399         ~Plane();
00400 
00404         int getType() const;
00405         
00406         void applyTransform(Shape* localShape,
00407                             const Ogre::Vector3& traslation = Ogre::Vector3::ZERO,
00408                             const Ogre::Vector3& scale = Ogre::Vector3::UNIT_SCALE,
00409                             const Ogre::Quaternion& orientation = Ogre::Quaternion::IDENTITY);
00410 
00411         Shape* getTransformedCopy(const Ogre::Vector3& traslation = Ogre::Vector3::ZERO,
00412                                   const Ogre::Vector3& scale = Ogre::Vector3::UNIT_SCALE,
00413                                   const Ogre::Quaternion& orientation = Ogre::Quaternion::IDENTITY);
00414 
00415 
00419         const Ogre::Vector3& getPosition() const;
00420 
00424         void setPosition(const Ogre::Vector3& position);
00425 
00429         const Ogre::Vector3& getNormal() const;
00430 
00434         void setNormal(const Ogre::Vector3& normal);
00435 
00436     private:
00437         Ogre::Vector3 _position;
00438         Ogre::Vector3 _normal;
00439 };
00440 
00441 
00443 
00451 class OrientedBox: public Shape {
00452     public:
00462         OrientedBox(const Ogre::String& name,
00463                     const Ogre::Vector3& center,
00464                     const Ogre::Vector3& extent,
00465                     const Ogre::Matrix3& axes);
00466         
00470         ~OrientedBox();
00471         
00475         int getType() const;
00476         
00483         void applyTransform(Shape* localShape,
00484                             const Ogre::Vector3& traslation = Ogre::Vector3::ZERO,
00485                             const Ogre::Vector3& scale = Ogre::Vector3::UNIT_SCALE,
00486                             const Ogre::Quaternion& orientation = Ogre::Quaternion::IDENTITY);
00487 
00495         Shape* getTransformedCopy(const Ogre::Vector3& traslation = Ogre::Vector3::ZERO,
00496                                   const Ogre::Vector3& scale = Ogre::Vector3::UNIT_SCALE,
00497                                   const Ogre::Quaternion& orientation = Ogre::Quaternion::IDENTITY);
00498 
00502         const Ogre::Vector3& getCenter() const;
00503 
00507         void setCenter(const Ogre::Vector3& center);
00508 
00512         const Ogre::Vector3& getExtent() const;
00513 
00517         void setExtent(const Ogre::Vector3& extent);
00518 
00522         const Ogre::Matrix3& getAxes() const;
00523 
00527         void setAxes(const Ogre::Matrix3& axes);
00528     private:
00529         Ogre::Vector3 _center;
00530         Ogre::Vector3 _extent;
00531         Ogre::Matrix3 _axes;
00532 };
00533 
00534 
00535 #endif  // SIONTOWER_TRUNK_SRC_INCLUDE_SHAPE_H_
 Todo Clases Archivos Funciones 'typedefs' Enumeraciones