public override void Update(float dt)
{
entityADynamic = entityA != null && entityA.isDynamic;
entityBDynamic = entityB != null && entityB.isDynamic;
//Compute the jacobian...... Real hard!
Vector3 normal = contactManifoldConstraint.penetrationConstraints.Elements[0].contact.Normal;
angularX = normal.X;
angularY = normal.Y;
angularZ = normal.Z;
//Compute inverse effective mass matrix
float entryA, entryB;
//these are the transformed coordinates
float tX, tY, tZ;
if (entityADynamic)
{
tX = angularX * entityA.inertiaTensorInverse.M11 + angularY * entityA.inertiaTensorInverse.M21 + angularZ * entityA.inertiaTensorInverse.M31;
tY = angularX * entityA.inertiaTensorInverse.M12 + angularY * entityA.inertiaTensorInverse.M22 + angularZ * entityA.inertiaTensorInverse.M32;
tZ = angularX * entityA.inertiaTensorInverse.M13 + angularY * entityA.inertiaTensorInverse.M23 + angularZ * entityA.inertiaTensorInverse.M33;
entryA = tX * angularX + tY * angularY + tZ * angularZ + entityA.inverseMass;
}
else
entryA = 0;
if (entityBDynamic)
{
tX = angularX * entityB.inertiaTensorInverse.M11 + angularY * entityB.inertiaTensorInverse.M21 + angularZ * entityB.inertiaTensorInverse.M31;
tY = angularX * entityB.inertiaTensorInverse.M12 + angularY * entityB.inertiaTensorInverse.M22 + angularZ * entityB.inertiaTensorInverse.M32;
tZ = angularX * entityB.inertiaTensorInverse.M13 + angularY * entityB.inertiaTensorInverse.M23 + angularZ * entityB.inertiaTensorInverse.M33;
entryB = tX * angularX + tY * angularY + tZ * angularZ + entityB.inverseMass;
}
else
entryB = 0;
velocityToImpulse = -1 / (entryA + entryB);
//Compute the relative velocity to determine what kind of friction to use
float relativeAngularVelocity = RelativeVelocity;
//Set up friction and find maximum friction force
Vector3 relativeSlidingVelocity = contactManifoldConstraint.SlidingFriction.relativeVelocity;
friction = Math.Abs(relativeAngularVelocity) > CollisionResponseSettings.StaticFrictionVelocityThreshold ||
Math.Abs(relativeSlidingVelocity.X) + Math.Abs(relativeSlidingVelocity.Y) + Math.Abs(relativeSlidingVelocity.Z) > CollisionResponseSettings.StaticFrictionVelocityThreshold
? contactManifoldConstraint.materialInteraction.KineticFriction
: contactManifoldConstraint.materialInteraction.StaticFriction;
friction *= CollisionResponseSettings.TwistFrictionFactor;
contactCount = contactManifoldConstraint.penetrationConstraints.Count;
Vector3 contactOffset;
for (int i = 0; i < contactCount; i++)
{
Vector3.Subtract(ref contactManifoldConstraint.penetrationConstraints.Elements[i].contact.Position, ref contactManifoldConstraint.SlidingFriction.manifoldCenter, out contactOffset);
leverArms[i] = contactOffset.Length();
}
}