• Página principal
  • Clases
  • Archivos
  • Lista de archivos

Collision.h

00001 //-----------------------------------------------------------------------------
00002 // Copyright (c) 2005-2007 dhpoware. All Rights Reserved.
00003 //
00004 // Permission is hereby granted, free of charge, to any person obtaining a
00005 // copy of this software and associated documentation files (the "Software"),
00006 // to deal in the Software without restriction, including without limitation
00007 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008 // and/or sell copies of the Software, and to permit persons to whom the
00009 // Software is furnished to do so, subject to the following conditions:
00010 //
00011 // The above copyright notice and this permission notice shall be included in
00012 // all copies or substantial portions of the Software.
00013 //
00014 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00019 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
00020 // IN THE SOFTWARE.
00021 //-----------------------------------------------------------------------------
00022 
00023 #if !defined(COLLISION_H)
00024 #define COLLISION_H
00025 
00026 #include "Maths.h"
00027 
00028 //-----------------------------------------------------------------------------
00029 // Classes.
00030 
00033 class BoundingBox
00034 {
00035 public:
00038     Vector3 min;
00041     Vector3 max;
00042 
00043     BoundingBox();
00044     BoundingBox(const Vector3 &min_, const Vector3 &max_);
00045     ~BoundingBox();
00046 
00049     Vector3 getCenter() const;
00052     float getRadius() const;
00055     float getSize() const;
00056 
00059         bool isPointInBox(const Vector3 & oPoint);
00060 };
00061 
00062 //-----------------------------------------------------------------------------
00063 
00066 class BoundingSphere
00067 {
00068 public:
00071     Vector3 center;
00074     float radius;
00075 
00076     BoundingSphere();
00077     BoundingSphere(const Vector3 &center_, float radius_);
00078     ~BoundingSphere();
00079 
00082     bool hasCollided(const BoundingSphere &other) const;
00083 };
00084 
00085 //-----------------------------------------------------------------------------
00086 
00092 class BoundingVolume
00093 {
00094 public:
00095     BoundingBox box;
00096     BoundingSphere sphere;
00097 
00098     BoundingVolume();
00099     ~BoundingVolume();
00100 };
00101 
00102 //-----------------------------------------------------------------------------
00103 
00111 class Plane
00112 {
00113 public:
00114     Vector3 n;
00115     float d;
00116 
00117     static float dot(const Plane &p, const Vector3 &pt);
00118 
00119     Plane();
00120     Plane(float a_, float b_, float c_, float d_);
00121     Plane(const Vector3 &pt, const Vector3 &normal);
00122     Plane(const Vector3 &pt1, const Vector3 &pt2, const Vector3 &pt3);
00123     ~Plane();
00124 
00125     bool operator==(const Plane &rhs) const;
00126     bool operator!=(const Plane &rhs) const;
00127 
00131     void fromPointNormal(const Vector3 &pt, const Vector3 &normal);
00132 
00136     void fromPoints(const Vector3 &pt1, const Vector3 &pt2, const Vector3 &pt3);
00137     const Vector3 &normal() const;
00138     Vector3 &normal();
00139     void normalize();
00140     void set(float a_, float b_, float c_, float d_);
00141 };
00142 
00143 //-----------------------------------------------------------------------------
00144 
00155 class Frustum
00156 {
00157 public:
00158     enum
00159     {
00160         FRUSTUM_PLANE_LEFT   = 0,
00161         FRUSTUM_PLANE_RIGHT  = 1,
00162         FRUSTUM_PLANE_BOTTOM = 2,
00163         FRUSTUM_PLANE_TOP    = 3,
00164         FRUSTUM_PLANE_NEAR   = 4,
00165         FRUSTUM_PLANE_FAR    = 5
00166     };
00167 
00168     Plane planes[6];
00169 
00170     void extractPlanes(const Matrix4 &viewMatrix4, const Matrix4 &projMatrix4);
00171 
00172     bool boxInFrustum(const BoundingBox &box) const;
00173     bool pointInFrustum(const Vector3 &point) const;
00174     bool sphereInFrustum(const BoundingSphere &sphere) const;
00175     bool volumeInFrustum(const BoundingVolume &volume) const;
00176 };
00177 
00178 //-----------------------------------------------------------------------------
00179 
00186 class Ray
00187 {
00188 public:
00189     Vector3 origin;
00190     Vector3 direction;
00191 
00192     Ray();
00193     Ray(const Vector3 &origin_, const Vector3 &direction_);
00194     ~Ray();
00195 
00196     bool hasIntersected(const BoundingSphere &sphere) const;
00197     bool hasIntersected(const BoundingBox &box) const;
00198     bool hasIntersected(const BoundingVolume &volume) const;
00199     bool hasIntersected(const Plane &plane) const;
00200 
00205     bool hasIntersected(const Plane &plane, float &t, Vector3 &intersection) const;
00206 };
00207 
00208 //-----------------------------------------------------------------------------
00209 
00210 #endif

Generado el Miércoles, 15 de Septiembre de 2010 14:56:31 para CGALib por  doxygen 1.7.1