Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 #ifndef __SP_COLLISION_CHARACTER_CONTROLLER_H__
00009 #define __SP_COLLISION_CHARACTER_CONTROLLER_H__
00010 
00011 
00012 #include "Base/spStandard.hpp"
00013 #include "SceneGraph/Collision/spCollisionCapsule.hpp"
00014 #include "SceneGraph/Collision/spBaseCollisionPhysicsObject.hpp"
00015 
00016 
00017 namespace sp
00018 {
00019 namespace scene
00020 {
00021 
00022 
00023 class CharacterController;
00024 
00025 
00033 typedef boost::function<bool (CharacterController* Controller, const CollisionNode* Rival, const SCollisionContact &Contact)> CharacterContactCallback;
00034 
00035 
00043 class SP_EXPORT CharacterController : public BaseCollisionPhysicsObject, public BaseObject
00044 {
00045     
00046     public:
00047         
00048         CharacterController(CollisionMaterial* Material, SceneNode* Node, f32 Radius, f32 Height);
00049         virtual ~CharacterController();
00050         
00051         
00052         
00056         virtual void update();
00057         
00063         virtual void move(const dim::vector3df &Direction);
00064         
00073         virtual void jump(f32 Force);
00074         
00075         void setRadius(f32 Radius);
00076         void setHeight(f32 Height);
00077         
00078         void setMaxStepHeight(f32 MaxHeight);
00079         
00080         
00081         
00083         inline CollisionCapsule* getCollisionModel()
00084         {
00085             return &CollModel_;
00086         }
00088         inline const CollisionCapsule* getCollisionModel() const
00089         {
00090             return &CollModel_;
00091         }
00092         
00094         inline CollisionCapsule* getStepDetector()
00095         {
00096             return &CollStepDetector_;
00097         }
00103         inline const CollisionCapsule* getStepDetector() const
00104         {
00105             return &CollStepDetector_;
00106         }
00107         
00112         inline void setViewRotation(f32 Rotation)
00113         {
00114             ViewRotation_ = Rotation;
00115         }
00117         inline f32 getViewRotation() const
00118         {
00119             return ViewRotation_;
00120         }
00121         
00126         inline f32 getMaxStepHeight() const
00127         {
00128             return MaxStepHeight_;
00129         }
00130         
00132         inline bool stayOnGround() const
00133         {
00134             return StayOnGround_;
00135         }
00136         
00138         inline void setOrientation(const dim::matrix3f &Orientation)
00139         {
00140             Orientation_ = Orientation;
00141         }
00143         inline dim::matrix3f getOrientation() const
00144         {
00145             return Orientation_;
00146         }
00147         
00149         inline void setContactCallback(const CharacterContactCallback &Callback)
00150         {
00151             CollContactCallback_ = Callback;
00152         }
00153         inline CharacterContactCallback getContactCallback() const
00154         {
00155             return CollContactCallback_;
00156         }
00157         
00165         inline f32 getMoveSpeed() const
00166         {
00167             return getVelocity().getLength();
00168         }
00169         
00171         inline void move(f32 LeftRight, f32 ForwardsBackwards)
00172         {
00173             move(dim::vector3df(LeftRight, 0.0f, ForwardsBackwards));
00174         }
00176         inline void moveLeft(f32 Speed)
00177         {
00178             move(dim::vector3df(-Speed, 0.0f, 0.0f));
00179         }
00181         inline void moveRight(f32 Speed)
00182         {
00183             move(dim::vector3df(Speed, 0.0f, 0.0f));
00184         }
00186         inline void moveForwards(f32 Speed)
00187         {
00188             move(dim::vector3df(0.0f, 0.0f, Speed));
00189         }
00191         inline void moveBackwards(f32 Speed)
00192         {
00193             move(dim::vector3df(0.0f, 0.0f, -Speed));
00194         }
00195         
00197         inline dim::vector3df getMovement() const
00198         {
00199             return CurPos_ - PrevPos_;
00200         }
00201         
00202     protected:
00203         
00204         
00205         
00206         
00207         
00208         
00209         f32 ViewRotation_;
00210         f32 MaxStepHeight_;
00211         
00212         dim::matrix3f Orientation_;
00213         
00214         dim::vector3df PrevPos_, CurPos_;
00215         
00216     private:
00217         
00218         friend bool ChCtrlCollisionMaterial(
00219             CollisionMaterial* Material, CollisionNode* Node,
00220             const CollisionNode* Rival, const SCollisionContact &Contact
00221         );
00222         
00223         
00224         
00225         CollisionCapsule CollModel_;
00226         CollisionCapsule CollStepDetector_;
00227         
00228         CharacterContactCallback CollContactCallback_;
00229         
00230         bool StayOnGround_;
00231         
00232 };
00233 
00234 
00235 } 
00236 
00237 } 
00238 
00239 
00240 #endif
00241 
00242 
00243 
00244