From 05c4522e5ff424c65aab7cd36c7a15313630ac61 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Sun, 25 Jul 2021 20:20:10 -0400 Subject: (mkosarek) Fix for wrong timestep --- shared_cpp/mathlib.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'shared_cpp/mathlib.cpp') 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 + }; +} -- cgit v1.2.1