summaryrefslogtreecommitdiff
path: root/themes/mathlib.h
diff options
context:
space:
mode:
authormattkae <mattkae@protonmail.com>2022-03-05 18:48:37 -0500
committermattkae <mattkae@protonmail.com>2022-03-05 18:48:37 -0500
commit1db914466663a1e4d0d827b8b9bd18840d7742eb (patch)
treed43b24947c71e4ce18321cf86672e4d52ecb9a11 /themes/mathlib.h
parentdd573a9bad435f7f16dd26458c8f0129eb6e54fe (diff)
Updating the mathlib
Diffstat (limited to 'themes/mathlib.h')
-rw-r--r--themes/mathlib.h22
1 files changed, 19 insertions, 3 deletions
diff --git a/themes/mathlib.h b/themes/mathlib.h
index 82f85a2..f89addc 100644
--- a/themes/mathlib.h
+++ b/themes/mathlib.h
@@ -18,9 +18,13 @@
#define ABS(x) (x < 0 ? -x : x)
#define SIGN(x) (x < 0 ? -1 : 1)
#define PI 3.141592653589793238463
+#define E 2.71828182845904523536
#define DEG_TO_RAD(x) (x * (PI / 180.f))
#define RAD_TO_DEG(x) (x * (180.f / PI))
+struct Vector4;
+
+
// -- Random
inline float randomFloatBetween(float min, float max) {
float random = static_cast<float>(rand()) / static_cast<float>(RAND_MAX);
@@ -36,19 +40,20 @@ struct Vector2 {
float y = 0;
Vector2();
- Vector2(float x, float y);
+ Vector2(float inX, float inY);
Vector2 operator+(Vector2 other);
Vector2& operator+=(Vector2 other);
Vector2 operator-(Vector2 other);
Vector2 operator*(float s);
Vector2 operator/(float s);
+ void operator=(const Vector4& other);
float dot(Vector2 other);
float length();
Vector2 normalize();
Vector2 negate();
Vector2 getPerp();
Vector2 rotate(float angle);
- Vector2 rotateAbout(float angle, Vector2 p);
+ Vector2 rotateAround(float angle, const Vector2& other);
float determinant(Vector2 other);
void printDebug(const char* name);
@@ -95,6 +100,8 @@ struct Vector4 {
Vector4(float inX, float inY, float inZ, float inW);
Vector4 fromColor(float r, float g, float b, float a);
Vector4 toNormalizedColor();
+ Vector4(Vector2& v);
+ Vector4(Vector3& v);
float length();
Vector4 normalize();
@@ -105,6 +112,8 @@ struct Vector4 {
Vector4 negate();
Vector4 cross(const Vector4& other);
+ void operator=(const Vector2& v2);
+ void operator=(const Vector3& v2);
Vector4 operator+(const Vector4& v2);
Vector4 operator-(const Vector4& v2);
Vector4 operator-();
@@ -115,6 +124,8 @@ struct Vector4 {
void printDebug(const char* name);
};
+Vector4 lerp(Vector4 start, Vector4 end, float t);
+
struct Mat4x4 {
float m[16] = {
1, 0, 0, 0,
@@ -143,11 +154,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;
@@ -158,6 +171,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);