From c025960c6fbeac17d94a14d14cd13b42737bc80e Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Sun, 17 Oct 2021 11:08:20 -0400 Subject: Rotating spheres in the 3D scene --- shared_cpp/mathlib.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'shared_cpp/mathlib.h') diff --git a/shared_cpp/mathlib.h b/shared_cpp/mathlib.h index e3c6875..5f9abff 100644 --- a/shared_cpp/mathlib.h +++ b/shared_cpp/mathlib.h @@ -21,6 +21,17 @@ #define DEG_TO_RAD(x) (x * (PI / 180.f)) #define RAD_TO_DEG(x) (x * (180.f / PI)) + +// -- Random +inline float randomFloatBetween(float min, float max) { + float random = static_cast(rand()) / static_cast(RAND_MAX); + return (max - min) * random + min; +} + +inline int randomIntBetween(int min, int max) { + return static_cast(randomFloatBetween(min, max)); +} + struct Vector2 { float x = 0; float y = 0; @@ -130,11 +141,13 @@ struct Mat4x4 { }; struct Quaternion { - float w = 0; + float w = 1; float x = 0; float y = 0; float z = 0; + Quaternion(); + Quaternion(float inW, float inX, float inY, float inZ); float operator [](int index); Quaternion operator*(const Quaternion& other) const; Quaternion operator*(const float& scale) const; @@ -145,6 +158,9 @@ struct Quaternion { Quaternion normalize() const; float length() const; float dot(const Quaternion& other) const; + + void printDebug(const char* name); }; Quaternion quaternionFromRotation(Vector3 axis, float angleRadians); +Quaternion quaternionFromEulerAngle(float yaw, float pitch, float roll); -- cgit v1.2.1