Page principale | Hiérarchie des classes | Liste alphabétique | Liste des classes | Liste des fichiers | Membres de classe

C:/Projects/ngn/include/collision.h

00001 /***************************************************************************
00002  *            collision.h
00003  *
00004  *  Sun Feb  1 12:12:39 2004
00005  *  Copyright  2004  thierry schartz
00006  *  thierry.schartz@bluebottle.com
00007  ****************************************************************************/
00008 /*
00009  *  This program is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  This program is 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 Library General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU General Public License
00020  *  along with this program; if not, write to the Free Software
00021  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00022  */
00023 
00024 #ifndef _COLLISION_H
00025 #define _COLLISION_H
00026 
00027 #ifdef WIN32
00028 #include <windows.h>
00029 #endif
00030 
00031 
00032 #define TRACE_RAY 0
00033 #define TRACE_SPHERE 1
00034 #define TRACE_BOX 2
00035 
00036 #include "vector3d.h"
00037 #include "aabb.h"
00038 
00039 namespace ngn {
00040 
00041         namespace core {
00042                 class Bsp;
00043                 struct tBSPBrush;
00044 
00045 
00046                 namespace bsp {
00047 
00048                 
00049 
00050                         class NGN_API BSPCollision
00051                         {
00052                         public:
00053                                 BSPCollision();
00054                                 BSPCollision( const BSPCollision& other );
00055                                 BSPCollision operator=( const BSPCollision& other );
00056                                 virtual ~BSPCollision();
00057                                 
00058                                 // set type of collision detection ( point, sphere or box )
00059                                 void setTraceType( int trace_type );
00060                                 // get collision detection type
00061                                 int getTraceType() const;
00062                                 // set radius of the sphere to check against bsp
00063                                 void setSphereRadius( float radius );
00064                                 // get sphere radius
00065                                 float getSphereRadius() const;
00066                                 // set AAB box to check collision against
00067                                 void setBox( core::AABB& box );
00068                                 // get AABB
00069                                 AABB& getAABB();
00070                                 // true if collision occured
00071                                 bool collided() const;
00072                                 // true if ground was hit
00073                                 bool hitGround() const;
00074                                 // true if small obstacle was hit
00075                                 bool hitStep() const;
00076                                 // trace and check collision
00077                                 core::Vector3df checkCollision( core::Bsp* bsp, core::Vector3df start, core::Vector3df end );
00078                                 // check collision with small objects, return new position and
00079                                 // set 'stepHeight' to obstacle height
00080                                 core::Vector3df checkStep( core::Bsp* bsp, core::Vector3df start, core::Vector3df end, float& stepHeight );
00081                                 
00082 
00083                         protected:
00084                                 // trace for collision
00085                                 core::Vector3df trace( core::Bsp* bsp, core::Vector3df start, core::Vector3df end );
00086                                 // checks all the nodes until find leafs that store the brushes
00087                                 void checkNode(core::Bsp* bsp, int nodeIndex, float startRatio, float endRatio, core::Vector3df start, core::Vector3df end );
00088                                 // checks current movement vector against the brush and its sides
00089                                 void checkBrush( core::Bsp* bsp, core::tBSPBrush *pBrush, core::Vector3df start, core::Vector3df end );
00090 
00091                         private:
00092                                 bool m_collided;                // true if object collided with BSP tree
00093                                 bool m_hitground;               // true if ground was hit
00094                                 bool m_hitstep;                 // true if a small obstacle was encountered
00095                                 const float m_epsilon;  // Quake 3 const for preventing float calculations errors
00096                                 int m_trace_type;               // type of tracing
00097                                 float m_trace_radius;   // collision offset
00098                                 float m_trace_ratio;    // % of trace colliding solid
00099                                 core::AABB m_box;               // box to check collision against
00100                                 core::Vector3df m_collision_normal;     // normal vector to collision plane
00101                                 static float m_max_step_height; // max height for stepping over obstacles
00102 
00103 
00104                         };
00105 
00106 
00107 
00108 
00109                 }//bsp
00110         }//core
00111 
00117         class NGN_API Collision
00118         {
00119         public:
00121                 Collision();
00122 
00125                 core::Vector3df checkCollision( core::Vector3df start, core::Vector3df end );
00127                 bool collided() const;
00130                 void setTraceType( int trace_type );
00132                 int getTraceType() const;
00134                 void setSphereRadius( float radius );
00136                 float getSphereRadius() const;
00138                 void setBox( core::AABB& box );
00139 
00140         private:
00141                 core::bsp::BSPCollision m_collision;
00142         
00143         };
00144                 
00145 
00146 
00147 
00148 
00149 
00150 }//ngn
00151 #endif /* _COLLISION_H */
00152 
00153 

Généré le Fri Nov 19 14:20:29 2004 pour NGN par  doxygen 1.3.9.1