76 lines
1.8 KiB
C++
76 lines
1.8 KiB
C++
#include "common.h"
|
|
|
|
void
|
|
CVector::Normalise(void)
|
|
{
|
|
#ifdef DC_SH4_BROKEN
|
|
// TODO: This needs to handle zero vectors here
|
|
vec3f_normalize(x, y, z);
|
|
#else
|
|
float sq = MagnitudeSqr();
|
|
if (sq > 0.0f) {
|
|
float invsqrt = RecipSqrt(sq);
|
|
x *= invsqrt;
|
|
y *= invsqrt;
|
|
z *= invsqrt;
|
|
} else
|
|
x = 1.0f;
|
|
#endif
|
|
}
|
|
|
|
CVector
|
|
CrossProduct(const CVector &v1, const CVector &v2)
|
|
{
|
|
return CVector(v1.y * v2.z - v1.z * v2.y, v1.z * v2.x - v1.x * v2.z, v1.x * v2.y - v1.y * v2.x);
|
|
}
|
|
|
|
CVector
|
|
Multiply3x3(const CMatrix &mat, const CVector &vec)
|
|
{
|
|
#ifndef DC_SH4
|
|
// TODO: VU0 code
|
|
return CVector(mat.rx * vec.x + mat.fx * vec.y + mat.ux * vec.z,
|
|
mat.ry * vec.x + mat.fy * vec.y + mat.uy * vec.z,
|
|
mat.rz * vec.x + mat.fz * vec.y + mat.uz * vec.z);
|
|
#else
|
|
CVector out;
|
|
dc::mat_load2(mat);
|
|
mat_trans_normal3_nomod(vec.x, vec.y, vec.z,
|
|
out.x, out.y, out.z);
|
|
return out;
|
|
#endif
|
|
}
|
|
|
|
CVector
|
|
Multiply3x3(const CVector &vec, const CMatrix &mat)
|
|
{
|
|
#ifndef DC_SH4
|
|
return CVector(mat.rx * vec.x + mat.ry * vec.y + mat.rz * vec.z,
|
|
mat.fx * vec.x + mat.fy * vec.y + mat.fz * vec.z,
|
|
mat.ux * vec.x + mat.uy * vec.y + mat.uz * vec.z);
|
|
#else
|
|
CVector out;
|
|
dc::mat_load2(mat);
|
|
mat_transpose();
|
|
mat_trans_normal3_nomod(vec.x, vec.y, vec.z,
|
|
out.x, out.y, out.z);
|
|
return out;
|
|
#endif
|
|
}
|
|
|
|
CVector
|
|
operator*(const CMatrix &mat, const CVector &vec)
|
|
{
|
|
#ifdef DC_SH4
|
|
CVector out;
|
|
dc::mat_load2(mat);
|
|
mat_trans_single3_nodiv_nomod(vec.x, vec.y, vec.z, out.x, out.y, out.z);
|
|
return out;
|
|
#else
|
|
// TODO: VU0 code
|
|
return CVector(mat.rx * vec.x + mat.fx * vec.y + mat.ux * vec.z + mat.px,
|
|
mat.ry * vec.x + mat.fy * vec.y + mat.uy * vec.z + mat.py,
|
|
mat.rz * vec.x + mat.fz * vec.y + mat.uz * vec.z + mat.pz);
|
|
#endif
|
|
}
|