00001
00002
00003
00004
00005
00006 #ifndef _CHARACTER_H_
00007 #define _CHARACTER_H_
00008
00014 #include <btScalar.h>
00015 #include <btVector3.h>
00016 #include <btCollisionAlgorithm.h>
00017
00018 class World;
00019 class Object;
00020
00021 namespace irr
00022 {
00023 struct SEvent;
00024 }
00025
00026 class btConvexShape;
00027 class btCollisionWorld;
00028 class btCollisionObject;
00029 class btCollisionDispatcher;
00030 class btOverlappingPairCache;
00031
00032 class Character
00033 {
00034 public:
00035 enum Direction
00036 {
00037 Left = 1,
00038 Right = 2,
00039 Forward = 4,
00040 Backward = 8,
00041
00042 Jump = 16,
00043
00044 DirectionCount
00045 };
00046
00047 Character(Object *object, World *world);
00048 virtual ~Character();
00049
00050 bool onGround() const;
00051
00052 virtual void update(btScalar dt);
00053 virtual void move(int direction);
00054
00055 void setFallSpeed (btScalar fallSpeed);
00056 void setJumpSpeed (btScalar jumpSpeed);
00057 void setMaxJumpHeight (btScalar maxJumpHeight);
00058
00059 bool canJump () const;
00060 void jump ();
00061
00062 protected:
00063 World *m_world;
00064 Object *m_object;
00065
00066 bool m_onGround;
00067 int m_directions;
00068 btScalar m_halfHeight;
00069 btConvexShape* m_shape;
00070 btCollisionObject* m_collisionObject;
00071 btOverlappingPairCache* m_pairCache;
00072 btCollisionDispatcher* m_dispatcher;
00073
00074 btScalar m_fallSpeed;
00075 btScalar m_jumpSpeed;
00076 btScalar m_maxJumpHeight;
00077
00078 btScalar m_turnAngle;
00079 btScalar m_walkVelocity;
00080
00081 btScalar m_height;
00082 btScalar m_width;
00083 btScalar m_stepHeight;
00084
00085 btVector3 m_currentPosition;
00086 btVector3 m_targetPosition;
00087
00088 bool m_touchingContact;
00089 btVector3 m_touchingNormal;
00090
00091 bool fall(const btCollisionWorld *w, btScalar dt, const btVector3& down);
00092 bool recoverFromPenetration (const btCollisionWorld* collisionWorld);
00093 void stepUp (const btCollisionWorld* collisionWorld);
00094 void updateTargetPositionBasedOnCollision (const btVector3& hit_normal,
00095 btScalar tangentMag = btScalar(0.0),
00096 btScalar normalMag = btScalar(1.0));
00097
00098 void stepForwardAndStrafe (const btCollisionWorld* collisionWorld, const btVector3& walkMove);
00099 void stepDown (const btCollisionWorld* collisionWorld, btScalar dt);
00100 };
00101
00102 #endif