1
0
Fork 0
mirror of https://git.rip/DMCA_FUCKER/re3.git synced 2024-11-10 18:09:16 +00:00
re3/src/math/Vector.cpp

47 lines
1.2 KiB
C++
Raw Normal View History

#include "common.h"
void
CVector::Normalise(void)
{
float sq = MagnitudeSqr();
if (sq > 0.0f) {
float invsqrt = RecipSqrt(sq);
x *= invsqrt;
y *= invsqrt;
z *= invsqrt;
} else
x = 1.0f;
}
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)
{
// TODO: VU0 code
2021-01-19 15:09:06 +00:00
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);
}
CVector
Multiply3x3(const CVector &vec, const CMatrix &mat)
{
2021-01-19 15:09:06 +00:00
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);
}
CVector
operator*(const CMatrix &mat, const CVector &vec)
{
// TODO: VU0 code
2021-01-19 15:09:06 +00:00
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);
}