tweak CcdPhysicsDemo
remove wrong cp.m_lateralFrictionInitialized = false; See http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?p=28851#p28851
This commit is contained in:
@@ -39,12 +39,14 @@ IF (WIN32)
|
|||||||
TARGET AppCcdPhysicsDemo
|
TARGET AppCcdPhysicsDemo
|
||||||
POST_BUILD
|
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}
|
||||||
|
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/glut64.dll ${CMAKE_CURRENT_BINARY_DIR}/Debug
|
||||||
)
|
)
|
||||||
ELSE(CMAKE_CL_64)
|
ELSE(CMAKE_CL_64)
|
||||||
ADD_CUSTOM_COMMAND(
|
ADD_CUSTOM_COMMAND(
|
||||||
TARGET AppCcdPhysicsDemo
|
TARGET AppCcdPhysicsDemo
|
||||||
POST_BUILD
|
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}
|
||||||
|
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/GLUT32.DLL ${CMAKE_CURRENT_BINARY_DIR}/Debug
|
||||||
)
|
)
|
||||||
ENDIF(CMAKE_CL_64)
|
ENDIF(CMAKE_CL_64)
|
||||||
ENDIF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
|
ENDIF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
|
||||||
|
|||||||
@@ -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
|
#define EXTRA_HEIGHT 1.f
|
||||||
|
|
||||||
#include "CcdPhysicsDemo.h"
|
#include "CcdPhysicsDemo.h"
|
||||||
@@ -40,7 +41,7 @@ CcdPhysicsDemo::CcdPhysicsDemo()
|
|||||||
:m_ccdMode(USE_CCD)
|
:m_ccdMode(USE_CCD)
|
||||||
{
|
{
|
||||||
setDebugMode(btIDebugDraw::DBG_DrawText+btIDebugDraw::DBG_NoHelpText);
|
setDebugMode(btIDebugDraw::DBG_DrawText+btIDebugDraw::DBG_NoHelpText);
|
||||||
setCameraDistance(btScalar(20.));
|
setCameraDistance(btScalar(40.));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -54,7 +55,7 @@ void CcdPhysicsDemo::clientMoveAndDisplay()
|
|||||||
///step the simulation
|
///step the simulation
|
||||||
if (m_dynamicsWorld)
|
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
|
//optional but useful: debug drawing
|
||||||
m_dynamicsWorld->debugDrawWorld();
|
m_dynamicsWorld->debugDrawWorld();
|
||||||
}
|
}
|
||||||
@@ -165,6 +166,7 @@ void CcdPhysicsDemo::initPhysics()
|
|||||||
|
|
||||||
m_ShootBoxInitialSpeed = 4000.f;
|
m_ShootBoxInitialSpeed = 4000.f;
|
||||||
|
|
||||||
|
m_defaultContactProcessingThreshold = 0.f;
|
||||||
|
|
||||||
///collision configuration contains default setup for memory, collision setup
|
///collision configuration contains default setup for memory, collision setup
|
||||||
m_collisionConfiguration = new btDefaultCollisionConfiguration();
|
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)
|
///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 = 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();
|
m_broadphase = new btDbvtBroadphase();
|
||||||
|
|
||||||
@@ -181,8 +183,15 @@ void CcdPhysicsDemo::initPhysics()
|
|||||||
m_solver = sol;
|
m_solver = sol;
|
||||||
|
|
||||||
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
|
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 ->setDebugDrawer(&sDebugDrawer);
|
||||||
|
|
||||||
|
//m_dynamicsWorld->getSolverInfo().m_splitImpulse=false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (m_ccdMode==USE_CCD)
|
if (m_ccdMode==USE_CCD)
|
||||||
{
|
{
|
||||||
@@ -202,7 +211,8 @@ void CcdPhysicsDemo::initPhysics()
|
|||||||
// btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),50);
|
// btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),50);
|
||||||
|
|
||||||
m_collisionShapes.push_back(groundShape);
|
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;
|
btTransform groundTransform;
|
||||||
groundTransform.setIdentity();
|
groundTransform.setIdentity();
|
||||||
@@ -223,7 +233,8 @@ void CcdPhysicsDemo::initPhysics()
|
|||||||
btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
|
btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
|
||||||
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia);
|
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia);
|
||||||
btRigidBody* body = new btRigidBody(rbInfo);
|
btRigidBody* body = new btRigidBody(rbInfo);
|
||||||
body->setRollingFriction(0.3);
|
body->setFriction(0.5);
|
||||||
|
//body->setRollingFriction(0.3);
|
||||||
//add the body to the dynamics world
|
//add the body to the dynamics world
|
||||||
m_dynamicsWorld->addRigidBody(body);
|
m_dynamicsWorld->addRigidBody(body);
|
||||||
}
|
}
|
||||||
@@ -251,7 +262,7 @@ void CcdPhysicsDemo::initPhysics()
|
|||||||
if (isDynamic)
|
if (isDynamic)
|
||||||
colShape->calculateLocalInertia(mass,localInertia);
|
colShape->calculateLocalInertia(mass,localInertia);
|
||||||
|
|
||||||
int gNumObjects = 120;
|
int gNumObjects = 120;//120;
|
||||||
int i;
|
int i;
|
||||||
for (i=0;i<gNumObjects;i++)
|
for (i=0;i<gNumObjects;i++)
|
||||||
{
|
{
|
||||||
@@ -282,8 +293,9 @@ void CcdPhysicsDemo::initPhysics()
|
|||||||
|
|
||||||
btRigidBody* body = localCreateRigidBody(mass,trans,shape);
|
btRigidBody* body = localCreateRigidBody(mass,trans,shape);
|
||||||
body->setAnisotropicFriction(shape->getAnisotropicRollingFrictionDirection(),btCollisionObject::CF_ANISOTROPIC_ROLLING_FRICTION);
|
body->setAnisotropicFriction(shape->getAnisotropicRollingFrictionDirection(),btCollisionObject::CF_ANISOTROPIC_ROLLING_FRICTION);
|
||||||
|
body->setFriction(0.5);
|
||||||
|
|
||||||
body->setRollingFriction(.3);
|
//body->setRollingFriction(.3);
|
||||||
///when using m_ccdMode
|
///when using m_ccdMode
|
||||||
if (m_ccdMode==USE_CCD)
|
if (m_ccdMode==USE_CCD)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ IF (USE_GLUT)
|
|||||||
POST_BUILD
|
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}
|
||||||
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}/Debug
|
||||||
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${BULLET_PHYSICS_SOURCE_DIR}/GLUT32.DLL ${CMAKE_CURRENT_BINARY_DIR}/Release
|
|
||||||
|
|
||||||
)
|
)
|
||||||
ENDIF(CMAKE_CL_64)
|
ENDIF(CMAKE_CL_64)
|
||||||
|
|||||||
@@ -830,9 +830,21 @@ void btSequentialImpulseConstraintSolver::convertContact(btPersistentManifold* m
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///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
|
||||||
cp.m_lateralFrictionInitialized = false;
|
///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)
|
if (!(infoGlobal.m_solverMode & SOLVER_ENABLE_FRICTION_DIRECTION_CACHING) || !cp.m_lateralFrictionInitialized)
|
||||||
{
|
{
|
||||||
cp.m_lateralFrictionDir1 = vel - cp.m_normalWorldOnB * rel_vel;
|
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);
|
applyAnisotropicFriction(colObj1,cp.m_lateralFrictionDir1,btCollisionObject::CF_ANISOTROPIC_FRICTION);
|
||||||
addFrictionConstraint(cp.m_lateralFrictionDir1,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
|
addFrictionConstraint(cp.m_lateralFrictionDir1,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
|
||||||
|
|
||||||
|
|
||||||
cp.m_lateralFrictionInitialized = true;
|
|
||||||
} else
|
} 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))
|
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);
|
applyAnisotropicFriction(colObj1,cp.m_lateralFrictionDir1,btCollisionObject::CF_ANISOTROPIC_FRICTION);
|
||||||
addFrictionConstraint(cp.m_lateralFrictionDir1,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
|
addFrictionConstraint(cp.m_lateralFrictionDir1,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
|
||||||
|
|
||||||
|
if ((infoGlobal.m_solverMode & SOLVER_USE_2_FRICTION_DIRECTIONS) && (infoGlobal.m_solverMode & SOLVER_DISABLE_VELOCITY_DEPENDENT_FRICTION_DIRECTION))
|
||||||
cp.m_lateralFrictionInitialized = true;
|
{
|
||||||
|
cp.m_lateralFrictionInitialized = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else
|
} else
|
||||||
@@ -882,10 +893,12 @@ void btSequentialImpulseConstraintSolver::convertContact(btPersistentManifold* m
|
|||||||
|
|
||||||
if ((infoGlobal.m_solverMode & SOLVER_USE_2_FRICTION_DIRECTIONS))
|
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);
|
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 (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; j<numNonContactPool; ++j) {
|
for (int j=0; j<numNonContactPool; ++j) {
|
||||||
int tmp = m_orderNonContactConstraintPool[j];
|
int tmp = m_orderNonContactConstraintPool[j];
|
||||||
@@ -1372,6 +1386,7 @@ btScalar btSequentialImpulseConstraintSolver::solveSingleIteration(int iteration
|
|||||||
int numRollingFrictionPoolConstraints = m_tmpSolverContactRollingFrictionConstraintPool.size();
|
int numRollingFrictionPoolConstraints = m_tmpSolverContactRollingFrictionConstraintPool.size();
|
||||||
for (j=0;j<numRollingFrictionPoolConstraints;j++)
|
for (j=0;j<numRollingFrictionPoolConstraints;j++)
|
||||||
{
|
{
|
||||||
|
|
||||||
btSolverConstraint& rollingFrictionConstraint = m_tmpSolverContactRollingFrictionConstraintPool[j];
|
btSolverConstraint& rollingFrictionConstraint = m_tmpSolverContactRollingFrictionConstraintPool[j];
|
||||||
btScalar totalImpulse = m_tmpSolverContactConstraintPool[rollingFrictionConstraint.m_frictionIndex].m_appliedImpulse;
|
btScalar totalImpulse = m_tmpSolverContactConstraintPool[rollingFrictionConstraint.m_frictionIndex].m_appliedImpulse;
|
||||||
if (totalImpulse>btScalar(0))
|
if (totalImpulse>btScalar(0))
|
||||||
|
|||||||
Reference in New Issue
Block a user