summaryrefslogtreecommitdiff
path: root/shared_cpp/mathlib.h
diff options
context:
space:
mode:
Diffstat (limited to 'shared_cpp/mathlib.h')
-rw-r--r--shared_cpp/mathlib.h59
1 files changed, 54 insertions, 5 deletions
diff --git a/shared_cpp/mathlib.h b/shared_cpp/mathlib.h
index cff9ece..d550e90 100644
--- a/shared_cpp/mathlib.h
+++ b/shared_cpp/mathlib.h
@@ -1,3 +1,12 @@
+// mathlib.h
+//
+// Created by Matt Kosarek
+//
+// A file containing some common math functionality that I find
+// useful in my projects. I don't like that I don't know what's happening
+// in glm, so I wrote most of this myself. All mistakes are my own.
+//
+
#pragma once
#include <cstdio>
#include <cstdlib>
@@ -8,6 +17,7 @@
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#define ABS(x) (x < 0 ? -x : x)
#define SIGN(x) (x < 0 ? -1 : 1)
+#define PI 3.141592653589793238463
struct Vector2 {
float x = 0;
@@ -24,8 +34,9 @@ struct Vector2 {
Vector2 negate();
Vector2 getPerp();
Vector2 rotate(float angle);
- void printDebug(const char* name);
float determinant(Vector2 other);
+
+ void printDebug(const char* name);
};
struct Vector3 {
@@ -33,20 +44,58 @@ struct Vector3 {
float y = 0.f;
float z = 0.f;
+ Vector3();
+ Vector3(float value);
+ Vector3(float x, float y, float z);
+
float length();
- Vector3 operator+(const Vector3& other);
+ float dot(const Vector3& other);
+ Vector3 scale(float scalar);
+ Vector3 add(const Vector3& other);
+ Vector3 subtract(const Vector3& other);
+ Vector3 negate();
+ Vector3 cross(const Vector3& other);
+ Vector3 normalize();
+
+ Vector3 operator+(const Vector3& v2);
+ Vector3 operator-(const Vector3& v2);
+ Vector3 operator-();
+ Vector3 operator*(float value);
+ Vector3 operator*(const Vector3& v2);
+ float operator[](int index);
+
+ void printDebug(const char* name);
};
struct Vector4 {
float x = 0.f;
float y = 0.f;
float z = 0.f;
- float w = 0.f;
+ float w = 1.f;
- float length();
- Vector4 normalize();
+ Vector4();
+ Vector4(float value);
+ Vector4(float inX = 0.f, float inY = 0.f, float inZ = 0.f, float inW = 1.f);
Vector4 fromColor(float r, float g, float b, float a);
Vector4 toNormalizedColor();
+
+ float length();
+ Vector4 normalize();
+ float dot(const Vector4& other);
+ Vector4 scale(float scalar);
+ Vector4 add(const Vector4& other);
+ Vector4 subtract(const Vector4& other);
+ Vector4 negate();
+ Vector4 cross(const Vector4& other);
+
+ Vector4 operator+(const Vector4& v2);
+ Vector4 operator-(const Vector4& v2);
+ Vector4 operator-();
+ Vector4 operator*(float value);
+ Vector4 operator*(const Vector4& v2);
+ float operator[](int index);
+
+ void printDebug(const char* name);
};
struct Mat4x4 {