00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef KINEMATIC_CHARACTER_CONTROLLER_H
00017 #define KINEMATIC_CHARACTER_CONTROLLER_H
00018
00019 #include "LinearMath/btVector3.h"
00020
00021 #include "btCharacterControllerInterface.h"
00022
00023 #include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h"
00024
00025
00026 class btCollisionShape;
00027 class btRigidBody;
00028 class btCollisionWorld;
00029 class btCollisionDispatcher;
00030 class btPairCachingGhostObject;
00031
00035 class btKinematicCharacterController : public btCharacterControllerInterface
00036 {
00037 protected:
00038
00039 btScalar m_halfHeight;
00040
00041 btPairCachingGhostObject* m_ghostObject;
00042 btConvexShape* m_convexShape;
00043
00044 btScalar m_fallSpeed;
00045 btScalar m_jumpSpeed;
00046 btScalar m_maxJumpHeight;
00047
00048 btScalar m_turnAngle;
00049
00050 btScalar m_stepHeight;
00051
00052 btScalar m_addedMargin;
00053
00055 btVector3 m_walkDirection;
00056 btVector3 m_normalizedDirection;
00057
00058
00059 btVector3 m_currentPosition;
00060 btScalar m_currentStepOffset;
00061 btVector3 m_targetPosition;
00062
00064 btManifoldArray m_manifoldArray;
00065
00066 bool m_touchingContact;
00067 btVector3 m_touchingNormal;
00068
00069 bool m_useGhostObjectSweepTest;
00070 bool m_useWalkDirection;
00071 btScalar m_velocityTimeInterval;
00072 int m_upAxis;
00073
00074 static btVector3* getUpAxisDirections();
00075
00076 btVector3 computeReflectionDirection (const btVector3& direction, const btVector3& normal);
00077 btVector3 parallelComponent (const btVector3& direction, const btVector3& normal);
00078 btVector3 perpindicularComponent (const btVector3& direction, const btVector3& normal);
00079
00080 bool recoverFromPenetration ( btCollisionWorld* collisionWorld);
00081 void stepUp (btCollisionWorld* collisionWorld);
00082 void updateTargetPositionBasedOnCollision (const btVector3& hit_normal, btScalar tangentMag = btScalar(0.0), btScalar normalMag = btScalar(1.0));
00083 void stepForwardAndStrafe (btCollisionWorld* collisionWorld, const btVector3& walkMove);
00084 void stepDown (btCollisionWorld* collisionWorld, btScalar dt);
00085 public:
00086 btKinematicCharacterController (btPairCachingGhostObject* ghostObject,btConvexShape* convexShape,btScalar stepHeight, int upAxis = 1);
00087 ~btKinematicCharacterController ();
00088
00089
00091 virtual void updateAction( btCollisionWorld* collisionWorld,btScalar deltaTime)
00092 {
00093 preStep ( collisionWorld);
00094 playerStep (collisionWorld, deltaTime);
00095 }
00096
00098 void debugDraw(btIDebugDraw* debugDrawer);
00099
00100 void setUpAxis (int axis)
00101 {
00102 if (axis < 0)
00103 axis = 0;
00104 if (axis > 2)
00105 axis = 2;
00106 m_upAxis = axis;
00107 }
00108
00114 virtual void setWalkDirection(const btVector3& walkDirection);
00115
00121 virtual void setVelocityForTimeInterval(const btVector3& velocity,
00122 btScalar timeInterval);
00123
00124 void reset ();
00125 void warp (const btVector3& origin);
00126
00127 void preStep ( btCollisionWorld* collisionWorld);
00128 void playerStep ( btCollisionWorld* collisionWorld, btScalar dt);
00129
00130 void setFallSpeed (btScalar fallSpeed);
00131 void setJumpSpeed (btScalar jumpSpeed);
00132 void setMaxJumpHeight (btScalar maxJumpHeight);
00133 bool canJump () const;
00134 void jump ();
00135
00136 btPairCachingGhostObject* getGhostObject();
00137 void setUseGhostSweepTest(bool useGhostObjectSweepTest)
00138 {
00139 m_useGhostObjectSweepTest = useGhostObjectSweepTest;
00140 }
00141
00142 bool onGround () const;
00143 };
00144
00145 #endif // KINEMATIC_CHARACTER_CONTROLLER_H