本文整理汇总了C++中Matrix3x3::Inverse方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix3x3::Inverse方法的具体用法?C++ Matrix3x3::Inverse怎么用?C++ Matrix3x3::Inverse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix3x3
的用法示例。
在下文中一共展示了Matrix3x3::Inverse方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CalculateFrictionImpulse
Vector3 RigidBodyContact::CalculateFrictionImpulse(Matrix3x3* inverseInertiaTensor)
{
float inverseMass = Body[0]->GetInverseMass();
// The equivalent of a cross-product in matrices is multiplication by a skew-symmetric matrix.
// We calculate the matrix for converting between linear and angular quantities.
Matrix3x3 impulseToTorque;
impulseToTorque.SetSkewSymmetric(m_relativeContactPosition[0]);
// Calculate the matrix to convert contact impulse to change in velocity in world coordinates
Matrix3x3 deltaVelocityWorldspace = impulseToTorque;
deltaVelocityWorldspace = deltaVelocityWorldspace * inverseInertiaTensor[0];
deltaVelocityWorldspace = deltaVelocityWorldspace * impulseToTorque;
deltaVelocityWorldspace *= -1;
if (Body[1] != NULL)
{
impulseToTorque.SetSkewSymmetric(m_relativeContactPosition[1]);
// Calculate the matrix to convert contact impulse to change in velocity in world coordinates
Matrix3x3 deltaVelocityWorldspace2 = impulseToTorque;
deltaVelocityWorldspace2 = deltaVelocityWorldspace2 * inverseInertiaTensor[1];
deltaVelocityWorldspace2 = deltaVelocityWorldspace2 * impulseToTorque;
deltaVelocityWorldspace2 *= -1;
// Add to the total delta velocity and inverse mass
deltaVelocityWorldspace = deltaVelocityWorldspace + deltaVelocityWorldspace2;
inverseMass += Body[1]->GetInverseMass();
}
// Perform a change of basis to convert into contact coordinates
Matrix3x3 deltaVelocity = m_contactToWorld.Transpose();
deltaVelocity = deltaVelocity * deltaVelocityWorldspace; // TODO multiplication order?
deltaVelocity = deltaVelocity * m_contactToWorld;
// Add in the linear velocity change
deltaVelocity[0][0] += inverseMass;
deltaVelocity[1][1] += inverseMass;
deltaVelocity[2][2] += inverseMass;
// Invert to get the impulse needed per unit velocity
Matrix3x3 impulseMatrix = deltaVelocity.Inverse();
// Find the target velocities to kill
Vector3 velKill(m_desiredDeltaVelocity, -m_contactVelocity.y(), -m_contactVelocity.z());
// Find the impulse to kill target velocities
Vector3 impulseContact = impulseMatrix * velKill;
// Check for exceeding friction
float planarImpulse = sqrtf(impulseContact.y()*impulseContact.y() + impulseContact.z()*impulseContact.z());
if (planarImpulse > impulseContact.x() * Friction)
{
// We need to use dynamic friction
impulseContact.SetY(impulseContact.y() / planarImpulse);
impulseContact.SetZ(impulseContact.z() / planarImpulse);
impulseContact.SetX(deltaVelocity[0][0] +
deltaVelocity[0][1] * Friction*impulseContact.y() +
deltaVelocity[0][2] * Friction*impulseContact.z());
impulseContact.SetX(m_desiredDeltaVelocity / impulseContact.x());
impulseContact.SetY(impulseContact.y()*Friction*impulseContact.x());
impulseContact.SetZ(impulseContact.z()*Friction*impulseContact.x());
}
return impulseContact;
}