Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_COLLISION_NODE_H__
00009 #define __SP_COLLISION_NODE_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013 #include "Base/spDimension.hpp"
00014 #include "Base/spMathCollisionLibrary.hpp"
00015 #include "Base/spBaseObject.hpp"
00016 #include "SceneGraph/spSceneNode.hpp"
00017 #include "SceneGraph/Collision/spCollisionConfigTypes.hpp"
00018
00019
00020 namespace sp
00021 {
00022 namespace scene
00023 {
00024
00025
00031 class SP_EXPORT CollisionNode : public BaseObject
00032 {
00033
00034 public:
00035
00036 virtual ~CollisionNode();
00037
00038
00039
00040
00041
00042
00043
00044 virtual s32 getSupportFlags() const = 0;
00045
00050 virtual f32 getMaxMovement() const = 0;
00051
00053 virtual void setMaterial(CollisionMaterial* Material);
00054
00061 virtual void findIntersections(const dim::line3df &Line, std::list<SIntersectionContact> &ContactList) const;
00062
00069 virtual bool checkIntersection(const dim::line3df &Line, SIntersectionContact &Contact) const;
00070
00078 virtual bool checkIntersection(const dim::line3df &Line, bool ExcludeCorners = false) const;
00079
00081 virtual bool checkCollision(const CollisionNode* Rival, SCollisionContact &Contact) const;
00082
00084 virtual bool checkCollision(const CollisionNode* Rival) const;
00085
00087 virtual void performCollisionResolving(const CollisionNode* Rival);
00088
00093 void setupTransformation(const dim::matrix4f &Matrix);
00094
00107 void updateTransformation();
00108
00110 void setPosition(const dim::vector3df &Position, bool UpdatePrevPosition = true);
00111
00113 void setOffset(const dim::matrix4f &Matrix, bool Enable = true);
00114
00119 void updateCollisions();
00120
00121
00122
00124 inline ECollisionModels getType() const
00125 {
00126 return Type_;
00127 }
00128
00133 inline void setFlags(s32 Flags)
00134 {
00135 Flags_ = Flags;
00136 }
00138 inline s32 getFlags() const
00139 {
00140 return Flags_;
00141 }
00142
00144 inline SceneNode* getNode() const
00145 {
00146 return Node_;
00147 }
00148
00150 inline CollisionMaterial* getMaterial() const
00151 {
00152 return Material_;
00153 }
00154
00156 inline dim::vector3df getPosition() const
00157 {
00158 return Trans_.getPosition();
00159 }
00160
00162 inline void translate(const dim::vector3df &Direction)
00163 {
00164 Node_->translate(Direction);
00165 updateTransformation();
00166 }
00168 inline void move(const dim::vector3df &Direction)
00169 {
00170 Node_->move(Direction);
00171 updateTransformation();
00172 }
00174 inline void turn(const dim::vector3df &Rotation)
00175 {
00176 Node_->turn(Rotation);
00177 updateTransformation();
00178 }
00179
00181 inline void setRotation(const dim::matrix4f &Rotation)
00182 {
00183 Node_->setRotationMatrix(Rotation, true);
00184 updateTransformation();
00185 }
00187 inline dim::matrix4f getRotation() const
00188 {
00189 return Trans_.getRotationMatrix();
00190 }
00191
00193 inline void setScale(const dim::vector3df &Scale)
00194 {
00195 Node_->setScale(Scale, true);
00196 updateTransformation();
00197 }
00199 inline dim::vector3df getScale() const
00200 {
00201 return Trans_.getScale();
00202 }
00203
00205 inline const dim::matrix4f& getTransformation() const
00206 {
00207 return Trans_;
00208 }
00210 inline const dim::matrix4f& getInverseTransformation() const
00211 {
00212 return InvTrans_;
00213 }
00214
00216 inline void getOffset(dim::matrix4f &Matrix, bool &Enable) const
00217 {
00218 Matrix = OffsetTrans_;
00219 Enable = UseOffsetTrans_;
00220 }
00221
00227 inline dim::vector3df getNodePosition() const
00228 {
00229 return NodePosition_;
00230 }
00236 inline dim::vector3df getPrevPosition() const
00237 {
00238 return PrevPosition_;
00239 }
00240
00241 protected:
00242
00243 friend class CollisionGraph;
00244
00245
00246
00247 CollisionNode(CollisionMaterial* Material, SceneNode* Node, const ECollisionModels Type);
00248
00249 virtual bool checkCollisionToSphere (const CollisionSphere* Rival, SCollisionContact &Contact) const;
00250 virtual bool checkCollisionToCapsule (const CollisionCapsule* Rival, SCollisionContact &Contact) const;
00251 virtual bool checkCollisionToCylinder (const CollisionCylinder* Rival, SCollisionContact &Contact) const;
00252 virtual bool checkCollisionToCone (const CollisionCone* Rival, SCollisionContact &Contact) const;
00253 virtual bool checkCollisionToBox (const CollisionBox* Rival, SCollisionContact &Contact) const;
00254 virtual bool checkCollisionToPlane (const CollisionPlane* Rival, SCollisionContact &Contact) const;
00255 virtual bool checkCollisionToMesh (const CollisionMesh* Rival, SCollisionContact &Contact) const;
00256
00257 virtual bool checkAnyCollisionToSphere (const CollisionSphere* Rival) const;
00258 virtual bool checkAnyCollisionToCapsule (const CollisionCapsule* Rival) const;
00259 virtual bool checkAnyCollisionToCylinder(const CollisionCylinder* Rival) const;
00260 virtual bool checkAnyCollisionToCone (const CollisionCone* Rival) const;
00261 virtual bool checkAnyCollisionToBox (const CollisionBox* Rival) const;
00262 virtual bool checkAnyCollisionToPlane (const CollisionPlane* Rival) const;
00263 virtual bool checkAnyCollisionToMesh (const CollisionMesh* Rival) const;
00264
00265 virtual void performCollisionResolvingToSphere (const CollisionSphere* Rival);
00266 virtual void performCollisionResolvingToCapsule (const CollisionCapsule* Rival);
00267 virtual void performCollisionResolvingToCylinder(const CollisionCylinder* Rival);
00268 virtual void performCollisionResolvingToCone (const CollisionCone* Rival);
00269 virtual void performCollisionResolvingToBox (const CollisionBox* Rival);
00270 virtual void performCollisionResolvingToPlane (const CollisionPlane* Rival);
00271 virtual void performCollisionResolvingToMesh (const CollisionMesh* Rival);
00272
00274 bool notifyCollisionContact(const CollisionNode* Rival, const SCollisionContact &Contact);
00276 bool performDetectedContact(const CollisionNode* Rival, const SCollisionContact &Contact);
00277
00278 bool checkCornerExlusion(const dim::line3df &Line, const dim::vector3df &Point) const;
00279
00280 void updatePrevPosition();
00281
00282 private:
00283
00284 friend class CollisionMaterial;
00285
00286
00287
00288 ECollisionModels Type_;
00289 s32 Flags_;
00290
00291 SceneNode* Node_;
00292
00293 CollisionMaterial* Material_;
00294
00295 dim::matrix4f Trans_;
00296 dim::matrix4f InvTrans_;
00297 dim::matrix4f OffsetTrans_;
00298
00299 dim::vector3df NodePosition_;
00300 dim::vector3df PrevPosition_;
00301
00302 bool UseOffsetTrans_;
00303
00304 };
00305
00306
00307 }
00308
00309 }
00310
00311
00312 #endif
00313
00314
00315
00316