Changeset 2430 for code/branches/physics/src/bullet/BulletDynamics/Dynamics
- Timestamp:
- Dec 13, 2008, 11:45:51 PM (16 years ago)
- Location:
- code/branches/physics/src/bullet/BulletDynamics/Dynamics
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/physics/src/bullet/BulletDynamics/Dynamics/Bullet-C-API.cpp
r2192 r2430 39 39 #include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h" 40 40 #include "BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h" 41 #include "BulletCollision/NarrowPhaseCollision/btGjkEpa .h"41 #include "BulletCollision/NarrowPhaseCollision/btGjkEpa2.h" 42 42 #include "BulletCollision/CollisionShapes/btMinkowskiSumShape.h" 43 43 #include "BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h" … … 256 256 btAssert(colShape->getShapeType()==CONVEX_HULL_SHAPE_PROXYTYPE); 257 257 btConvexHullShape* convexHullShape = reinterpret_cast<btConvexHullShape*>( cshape); 258 convexHullShape->addPoint(bt Point3(x,y,z));258 convexHullShape->addPoint(btVector3(x,y,z)); 259 259 260 260 } -
code/branches/physics/src/bullet/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp
r2192 r2430 52 52 #include "BulletDynamics/Vehicle/btVehicleRaycaster.h" 53 53 #include "BulletDynamics/Vehicle/btWheelInfo.h" 54 //character 55 #include "BulletDynamics/Character/btCharacterControllerInterface.h" 56 54 57 #include "LinearMath/btIDebugDraw.h" 55 58 #include "LinearMath/btQuickprof.h" … … 126 129 void btDiscreteDynamicsWorld::debugDrawWorld() 127 130 { 131 BT_PROFILE("debugDrawWorld"); 128 132 129 133 if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawContactPoints) … … 151 155 int i; 152 156 153 //todo: iterate over awake simulation islands!154 157 for ( i=0;i<m_collisionObjects.size();i++) 155 158 { … … 180 183 if (m_debugDrawer && (m_debugDrawer->getDebugMode() & btIDebugDraw::DBG_DrawAabb)) 181 184 { 182 bt Point3 minAabb,maxAabb;185 btVector3 minAabb,maxAabb; 183 186 btVector3 colorvec(1,0,0); 184 187 colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(), minAabb,maxAabb); … … 221 224 void btDiscreteDynamicsWorld::clearForces() 222 225 { 223 // todo: iterate over awake simulation islands!226 ///@todo: iterate over awake simulation islands! 224 227 for ( int i=0;i<m_collisionObjects.size();i++) 225 228 { … … 237 240 void btDiscreteDynamicsWorld::applyGravity() 238 241 { 239 // todo: iterate over awake simulation islands!242 ///@todo: iterate over awake simulation islands! 240 243 for ( int i=0;i<m_collisionObjects.size();i++) 241 244 { … … 251 254 252 255 256 void btDiscreteDynamicsWorld::synchronizeSingleMotionState(btRigidBody* body) 257 { 258 btAssert(body); 259 260 if (body->getMotionState() && !body->isStaticOrKinematicObject()) 261 { 262 //we need to call the update at least once, even for sleeping objects 263 //otherwise the 'graphics' transform never updates properly 264 ///@todo: add 'dirty' flag 265 //if (body->getActivationState() != ISLAND_SLEEPING) 266 { 267 btTransform interpolatedTransform; 268 btTransformUtil::integrateTransform(body->getInterpolationWorldTransform(), 269 body->getInterpolationLinearVelocity(),body->getInterpolationAngularVelocity(),m_localTime*body->getHitFraction(),interpolatedTransform); 270 body->getMotionState()->setWorldTransform(interpolatedTransform); 271 } 272 } 273 } 274 253 275 254 276 void btDiscreteDynamicsWorld::synchronizeMotionStates() 255 277 { 278 BT_PROFILE("synchronizeMotionStates"); 256 279 { 257 280 //todo: iterate over awake simulation islands! … … 261 284 262 285 btRigidBody* body = btRigidBody::upcast(colObj); 263 if (body && body->getMotionState() && !body->isStaticOrKinematicObject()) 264 { 265 //we need to call the update at least once, even for sleeping objects 266 //otherwise the 'graphics' transform never updates properly 267 //so todo: add 'dirty' flag 268 //if (body->getActivationState() != ISLAND_SLEEPING) 269 { 270 btTransform interpolatedTransform; 271 btTransformUtil::integrateTransform(body->getInterpolationWorldTransform(), 272 body->getInterpolationLinearVelocity(),body->getInterpolationAngularVelocity(),m_localTime*body->getHitFraction(),interpolatedTransform); 273 body->getMotionState()->setWorldTransform(interpolatedTransform); 274 } 275 } 286 if (body) 287 synchronizeSingleMotionState(body); 276 288 } 277 289 } … … 393 405 ///update vehicle simulation 394 406 updateVehicles(timeStep); 395 407 408 updateCharacters(timeStep); 396 409 397 410 updateActivationState( timeStep ); … … 469 482 } 470 483 484 void btDiscreteDynamicsWorld::updateCharacters(btScalar timeStep) 485 { 486 BT_PROFILE("updateCharacters"); 487 488 for ( int i=0;i<m_characters.size();i++) 489 { 490 btCharacterControllerInterface* character = m_characters[i]; 491 character->preStep (this); 492 character->playerStep (this,timeStep); 493 } 494 } 495 496 497 471 498 void btDiscreteDynamicsWorld::updateActivationState(btScalar timeStep) 472 499 { … … 532 559 m_vehicles.remove(vehicle); 533 560 } 561 562 void btDiscreteDynamicsWorld::addCharacter(btCharacterControllerInterface* character) 563 { 564 m_characters.push_back(character); 565 } 566 567 void btDiscreteDynamicsWorld::removeCharacter(btCharacterControllerInterface* character) 568 { 569 m_characters.remove(character); 570 } 571 534 572 535 573 SIMD_FORCE_INLINE int btGetConstraintIslandId(const btTypedConstraint* lhs) … … 665 703 666 704 /// solve all the constraints for this island 667 m_islandManager->buildAndProcessIslands(getCollisionWorld()->getDispatcher(),getCollisionWorld() ->getCollisionObjectArray(),&solverCallback);705 m_islandManager->buildAndProcessIslands(getCollisionWorld()->getDispatcher(),getCollisionWorld(),&solverCallback); 668 706 669 707 m_constraintSolver->allSolved(solverInfo, m_debugDrawer, m_stackAlloc); … … 730 768 { 731 769 if (convexResult.m_hitCollisionObject == m_me) 732 return 1.0; 770 return 1.0f; 771 772 //ignore result if there is no contact response 773 if(!convexResult.m_hitCollisionObject->hasContactResponse()) 774 return 1.0f; 733 775 734 776 btVector3 linVelA,linVelB; … … 751 793 752 794 ///don't do CCD when the collision filters are not matching 753 if (! btCollisionWorld::ClosestConvexResultCallback::needsCollision(proxy0))795 if (!ClosestConvexResultCallback::needsCollision(proxy0)) 754 796 return false; 755 797 … … 808 850 btConvexShape* convexShape = static_cast<btConvexShape*>(body->getCollisionShape()); 809 851 btSphereShape tmpSphere(body->getCcdSweptSphereRadius());//btConvexShape* convexShape = static_cast<btConvexShape*>(body->getCollisionShape()); 852 853 sweepResults.m_collisionFilterGroup = body->getBroadphaseProxy()->m_collisionFilterGroup; 854 sweepResults.m_collisionFilterMask = body->getBroadphaseProxy()->m_collisionFilterMask; 855 810 856 convexSweepTest(&tmpSphere,body->getWorldTransform(),predictedTrans,sweepResults); 811 857 if (sweepResults.hasHit() && (sweepResults.m_closestHitFraction < 1.f)) … … 827 873 828 874 875 876 829 877 void btDiscreteDynamicsWorld::predictUnconstraintMotion(btScalar timeStep) 830 878 { … … 838 886 if (!body->isStaticOrKinematicObject()) 839 887 { 840 if (body->isActive()) 841 { 842 body->integrateVelocities( timeStep); 843 //damping 844 body->applyDamping(timeStep); 845 846 body->predictIntegratedTransform(timeStep,body->getInterpolationWorldTransform()); 847 } 888 889 body->integrateVelocities( timeStep); 890 //damping 891 body->applyDamping(timeStep); 892 893 body->predictIntegratedTransform(timeStep,body->getInterpolationWorldTransform()); 848 894 } 849 895 } … … 1097 1143 btConcaveShape* concaveMesh = (btConcaveShape*) shape; 1098 1144 1099 // todo pass camera, for some culling1145 ///@todo pass camera, for some culling? no -> we are not a graphics lib 1100 1146 btVector3 aabbMax(btScalar(1e30),btScalar(1e30),btScalar(1e30)); 1101 1147 btVector3 aabbMin(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30)); … … 1126 1172 for (i=0;i<polyshape->getNumEdges();i++) 1127 1173 { 1128 bt Point3 a,b;1174 btVector3 a,b; 1129 1175 polyshape->getEdge(i,a,b); 1130 1176 btVector3 wa = worldTransform * a; -
code/branches/physics/src/bullet/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h
r2192 r2430 27 27 28 28 class btRaycastVehicle; 29 class btCharacterControllerInterface; 29 30 class btIDebugDraw; 30 31 #include "LinearMath/btAlignedObjectArray.h" … … 43 44 btAlignedObjectArray<btTypedConstraint*> m_constraints; 44 45 45 46 46 btVector3 m_gravity; 47 47 … … 55 55 56 56 btAlignedObjectArray<btRaycastVehicle*> m_vehicles; 57 58 btAlignedObjectArray<btCharacterControllerInterface*> m_characters; 59 57 60 58 61 int m_profileTimings; … … 62 65 virtual void integrateTransforms(btScalar timeStep); 63 66 64 v oid calculateSimulationIslands();67 virtual void calculateSimulationIslands(); 65 68 66 v oid solveConstraints(btContactSolverInfo& solverInfo);69 virtual void solveConstraints(btContactSolverInfo& solverInfo); 67 70 68 71 void updateActivationState(btScalar timeStep); … … 70 73 void updateVehicles(btScalar timeStep); 71 74 75 void updateCharacters(btScalar timeStep); 76 72 77 void startProfiling(btScalar timeStep); 73 78 74 79 virtual void internalSingleStepSimulation( btScalar timeStep); 75 80 76 void synchronizeMotionStates();77 81 78 v oid saveKinematicState(btScalar timeStep);82 virtual void saveKinematicState(btScalar timeStep); 79 83 80 84 void debugDrawSphere(btScalar radius, const btTransform& transform, const btVector3& color); 85 81 86 82 87 public: … … 92 97 93 98 94 v oid addConstraint(btTypedConstraint* constraint, bool disableCollisionsBetweenLinkedBodies=false);99 virtual void synchronizeMotionStates(); 95 100 96 void removeConstraint(btTypedConstraint* constraint); 101 ///this can be useful to synchronize a single rigid body -> graphics object 102 void synchronizeSingleMotionState(btRigidBody* body); 97 103 98 v oid addVehicle(btRaycastVehicle* vehicle);104 virtual void addConstraint(btTypedConstraint* constraint, bool disableCollisionsBetweenLinkedBodies=false); 99 105 100 void removeVehicle(btRaycastVehicle* vehicle); 106 virtual void removeConstraint(btTypedConstraint* constraint); 107 108 virtual void addVehicle(btRaycastVehicle* vehicle); 109 110 virtual void removeVehicle(btRaycastVehicle* vehicle); 111 112 virtual void addCharacter(btCharacterControllerInterface* character); 113 114 virtual void removeCharacter(btCharacterControllerInterface* character); 115 101 116 102 117 btSimulationIslandManager* getSimulationIslandManager() … … 114 129 return this; 115 130 } 116 117 131 118 132 virtual void setGravity(const btVector3& gravity); … … 153 167 virtual void setNumTasks(int numTasks) 154 168 { 169 (void) numTasks; 155 170 } 156 171 -
code/branches/physics/src/bullet/BulletDynamics/Dynamics/btDynamicsWorld.h
r2192 r2430 24 24 class btConstraintSolver; 25 25 class btDynamicsWorld; 26 class btCharacterControllerInterface; 26 27 27 28 /// Type for the callback for each tick … … 76 77 virtual void removeVehicle(btRaycastVehicle* vehicle) {(void)vehicle;} 77 78 79 virtual void addCharacter(btCharacterControllerInterface* character) {(void)character;} 80 81 virtual void removeCharacter(btCharacterControllerInterface* character) {(void)character;} 82 83 78 84 //once a rigidbody is added to the dynamics world, it will get this gravity assigned 79 85 //existing rigidbodies in the world get gravity assigned too, during this method 80 86 virtual void setGravity(const btVector3& gravity) = 0; 81 87 virtual btVector3 getGravity () const = 0; 88 89 virtual void synchronizeMotionStates() = 0; 82 90 83 91 virtual void addRigidBody(btRigidBody* body) = 0; -
code/branches/physics/src/bullet/BulletDynamics/Dynamics/btRigidBody.h
r2192 r2430 18 18 19 19 #include "LinearMath/btAlignedObjectArray.h" 20 #include "LinearMath/btPoint3.h"21 20 #include "LinearMath/btTransform.h" 22 21 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" … … 32 31 33 32 34 /// btRigidBody is the main class for rigid body objects. It is derived from btCollisionObject, so it keeps a pointer to a btCollisionShape.33 ///The btRigidBody is the main class for rigid body objects. It is derived from btCollisionObject, so it keeps a pointer to a btCollisionShape. 35 34 ///It is recommended for performance and memory use to share btCollisionShape objects whenever possible. 36 35 ///There are 3 types of rigid bodies: … … 76 75 77 76 78 /// btRigidBodyConstructionInfoprovides information to create a rigid body. Setting mass to zero creates a fixed (non-dynamic) rigid body.77 ///The btRigidBodyConstructionInfo structure provides information to create a rigid body. Setting mass to zero creates a fixed (non-dynamic) rigid body. 79 78 ///For dynamic objects, you can use the collision shape to approximate the local inertia tensor, otherwise use the zero vector (default argument) 80 79 ///You can use the motion state to synchronize the world transform between physics and graphics objects. … … 304 303 void updateInertiaTensor(); 305 304 306 const bt Point3& getCenterOfMassPosition() const {305 const btVector3& getCenterOfMassPosition() const { 307 306 return m_worldTransform.getOrigin(); 308 307 } … … 322 321 inline void setLinearVelocity(const btVector3& lin_vel) 323 322 { 324 assert (m_collisionFlags != btCollisionObject::CF_STATIC_OBJECT);325 323 m_linearVelocity = lin_vel; 326 324 } 327 325 328 inline void setAngularVelocity(const btVector3& ang_vel) { 329 assert (m_collisionFlags != btCollisionObject::CF_STATIC_OBJECT); 330 { 331 m_angularVelocity = ang_vel; 332 } 326 inline void setAngularVelocity(const btVector3& ang_vel) 327 { 328 m_angularVelocity = ang_vel; 333 329 } 334 330 … … 354 350 355 351 356 SIMD_FORCE_INLINE btScalar computeImpulseDenominator(const bt Point3& pos, const btVector3& normal) const352 SIMD_FORCE_INLINE btScalar computeImpulseDenominator(const btVector3& pos, const btVector3& normal) const 357 353 { 358 354 btVector3 r0 = pos - getCenterOfMassPosition(); -
code/branches/physics/src/bullet/BulletDynamics/Dynamics/btSimpleDynamicsWorld.cpp
r2192 r2430 98 98 void btSimpleDynamicsWorld::clearForces() 99 99 { 100 // todo: iterate over awake simulation islands!100 ///@todo: iterate over awake simulation islands! 101 101 for ( int i=0;i<m_collisionObjects.size();i++) 102 102 { … … 157 157 if (body->isActive() && (!body->isStaticObject())) 158 158 { 159 bt Point3 minAabb,maxAabb;159 btVector3 minAabb,maxAabb; 160 160 colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(), minAabb,maxAabb); 161 161 btBroadphaseInterface* bp = getBroadphase(); … … 211 211 void btSimpleDynamicsWorld::synchronizeMotionStates() 212 212 { 213 // todo: iterate over awake simulation islands!213 ///@todo: iterate over awake simulation islands! 214 214 for ( int i=0;i<m_collisionObjects.size();i++) 215 215 { -
code/branches/physics/src/bullet/BulletDynamics/Dynamics/btSimpleDynamicsWorld.h
r2192 r2430 23 23 class btConstraintSolver; 24 24 25 /// btSimpleDynamicsWorld serves as unit-test and to verify more complicated and optimized dynamics worlds.25 ///The btSimpleDynamicsWorld serves as unit-test and to verify more complicated and optimized dynamics worlds. 26 26 ///Please use btDiscreteDynamicsWorld instead (or btContinuousDynamicsWorld once it is finished). 27 27 class btSimpleDynamicsWorld : public btDynamicsWorld … … 61 61 virtual void updateAabbs(); 62 62 63 v oid synchronizeMotionStates();63 virtual void synchronizeMotionStates(); 64 64 65 65 virtual void setConstraintSolver(btConstraintSolver* solver);
Note: See TracChangeset
for help on using the changeset viewer.