Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/questsystem5/src/bullet/BulletDynamics/Character/btKinematicCharacterController.h @ 2907

Last change on this file since 2907 was 2907, checked in by dafrick, 16 years ago

Merging of the current QuestSystem branch.

  • Property svn:eol-style set to native
File size: 4.3 KB
Line 
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2008 Erwin Coumans  http://bulletphysics.com
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. This notice may not be removed or altered from any source distribution.
14*/
15
16#ifndef KINEMATIC_CHARACTER_CONTROLLER_H
17#define KINEMATIC_CHARACTER_CONTROLLER_H
18
19#include "LinearMath/btVector3.h"
20
21#include "btCharacterControllerInterface.h"
22
23class btCollisionShape;
24class btRigidBody;
25class btCollisionWorld;
26class btCollisionDispatcher;
27class btPairCachingGhostObject;
28
29///btKinematicCharacterController is an object that supports a sliding motion in a world.
30///It uses a ghost object and convex sweep test to test for upcoming collisions. This is combined with discrete collision detection to recover from penetrations.
31///Interaction between btKinematicCharacterController and dynamic rigid bodies needs to be explicity implemented by the user.
32class btKinematicCharacterController : public btCharacterControllerInterface
33{
34protected:
35        btScalar m_halfHeight;
36       
37        btPairCachingGhostObject* m_ghostObject;
38        btConvexShape*  m_convexShape;//is also in m_ghostObject, but it needs to be convex, so we store it here to avoid upcast
39       
40        btScalar m_fallSpeed;
41        btScalar m_jumpSpeed;
42        btScalar m_maxJumpHeight;
43
44        btScalar m_turnAngle;
45       
46        btScalar m_stepHeight;
47
48        btScalar        m_addedMargin;//@todo: remove this and fix the code
49
50        ///this is the desired walk direction, set by the user
51        btVector3       m_walkDirection;
52
53        //some internal variables
54        btVector3 m_currentPosition;
55        btScalar  m_currentStepOffset;
56        btVector3 m_targetPosition;
57
58        ///keep track of the contact manifolds
59        btManifoldArray m_manifoldArray;
60
61        bool m_touchingContact;
62        btVector3 m_touchingNormal;
63
64        bool    m_useGhostObjectSweepTest;
65
66        int m_upAxis;
67       
68        btVector3 computeReflectionDirection (const btVector3& direction, const btVector3& normal);
69        btVector3 parallelComponent (const btVector3& direction, const btVector3& normal);
70        btVector3 perpindicularComponent (const btVector3& direction, const btVector3& normal);
71
72        bool recoverFromPenetration ( btCollisionWorld* collisionWorld);
73        void stepUp (btCollisionWorld* collisionWorld);
74        void updateTargetPositionBasedOnCollision (const btVector3& hit_normal, btScalar tangentMag = btScalar(0.0), btScalar normalMag = btScalar(1.0));
75        void stepForwardAndStrafe (btCollisionWorld* collisionWorld, const btVector3& walkMove);
76        void stepDown (btCollisionWorld* collisionWorld, btScalar dt);
77public:
78        btKinematicCharacterController (btPairCachingGhostObject* ghostObject,btConvexShape* convexShape,btScalar stepHeight, int upAxis = 1);
79        ~btKinematicCharacterController ();
80       
81
82        ///btActionInterface interface
83        virtual void updateAction( btCollisionWorld* collisionWorld,btScalar deltaTime)
84        {
85                preStep ( collisionWorld);
86                playerStep (collisionWorld, deltaTime);
87        }
88       
89        ///btActionInterface interface
90        void    debugDraw(btIDebugDraw* debugDrawer);
91
92        void setUpAxis (int axis)
93        {
94                if (axis < 0)
95                        axis = 0;
96                if (axis > 2)
97                        axis = 2;
98                m_upAxis = axis;
99        }
100
101        virtual void    setWalkDirection(const btVector3& walkDirection)
102        {
103                m_walkDirection = walkDirection;
104        }
105
106        void reset ();
107        void warp (const btVector3& origin);
108
109        void preStep (  btCollisionWorld* collisionWorld);
110        void playerStep ( btCollisionWorld* collisionWorld, btScalar dt);
111
112        void setFallSpeed (btScalar fallSpeed);
113        void setJumpSpeed (btScalar jumpSpeed);
114        void setMaxJumpHeight (btScalar maxJumpHeight);
115        bool canJump () const;
116        void jump ();
117
118        btPairCachingGhostObject* getGhostObject();
119        void    setUseGhostSweepTest(bool useGhostObjectSweepTest)
120        {
121                m_useGhostObjectSweepTest = useGhostObjectSweepTest;
122        }
123
124        bool onGround () const;
125};
126
127#endif // KINEMATIC_CHARACTER_CONTROLLER_H
Note: See TracBrowser for help on using the repository browser.