Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 13, 2008, 11:45:51 PM (16 years ago)
Author:
rgrieder
Message:

Updated to Bullet 2.73 (first part).

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  
    3939#include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h"
    4040#include "BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h"
    41 #include "BulletCollision/NarrowPhaseCollision/btGjkEpa.h"
     41#include "BulletCollision/NarrowPhaseCollision/btGjkEpa2.h"
    4242#include "BulletCollision/CollisionShapes/btMinkowskiSumShape.h"
    4343#include "BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h"
     
    256256        btAssert(colShape->getShapeType()==CONVEX_HULL_SHAPE_PROXYTYPE);
    257257        btConvexHullShape* convexHullShape = reinterpret_cast<btConvexHullShape*>( cshape);
    258         convexHullShape->addPoint(btPoint3(x,y,z));
     258        convexHullShape->addPoint(btVector3(x,y,z));
    259259
    260260}
  • code/branches/physics/src/bullet/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp

    r2192 r2430  
    5252#include "BulletDynamics/Vehicle/btVehicleRaycaster.h"
    5353#include "BulletDynamics/Vehicle/btWheelInfo.h"
     54//character
     55#include "BulletDynamics/Character/btCharacterControllerInterface.h"
     56
    5457#include "LinearMath/btIDebugDraw.h"
    5558#include "LinearMath/btQuickprof.h"
     
    126129void    btDiscreteDynamicsWorld::debugDrawWorld()
    127130{
     131        BT_PROFILE("debugDrawWorld");
    128132
    129133        if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawContactPoints)
     
    151155                int i;
    152156
    153                 //todo: iterate over awake simulation islands!
    154157                for (  i=0;i<m_collisionObjects.size();i++)
    155158                {
     
    180183                        if (m_debugDrawer && (m_debugDrawer->getDebugMode() & btIDebugDraw::DBG_DrawAabb))
    181184                        {
    182                                 btPoint3 minAabb,maxAabb;
     185                                btVector3 minAabb,maxAabb;
    183186                                btVector3 colorvec(1,0,0);
    184187                                colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(), minAabb,maxAabb);
     
    221224void    btDiscreteDynamicsWorld::clearForces()
    222225{
    223         //todo: iterate over awake simulation islands!
     226        ///@todo: iterate over awake simulation islands!
    224227        for ( int i=0;i<m_collisionObjects.size();i++)
    225228        {
     
    237240void    btDiscreteDynamicsWorld::applyGravity()
    238241{
    239         //todo: iterate over awake simulation islands!
     242        ///@todo: iterate over awake simulation islands!
    240243        for ( int i=0;i<m_collisionObjects.size();i++)
    241244        {
     
    251254
    252255
     256void    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
    253275
    254276void    btDiscreteDynamicsWorld::synchronizeMotionStates()
    255277{
     278        BT_PROFILE("synchronizeMotionStates");
    256279        {
    257280                //todo: iterate over awake simulation islands!
     
    261284                       
    262285                        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);
    276288                }
    277289        }
     
    393405        ///update vehicle simulation
    394406        updateVehicles(timeStep);
    395 
     407       
     408        updateCharacters(timeStep);
    396409
    397410        updateActivationState( timeStep );
     
    469482}
    470483
     484void    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       
    471498void    btDiscreteDynamicsWorld::updateActivationState(btScalar timeStep)
    472499{
     
    532559        m_vehicles.remove(vehicle);
    533560}
     561
     562void    btDiscreteDynamicsWorld::addCharacter(btCharacterControllerInterface* character)
     563{
     564        m_characters.push_back(character);
     565}
     566
     567void    btDiscreteDynamicsWorld::removeCharacter(btCharacterControllerInterface* character)
     568{
     569        m_characters.remove(character);
     570}
     571
    534572
    535573SIMD_FORCE_INLINE       int     btGetConstraintIslandId(const btTypedConstraint* lhs)
     
    665703       
    666704        /// solve all the constraints for this island
    667         m_islandManager->buildAndProcessIslands(getCollisionWorld()->getDispatcher(),getCollisionWorld()->getCollisionObjectArray(),&solverCallback);
     705        m_islandManager->buildAndProcessIslands(getCollisionWorld()->getDispatcher(),getCollisionWorld(),&solverCallback);
    668706
    669707        m_constraintSolver->allSolved(solverInfo, m_debugDrawer, m_stackAlloc);
     
    730768        {
    731769                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;
    733775
    734776                btVector3 linVelA,linVelB;
     
    751793
    752794                ///don't do CCD when the collision filters are not matching
    753                 if (!btCollisionWorld::ClosestConvexResultCallback::needsCollision(proxy0))
     795                if (!ClosestConvexResultCallback::needsCollision(proxy0))
    754796                        return false;
    755797
     
    808850                                                btConvexShape* convexShape = static_cast<btConvexShape*>(body->getCollisionShape());
    809851                                                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
    810856                                                convexSweepTest(&tmpSphere,body->getWorldTransform(),predictedTrans,sweepResults);
    811857                                                if (sweepResults.hasHit() && (sweepResults.m_closestHitFraction < 1.f))
     
    827873
    828874
     875
     876
    829877void    btDiscreteDynamicsWorld::predictUnconstraintMotion(btScalar timeStep)
    830878{
     
    838886                        if (!body->isStaticOrKinematicObject())
    839887                        {
    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());
    848894                        }
    849895                }
     
    10971143                                        btConcaveShape* concaveMesh = (btConcaveShape*) shape;
    10981144                                       
    1099                                         //todo pass camera, for some culling
     1145                                        ///@todo pass camera, for some culling? no -> we are not a graphics lib
    11001146                                        btVector3 aabbMax(btScalar(1e30),btScalar(1e30),btScalar(1e30));
    11011147                                        btVector3 aabbMin(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30));
     
    11261172                                        for (i=0;i<polyshape->getNumEdges();i++)
    11271173                                        {
    1128                                                 btPoint3 a,b;
     1174                                                btVector3 a,b;
    11291175                                                polyshape->getEdge(i,a,b);
    11301176                                                btVector3 wa = worldTransform * a;
  • code/branches/physics/src/bullet/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h

    r2192 r2430  
    2727
    2828class btRaycastVehicle;
     29class btCharacterControllerInterface;
    2930class btIDebugDraw;
    3031#include "LinearMath/btAlignedObjectArray.h"
     
    4344        btAlignedObjectArray<btTypedConstraint*> m_constraints;
    4445
    45 
    4646        btVector3       m_gravity;
    4747
     
    5555       
    5656        btAlignedObjectArray<btRaycastVehicle*> m_vehicles;
     57       
     58        btAlignedObjectArray<btCharacterControllerInterface*> m_characters;
     59       
    5760
    5861        int     m_profileTimings;
     
    6265        virtual void    integrateTransforms(btScalar timeStep);
    6366               
    64         void    calculateSimulationIslands();
     67        virtual void    calculateSimulationIslands();
    6568
    66         void    solveConstraints(btContactSolverInfo& solverInfo);
     69        virtual void    solveConstraints(btContactSolverInfo& solverInfo);
    6770       
    6871        void    updateActivationState(btScalar timeStep);
     
    7073        void    updateVehicles(btScalar timeStep);
    7174
     75        void    updateCharacters(btScalar timeStep);
     76
    7277        void    startProfiling(btScalar timeStep);
    7378
    7479        virtual void    internalSingleStepSimulation( btScalar timeStep);
    7580
    76         void    synchronizeMotionStates();
    7781
    78         void    saveKinematicState(btScalar timeStep);
     82        virtual void    saveKinematicState(btScalar timeStep);
    7983
    8084        void    debugDrawSphere(btScalar radius, const btTransform& transform, const btVector3& color);
     85
    8186
    8287public:
     
    9297
    9398
    94         void    addConstraint(btTypedConstraint* constraint, bool disableCollisionsBetweenLinkedBodies=false);
     99        virtual void    synchronizeMotionStates();
    95100
    96         void    removeConstraint(btTypedConstraint* constraint);
     101        ///this can be useful to synchronize a single rigid body -> graphics object
     102        void    synchronizeSingleMotionState(btRigidBody* body);
    97103
    98         void    addVehicle(btRaycastVehicle* vehicle);
     104        virtual void    addConstraint(btTypedConstraint* constraint, bool disableCollisionsBetweenLinkedBodies=false);
    99105
    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               
    101116
    102117        btSimulationIslandManager*      getSimulationIslandManager()
     
    114129                return this;
    115130        }
    116 
    117131
    118132        virtual void    setGravity(const btVector3& gravity);
     
    153167        virtual void    setNumTasks(int numTasks)
    154168        {
     169        (void) numTasks;
    155170        }
    156171
  • code/branches/physics/src/bullet/BulletDynamics/Dynamics/btDynamicsWorld.h

    r2192 r2430  
    2424class btConstraintSolver;
    2525class btDynamicsWorld;
     26class btCharacterControllerInterface;
    2627
    2728/// Type for the callback for each tick
     
    7677                virtual void    removeVehicle(btRaycastVehicle* vehicle) {(void)vehicle;}
    7778
     79                virtual void    addCharacter(btCharacterControllerInterface* character) {(void)character;}
     80
     81                virtual void    removeCharacter(btCharacterControllerInterface* character) {(void)character;}
     82
     83
    7884                //once a rigidbody is added to the dynamics world, it will get this gravity assigned
    7985                //existing rigidbodies in the world get gravity assigned too, during this method
    8086                virtual void    setGravity(const btVector3& gravity) = 0;
    8187                virtual btVector3 getGravity () const = 0;
     88
     89                virtual void    synchronizeMotionStates() = 0;
    8290
    8391                virtual void    addRigidBody(btRigidBody* body) = 0;
  • code/branches/physics/src/bullet/BulletDynamics/Dynamics/btRigidBody.h

    r2192 r2430  
    1818
    1919#include "LinearMath/btAlignedObjectArray.h"
    20 #include "LinearMath/btPoint3.h"
    2120#include "LinearMath/btTransform.h"
    2221#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
     
    3231
    3332
    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.
    3534///It is recommended for performance and memory use to share btCollisionShape objects whenever possible.
    3635///There are 3 types of rigid bodies:
     
    7675
    7776
    78         ///btRigidBodyConstructionInfo provides 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.
    7978        ///For dynamic objects, you can use the collision shape to approximate the local inertia tensor, otherwise use the zero vector (default argument)
    8079        ///You can use the motion state to synchronize the world transform between physics and graphics objects.
     
    304303        void updateInertiaTensor();   
    305304       
    306         const btPoint3&     getCenterOfMassPosition() const {
     305        const btVector3&     getCenterOfMassPosition() const {
    307306                return m_worldTransform.getOrigin();
    308307        }
     
    322321        inline void setLinearVelocity(const btVector3& lin_vel)
    323322        {
    324                 assert (m_collisionFlags != btCollisionObject::CF_STATIC_OBJECT);
    325323                m_linearVelocity = lin_vel;
    326324        }
    327325
    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;
    333329        }
    334330
     
    354350
    355351       
    356         SIMD_FORCE_INLINE btScalar computeImpulseDenominator(const btPoint3& pos, const btVector3& normal) const
     352        SIMD_FORCE_INLINE btScalar computeImpulseDenominator(const btVector3& pos, const btVector3& normal) const
    357353        {
    358354                btVector3 r0 = pos - getCenterOfMassPosition();
  • code/branches/physics/src/bullet/BulletDynamics/Dynamics/btSimpleDynamicsWorld.cpp

    r2192 r2430  
    9898void    btSimpleDynamicsWorld::clearForces()
    9999{
    100         //todo: iterate over awake simulation islands!
     100        ///@todo: iterate over awake simulation islands!
    101101        for ( int i=0;i<m_collisionObjects.size();i++)
    102102        {
     
    157157                        if (body->isActive() && (!body->isStaticObject()))
    158158                        {
    159                                 btPoint3 minAabb,maxAabb;
     159                                btVector3 minAabb,maxAabb;
    160160                                colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(), minAabb,maxAabb);
    161161                                btBroadphaseInterface* bp = getBroadphase();
     
    211211void    btSimpleDynamicsWorld::synchronizeMotionStates()
    212212{
    213         //todo: iterate over awake simulation islands!
     213        ///@todo: iterate over awake simulation islands!
    214214        for ( int i=0;i<m_collisionObjects.size();i++)
    215215        {
  • code/branches/physics/src/bullet/BulletDynamics/Dynamics/btSimpleDynamicsWorld.h

    r2192 r2430  
    2323class btConstraintSolver;
    2424
    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.
    2626///Please use btDiscreteDynamicsWorld instead (or btContinuousDynamicsWorld once it is finished).
    2727class btSimpleDynamicsWorld : public btDynamicsWorld
     
    6161        virtual void    updateAabbs();
    6262
    63         void    synchronizeMotionStates();
     63        virtual void    synchronizeMotionStates();
    6464
    6565        virtual void    setConstraintSolver(btConstraintSolver* solver);
Note: See TracChangeset for help on using the changeset viewer.