From a4e63aed0009c7b847497c918847bee1fd9757ad Mon Sep 17 00:00:00 2001 From: ejcoumans Date: Thu, 7 Feb 2008 08:00:16 +0000 Subject: [PATCH] - DemoApplication, debug text rendering was broken, glLoadIdentity() missing - copy user data over to child shape - added applied impulse to btManifoldPoint - add ContactProcessedCallback (needs test/demo) - didn't copy over m_additionalDampingFactor into btRigidBody. --- Demos/OpenGL/DemoApplication.cpp | 13 +++++++-- .../btConvexConcaveCollisionAlgorithm.cpp | 7 +++-- .../NarrowPhaseCollision/btManifoldPoint.h | 5 +++- .../btPersistentManifold.cpp | 6 ++++ .../btPersistentManifold.h | 4 +++ .../btSequentialImpulseConstraintSolver.cpp | 28 +++++++++++++++++-- .../ConstraintSolver/btSolverConstraint.h | 4 ++- src/BulletDynamics/Dynamics/btRigidBody.cpp | 2 +- 8 files changed, 60 insertions(+), 9 deletions(-) diff --git a/Demos/OpenGL/DemoApplication.cpp b/Demos/OpenGL/DemoApplication.cpp index 67aa7ebdf..5c652ce46 100644 --- a/Demos/OpenGL/DemoApplication.cpp +++ b/Demos/OpenGL/DemoApplication.cpp @@ -742,12 +742,16 @@ btRigidBody* DemoApplication::localCreateRigidBody(float mass, const btTransform #define USE_MOTIONSTATE 1 #ifdef USE_MOTIONSTATE btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform); - btRigidBody* body = new btRigidBody(btRigidBody::btRigidBodyConstructionInfo(mass,myMotionState,shape,localInertia)); + + btRigidBody::btRigidBodyConstructionInfo cInfo(mass,myMotionState,shape,localInertia); + + btRigidBody* body = new btRigidBody(cInfo); #else btRigidBody* body = new btRigidBody(mass,0,shape,localInertia); body->setWorldTransform(startTransform); #endif// + m_dynamicsWorld->addRigidBody(body); return body; @@ -759,6 +763,7 @@ void DemoApplication::setOrthographicProjection() // switch to projection mode glMatrixMode(GL_PROJECTION); + // save previous matrix which contains the //settings for the perspective projection glPushMatrix(); @@ -766,16 +771,20 @@ void DemoApplication::setOrthographicProjection() glLoadIdentity(); // set a 2D orthographic projection gluOrtho2D(0, m_glutScreenWidth, 0, m_glutScreenHeight); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + // invert the y axis, down is positive glScalef(1, -1, 1); // mover the origin from the bottom left corner // to the upper left corner glTranslatef(0, -m_glutScreenHeight, 0); - glMatrixMode(GL_MODELVIEW); + } void DemoApplication::resetPerspectiveProjection() { + glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); diff --git a/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp b/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp index 559b633fe..e148eae9f 100644 --- a/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp +++ b/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp @@ -109,9 +109,12 @@ void btConvexTriangleCallback::processTriangle(btVector3* triangle,int partId, i { btTriangleShape tm(triangle[0],triangle[1],triangle[2]); tm.setMargin(m_collisionMarginTriangle); - - btCollisionShape* tmpShape = ob->getCollisionShape(); + + //copy over user pointers to temporary shape + tm.setTypedUserInfo(tmpShape->getTypedUserInfo()); + tm.setUserPointer(tmpShape->getUserPointer()); + ob->setCollisionShape( &tm ); diff --git a/src/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h b/src/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h index 1933d378f..99bea8f26 100644 --- a/src/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h +++ b/src/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h @@ -30,6 +30,7 @@ class btManifoldPoint public: btManifoldPoint() :m_userPersistentData(0), + m_appliedImpulse(0.f), m_lifeTime(0) { } @@ -43,7 +44,8 @@ class btManifoldPoint m_distance1( distance ), m_combinedFriction(btScalar(0.)), m_combinedRestitution(btScalar(0.)), - m_userPersistentData(0), + m_userPersistentData(0), + m_appliedImpulse(0.f), m_lifeTime(0) { @@ -65,6 +67,7 @@ class btManifoldPoint mutable void* m_userPersistentData; + btScalar m_appliedImpulse; int m_lifeTime;//lifetime of the contactpoint in frames diff --git a/src/BulletCollision/NarrowPhaseCollision/btPersistentManifold.cpp b/src/BulletCollision/NarrowPhaseCollision/btPersistentManifold.cpp index ee94ee011..1335bbf67 100644 --- a/src/BulletCollision/NarrowPhaseCollision/btPersistentManifold.cpp +++ b/src/BulletCollision/NarrowPhaseCollision/btPersistentManifold.cpp @@ -20,6 +20,7 @@ subject to the following restrictions: btScalar gContactBreakingThreshold = btScalar(0.02); ContactDestroyedCallback gContactDestroyedCallback = 0; +ContactProcessedCallback gContactProcessedCallback = 0; @@ -234,6 +235,11 @@ void btPersistentManifold::refreshContactPoints(const btTransform& trA,const btT if (distance2d > getContactBreakingThreshold()*getContactBreakingThreshold() ) { removeContactPoint(i); + } else + { + //contact point processed callback + if (gContactProcessedCallback) + (*gContactProcessedCallback)(manifoldPoint,m_body0,m_body1); } } } diff --git a/src/BulletCollision/NarrowPhaseCollision/btPersistentManifold.h b/src/BulletCollision/NarrowPhaseCollision/btPersistentManifold.h index 763578bd3..3722d1afd 100644 --- a/src/BulletCollision/NarrowPhaseCollision/btPersistentManifold.h +++ b/src/BulletCollision/NarrowPhaseCollision/btPersistentManifold.h @@ -28,6 +28,7 @@ struct btCollisionResult; extern btScalar gContactBreakingThreshold; typedef bool (*ContactDestroyedCallback)(void* userPersistentData); +typedef bool (*ContactProcessedCallback)(btManifoldPoint& cp,void* body0,void* body1); extern ContactDestroyedCallback gContactDestroyedCallback; @@ -123,6 +124,7 @@ public: m_pointCache[index] = m_pointCache[lastUsedIndex]; //get rid of duplicated userPersistentData pointer m_pointCache[lastUsedIndex].m_userPersistentData = 0; + m_pointCache[lastUsedIndex].m_appliedImpulse = 0.f; m_pointCache[lastUsedIndex].m_lifeTime = 0; } @@ -136,12 +138,14 @@ public: #define MAINTAIN_PERSISTENCY 1 #ifdef MAINTAIN_PERSISTENCY int lifeTime = m_pointCache[insertIndex].getLifeTime(); + btScalar appliedImpulse = m_pointCache[insertIndex].m_appliedImpulse; btAssert(lifeTime>=0); void* cache = m_pointCache[insertIndex].m_userPersistentData; m_pointCache[insertIndex] = newPoint; m_pointCache[insertIndex].m_userPersistentData = cache; + m_pointCache[insertIndex].m_appliedImpulse = appliedImpulse; m_pointCache[insertIndex].m_lifeTime = lifeTime; #else clearUserCache(m_pointCache[insertIndex]); diff --git a/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp b/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp index a09e134bf..ac0c9956c 100644 --- a/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp +++ b/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp @@ -106,7 +106,7 @@ bool MyContactDestroyedCallback(void* userPersistentData) btSequentialImpulseConstraintSolver::btSequentialImpulseConstraintSolver() -:m_solverMode(SOLVER_RANDMIZE_ORDER | SOLVER_CACHE_FRIENDLY), //not using SOLVER_USE_WARMSTARTING, +:m_solverMode(SOLVER_RANDMIZE_ORDER | SOLVER_CACHE_FRIENDLY | SOLVER_USE_WARMSTARTING ), m_btSeed2(0) { gContactDestroyedCallback = &MyContactDestroyedCallback; @@ -386,6 +386,7 @@ void btSequentialImpulseConstraintSolver::addFrictionConstraint(const btVector3& solverConstraint.m_frictionIndex = frictionIndex; solverConstraint.m_friction = cp.m_combinedFriction; + solverConstraint.m_originalContactPoint = 0; solverConstraint.m_appliedImpulse = btScalar(0.); solverConstraint.m_appliedVelocityImpulse = 0.f; @@ -609,6 +610,8 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol solverConstraint.m_solverBodyIdB = solverBodyIdB; solverConstraint.m_constraintType = btSolverConstraint::BT_SOLVER_CONTACT_1D; + solverConstraint.m_originalContactPoint = &cp; + btVector3 torqueAxis0 = rel_pos1.cross(cp.m_normalWorldOnB); solverConstraint.m_angularComponentA = rb0 ? rb0->getInvInertiaTensorWorld()*torqueAxis0 : btVector3(0,0,0); btVector3 torqueAxis1 = rel_pos2.cross(cp.m_normalWorldOnB); @@ -668,7 +671,14 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol - solverConstraint.m_appliedImpulse = 0.f; + ///warm starting (or zero if disabled) + if (m_solverMode & SOLVER_USE_WARMSTARTING) + { + solverConstraint.m_appliedImpulse = cp.m_appliedImpulse; + } else + { + solverConstraint.m_appliedImpulse = 0.f; + } solverConstraint.m_appliedVelocityImpulse = 0.f; @@ -830,6 +840,20 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlyIterations( } } + { + int numPoolConstraints = m_tmpSolverConstraintPool.size(); + int j; + for (j=0;jm_appliedImpulse = solveManifold.m_appliedImpulse; + //do a callback here? + + } + } return 0.f; } diff --git a/src/BulletDynamics/ConstraintSolver/btSolverConstraint.h b/src/BulletDynamics/ConstraintSolver/btSolverConstraint.h index a750560d3..b590b73d6 100644 --- a/src/BulletDynamics/ConstraintSolver/btSolverConstraint.h +++ b/src/BulletDynamics/ConstraintSolver/btSolverConstraint.h @@ -50,7 +50,9 @@ ATTRIBUTE_ALIGNED16 (struct) btSolverConstraint int m_constraintType; int m_frictionIndex; - int m_unusedPadding[2]; + void* m_originalContactPoint; + int m_unusedPadding[1]; + enum btSolverConstraintType { diff --git a/src/BulletDynamics/Dynamics/btRigidBody.cpp b/src/BulletDynamics/Dynamics/btRigidBody.cpp index 690662366..0eeea241e 100644 --- a/src/BulletDynamics/Dynamics/btRigidBody.cpp +++ b/src/BulletDynamics/Dynamics/btRigidBody.cpp @@ -54,7 +54,7 @@ void btRigidBody::setupRigidBody(const btRigidBody::btRigidBodyConstructionInfo& m_contactSolverType = 0; m_frictionSolverType = 0; m_additionalDamping = constructionInfo.m_additionalDamping; - + m_additionalDampingFactor = constructionInfo.m_additionalDampingFactor; m_additionalLinearDampingThresholdSqr = constructionInfo.m_additionalLinearDampingThresholdSqr; m_additionalAngularDampingThresholdSqr = constructionInfo.m_additionalAngularDampingThresholdSqr; m_additionalAngularDampingFactor = constructionInfo.m_additionalAngularDampingFactor;