Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_COLLISION_GRAPH_H__
00009 #define __SP_COLLISION_GRAPH_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013 #include "SceneGraph/Collision/spCollisionSphere.hpp"
00014 #include "SceneGraph/Collision/spCollisionCapsule.hpp"
00015 #include "SceneGraph/Collision/spCollisionCylinder.hpp"
00016 #include "SceneGraph/Collision/spCollisionCone.hpp"
00017 #include "SceneGraph/Collision/spCollisionBox.hpp"
00018 #include "SceneGraph/Collision/spCollisionPlane.hpp"
00019 #include "SceneGraph/Collision/spCollisionMesh.hpp"
00020 #include "SceneGraph/Collision/spCollisionMaterial.hpp"
00021 #include "SceneGraph/Collision/spCharacterController.hpp"
00022
00023 #include <boost/function.hpp>
00024
00025
00026 namespace sp
00027 {
00028 namespace scene
00029 {
00030
00031
00038 typedef boost::function<bool (const CollisionNode* Node)> IntersectionCriteriaCallback;
00039
00040
00092 class SP_EXPORT CollisionGraph
00093 {
00094
00095 public:
00096
00097 CollisionGraph();
00098 virtual ~CollisionGraph();
00099
00100
00101
00103 virtual CollisionMaterial* createMaterial();
00105 virtual void deleteMaterial(CollisionMaterial* Material);
00106
00108 virtual void addCollisionNode(CollisionNode* Node);
00110 virtual void removeCollisionNode(CollisionNode* Node);
00111
00119 virtual CollisionSphere* createSphere(CollisionMaterial* Material, scene::SceneNode* Node, f32 Radius);
00127 virtual CollisionCapsule* createCapsule(CollisionMaterial* Material, scene::SceneNode* Node, f32 Radius, f32 Height);
00128
00129 virtual CollisionCylinder* createCylinder(CollisionMaterial* Material, scene::SceneNode* Node, f32 Radius, f32 Height);
00130
00131 virtual CollisionCone* createCone(CollisionMaterial* Material, scene::SceneNode* Node, f32 Radius, f32 Height);
00138 virtual CollisionBox* createBox(CollisionMaterial* Material, scene::SceneNode* Node, const dim::aabbox3df &Box);
00145 virtual CollisionPlane* createPlane(CollisionMaterial* Material, scene::SceneNode* Node, const dim::plane3df &Plane);
00153 virtual CollisionMesh* createMesh(CollisionMaterial* Material, scene::Mesh* Mesh, u8 MaxTreeLevel = DEF_KDTREE_LEVEL);
00158 virtual CollisionMesh* createMeshList(CollisionMaterial* Material, const std::list<Mesh*> &MeshList, u8 MaxTreeLevel = DEF_KDTREE_LEVEL);
00159
00161 virtual bool deleteNode(CollisionNode* Node);
00162
00168 virtual CharacterController* createCharacterController(
00169 CollisionMaterial* Material, scene::SceneNode* Node, f32 Radius, f32 Height
00170 );
00171 virtual bool deleteCharacterController(CharacterController* Object);
00172
00174 virtual void clearScene(
00175 bool isDeleteNodes = true, bool isDeleteMaterials = true, bool isDeleteCharacters = true
00176 );
00177
00191 virtual bool checkIntersection(
00192 const dim::line3df &Line, bool ExcludeCorners = false, const IntersectionCriteriaCallback &CriteriaCallback = 0
00193 ) const;
00194
00204 virtual void findIntersections(
00205 const dim::line3df &Line, std::list<SIntersectionContact> &ContactList,
00206 bool SearchBidirectional = false, const IntersectionCriteriaCallback &CriteriaCallback = 0
00207 ) const;
00208
00210 virtual void updateScene();
00211
00212
00213
00214 static void sortContactList(
00215 const dim::vector3df &LineStart, std::list<SIntersectionContact> &ContactList
00216 );
00217
00218
00219
00220 inline const std::list<CollisionNode*>& getNodeList() const
00221 {
00222 return CollNodes_;
00223 }
00224 inline const std::list<CollisionMaterial*>& getMaterialList() const
00225 {
00226 return CollMaterials_;
00227 }
00228
00230 inline TreeNode* getRootTreeNode() const
00231 {
00232 return RootTreeNode_;
00233 }
00234
00236 inline std::list<SIntersectionContact> findIntersections(
00237 const dim::line3df &Line, bool SearchBidirectional = false,
00238 const IntersectionCriteriaCallback &CriteriaCallback = 0) const
00239 {
00240 std::list<SIntersectionContact> ContactList;
00241 findIntersections(Line, ContactList, SearchBidirectional, CriteriaCallback);
00242 return ContactList;
00243 }
00244
00245 protected:
00246
00247
00248
00249 virtual void findIntersectionsUnidirectional(
00250 const dim::line3df &Line, std::list<SIntersectionContact> &ContactList,
00251 const IntersectionCriteriaCallback &CriteriaCallback
00252 ) const;
00253
00254
00255
00256 template <class T> T* addCollNode(T* Node)
00257 {
00258 CollNodes_.push_back(Node);
00259 return Node;
00260 }
00261
00262
00263
00264 std::list<CollisionNode*> CollNodes_;
00265 std::list<CollisionMaterial*> CollMaterials_;
00266 std::list<CharacterController*> CharacterControllers_;
00267
00268 TreeNode* RootTreeNode_;
00269
00270 };
00271
00272
00273 }
00274
00275 }
00276
00277
00278 #endif
00279
00280
00281
00282