Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Updated to Bullet 2.73 (first part).

Location:
code/branches/physics/src/bullet/BulletDynamics
Files:
4 added
18 edited

Legend:

Unmodified
Added
Removed
  • code/branches/physics/src/bullet/BulletDynamics/CMakeLists.txt

    r2192 r2430  
    1 ADD_LIBRARY(LibBulletDynamics
    2 
     1SET(BulletDynamics_SRCS
    32        ConstraintSolver/btContactConstraint.cpp
    4         ConstraintSolver/btContactConstraint.h
    53        ConstraintSolver/btConeTwistConstraint.cpp
    6         ConstraintSolver/btConeTwistConstraint.h
    74        ConstraintSolver/btGeneric6DofConstraint.cpp
    8         ConstraintSolver/btGeneric6DofConstraint.h
    95        ConstraintSolver/btHingeConstraint.cpp
    10         ConstraintSolver/btHingeConstraint.h
    116        ConstraintSolver/btPoint2PointConstraint.cpp
    12         ConstraintSolver/btPoint2PointConstraint.h
    137        ConstraintSolver/btSequentialImpulseConstraintSolver.cpp
    14         ConstraintSolver/btSequentialImpulseConstraintSolver.h
    158        ConstraintSolver/btSliderConstraint.cpp
    16         ConstraintSolver/btSliderConstraint.h
    179        ConstraintSolver/btSolve2LinearConstraint.cpp
    18         ConstraintSolver/btSolve2LinearConstraint.h
    1910        ConstraintSolver/btTypedConstraint.cpp
    20         ConstraintSolver/btTypedConstraint.h
    2111        Dynamics/Bullet-C-API.cpp
    2212        Dynamics/btDiscreteDynamicsWorld.cpp
    23         Dynamics/btDiscreteDynamicsWorld.h
    2413        Dynamics/btSimpleDynamicsWorld.cpp
    25         Dynamics/btSimpleDynamicsWorld.h
    2614        Dynamics/btRigidBody.cpp
    27         Dynamics/btRigidBody.h
    2815        Vehicle/btRaycastVehicle.cpp
    29         Vehicle/btRaycastVehicle.h
    3016        Vehicle/btWheelInfo.cpp
    31         Vehicle/btWheelInfo.h
     17        Character/btKinematicCharacterController.cpp
    3218)
     19
     20ADD_LIBRARY(BulletDynamics ${BulletDynamics_SRCS})
  • code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btConeTwistConstraint.h

    r2192 r2430  
    2121#define CONETWISTCONSTRAINT_H
    2222
    23 #include "../../LinearMath/btVector3.h"
     23#include "LinearMath/btVector3.h"
    2424#include "btJacobianEntry.h"
    2525#include "btTypedConstraint.h"
  • code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btContactConstraint.cpp

    r2192 r2430  
    426426
    427427        return btScalar(0.);
    428 };
    429 
     428}
     429
  • code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btContactConstraint.h

    r2192 r2430  
    1717#define CONTACT_CONSTRAINT_H
    1818
    19 //todo: make into a proper class working with the iterative constraint solver
     19///@todo: make into a proper class working with the iterative constraint solver
    2020
    2121class btRigidBody;
  • code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btContactSolverInfo.h

    r2192 r2430  
    2222        SOLVER_FRICTION_SEPARATE = 2,
    2323        SOLVER_USE_WARMSTARTING = 4,
    24         SOLVER_CACHE_FRIENDLY = 8
     24        SOLVER_USE_FRICTION_WARMSTARTING = 8,
     25        SOLVER_CACHE_FRIENDLY = 16
    2526};
    2627
     
    4546
    4647        int                     m_solverMode;
     48        int     m_restingContactRestitutionThreshold;
    4749
    4850
     
    6971                m_linearSlop = btScalar(0.0);
    7072                m_warmstartingFactor=btScalar(0.85);
    71                 m_solverMode = SOLVER_RANDMIZE_ORDER | SOLVER_CACHE_FRIENDLY | SOLVER_USE_WARMSTARTING;
     73                m_solverMode = SOLVER_CACHE_FRIENDLY |  SOLVER_RANDMIZE_ORDER |  SOLVER_USE_WARMSTARTING;
     74                m_restingContactRestitutionThreshold = 2;//resting contact lifetime threshold to disable restitution
    7275        }
    7376};
  • code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.cpp

    r2192 r2430  
    2727
    2828
    29 static const btScalar kSign[] = { btScalar(1.0), btScalar(-1.0), btScalar(1.0) };
    30 static const int kAxisA[] = { 1, 0, 0 };
    31 static const int kAxisB[] = { 2, 2, 1 };
    3229#define GENERIC_D6_DISABLE_WARMSTARTING 1
    3330
     
    157154    btScalar clippedMotorImpulse;
    158155
    159     //todo: should clip against accumulated impulse
     156    ///@todo: should clip against accumulated impulse
    160157    if (unclippedMotorImpulse>0.0f)
    161158    {
  • code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btHingeConstraint.cpp

    r2192 r2430  
    324324                                        getRigidBodyB().computeAngularImpulseDenominator(normal);
    325325                                // scale for mass and relaxation
    326                                 //todo:  expose this 0.9 factor to developer
    327326                                velrelOrthog *= (btScalar(1.)/denom) * m_relaxationFactor;
    328327                        }
  • code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp

    r2192 r2430  
    438438
    439439
    440 void    btSequentialImpulseConstraintSolver::addFrictionConstraint(const btVector3& normalAxis,int solverBodyIdA,int solverBodyIdB,int frictionIndex,btManifoldPoint& cp,const btVector3& rel_pos1,const btVector3& rel_pos2,btCollisionObject* colObj0,btCollisionObject* colObj1, btScalar relaxation)
     440btSolverConstraint&     btSequentialImpulseConstraintSolver::addFrictionConstraint(const btVector3& normalAxis,int solverBodyIdA,int solverBodyIdB,int frictionIndex,btManifoldPoint& cp,const btVector3& rel_pos1,const btVector3& rel_pos2,btCollisionObject* colObj0,btCollisionObject* colObj1, btScalar relaxation)
    441441{
    442442
     
    492492        solverConstraint.m_jacDiagABInv = denom;
    493493
    494 
     494        return solverConstraint;
    495495}
    496496
     
    719719
    720720                                                        solverConstraint.m_friction = cp.m_combinedFriction;
    721                                                         solverConstraint.m_restitution =  restitutionCurve(rel_vel, cp.m_combinedRestitution);
    722                                                         if (solverConstraint.m_restitution <= btScalar(0.))
     721
     722                                                       
     723                                                        if (cp.m_lifeTime>infoGlobal.m_restingContactRestitutionThreshold)
    723724                                                        {
    724725                                                                solverConstraint.m_restitution = 0.f;
    725                                                         };
     726                                                        } else
     727                                                        {
     728                                                                solverConstraint.m_restitution =  restitutionCurve(rel_vel, cp.m_combinedRestitution);
     729                                                                if (solverConstraint.m_restitution <= btScalar(0.))
     730                                                                {
     731                                                                        solverConstraint.m_restitution = 0.f;
     732                                                                };
     733                                                        }
    726734
    727735                                                       
     
    761769                                                                        cp.m_lateralFrictionDir1 /= btSqrt(lat_rel_vel);
    762770                                                                        addFrictionConstraint(cp.m_lateralFrictionDir1,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
    763                                                                         cp.m_lateralFrictionDir2 = cp.m_lateralFrictionDir1.cross(cp.m_normalWorldOnB);
    764                                                                         cp.m_lateralFrictionDir2.normalize();//??
    765                                                                         addFrictionConstraint(cp.m_lateralFrictionDir2,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
     771                                                                        if(infoGlobal.m_solverMode & SOLVER_USE_FRICTION_WARMSTARTING)
     772                                                                        {
     773                                                                                cp.m_lateralFrictionDir2 = cp.m_lateralFrictionDir1.cross(cp.m_normalWorldOnB);
     774                                                                                cp.m_lateralFrictionDir2.normalize();//??
     775                                                                                addFrictionConstraint(cp.m_lateralFrictionDir2,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
     776                                                                                cp.m_lateralFrictionInitialized = true;
     777                                                                        }
    766778                                                                } else
    767779                                                                {
    768780                                                                        //re-calculate friction direction every frame, todo: check if this is really needed
    769                                                                        
    770781                                                                        btPlaneSpace1(cp.m_normalWorldOnB,cp.m_lateralFrictionDir1,cp.m_lateralFrictionDir2);
    771782                                                                        addFrictionConstraint(cp.m_lateralFrictionDir1,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
    772783                                                                        addFrictionConstraint(cp.m_lateralFrictionDir2,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
     784                                                                        if (infoGlobal.m_solverMode & SOLVER_USE_FRICTION_WARMSTARTING)
     785                                                                        {
     786                                                                                cp.m_lateralFrictionInitialized = true;
     787                                                                        }
    773788                                                                }
    774                                                                 cp.m_lateralFrictionInitialized = true;
    775789                                                               
    776790                                                        } else
    777791                                                        {
    778792                                                                addFrictionConstraint(cp.m_lateralFrictionDir1,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
    779                                                                 addFrictionConstraint(cp.m_lateralFrictionDir2,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
     793                                                                if (infoGlobal.m_solverMode & SOLVER_USE_FRICTION_WARMSTARTING)
     794                                                                        addFrictionConstraint(cp.m_lateralFrictionDir2,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
    780795                                                        }
    781796
     797                                                        if (infoGlobal.m_solverMode & SOLVER_USE_FRICTION_WARMSTARTING)
    782798                                                        {
    783                                                                 btSolverConstraint& frictionConstraint1 = m_tmpSolverFrictionConstraintPool[solverConstraint.m_frictionIndex];
    784                                                                 if (infoGlobal.m_solverMode & SOLVER_USE_WARMSTARTING)
    785799                                                                {
    786                                                                         frictionConstraint1.m_appliedImpulse = cp.m_appliedImpulseLateral1 * infoGlobal.m_warmstartingFactor;
    787                                                                         if (rb0)
    788                                                                                 m_tmpSolverBodyPool[solverConstraint.m_solverBodyIdA].internalApplyImpulse(frictionConstraint1.m_contactNormal*rb0->getInvMass(),frictionConstraint1.m_angularComponentA,frictionConstraint1.m_appliedImpulse);
    789                                                                         if (rb1)
    790                                                                                 m_tmpSolverBodyPool[solverConstraint.m_solverBodyIdB].internalApplyImpulse(frictionConstraint1.m_contactNormal*rb1->getInvMass(),frictionConstraint1.m_angularComponentB,-frictionConstraint1.m_appliedImpulse);
    791                                                                 } else
     800                                                                        btSolverConstraint& frictionConstraint1 = m_tmpSolverFrictionConstraintPool[solverConstraint.m_frictionIndex];
     801                                                                        if (infoGlobal.m_solverMode & SOLVER_USE_WARMSTARTING)
     802                                                                        {
     803                                                                                frictionConstraint1.m_appliedImpulse = cp.m_appliedImpulseLateral1 * infoGlobal.m_warmstartingFactor;
     804                                                                                if (rb0)
     805                                                                                        m_tmpSolverBodyPool[solverConstraint.m_solverBodyIdA].internalApplyImpulse(frictionConstraint1.m_contactNormal*rb0->getInvMass(),frictionConstraint1.m_angularComponentA,frictionConstraint1.m_appliedImpulse);
     806                                                                                if (rb1)
     807                                                                                        m_tmpSolverBodyPool[solverConstraint.m_solverBodyIdB].internalApplyImpulse(frictionConstraint1.m_contactNormal*rb1->getInvMass(),frictionConstraint1.m_angularComponentB,-frictionConstraint1.m_appliedImpulse);
     808                                                                        } else
     809                                                                        {
     810                                                                                frictionConstraint1.m_appliedImpulse = 0.f;
     811                                                                        }
     812                                                                }
    792813                                                                {
    793                                                                         frictionConstraint1.m_appliedImpulse = 0.f;
    794                                                                 }
    795                                                         }
    796                                                         {
    797                                                                 btSolverConstraint& frictionConstraint2 = m_tmpSolverFrictionConstraintPool[solverConstraint.m_frictionIndex+1];
    798                                                                 if (infoGlobal.m_solverMode & SOLVER_USE_WARMSTARTING)
    799                                                                 {
    800                                                                         frictionConstraint2.m_appliedImpulse = cp.m_appliedImpulseLateral2 * infoGlobal.m_warmstartingFactor;
    801                                                                         if (rb0)
    802                                                                                 m_tmpSolverBodyPool[solverConstraint.m_solverBodyIdA].internalApplyImpulse(frictionConstraint2.m_contactNormal*rb0->getInvMass(),frictionConstraint2.m_angularComponentA,frictionConstraint2.m_appliedImpulse);
    803                                                                         if (rb1)
    804                                                                                 m_tmpSolverBodyPool[solverConstraint.m_solverBodyIdB].internalApplyImpulse(frictionConstraint2.m_contactNormal*rb1->getInvMass(),frictionConstraint2.m_angularComponentB,-frictionConstraint2.m_appliedImpulse);
    805                                                                 } else
    806                                                                 {
    807                                                                         frictionConstraint2.m_appliedImpulse = 0.f;
     814                                                                        btSolverConstraint& frictionConstraint2 = m_tmpSolverFrictionConstraintPool[solverConstraint.m_frictionIndex+1];
     815                                                                        if (infoGlobal.m_solverMode & SOLVER_USE_WARMSTARTING)
     816                                                                        {
     817                                                                                frictionConstraint2.m_appliedImpulse = cp.m_appliedImpulseLateral2 * infoGlobal.m_warmstartingFactor;
     818                                                                                if (rb0)
     819                                                                                        m_tmpSolverBodyPool[solverConstraint.m_solverBodyIdA].internalApplyImpulse(frictionConstraint2.m_contactNormal*rb0->getInvMass(),frictionConstraint2.m_angularComponentA,frictionConstraint2.m_appliedImpulse);
     820                                                                                if (rb1)
     821                                                                                        m_tmpSolverBodyPool[solverConstraint.m_solverBodyIdB].internalApplyImpulse(frictionConstraint2.m_contactNormal*rb1->getInvMass(),frictionConstraint2.m_angularComponentB,-frictionConstraint2.m_appliedImpulse);
     822                                                                        } else
     823                                                                        {
     824                                                                                frictionConstraint2.m_appliedImpulse = 0.f;
     825                                                                        }
    808826                                                                }
    809827                                                        }
     
    833851        int numFrictionPool = m_tmpSolverFrictionConstraintPool.size();
    834852
    835         ///todo: use stack allocator for such temporarily memory, same for solver bodies/constraints
     853        ///@todo: use stack allocator for such temporarily memory, same for solver bodies/constraints
    836854        m_orderTmpConstraintPool.resize(numConstraintPool);
    837855        m_orderFrictionConstraintPool.resize(numFrictionPool);
     
    9851003                btAssert(pt);
    9861004                pt->m_appliedImpulse = solveManifold.m_appliedImpulse;
    987                 pt->m_appliedImpulseLateral1 = m_tmpSolverFrictionConstraintPool[solveManifold.m_frictionIndex].m_appliedImpulse;
    988                 pt->m_appliedImpulseLateral1 = m_tmpSolverFrictionConstraintPool[solveManifold.m_frictionIndex+1].m_appliedImpulse;
     1005                if (infoGlobal.m_solverMode & SOLVER_USE_FRICTION_WARMSTARTING)
     1006                {
     1007                        pt->m_appliedImpulseLateral1 = m_tmpSolverFrictionConstraintPool[solveManifold.m_frictionIndex].m_appliedImpulse;
     1008                        pt->m_appliedImpulseLateral2 = m_tmpSolverFrictionConstraintPool[solveManifold.m_frictionIndex+1].m_appliedImpulse;
     1009                }
    9891010
    9901011                //do a callback here?
     
    12211242                                cpd->m_penetration = cp.getDistance();///btScalar(info.m_numIterations);
    12221243                                cpd->m_friction = cp.m_combinedFriction;
    1223                                 cpd->m_restitution = restitutionCurve(rel_vel, combinedRestitution);
    1224                                 if (cpd->m_restitution <= btScalar(0.))
    1225                                 {
    1226                                         cpd->m_restitution = btScalar(0.0);
    1227 
    1228                                 };
     1244                                if (cp.m_lifeTime>info.m_restingContactRestitutionThreshold)
     1245                                {
     1246                                        cpd->m_restitution = 0.f;
     1247                                } else
     1248                                {
     1249                                        cpd->m_restitution = restitutionCurve(rel_vel, combinedRestitution);
     1250                                        if (cpd->m_restitution <= btScalar(0.))
     1251                                        {
     1252                                                cpd->m_restitution = btScalar(0.0);
     1253                                        };
     1254                                }
    12291255                               
    12301256                                //restitution and penetration work in same direction so
  • code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h

    r2192 r2430  
    2424
    2525
    26 /// btSequentialImpulseConstraintSolver uses a Propagation Method and Sequentially applies impulses
    27 /// The approach is the 3D version of Erin Catto's GDC 2006 tutorial. See http://www.gphysics.com
    28 /// Although Sequential Impulse is more intuitive, it is mathematically equivalent to Projected Successive Overrelaxation (iterative LCP)
    29 /// Applies impulses for combined restitution and penetration recovery and to simulate friction
     26///The btSequentialImpulseConstraintSolver uses a Propagation Method and Sequentially applies impulses
     27///The approach is the 3D version of Erin Catto's GDC 2006 tutorial. See http://www.gphysics.com
     28///Although Sequential Impulse is more intuitive, it is mathematically equivalent to Projected Successive Overrelaxation (iterative LCP)
     29///Applies impulses for combined restitution and penetration recovery and to simulate friction
    3030class btSequentialImpulseConstraintSolver : public btConstraintSolver
    3131{
     
    4242        btScalar solveFriction(btRigidBody* body0,btRigidBody* body1, btManifoldPoint& cp, const btContactSolverInfo& info,int iter,btIDebugDraw* debugDrawer);
    4343        void  prepareConstraints(btPersistentManifold* manifoldPtr, const btContactSolverInfo& info,btIDebugDraw* debugDrawer);
    44         void    addFrictionConstraint(const btVector3& normalAxis,int solverBodyIdA,int solverBodyIdB,int frictionIndex,btManifoldPoint& cp,const btVector3& rel_pos1,const btVector3& rel_pos2,btCollisionObject* colObj0,btCollisionObject* colObj1, btScalar relaxation);
     44        btSolverConstraint&     addFrictionConstraint(const btVector3& normalAxis,int solverBodyIdA,int solverBodyIdB,int frictionIndex,btManifoldPoint& cp,const btVector3& rel_pos1,const btVector3& rel_pos2,btCollisionObject* colObj0,btCollisionObject* colObj1, btScalar relaxation);
    4545
    4646        ContactSolverFunc m_contactDispatch[MAX_CONTACT_SOLVER_TYPES][MAX_CONTACT_SOLVER_TYPES];
  • code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btSolverBody.h

    r2192 r2430  
    2525
    2626
    27 ///btSolverBody is an internal datastructure for the constraint solver. Only necessary data is packed to increase cache coherence/performance.
     27///The btSolverBody is an internal datastructure for the constraint solver. Only necessary data is packed to increase cache coherence/performance.
    2828ATTRIBUTE_ALIGNED16 (struct)    btSolverBody
    2929{
    3030        BT_DECLARE_ALIGNED_ALLOCATOR();
    3131       
     32        btMatrix3x3             m_worldInvInertiaTensor;
     33
    3234        btVector3               m_angularVelocity;
     35        btVector3               m_linearVelocity;
     36        btVector3               m_centerOfMassPosition;
     37        btVector3               m_pushVelocity;
     38        btVector3               m_turnVelocity;
     39
    3340        float                   m_angularFactor;
    3441        float                   m_invMass;
    3542        float                   m_friction;
    3643        btRigidBody*    m_originalBody;
    37         btVector3               m_linearVelocity;
    38         btVector3               m_centerOfMassPosition;
    39        
    40         btVector3               m_pushVelocity;
    41         btVector3               m_turnVelocity;
    4244       
    4345       
  • 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);
  • code/branches/physics/src/bullet/BulletDynamics/Vehicle/btRaycastVehicle.cpp

    r2192 r2430  
    189189                wheel.m_raycastInfo.m_isInContact = true;
    190190               
    191                 wheel.m_raycastInfo.m_groundObject = &s_fixedObject;//todo for driving on dynamic/movable objects!;
     191                wheel.m_raycastInfo.m_groundObject = &s_fixedObject;///@todo for driving on dynamic/movable objects!;
    192192                //wheel.m_raycastInfo.m_groundObject = object;
    193193
     
    692692                                        btVector3 sideImp = m_axle[wheel] * m_sideImpulse[wheel];
    693693
    694                                         rel_pos[2] *= wheelInfo.m_rollInfluence;
     694                                        rel_pos[m_indexForwardAxis] *= wheelInfo.m_rollInfluence;
    695695                                        m_chassisBody->applyImpulse(sideImp,rel_pos);
    696696
Note: See TracChangeset for help on using the changeset viewer.