00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00059 void setTraceType( int trace_type );
00060
00061 int getTraceType() const;
00062
00063 void setSphereRadius( float radius );
00064
00065 float getSphereRadius() const;
00066
00067 void setBox( core::AABB& box );
00068
00069 AABB& getAABB();
00070
00071 bool collided() const;
00072
00073 bool hitGround() const;
00074
00075 bool hitStep() const;
00076
00077 core::Vector3df checkCollision( core::Bsp* bsp, core::Vector3df start, core::Vector3df end );
00078
00079
00080 core::Vector3df checkStep( core::Bsp* bsp, core::Vector3df start, core::Vector3df end, float& stepHeight );
00081
00082
00083 protected:
00084
00085 core::Vector3df trace( core::Bsp* bsp, core::Vector3df start, core::Vector3df end );
00086
00087 void checkNode(core::Bsp* bsp, int nodeIndex, float startRatio, float endRatio, core::Vector3df start, core::Vector3df end );
00088
00089 void checkBrush( core::Bsp* bsp, core::tBSPBrush *pBrush, core::Vector3df start, core::Vector3df end );
00090
00091 private:
00092 bool m_collided;
00093 bool m_hitground;
00094 bool m_hitstep;
00095 const float m_epsilon;
00096 int m_trace_type;
00097 float m_trace_radius;
00098 float m_trace_ratio;
00099 core::AABB m_box;
00100 core::Vector3df m_collision_normal;
00101 static float m_max_step_height;
00102
00103
00104 };
00105
00106
00107
00108
00109 }
00110 }
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 }
00151 #endif
00152
00153