rename function, remove indirection, fix bug

This commit is contained in:
Irlan
2017-04-11 16:35:18 -03:00
parent d082c59754
commit bd69458750
16 changed files with 74 additions and 63 deletions

View File

@ -100,33 +100,6 @@ inline void b3BarycentricCoordinates(float32 out[3],
out[2] = divisor;
}
// Convert a point Q from euclidean coordinates to barycentric coordinates (u, v, w)
// with respect to a triangle ABC.
// The last output value is the divisor.
inline void b3BarycentricCoordinates(float32 out[4],
const b3Vec3& A, const b3Vec3& B, const b3Vec3& C,
const b3Vec3& Q)
{
b3Vec3 AB = B - A;
b3Vec3 AC = C - A;
b3Vec3 QA = A - Q;
b3Vec3 QB = B - Q;
b3Vec3 QC = C - Q;
b3Vec3 QB_x_QC = b3Cross(QB, QC);
b3Vec3 QC_x_QA = b3Cross(QC, QA);
b3Vec3 QA_x_QB = b3Cross(QA, QB);
b3Vec3 AB_x_AC = b3Cross(AB, AC);
float32 divisor = b3Dot(AB_x_AC, AB_x_AC);
out[0] = b3Dot(QB_x_QC, AB_x_AC);
out[1] = b3Dot(QC_x_QA, AB_x_AC);
out[2] = b3Dot(QA_x_QB, AB_x_AC);
out[3] = divisor;
}
// Project a point onto a segment AB.
inline b3Vec3 b3ClosestPointOnSegment(const b3Vec3& P, const b3Vec3& A, const b3Vec3& B)
{

View File

@ -205,7 +205,7 @@ inline b3Quat b3Conjugate(const b3Quat& q)
return b3Quat(-q.x, -q.y, -q.z, q.w);
}
// Rotate a vector by an orientation quaternion.
// Rotate a vector.
inline b3Vec3 b3Mul(const b3Quat& q, const b3Vec3& v)
{
b3Vec3 qv(q.x, q.y, q.z);
@ -215,14 +215,14 @@ inline b3Vec3 b3Mul(const b3Quat& q, const b3Vec3& v)
return v + qs * t + b3Cross(qv, t);
}
// Inverse rotate a vector by an orientation quaternion.
// Inverse rotate a vector.
inline b3Vec3 b3MulT(const b3Quat& q, const b3Vec3& v)
{
return b3Mul(b3Conjugate(q), v);
}
// Convert a 3-by-3 rotation matrix to an orientation quaternion.
inline b3Quat b3ConvertRotToQuat(const b3Mat33& m)
// Convert a 3-by-3 rotation matrix to an rotation quaternion.
inline b3Quat b3ConvertMatToQuat(const b3Mat33& m)
{
// Check the diagonal.
float32 trace = m[0][0] + m[1][1] + m[2][2];
@ -286,8 +286,8 @@ inline b3Quat b3ConvertRotToQuat(const b3Mat33& m)
return result;
}
// Convert an orientation quaternion to a 3-by-3 rotation matrix.
inline b3Mat33 b3ConvertQuatToRot(const b3Quat& q)
// Convert an rotation quaternion to a 3-by-3 rotation matrix.
inline b3Mat33 b3ConvertQuatToMat(const b3Quat& q)
{
float32 x = q.x, y = q.y, z = q.z, w = q.w;
float32 x2 = x + x, y2 = y + y, z2 = z + z;
@ -301,4 +301,4 @@ inline b3Mat33 b3ConvertQuatToRot(const b3Quat& q)
b3Vec3( xz + wy, yz - wx, 1.0f - (xx + yy)));
}
#endif
#endif

View File

@ -35,7 +35,7 @@ struct b3Transform
b3Transform(const b3Vec3& p, const b3Quat& q)
{
position = p;
rotation = b3ConvertQuatToRot(q);
rotation = b3ConvertQuatToMat(q);
}
// Set this transform to the identity.
@ -75,7 +75,7 @@ inline b3Transform b3Sweep::GetTransform(float32 t) const
q.Normalize();
b3Transform xf;
xf.rotation = b3ConvertQuatToRot(q);
xf.rotation = b3ConvertQuatToMat(q);
xf.position = c - b3Mul(q, localCenter);
return xf;
}

View File

@ -385,7 +385,7 @@ inline void b3Body::SetTransform(const b3Vec3& position, const b3Vec3& axis, flo
b3Quat q = b3Quat(axis, angle);
m_xf.position = position;
m_xf.rotation = b3ConvertQuatToRot(q);
m_xf.rotation = b3ConvertQuatToMat(q);
m_sweep.worldCenter = b3Mul(m_xf, m_sweep.localCenter);
m_sweep.orientation = q;