diff options
author | Matthew Kosarek <mattkae@protonmail.com> | 2021-10-17 11:08:20 -0400 |
---|---|---|
committer | Matthew Kosarek <mattkae@protonmail.com> | 2021-10-17 11:08:20 -0400 |
commit | c025960c6fbeac17d94a14d14cd13b42737bc80e (patch) | |
tree | 32bd64a59766245885da7ffa177880116fd47785 /shared_cpp/mathlib.h | |
parent | 05c4522e5ff424c65aab7cd36c7a15313630ac61 (diff) |
Rotating spheres in the 3D scene
Diffstat (limited to 'shared_cpp/mathlib.h')
-rw-r--r-- | shared_cpp/mathlib.h | 18 |
1 files changed, 17 insertions, 1 deletions
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<float>(rand()) / static_cast<float>(RAND_MAX); + return (max - min) * random + min; +} + +inline int randomIntBetween(int min, int max) { + return static_cast<int>(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); |