Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/archive/tutorialFS09/src/bullet/BulletDynamics/Character/btKinematicCharacterController.h @ 10179

Last change on this file since 10179 was 2662, checked in by rgrieder, 16 years ago

Merged presentation branch back to trunk.

  • Property svn:eol-style set to native
File size: 3.9 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        btVector3 computeReflectionDirection (const btVector3& direction, const btVector3& normal);
67        btVector3 parallelComponent (const btVector3& direction, const btVector3& normal);
68        btVector3 perpindicularComponent (const btVector3& direction, const btVector3& normal);
69
70        bool recoverFromPenetration (btCollisionWorld* collisionWorld);
71        void stepUp (btCollisionWorld* collisionWorld);
72        void updateTargetPositionBasedOnCollision (const btVector3& hit_normal, btScalar tangentMag = btScalar(0.0), btScalar normalMag = btScalar(1.0));
73        void stepForwardAndStrafe (btCollisionWorld* collisionWorld, const btVector3& walkMove);
74        void stepDown (btCollisionWorld* collisionWorld, btScalar dt);
75public:
76        btKinematicCharacterController (btPairCachingGhostObject* ghostObject,btConvexShape* convexShape,btScalar stepHeight);
77        ~btKinematicCharacterController ();
78       
79        virtual void    setWalkDirection(const btVector3& walkDirection)
80        {
81                m_walkDirection = walkDirection;
82        }
83
84        void reset ();
85        void warp (const btVector3& origin);
86
87        void preStep ( btCollisionWorld* collisionWorld);
88        void playerStep (btCollisionWorld* collisionWorld, btScalar dt);
89
90        void setFallSpeed (btScalar fallSpeed);
91        void setJumpSpeed (btScalar jumpSpeed);
92        void setMaxJumpHeight (btScalar maxJumpHeight);
93        bool canJump () const;
94        void jump ();
95
96        btPairCachingGhostObject* getGhostObject();
97        void    setUseGhostSweepTest(bool useGhostObjectSweepTest)
98        {
99                m_useGhostObjectSweepTest = useGhostObjectSweepTest;
100        }
101
102        bool onGround () const;
103};
104
105#endif // KINEMATIC_CHARACTER_CONTROLLER_H
Note: See TracBrowser for help on using the repository browser.