diff --git a/Demos/CcdPhysicsDemo/CMakeLists.txt b/Demos/CcdPhysicsDemo/CMakeLists.txt index 7324593fb..ea8d451dd 100644 --- a/Demos/CcdPhysicsDemo/CMakeLists.txt +++ b/Demos/CcdPhysicsDemo/CMakeLists.txt @@ -39,12 +39,14 @@ IF (WIN32) TARGET AppCcdPhysicsDemo POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/glut64.dll ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/glut64.dll ${CMAKE_CURRENT_BINARY_DIR}/Debug ) ELSE(CMAKE_CL_64) ADD_CUSTOM_COMMAND( TARGET AppCcdPhysicsDemo POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/GLUT32.DLL ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/GLUT32.DLL ${CMAKE_CURRENT_BINARY_DIR}/Debug ) ENDIF(CMAKE_CL_64) ENDIF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES) diff --git a/Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp b/Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp index 9d7477b1a..c0acf6551 100644 --- a/Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp +++ b/Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp @@ -15,7 +15,8 @@ subject to the following restrictions: -#define CUBE_HALF_EXTENTS 0.5 +#define CUBE_HALF_EXTENTS 1 + #define EXTRA_HEIGHT 1.f #include "CcdPhysicsDemo.h" @@ -40,7 +41,7 @@ CcdPhysicsDemo::CcdPhysicsDemo() :m_ccdMode(USE_CCD) { setDebugMode(btIDebugDraw::DBG_DrawText+btIDebugDraw::DBG_NoHelpText); - setCameraDistance(btScalar(20.)); + setCameraDistance(btScalar(40.)); } @@ -54,7 +55,7 @@ void CcdPhysicsDemo::clientMoveAndDisplay() ///step the simulation if (m_dynamicsWorld) { - m_dynamicsWorld->stepSimulation(1./60.);//ms / 1000000.f); + m_dynamicsWorld->stepSimulation(1./60.,0);//ms / 1000000.f); //optional but useful: debug drawing m_dynamicsWorld->debugDrawWorld(); } @@ -165,6 +166,7 @@ void CcdPhysicsDemo::initPhysics() m_ShootBoxInitialSpeed = 4000.f; + m_defaultContactProcessingThreshold = 0.f; ///collision configuration contains default setup for memory, collision setup m_collisionConfiguration = new btDefaultCollisionConfiguration(); @@ -172,7 +174,7 @@ void CcdPhysicsDemo::initPhysics() ///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded) m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration); - m_dispatcher->registerCollisionCreateFunc(BOX_SHAPE_PROXYTYPE,BOX_SHAPE_PROXYTYPE,m_collisionConfiguration->getCollisionAlgorithmCreateFunc(CONVEX_SHAPE_PROXYTYPE,CONVEX_SHAPE_PROXYTYPE)); + //m_dispatcher->registerCollisionCreateFunc(BOX_SHAPE_PROXYTYPE,BOX_SHAPE_PROXYTYPE,m_collisionConfiguration->getCollisionAlgorithmCreateFunc(CONVEX_SHAPE_PROXYTYPE,CONVEX_SHAPE_PROXYTYPE)); m_broadphase = new btDbvtBroadphase(); @@ -181,8 +183,15 @@ void CcdPhysicsDemo::initPhysics() m_solver = sol; m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration); + m_dynamicsWorld->getSolverInfo().m_solverMode |=SOLVER_USE_2_FRICTION_DIRECTIONS|SOLVER_RANDMIZE_ORDER; + + + m_dynamicsWorld ->setDebugDrawer(&sDebugDrawer); + //m_dynamicsWorld->getSolverInfo().m_splitImpulse=false; + + if (m_ccdMode==USE_CCD) { @@ -202,7 +211,8 @@ void CcdPhysicsDemo::initPhysics() // btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),50); m_collisionShapes.push_back(groundShape); - m_collisionShapes.push_back(new btCylinderShape (btVector3(CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS))); + //m_collisionShapes.push_back(new btCylinderShape (btVector3(CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS))); + m_collisionShapes.push_back(new btBoxShape (btVector3(CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS))); btTransform groundTransform; groundTransform.setIdentity(); @@ -223,7 +233,8 @@ void CcdPhysicsDemo::initPhysics() btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform); btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia); btRigidBody* body = new btRigidBody(rbInfo); - body->setRollingFriction(0.3); + body->setFriction(0.5); + //body->setRollingFriction(0.3); //add the body to the dynamics world m_dynamicsWorld->addRigidBody(body); } @@ -251,7 +262,7 @@ void CcdPhysicsDemo::initPhysics() if (isDynamic) colShape->calculateLocalInertia(mass,localInertia); - int gNumObjects = 120; + int gNumObjects = 120;//120; int i; for (i=0;isetAnisotropicFriction(shape->getAnisotropicRollingFrictionDirection(),btCollisionObject::CF_ANISOTROPIC_ROLLING_FRICTION); + body->setFriction(0.5); - body->setRollingFriction(.3); + //body->setRollingFriction(.3); ///when using m_ccdMode if (m_ccdMode==USE_CCD) { diff --git a/Demos/GyroscopicDemo/CMakeLists.txt b/Demos/GyroscopicDemo/CMakeLists.txt index ca6856637..828b9c412 100644 --- a/Demos/GyroscopicDemo/CMakeLists.txt +++ b/Demos/GyroscopicDemo/CMakeLists.txt @@ -43,7 +43,6 @@ IF (USE_GLUT) POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/GLUT32.DLL ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/GLUT32.DLL ${CMAKE_CURRENT_BINARY_DIR}/Debug - COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/GLUT32.DLL ${CMAKE_CURRENT_BINARY_DIR}/Release ) ENDIF(CMAKE_CL_64) diff --git a/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp b/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp index cd8b87469..a8534d194 100644 --- a/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp +++ b/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp @@ -830,9 +830,21 @@ void btSequentialImpulseConstraintSolver::convertContact(btPersistentManifold* m } } - - - cp.m_lateralFrictionInitialized = false; + ///Bullet has several options to set the friction directions + ///By default, each contact has only a single friction direction that is recomputed automatically very frame + ///based on the relative linear velocity. + ///If the relative velocity it zero, it will automatically compute a friction direction. + + ///You can also enable two friction directions, using the SOLVER_USE_2_FRICTION_DIRECTIONS. + ///In that case, the second friction direction will be orthogonal to both contact normal and first friction direction. + /// + ///If you choose SOLVER_DISABLE_VELOCITY_DEPENDENT_FRICTION_DIRECTION, then the friction will be independent from the relative projected velocity. + /// + ///The user can manually override the friction directions for certain contacts using a contact callback, + ///and set the cp.m_lateralFrictionInitialized to true + ///In that case, you can set the target relative motion in each friction direction (cp.m_contactMotion1 and cp.m_contactMotion2) + ///this will give a conveyor belt effect + /// if (!(infoGlobal.m_solverMode & SOLVER_ENABLE_FRICTION_DIRECTION_CACHING) || !cp.m_lateralFrictionInitialized) { cp.m_lateralFrictionDir1 = vel - cp.m_normalWorldOnB * rel_vel; @@ -854,12 +866,9 @@ void btSequentialImpulseConstraintSolver::convertContact(btPersistentManifold* m applyAnisotropicFriction(colObj1,cp.m_lateralFrictionDir1,btCollisionObject::CF_ANISOTROPIC_FRICTION); addFrictionConstraint(cp.m_lateralFrictionDir1,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation); - - cp.m_lateralFrictionInitialized = true; } else { - if (!(infoGlobal.m_solverMode & SOLVER_ALLOW_ZERO_LENGTH_FRICTION_DIRECTIONS)) - btPlaneSpace1(cp.m_normalWorldOnB,cp.m_lateralFrictionDir1,cp.m_lateralFrictionDir2); + btPlaneSpace1(cp.m_normalWorldOnB,cp.m_lateralFrictionDir1,cp.m_lateralFrictionDir2); if ((infoGlobal.m_solverMode & SOLVER_USE_2_FRICTION_DIRECTIONS)) { @@ -872,8 +881,10 @@ void btSequentialImpulseConstraintSolver::convertContact(btPersistentManifold* m applyAnisotropicFriction(colObj1,cp.m_lateralFrictionDir1,btCollisionObject::CF_ANISOTROPIC_FRICTION); addFrictionConstraint(cp.m_lateralFrictionDir1,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation); - - cp.m_lateralFrictionInitialized = true; + if ((infoGlobal.m_solverMode & SOLVER_USE_2_FRICTION_DIRECTIONS) && (infoGlobal.m_solverMode & SOLVER_DISABLE_VELOCITY_DEPENDENT_FRICTION_DIRECTION)) + { + cp.m_lateralFrictionInitialized = true; + } } } else @@ -882,10 +893,12 @@ void btSequentialImpulseConstraintSolver::convertContact(btPersistentManifold* m if ((infoGlobal.m_solverMode & SOLVER_USE_2_FRICTION_DIRECTIONS)) addFrictionConstraint(cp.m_lateralFrictionDir2,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation, cp.m_contactMotion2, cp.m_contactCFM2); + + setFrictionConstraintImpulse( solverConstraint, solverBodyIdA, solverBodyIdB, cp, infoGlobal); } + - - setFrictionConstraintImpulse( solverConstraint, solverBodyIdA, solverBodyIdB, cp, infoGlobal); + } } @@ -1235,7 +1248,8 @@ btScalar btSequentialImpulseConstraintSolver::solveSingleIteration(int iteration if (infoGlobal.m_solverMode & SOLVER_RANDMIZE_ORDER) { - if ((iteration & 7) == 0) { + if (1) // uncomment this for a bit less random ((iteration & 7) == 0) + { for (int j=0; jbtScalar(0))