Blender  V3.3
btKinematicCharacterController.h
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2008 Erwin Coumans http://bulletphysics.com
4 
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
10 
11 1. 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.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 */
15 
16 #ifndef BT_KINEMATIC_CHARACTER_CONTROLLER_H
17 #define BT_KINEMATIC_CHARACTER_CONTROLLER_H
18 
19 #include "LinearMath/btVector3.h"
20 
22 
24 
25 class btCollisionShape;
26 class btConvexShape;
27 class btRigidBody;
28 class btCollisionWorld;
31 
37 {
38 protected:
39  btScalar m_halfHeight;
40 
42  btConvexShape* m_convexShape; //is also in m_ghostObject, but it needs to be convex, so we store it here to avoid upcast
43 
51  btScalar m_maxSlopeRadians; // Slope angle that is set (used for returning the exact value)
52  btScalar m_maxSlopeCosine; // Cosine equivalent of m_maxSlopeRadians (calculated once when set, for optimization)
54 
56 
58 
59  btScalar m_addedMargin; //@todo: remove this and fix the code
60 
65 
67 
68  //some internal variables
72 
75 
78 
81 
84 
92 
95  bool full_drop;
96  bool bounce_fix;
97 
99  btVector3 parallelComponent(const btVector3& direction, const btVector3& normal);
100  btVector3 perpindicularComponent(const btVector3& direction, const btVector3& normal);
101 
102  bool recoverFromPenetration(btCollisionWorld * collisionWorld);
103  void stepUp(btCollisionWorld * collisionWorld);
104  void updateTargetPositionBasedOnCollision(const btVector3& hit_normal, btScalar tangentMag = btScalar(0.0), btScalar normalMag = btScalar(1.0));
105  void stepForwardAndStrafe(btCollisionWorld * collisionWorld, const btVector3& walkMove);
106  void stepDown(btCollisionWorld * collisionWorld, btScalar dt);
107 
108  virtual bool needsCollision(const btCollisionObject* body0, const btCollisionObject* body1);
109 
110  void setUpVector(const btVector3& up);
111 
113 
114 public:
116 
117  btKinematicCharacterController(btPairCachingGhostObject * ghostObject, btConvexShape * convexShape, btScalar stepHeight, const btVector3& up = btVector3(1.0, 0.0, 0.0));
119 
121  virtual void updateAction(btCollisionWorld * collisionWorld, btScalar deltaTime)
122  {
123  preStep(collisionWorld);
124  playerStep(collisionWorld, deltaTime);
125  }
126 
128  void debugDraw(btIDebugDraw * debugDrawer);
129 
130  void setUp(const btVector3& up);
131 
132  const btVector3& getUp() { return m_up; }
133 
139  virtual void setWalkDirection(const btVector3& walkDirection);
140 
146  virtual void setVelocityForTimeInterval(const btVector3& velocity,
147  btScalar timeInterval);
148 
149  virtual void setAngularVelocity(const btVector3& velocity);
150  virtual const btVector3& getAngularVelocity() const;
151 
152  virtual void setLinearVelocity(const btVector3& velocity);
153  virtual btVector3 getLinearVelocity() const;
154 
159 
160  void reset(btCollisionWorld * collisionWorld);
161  void warp(const btVector3& origin);
162 
163  void preStep(btCollisionWorld * collisionWorld);
164  void playerStep(btCollisionWorld * collisionWorld, btScalar dt);
165 
166  void setStepHeight(btScalar h);
167  btScalar getStepHeight() const { return m_stepHeight; }
168  void setFallSpeed(btScalar fallSpeed);
169  btScalar getFallSpeed() const { return m_fallSpeed; }
170  void setJumpSpeed(btScalar jumpSpeed);
171  btScalar getJumpSpeed() const { return m_jumpSpeed; }
172  void setMaxJumpHeight(btScalar maxJumpHeight);
173  bool canJump() const;
174 
175  void jump(const btVector3& v = btVector3(0, 0, 0));
176 
177  void applyImpulse(const btVector3& v) { jump(v); }
178 
179  void setGravity(const btVector3& gravity);
181 
184  void setMaxSlope(btScalar slopeRadians);
185  btScalar getMaxSlope() const;
186 
189 
191  void setUseGhostSweepTest(bool useGhostObjectSweepTest)
192  {
193  m_useGhostObjectSweepTest = useGhostObjectSweepTest;
194  }
195 
196  bool onGround() const;
197  void setUpInterpolate(bool value);
198 };
199 
200 #endif // BT_KINEMATIC_CHARACTER_CONTROLLER_H
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble v1
ATTR_WARN_UNUSED_RESULT const BMVert * v
btCollisionObject
btCollisionShape
The btCollisionShape class provides an interface for collision shapes that can be shared among btColl...
btConvexShape()
not supported on IBM SDK, until we fix the alignment of btVector3
btVector3 m_jumpAxis
btScalar m_maxSlopeRadians
virtual btVector3 getLinearVelocity() const
void setLinearDamping(btScalar d)
btConvexShape * m_convexShape
BT_DECLARE_ALIGNED_ALLOCATOR()
void setUp(const btVector3 &up)
void setUpVector(const btVector3 &up)
btVector3 perpindicularComponent(const btVector3 &direction, const btVector3 &normal)
btScalar m_fallSpeed
btVector3 m_targetPosition
btScalar m_jumpSpeed
btVector3 getGravity() const
btScalar m_angularDamping
btScalar m_linearDamping
void setUseGhostSweepTest(bool useGhostObjectSweepTest)
const btVector3 & getUp()
virtual void setWalkDirection(const btVector3 &walkDirection)
btScalar getAngularDamping() const
btScalar m_turnAngle
void applyImpulse(const btVector3 &v)
virtual void setAngularVelocity(const btVector3 &velocity)
btVector3 computeReflectionDirection(const btVector3 &direction, const btVector3 &normal)
btScalar m_velocityTimeInterval
btScalar m_addedMargin
btScalar m_maxPenetrationDepth
void debugDraw(btIDebugDraw *debugDrawer)
btActionInterface interface
void stepDown(btCollisionWorld *collisionWorld, btScalar dt)
bool onGround() const
btVector3 m_up
void jump(const btVector3 &v=btVector3(0, 0, 0))
btScalar m_stepHeight
btScalar getMaxPenetrationDepth() const
btKinematicCharacterController(btPairCachingGhostObject *ghostObject, btConvexShape *convexShape, btScalar stepHeight, const btVector3 &up=btVector3(1.0, 0.0, 0.0))
btQuaternion m_targetOrientation
void setJumpSpeed(btScalar jumpSpeed)
btScalar getStepHeight() const
btManifoldArray m_manifoldArray
keep track of the contact manifolds
btVector3 m_jumpPosition
btVector3 m_walkDirection
this is the desired walk direction, set by the user
void stepForwardAndStrafe(btCollisionWorld *collisionWorld, const btVector3 &walkMove)
btScalar m_maxSlopeCosine
btScalar m_gravity
void setMaxSlope(btScalar slopeRadians)
void setStepHeight(btScalar h)
void setUpInterpolate(bool value)
void reset(btCollisionWorld *collisionWorld)
void setMaxPenetrationDepth(btScalar d)
void setFallSpeed(btScalar fallSpeed)
void setGravity(const btVector3 &gravity)
btScalar m_currentStepOffset
void updateTargetPositionBasedOnCollision(const btVector3 &hit_normal, btScalar tangentMag=btScalar(0.0), btScalar normalMag=btScalar(1.0))
bool canJump() const
void stepUp(btCollisionWorld *collisionWorld)
virtual void setLinearVelocity(const btVector3 &velocity)
void setAngularDamping(btScalar d)
void preStep(btCollisionWorld *collisionWorld)
btVector3 m_AngVel
void setMaxJumpHeight(btScalar maxJumpHeight)
virtual const btVector3 & getAngularVelocity() const
btPairCachingGhostObject * getGhostObject()
virtual bool needsCollision(const btCollisionObject *body0, const btCollisionObject *body1)
bool m_useGhostObjectSweepTest
btScalar m_SetjumpSpeed
virtual void setVelocityForTimeInterval(const btVector3 &velocity, btScalar timeInterval)
btScalar getJumpSpeed() const
btQuaternion m_currentOrientation
virtual void updateAction(btCollisionWorld *collisionWorld, btScalar deltaTime)
btActionInterface interface
btScalar getFallSpeed() const
btScalar m_verticalVelocity
btVector3 m_normalizedDirection
btVector3 m_currentPosition
void warp(const btVector3 &origin)
btQuaternion getRotation(btVector3 &v0, btVector3 &v1) const
btVector3 parallelComponent(const btVector3 &direction, const btVector3 &normal)
bool recoverFromPenetration(btCollisionWorld *collisionWorld)
btVector3 m_touchingNormal
btScalar m_verticalOffset
static btVector3 * getUpAxisDirections()
btScalar m_maxJumpHeight
btScalar getMaxSlope() const
void playerStep(btCollisionWorld *collisionWorld, btScalar dt)
btPairCachingGhostObject * m_ghostObject
btScalar getLinearDamping() const
SIMD_FORCE_INLINE const T & btClamped(const T &a, const T &lb, const T &ub)
Definition: btMinMax.h:33
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
#define ATTRIBUTE_ALIGNED16(a)
Definition: btScalar.h:285
btVector3
btVector3 can be used to represent 3D points and vectors. It has an un-used w component to suit 16-by...
Definition: btVector3.h:82
CollisionWorld is interface and container for the collision detection.
The btQuaternion implements quaternion to perform linear algebra rotations in combination with btMatr...
Definition: btQuaternion.h:50
IconTextureDrawCall normal