summaryrefslogtreecommitdiff
path: root/shared_cpp/mathlib.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'shared_cpp/mathlib.cpp')
-rw-r--r--shared_cpp/mathlib.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/shared_cpp/mathlib.cpp b/shared_cpp/mathlib.cpp
index b7748fe..fb09cd9 100644
--- a/shared_cpp/mathlib.cpp
+++ b/shared_cpp/mathlib.cpp
@@ -155,6 +155,13 @@ Vector3 Vector3::operator+(const Vector3& v2) {
return add(v2);
}
+Vector3& Vector3::operator+=(Vector3 other) {
+ x += other.x;
+ y += other.y;
+ z += other.z;
+ return *this;
+}
+
Vector3 Vector3::operator-(const Vector3& v2) {
return subtract(v2);
}
@@ -167,6 +174,14 @@ Vector3 Vector3::operator*(float value) {
return scale(value);
}
+Vector3 Vector3::operator/(const Vector3& v2) {
+ return {
+ x / v2.x,
+ y / v2.y,
+ z / v2.z
+ };
+}
+
Vector3 Vector3::operator*(const Vector3& v2) {
return {
x * v2.x,
@@ -623,3 +638,16 @@ Mat4x4 Quaternion::toMatrix() const {
float Quaternion::dot(const Quaternion& other) const {
return w * other.w + x * other.x + y * other.y + z * other.z;
}
+
+Quaternion quaternionFromRotation(Vector3 axis, float angleRadians) {
+ float halfAngleRadians = angleRadians / 2.f;
+ float cosHalfAngRad = cosf(halfAngleRadians);
+ float sinHalfAngRad = sinf(halfAngleRadians);
+
+ return {
+ cosHalfAngRad,
+ axis.x * sinHalfAngRad,
+ axis.y * sinHalfAngRad,
+ axis.z * sinHalfAngRad
+ };
+}