summaryrefslogtreecommitdiffstats
path: root/src/math/Vector.cpp
diff options
context:
space:
mode:
authorNikolay Korolev <nickvnuk@gmail.com>2020-09-26 12:28:33 +0200
committerNikolay Korolev <nickvnuk@gmail.com>2020-09-26 12:28:33 +0200
commiteefb0c817f1c86cb24d3a730da848e1f98277948 (patch)
treed4872bafd56e69213a6e973ac539c01942042a01 /src/math/Vector.cpp
parentMerge remote-tracking branch 'upstream/master' (diff)
parentFix MASTER build with glfw (diff)
downloadre3-eefb0c817f1c86cb24d3a730da848e1f98277948.tar
re3-eefb0c817f1c86cb24d3a730da848e1f98277948.tar.gz
re3-eefb0c817f1c86cb24d3a730da848e1f98277948.tar.bz2
re3-eefb0c817f1c86cb24d3a730da848e1f98277948.tar.lz
re3-eefb0c817f1c86cb24d3a730da848e1f98277948.tar.xz
re3-eefb0c817f1c86cb24d3a730da848e1f98277948.tar.zst
re3-eefb0c817f1c86cb24d3a730da848e1f98277948.zip
Diffstat (limited to '')
-rw-r--r--src/math/Vector.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/math/Vector.cpp b/src/math/Vector.cpp
new file mode 100644
index 00000000..42e1828e
--- /dev/null
+++ b/src/math/Vector.cpp
@@ -0,0 +1,46 @@
+#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
+ return CVector(mat.m_matrix.right.x * vec.x + mat.m_matrix.up.x * vec.y + mat.m_matrix.at.x * vec.z,
+ mat.m_matrix.right.y * vec.x + mat.m_matrix.up.y * vec.y + mat.m_matrix.at.y * vec.z,
+ mat.m_matrix.right.z * vec.x + mat.m_matrix.up.z * vec.y + mat.m_matrix.at.z * vec.z);
+}
+
+CVector
+Multiply3x3(const CVector &vec, const CMatrix &mat)
+{
+ return CVector(mat.m_matrix.right.x * vec.x + mat.m_matrix.right.y * vec.y + mat.m_matrix.right.z * vec.z,
+ mat.m_matrix.up.x * vec.x + mat.m_matrix.up.y * vec.y + mat.m_matrix.up.z * vec.z,
+ mat.m_matrix.at.x * vec.x + mat.m_matrix.at.y * vec.y + mat.m_matrix.at.z * vec.z);
+}
+
+CVector
+operator*(const CMatrix &mat, const CVector &vec)
+{
+ // TODO: VU0 code
+ return CVector(mat.m_matrix.right.x * vec.x + mat.m_matrix.up.x * vec.y + mat.m_matrix.at.x * vec.z + mat.m_matrix.pos.x,
+ mat.m_matrix.right.y * vec.x + mat.m_matrix.up.y * vec.y + mat.m_matrix.at.y * vec.z + mat.m_matrix.pos.y,
+ mat.m_matrix.right.z * vec.x + mat.m_matrix.up.z * vec.y + mat.m_matrix.at.z * vec.z + mat.m_matrix.pos.z);
+}