Changeset 2882 for code/trunk/src/bullet/BulletDynamics/Character
- Timestamp:
- Mar 31, 2009, 8:05:51 PM (16 years ago)
- Location:
- code/trunk/src/bullet/BulletDynamics/Character
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/bullet/BulletDynamics/Character/btCharacterControllerInterface.h
r2662 r2882 18 18 19 19 #include "LinearMath/btVector3.h" 20 #include "BulletDynamics/Dynamics/btActionInterface.h" 20 21 21 22 class btCollisionShape; … … 23 24 class btCollisionWorld; 24 25 25 class btCharacterControllerInterface 26 class btCharacterControllerInterface : public btActionInterface 26 27 { 27 28 public: -
code/trunk/src/bullet/BulletDynamics/Character/btKinematicCharacterController.cpp
r2662 r2882 23 23 #include "btKinematicCharacterController.h" 24 24 25 static btVector3 upAxisDirection[3] = { btVector3(1.0f, 0.0f, 0.0f), btVector3(0.0f, 1.0f, 0.0f), btVector3(0.0f, 0.0f, 1.0f) }; 26 25 27 ///@todo Interact with dynamic objects, 26 28 ///Ride kinematicly animated platforms properly … … 94 96 } 95 97 96 btKinematicCharacterController::btKinematicCharacterController (btPairCachingGhostObject* ghostObject,btConvexShape* convexShape,btScalar stepHeight) 97 { 98 btKinematicCharacterController::btKinematicCharacterController (btPairCachingGhostObject* ghostObject,btConvexShape* convexShape,btScalar stepHeight, int upAxis) 99 { 100 m_upAxis = upAxis; 98 101 m_addedMargin = 0.02f; 99 102 m_walkDirection.setValue(0,0,0); … … 102 105 m_stepHeight = stepHeight; 103 106 m_turnAngle = btScalar(0.0); 104 m_convexShape=convexShape; 105 107 m_convexShape=convexShape; 106 108 } 107 109 … … 110 112 } 111 113 112 113 114 btPairCachingGhostObject* btKinematicCharacterController::getGhostObject() 114 115 { … … 116 117 } 117 118 118 bool btKinematicCharacterController::recoverFromPenetration ( btCollisionWorld* collisionWorld)119 bool btKinematicCharacterController::recoverFromPenetration ( btCollisionWorld* collisionWorld) 119 120 { 120 121 … … 173 174 // phase 1: up 174 175 btTransform start, end; 175 m_targetPosition = m_currentPosition + btVector3 (btScalar(0.0), m_stepHeight, btScalar(0.0));176 m_targetPosition = m_currentPosition + upAxisDirection[m_upAxis] * m_stepHeight; 176 177 177 178 start.setIdentity (); … … 179 180 180 181 /* FIXME: Handle penetration properly */ 181 start.setOrigin (m_currentPosition + btVector3(btScalar(0.0), btScalar(0.1), btScalar(0.0)));182 start.setOrigin (m_currentPosition + upAxisDirection[m_upAxis] * btScalar(0.1f)); 182 183 end.setOrigin (m_targetPosition); 183 184 … … 344 345 345 346 // phase 3: down 346 btVector3 step_drop = btVector3(btScalar(0.0), m_currentStepOffset, btScalar(0.0));347 btVector3 gravity_drop = btVector3(btScalar(0.0), m_stepHeight, btScalar(0.0));347 btVector3 step_drop = upAxisDirection[m_upAxis] * m_currentStepOffset; 348 btVector3 gravity_drop = upAxisDirection[m_upAxis] * m_stepHeight; 348 349 m_targetPosition -= (step_drop + gravity_drop); 349 350 … … 390 391 391 392 392 void btKinematicCharacterController::preStep ( btCollisionWorld* collisionWorld)393 void btKinematicCharacterController::preStep ( btCollisionWorld* collisionWorld) 393 394 { 394 395 … … 413 414 } 414 415 415 void btKinematicCharacterController::playerStep ( btCollisionWorld* collisionWorld, btScalar dt)416 void btKinematicCharacterController::playerStep ( btCollisionWorld* collisionWorld, btScalar dt) 416 417 { 417 418 btTransform xform; … … 469 470 return true; 470 471 } 472 473 474 void btKinematicCharacterController::debugDraw(btIDebugDraw* debugDrawer) 475 { 476 } -
code/trunk/src/bullet/BulletDynamics/Character/btKinematicCharacterController.h
r2662 r2882 63 63 64 64 bool m_useGhostObjectSweepTest; 65 66 int m_upAxis; 65 67 66 68 btVector3 computeReflectionDirection (const btVector3& direction, const btVector3& normal); … … 68 70 btVector3 perpindicularComponent (const btVector3& direction, const btVector3& normal); 69 71 70 bool recoverFromPenetration ( btCollisionWorld* collisionWorld);72 bool recoverFromPenetration ( btCollisionWorld* collisionWorld); 71 73 void stepUp (btCollisionWorld* collisionWorld); 72 74 void updateTargetPositionBasedOnCollision (const btVector3& hit_normal, btScalar tangentMag = btScalar(0.0), btScalar normalMag = btScalar(1.0)); … … 74 76 void stepDown (btCollisionWorld* collisionWorld, btScalar dt); 75 77 public: 76 btKinematicCharacterController (btPairCachingGhostObject* ghostObject,btConvexShape* convexShape,btScalar stepHeight );78 btKinematicCharacterController (btPairCachingGhostObject* ghostObject,btConvexShape* convexShape,btScalar stepHeight, int upAxis = 1); 77 79 ~btKinematicCharacterController (); 78 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 79 101 virtual void setWalkDirection(const btVector3& walkDirection) 80 102 { … … 85 107 void warp (const btVector3& origin); 86 108 87 void preStep ( btCollisionWorld* collisionWorld);88 void playerStep ( btCollisionWorld* collisionWorld, btScalar dt);109 void preStep ( btCollisionWorld* collisionWorld); 110 void playerStep ( btCollisionWorld* collisionWorld, btScalar dt); 89 111 90 112 void setFallSpeed (btScalar fallSpeed);
Note: See TracChangeset
for help on using the changeset viewer.