From 42fac2e3644923ac79805a9656ca65320969862d Mon Sep 17 00:00:00 2001 From: jingyuc Date: Tue, 31 Aug 2021 01:33:38 -0400 Subject: [PATCH] fixed a minor issue: disable deactivation for the reduced collision example --- examples/ReducedDeformableDemo/FreeFall.cpp | 18 +++++++++++------- .../ReducedDeformableDemo/ReducedCollide.cpp | 9 +++++---- .../btReducedDeformableContactConstraint.cpp | 7 ++++--- .../btReducedDeformableContactConstraint.h | 6 ++++-- .../btReducedSoftBody.cpp | 2 +- .../btDeformableMultiBodyConstraintSolver.cpp | 9 ++------- .../btDeformableMultiBodyConstraintSolver.h | 2 +- 7 files changed, 28 insertions(+), 25 deletions(-) diff --git a/examples/ReducedDeformableDemo/FreeFall.cpp b/examples/ReducedDeformableDemo/FreeFall.cpp index dbd2411a0..b138e88bb 100644 --- a/examples/ReducedDeformableDemo/FreeFall.cpp +++ b/examples/ReducedDeformableDemo/FreeFall.cpp @@ -65,13 +65,17 @@ public: void Ctor_RbUpStack() { - float mass = 0.5; - btCollisionShape* shape = new btBoxShape(btVector3(2, 2, 2)); + float mass = 10; + btCollisionShape* shape = new btBoxShape(btVector3(1, 1, 1)); btTransform startTransform; startTransform.setIdentity(); - startTransform.setOrigin(btVector3(0,-2,0)); - btRigidBody* rb = createRigidBody(mass, startTransform, shape); - rb->setLinearVelocity(btVector3(0,+COLLIDING_VELOCITY, 0)); + startTransform.setOrigin(btVector3(0, 12, 0)); + btRigidBody* rb0 = createRigidBody(mass, startTransform, shape); + rb0->setLinearVelocity(btVector3(0, 0, 0)); + + // startTransform.setOrigin(btVector3(0,8,0)); + // btRigidBody* rb1 = createRigidBody(mass, startTransform, shape); + // rb1->setLinearVelocity(btVector3(0, 0, 0)); } void stepSimulation(float deltaTime) @@ -180,7 +184,7 @@ void FreeFall::initPhysics() btTransform groundTransform; groundTransform.setIdentity(); - groundTransform.setRotation(btQuaternion(btVector3(1, 0, 0), SIMD_PI / 6.0)); + // groundTransform.setRotation(btQuaternion(btVector3(1, 0, 0), SIMD_PI / 6.0)); groundTransform.setOrigin(btVector3(0, 0, 0)); // groundTransform.setOrigin(btVector3(0, 0, 6)); // groundTransform.setOrigin(btVector3(0, -50, 0)); @@ -199,7 +203,7 @@ void FreeFall::initPhysics() getDeformableDynamicsWorld()->getSolverInfo().m_splitImpulse = true; getDeformableDynamicsWorld()->getSolverInfo().m_numIterations = 100; // add a few rigid bodies - // Ctor_RbUpStack(); // TODO: no rigid body for now + Ctor_RbUpStack(); m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld); // { diff --git a/examples/ReducedDeformableDemo/ReducedCollide.cpp b/examples/ReducedDeformableDemo/ReducedCollide.cpp index f657c5ee2..3b76db3bc 100644 --- a/examples/ReducedDeformableDemo/ReducedCollide.cpp +++ b/examples/ReducedDeformableDemo/ReducedCollide.cpp @@ -31,7 +31,7 @@ // static btScalar nu = 0.3; static btScalar damping_alpha = 0.0; static btScalar damping_beta = 0.0; -static btScalar COLLIDING_VELOCITY = 4; +static btScalar COLLIDING_VELOCITY = 15; static int start_mode = 6; static int num_modes = 1; @@ -65,12 +65,13 @@ public: void Ctor_RbUpStack() { - float mass = 8; - btCollisionShape* shape = new btBoxShape(btVector3(2, 2, 2)); + float mass = 10; + btCollisionShape* shape = new btBoxShape(btVector3(3, 3, 3)); btTransform startTransform; startTransform.setIdentity(); - startTransform.setOrigin(btVector3(0,-2,0)); + startTransform.setOrigin(btVector3(0,-3,0)); btRigidBody* rb = createRigidBody(mass, startTransform, shape); + rb->setActivationState(DISABLE_DEACTIVATION); rb->setLinearVelocity(btVector3(0, +COLLIDING_VELOCITY, 0)); } diff --git a/src/BulletSoftBody/BulletReducedSoftBody/btReducedDeformableContactConstraint.cpp b/src/BulletSoftBody/BulletReducedSoftBody/btReducedDeformableContactConstraint.cpp index ca2f5c9da..81bf9b092 100644 --- a/src/BulletSoftBody/BulletReducedSoftBody/btReducedDeformableContactConstraint.cpp +++ b/src/BulletSoftBody/BulletReducedSoftBody/btReducedDeformableContactConstraint.cpp @@ -77,9 +77,9 @@ btReducedDeformableRigidContactConstraint::btReducedDeformableRigidContactConstr void btReducedDeformableRigidContactConstraint::setSolverBody(btSolverBody& solver_body) { m_solverBody = &solver_body; - m_linearComponent = m_contactNormalA * m_solverBody->internalGetInvMass(); + m_linearComponentNormal = m_contactNormalA * m_solverBody->internalGetInvMass(); btVector3 torqueAxis = m_relPosA.cross(m_contactNormalA); - m_angularComponent = m_solverBody->m_originalBody->getInvInertiaTensorWorld() * torqueAxis; + m_angularComponentNormal = m_solverBody->m_originalBody->getInvInertiaTensorWorld() * torqueAxis; } btVector3 btReducedDeformableRigidContactConstraint::getVa() const @@ -105,6 +105,7 @@ btScalar btReducedDeformableRigidContactConstraint::solveConstraint(const btCont btVector3 deltaV_rel = deltaVa - deltaVb; btScalar deltaV_rel_normal = -btDot(deltaV_rel, m_contactNormalA); std::cout << "deltaV_rel_normal: " << deltaV_rel_normal << "\n"; + std::cout << "normal_A: " << m_contactNormalA[0] << '\t' << m_contactNormalA[1] << '\t' << m_contactNormalA[2] << '\n'; // get the normal impulse to be applied btScalar deltaImpulse = m_rhs - deltaV_rel_normal / m_normalImpulseFactor; @@ -186,7 +187,7 @@ btScalar btReducedDeformableRigidContactConstraint::solveConstraint(const btCont const btSoftBody::sCti& cti = m_contact->m_cti; if (cti.m_colObj->getInternalType() == btCollisionObject::CO_RIGID_BODY) { - m_solverBody->internalApplyImpulse(m_linearComponent, m_angularComponent, -deltaImpulse); + m_solverBody->internalApplyImpulse(m_linearComponentNormal, m_angularComponentNormal, -deltaImpulse); // m_solverBody->internalApplyImpulse(m_linearComponent, m_angularComponent, -deltaImpulse_tangent); } else if (cti.m_colObj->getInternalType() == btCollisionObject::CO_FEATHERSTONE_LINK) diff --git a/src/BulletSoftBody/BulletReducedSoftBody/btReducedDeformableContactConstraint.h b/src/BulletSoftBody/BulletReducedSoftBody/btReducedDeformableContactConstraint.h index 9494c5d99..b05fd2f26 100644 --- a/src/BulletSoftBody/BulletReducedSoftBody/btReducedDeformableContactConstraint.h +++ b/src/BulletSoftBody/BulletReducedSoftBody/btReducedDeformableContactConstraint.h @@ -56,8 +56,10 @@ class btReducedDeformableRigidContactConstraint : public btDeformableRigidContac btVector3 m_bufferVelocityA; // velocity at the beginning of the iteration btVector3 m_bufferVelocityB; - btVector3 m_linearComponent; // linear components for the solver body - btVector3 m_angularComponent; // angular components for the solver body + btVector3 m_linearComponentNormal; // linear components for the solver body + btVector3 m_angularComponentNormal; // angular components for the solver body + btVector3 m_linearComponentTangent; + btVector3 m_angularComponentTangent; btReducedDeformableRigidContactConstraint(btReducedSoftBody* rsb, const btSoftBody::DeformableRigidContact& c, diff --git a/src/BulletSoftBody/BulletReducedSoftBody/btReducedSoftBody.cpp b/src/BulletSoftBody/BulletReducedSoftBody/btReducedSoftBody.cpp index 7bc7fad02..e0184644c 100644 --- a/src/BulletSoftBody/BulletReducedSoftBody/btReducedSoftBody.cpp +++ b/src/BulletSoftBody/BulletReducedSoftBody/btReducedSoftBody.cpp @@ -8,7 +8,7 @@ btReducedSoftBody::btReducedSoftBody(btSoftBodyWorldInfo* worldInfo, int node_count, const btVector3* x, const btScalar* m) : btSoftBody(worldInfo, node_count, x, m) { - m_rigidOnly = false; //! only use rigid frame to debug + m_rigidOnly = true; //! only use rigid frame to debug // reduced deformable m_reducedModel = true; diff --git a/src/BulletSoftBody/btDeformableMultiBodyConstraintSolver.cpp b/src/BulletSoftBody/btDeformableMultiBodyConstraintSolver.cpp index db5b2f50c..ca3ba13f7 100644 --- a/src/BulletSoftBody/btDeformableMultiBodyConstraintSolver.cpp +++ b/src/BulletSoftBody/btDeformableMultiBodyConstraintSolver.cpp @@ -22,7 +22,7 @@ btScalar btDeformableMultiBodyConstraintSolver::solveDeformableGroupIterations(b { { // pair deformable body with solver body - pairDeformableAndSolverBody(bodies, numBodies, deformableBodies, numDeformableBodies, infoGlobal); + pairDeformableAndSolverBody(bodies, numBodies, infoGlobal); ///this is a special step to resolve penetrations (just for contacts) solveGroupCacheFriendlySplitImpulseIterations(bodies, numBodies, deformableBodies, numDeformableBodies, manifoldPtr, numManifolds, constraints, numConstraints, infoGlobal, debugDrawer); @@ -132,7 +132,7 @@ void btDeformableMultiBodyConstraintSolver::solverBodyWriteBack(const btContactS } -void btDeformableMultiBodyConstraintSolver::pairDeformableAndSolverBody(btCollisionObject** bodies, int numBodies, btCollisionObject** deformableBodies, int numDeformableBodies, const btContactSolverInfo& infoGlobal) +void btDeformableMultiBodyConstraintSolver::pairDeformableAndSolverBody(btCollisionObject** bodies, int numBodies, const btContactSolverInfo& infoGlobal) { if (!m_deformableSolver->isReducedSolver()) { @@ -150,11 +150,6 @@ void btDeformableMultiBodyConstraintSolver::pairDeformableAndSolverBody(btCollis m_deformableSolver->pairConstraintWithSolverBody(solverBody); } } - - for (int i = 0; i < numDeformableBodies; ++i) - { - // - } } void btDeformableMultiBodyConstraintSolver::solveGroupCacheFriendlySplitImpulseIterations(btCollisionObject** bodies, int numBodies, btCollisionObject** deformableBodies, int numDeformableBodies, btPersistentManifold** manifoldPtr, int numManifolds, btTypedConstraint** constraints, int numConstraints, const btContactSolverInfo& infoGlobal, btIDebugDraw* debugDrawer) diff --git a/src/BulletSoftBody/btDeformableMultiBodyConstraintSolver.h b/src/BulletSoftBody/btDeformableMultiBodyConstraintSolver.h index e95f51273..672ace888 100644 --- a/src/BulletSoftBody/btDeformableMultiBodyConstraintSolver.h +++ b/src/BulletSoftBody/btDeformableMultiBodyConstraintSolver.h @@ -44,7 +44,7 @@ protected: void writeToSolverBody(btCollisionObject * *bodies, int numBodies, const btContactSolverInfo& infoGlobal); // let each deformable body knows which solver body is in constact - void pairDeformableAndSolverBody(btCollisionObject** bodies, int numBodies, btCollisionObject** deformableBodies, int numDeformableBodies, const btContactSolverInfo& infoGlobal); + void pairDeformableAndSolverBody(btCollisionObject** bodies, int numBodies, const btContactSolverInfo& infoGlobal); virtual void solveGroupCacheFriendlySplitImpulseIterations(btCollisionObject * *bodies, int numBodies, btCollisionObject** deformableBodies, int numDeformableBodies, btPersistentManifold** manifoldPtr, int numManifolds, btTypedConstraint** constraints, int numConstraints, const btContactSolverInfo& infoGlobal, btIDebugDraw* debugDrawer);