SOLVER_DISABLE_VELOCITY_DEPENDENT_FRICTION_DIRECTION if setting friction directions in gContactAddedCallback

Post Reply
teolazza
Posts: 21
Joined: Fri Aug 11, 2017 1:16 pm

SOLVER_DISABLE_VELOCITY_DEPENDENT_FRICTION_DIRECTION if setting friction directions in gContactAddedCallback

Post by teolazza »

In my gContactAddedCallback I always set m_lateralFrictionDir1 and m_lateralFrictionDir2.
Should I set the flag SOLVER_DISABLE_VELOCITY_DEPENDENT_FRICTION_DIRECTION

Code: Select all

pWorld->getSolverInfo().m_solverMode |= SOLVER_DISABLE_VELOCITY_DEPENDENT_FRICTION_DIRECTION ;
?

Would setting it give me advantages?

This is part of my contactAddedCallback

Code: Select all

	auto[direction, desired_speed] = ...

	// In case it helps, note that soft body friction is controlled via the softBody->m_cfg.kDF parameter (0 = no friction, 1 = max):
	// http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=6730
	// m_lateralFrictionDir1 is in local coordinates
	auto proposed_lateral_friction_dir1 = beltBody.getWorldTransform().getBasis() * direction;
	auto proposed_lateral_friction_dir2 = proposed_lateral_friction_dir1.cross(cp.m_normalWorldOnB);
	// we should normalize dir2, but only if possible
	btScalar l2 = proposed_lateral_friction_dir2.length2();
	if (l2 >= SIMD_EPSILON * SIMD_EPSILON)
	{
		// yes: this is now normalized!
		proposed_lateral_friction_dir2 /= btSqrt(l2);

		cp.m_lateralFrictionDir1 = std::move(proposed_lateral_friction_dir1);
		cp.m_contactMotion1 = desired_speed;

		// This is needed together with SOLVER_USE_2_FRICTION_DIRECTIONS
		// m_lateralFrictionDir2 should always be perpendicular to m_lateralFrictionDir1
		cp.m_lateralFrictionDir2 = std::move(proposed_lateral_friction_dir2);

		cp.m_combinedFriction = ...

		if (not body.isActive())
			body.activate();

		cp.m_contactPointFlags |= BT_CONTACT_FLAG_LATERAL_FRICTION_INITIALIZED;
	}
Thanks
Post Reply