This commit is contained in:
2025-05-13 02:46:21 +03:00
parent 143e16692e
commit 86914b7fcc
610 changed files with 92343 additions and 2 deletions
+125
View File
@@ -0,0 +1,125 @@
#include "LifeMath.h"
namespace LifeMath
{
extern INLINE void Mat4x4Invert(const Matrix4x4* matrix, Matrix4x4* result)
{
float num5 = matrix->M11;
float num4 = matrix->M12;
float num3 = matrix->M13;
float num2 = matrix->M14;
float num9 = matrix->M21;
float num8 = matrix->M22;
float num7 = matrix->M23;
float num6 = matrix->M24;
float num17 = matrix->M31;
float num16 = matrix->M32;
float num15 = matrix->M33;
float num14 = matrix->M34;
float num13 = matrix->M41;
float num12 = matrix->M42;
float num11 = matrix->M43;
float num10 = matrix->M44;
float num23 = (num15 * num10) - (num14 * num11);
float num22 = (num16 * num10) - (num14 * num12);
float num21 = (num16 * num11) - (num15 * num12);
float num20 = (num17 * num10) - (num14 * num13);
float num19 = (num17 * num11) - (num15 * num13);
float num18 = (num17 * num12) - (num16 * num13);
float num39 = ((num8 * num23) - (num7 * num22)) + (num6 * num21);
float num38 = -(((num9 * num23) - (num7 * num20)) + (num6 * num19));
float num37 = ((num9 * num22) - (num8 * num20)) + (num6 * num18);
float num36 = -(((num9 * num21) - (num8 * num19)) + (num7 * num18));
float num = 1.0f / ((((num5 * num39) + (num4 * num38)) + (num3 * num37)) + (num2 * num36));
result->M11 = num39 * num;
result->M21 = num38 * num;
result->M31 = num37 * num;
result->M41 = num36 * num;
result->M12 = -(((num4 * num23) - (num3 * num22)) + (num2 * num21)) * num;
result->M22 = (((num5 * num23) - (num3 * num20)) + (num2 * num19)) * num;
result->M32 = -(((num5 * num22) - (num4 * num20)) + (num2 * num18)) * num;
result->M42 = (((num5 * num21) - (num4 * num19)) + (num3 * num18)) * num;
float num35 = (num7 * num10) - (num6 * num11);
float num34 = (num8 * num10) - (num6 * num12);
float num33 = (num8 * num11) - (num7 * num12);
float num32 = (num9 * num10) - (num6 * num13);
float num31 = (num9 * num11) - (num7 * num13);
float num30 = (num9 * num12) - (num8 * num13);
result->M13 = (((num4 * num35) - (num3 * num34)) + (num2 * num33)) * num;
result->M23 = -(((num5 * num35) - (num3 * num32)) + (num2 * num31)) * num;
result->M33 = (((num5 * num34) - (num4 * num32)) + (num2 * num30)) * num;
result->M43 = -(((num5 * num33) - (num4 * num31)) + (num3 * num30)) * num;
float num29 = (num7 * num14) - (num6 * num15);
float num28 = (num8 * num14) - (num6 * num16);
float num27 = (num8 * num15) - (num7 * num16);
float num26 = (num9 * num14) - (num6 * num17);
float num25 = (num9 * num15) - (num7 * num17);
float num24 = (num9 * num16) - (num8 * num17);
result->M14 = -(((num4 * num29) - (num3 * num28)) + (num2 * num27)) * num;
result->M24 = (((num5 * num29) - (num3 * num26)) + (num2 * num25)) * num;
result->M34 = -(((num5 * num28) - (num4 * num26)) + (num2 * num24)) * num;
result->M44 = (((num5 * num27) - (num4 * num25)) + (num3 * num24)) * num;
}
extern INLINE void QuatRotationYawPitchRoll(float yaw, float pitch, float roll, Quaternion& result)
{
float num13 = roll * 0.5f;
float num2 = sinf(num13);
float num = cosf(num13);
float num12 = pitch * 0.5f;
float num11 = sinf(num12);
float num10 = cosf(num12);
float num9 = yaw * 0.5f;
float num8 = sinf(num9);
float num7 = cosf(num9);
float num6 = num7 * num11;
float num5 = num8 * num10;
result.X = ((num2 * num5) + (num * num6));
result.Y = ((num * num5) - (num2 * num6));
float num4 = num7 * num10;
float num3 = num8 * num11;
result.Z = ((num2 * num4) - (num * num3));
result.W = ((num2 * num3) + (num * num4));
}
extern INLINE void QuatRotationMatrix(const Matrix4x4& matrix, Quaternion& dst)
{
float num8 = (matrix.M11 + matrix.M22) + matrix.M33;
if (num8 > 0.0f)
{
float num = sqrtf(num8 + 1.0f);
dst.W = num * 0.5f;
num = 0.5f / num;
dst.X = (matrix.M23 - matrix.M32) * num;
dst.Y = (matrix.M31 - matrix.M13) * num;
dst.Z = (matrix.M12 - matrix.M21) * num;
}
else if ((matrix.M11 >= matrix.M22) && (matrix.M11 >= matrix.M33))
{
float num7 = sqrtf((((1.0f + matrix.M11) - matrix.M22) - matrix.M33));
float num4 = 0.5f / num7;
dst.X = 0.5f * num7;
dst.Y = (matrix.M12 + matrix.M21) * num4;
dst.Z = (matrix.M13 + matrix.M31) * num4;
dst.W = (matrix.M23 - matrix.M32) * num4;
}
else if (matrix.M22 > matrix.M33)
{
float num6 = sqrtf((((1.0f + matrix.M22) - matrix.M11) - matrix.M33));
float num3 = 0.5f / num6;
dst.X = (matrix.M21 + matrix.M12) * num3;
dst.Y = 0.5f * num6;
dst.Z = (matrix.M32 + matrix.M23) * num3;
dst.W = (matrix.M31 - matrix.M13) * num3;
}
else
{
float num5 = sqrtf((((1.0f + matrix.M33) - matrix.M11) - matrix.M22));
float num2 = 0.5f / num5;
dst.X = (matrix.M31 + matrix.M13) * num2;
dst.Y = (matrix.M32 + matrix.M23) * num2;
dst.Z = 0.5f * num5;
dst.W = (matrix.M12 - matrix.M21) * num2;
}
}
}
File diff suppressed because it is too large Load Diff
+274
View File
@@ -0,0 +1,274 @@
#ifndef __MATRIX4X4__
#define __MATRIX4X4__
#include "Math.h"
namespace LifeMath
{
#undef INLINE
#ifdef _WIN32
#ifdef _MSC_VER
#define INLINE __forceinline
#define ALIGN_MATRIX __declspec(align(16))
#endif
#else
#define ALIGN_MATRIX
#ifdef __GNUC__
#define INLINE __attribute__((always_inline))
#endif
#endif
#ifndef INLINE
#define INLINE inline
#endif
typedef ALIGN_MATRIX struct Matrix4x4
{
public:
float M11;
float M12;
float M13;
float M14;
float M21;
float M22;
float M23;
float M24;
float M31;
float M32;
float M33;
float M34;
float M41;
float M42;
float M43;
float M44;
void setup(
float _m11, float _m12, float _m13, float _m14,
float _m21, float _m22, float _m23, float _m24,
float _m31, float _m32, float _m33, float _m34,
float _m41, float _m42, float _m43, float _m44)
{
M11 = _m11;
M12 = _m12;
M13 = _m13;
M14 = _m14;
M21 = _m21;
M22 = _m22;
M23 = _m23;
M24 = _m24;
M31 = _m31;
M32 = _m32;
M33 = _m33;
M34 = _m34;
M41 = _m41;
M42 = _m42;
M43 = _m43;
M44 = _m44;
}
INLINE Matrix4x4 operator *(const Matrix4x4& matrix2) const
{
Matrix4x4 matrix;
matrix.M11 = (((this->M11 * matrix2.M11) + (this->M12 * matrix2.M21)) + (this->M13 * matrix2.M31)) + (this->M14 * matrix2.M41);
matrix.M12 = (((this->M11 * matrix2.M12) + (this->M12 * matrix2.M22)) + (this->M13 * matrix2.M32)) + (this->M14 * matrix2.M42);
matrix.M13 = (((this->M11 * matrix2.M13) + (this->M12 * matrix2.M23)) + (this->M13 * matrix2.M33)) + (this->M14 * matrix2.M43);
matrix.M14 = (((this->M11 * matrix2.M14) + (this->M12 * matrix2.M24)) + (this->M13 * matrix2.M34)) + (this->M14 * matrix2.M44);
matrix.M21 = (((this->M21 * matrix2.M11) + (this->M22 * matrix2.M21)) + (this->M23 * matrix2.M31)) + (this->M24 * matrix2.M41);
matrix.M22 = (((this->M21 * matrix2.M12) + (this->M22 * matrix2.M22)) + (this->M23 * matrix2.M32)) + (this->M24 * matrix2.M42);
matrix.M23 = (((this->M21 * matrix2.M13) + (this->M22 * matrix2.M23)) + (this->M23 * matrix2.M33)) + (this->M24 * matrix2.M43);
matrix.M24 = (((this->M21 * matrix2.M14) + (this->M22 * matrix2.M24)) + (this->M23 * matrix2.M34)) + (this->M24 * matrix2.M44);
matrix.M31 = (((this->M31 * matrix2.M11) + (this->M32 * matrix2.M21)) + (this->M33 * matrix2.M31)) + (this->M34 * matrix2.M41);
matrix.M32 = (((this->M31 * matrix2.M12) + (this->M32 * matrix2.M22)) + (this->M33 * matrix2.M32)) + (this->M34 * matrix2.M42);
matrix.M33 = (((this->M31 * matrix2.M13) + (this->M32 * matrix2.M23)) + (this->M33 * matrix2.M33)) + (this->M34 * matrix2.M43);
matrix.M34 = (((this->M31 * matrix2.M14) + (this->M32 * matrix2.M24)) + (this->M33 * matrix2.M34)) + (this->M34 * matrix2.M44);
matrix.M41 = (((this->M41 * matrix2.M11) + (this->M42 * matrix2.M21)) + (this->M43 * matrix2.M31)) + (this->M44 * matrix2.M41);
matrix.M42 = (((this->M41 * matrix2.M12) + (this->M42 * matrix2.M22)) + (this->M43 * matrix2.M32)) + (this->M44 * matrix2.M42);
matrix.M43 = (((this->M41 * matrix2.M13) + (this->M42 * matrix2.M23)) + (this->M43 * matrix2.M33)) + (this->M44 * matrix2.M43);
matrix.M44 = (((this->M41 * matrix2.M14) + (this->M42 * matrix2.M24)) + (this->M43 * matrix2.M34)) + (this->M44 * matrix2.M44);
return matrix;
}
/* public MatrixBasis Basis
{
get
{
MatrixBasis basis = new MatrixBasis();
basis.M11 = this.M11;
basis.M12 = this.M12;
basis.M13 = this.M13;
basis.M21 = this.M21;
basis.M22 = this.M22;
basis.M23 = this.M23;
basis.M31 = this.M31;
basis.M32 = this.M32;
basis.M33 = this.M33;
return basis;
}
set
{
this.M11 = value.M11;
this.M12 = value.M12;
this.M13 = value.M13;
this.M21 = value.M21;
this.M22 = value.M22;
this.M23 = value.M23;
this.M31 = value.M31;
this.M32 = value.M32;
this.M33 = value.M33;
}
}*/
/*
#region Decomposition
public Vec3f Up
{
get
{
Vec3f vector;
vector.X = this.M21;
vector.Y = this.M22;
vector.Z = this.M23;
return vector;
}
set
{
this.M21 = value.X;
this.M22 = value.Y;
this.M23 = value.Z;
}
}
public Vec3f Down
{
get
{
Vec3f vector;
vector.X = -this.M21;
vector.Y = -this.M22;
vector.Z = -this.M23;
return vector;
}
set
{
this.M21 = -value.X;
this.M22 = -value.Y;
this.M23 = -value.Z;
}
}
public Vec3f Right
{
get
{
Vec3f vector;
vector.X = this.M11;
vector.Y = this.M12;
vector.Z = this.M13;
return vector;
}
set
{
this.M11 = value.X;
this.M12 = value.Y;
this.M13 = value.Z;
}
}
public Vec3f Left
{
get
{
Vec3f vector;
vector.X = -this.M11;
vector.Y = -this.M12;
vector.Z = -this.M13;
return vector;
}
set
{
this.M11 = -value.X;
this.M12 = -value.Y;
this.M13 = -value.Z;
}
}
public Vec3f Forward
{
get
{
Vec3f vector;
vector.X = -this.M31;
vector.Y = -this.M32;
vector.Z = -this.M33;
return vector;
}
set
{
this.M31 = -value.X;
this.M32 = -value.Y;
this.M33 = -value.Z;
}
}
public Vec3f Backward
{
get
{
Vec3f vector;
vector.X = this.M31;
vector.Y = this.M32;
vector.Z = this.M33;
return vector;
}
set
{
this.M31 = value.X;
this.M32 = value.Y;
this.M33 = value.Z;
}
}
public Vec3f Position
{
get
{
Vec3f vector;
vector.X = this.M41;
vector.Y = this.M42;
vector.Z = this.M43;
return vector;
}
set
{
this.M41 = value.X;
this.M42 = value.Y;
this.M43 = value.Z;
}
}
public void Decompose(out Vec3f scale, out CQuaternion rotation, out Vec3f translation)
{
MatrixBasis b = this.Basis;
scale = b.Scaling;
translation.X = this.M41;
translation.Y = this.M42;
translation.Z = this.M43;
b.Scaling = new Vec3f(1, 1, 1);
rotation = CQuaternion.RotationBasis(b);
}
#endregion*/
} Matrix4x4, *PMatrix4x4, **LPMatrix4x4;
typedef Matrix4x4 float4x4;
}
#endif
+96
View File
@@ -0,0 +1,96 @@
#ifndef Plane_h__
#define Plane_h__
#include "Vector3D.h"
#include "Vector4D.h"
#include <cmath>
namespace LifeMath
{
#undef INLINE
#ifdef _WIN32
#ifdef _MSC_VER
#define INLINE __forceinline
#endif
#else
#ifdef __GNUC__
#define INLINE __attribute__((always_inline))
#endif
#endif
#ifndef INLINE
#define INLINE inline
#endif
class Plane
{
public:
Vec3f Normal;
float D;
Plane(float a, float b, float c, float d)
{
Normal.X = a;
Normal.Y = b;
Normal.Z = c;
D = d;
}
Plane()
{
Normal.X = 0.0f;
Normal.Y = 1.0f;
Normal.Z = 0.0f;
D = 0.0f;
}
Plane(const Vec3f& _normal, float d)
{
Normal = _normal;
D = d;
}
Plane(const Vec3f& point, const Vec3f& normal)
{
Normal = normal;
D = -(((normal.Y * point.Y) + (normal.X * point.X)) + (normal.Z * point.Z));
}
Plane(const Vec4f& val)
{
Normal.X = val.X;
Normal.Y = val.Y;
Normal.Z = val.Z;
D = val.W;
}
Plane(Vec3f& point1, Vec3f& point2, Vec3f& point3)
{
float num10 = point2.X - point1.X;
float num9 = point2.Y - point1.Y;
float num8 = point2.Z - point1.Z;
float num7 = point3.X - point1.X;
float num6 = point3.Y - point1.Y;
float num5 = point3.Z - point1.Z;
float num4 = (num9 * num5) - (num8 * num6);
float num3 = (num8 * num7) - (num10 * num5);
float num2 = (num10 * num6) - (num9 * num7);
float num11 = ((num4 * num4) + (num3 * num3)) + (num2 * num2);
float num = 1.0f / sqrtf(num11);
Normal.X = num4 * num;
Normal.Y = num3 * num;
Normal.Z = num2 * num;
D = -(((Normal.X * point1.X) + (Normal.Y * point1.Y)) + (Normal.Z * point1.Z));
}
INLINE bool operator ==(const Plane& other) const
{
return (other.Normal == this->Normal && other.D == this->D);
}
INLINE bool operator !=(const Plane& other) const
{
if(this->Normal == other.Normal)
{
return (this->D != other.D);
}
return true;
}
};
}
#endif // Plane_h__
+93
View File
@@ -0,0 +1,93 @@
#ifndef __QUATERNION__
#define __QUATERNION__
#include "Math.h"
#include <cmath>
namespace LifeMath
{
#undef INLINE
#ifdef _WIN32
#ifdef _MSC_VER
#define INLINE __forceinline
#endif
#else
#ifdef __GNUC__
#define INLINE __attribute__((always_inline))
#endif
#endif
#ifndef INLINE
#define INLINE inline
#endif
struct Quaternion
{
public:
float X,Y,Z,W;
INLINE Quaternion()
{
X = Y = Z = W = 0.0f;
}
INLINE Quaternion operator -() const
{
return Quaternion(-X, -Y, -Z, -W);
}
INLINE bool operator == (const Quaternion& right) const
{
return (X == right.X && Y == right.Y && Z == right.Z && W == right.W);
}
INLINE bool operator != (const Quaternion& right) const
{
return (X != right.X || Y != right.Y || Z != right.Z || W != right.W);
}
INLINE Quaternion(float x, float y, float z, float w)
{
X = x;
Y = y;
Z = z;
W = w;
}
INLINE Quaternion& operator =(const Quaternion& other)
{
X = other.X;
Y = other.Y;
Z = other.Z;
W = other.W;
return *this;
}
INLINE Quaternion operator *(float other) const
{
return Quaternion(X * other, Y * other, Z * other, W * other);
}
INLINE Quaternion operator +(const Quaternion& other) const
{
return Quaternion(X + other.X, Y + other.Y, Z + other.Z, W + other.W);
}
INLINE Quaternion operator *(const Quaternion& other) const
{
Quaternion quaternion;
float x = this->X;
float y = this->Y;
float z = this->Z;
float w = this->W;
float num4 = other.X;
float num3 = other.Y;
float num2 = other.Z;
float num = other.W;
float num12 = (y * num2) - (z * num3);
float num11 = (z * num4) - (x * num2);
float num10 = (x * num3) - (y * num4);
float num9 = ((x * num4) + (y * num3)) + (z * num2);
quaternion.X = ((x * num) + (num4 * w)) + num12;
quaternion.Y = ((y * num) + (num3 * w)) + num11;
quaternion.Z = ((z * num) + (num2 * w)) + num10;
quaternion.W = (w * num) - num9;
return quaternion;
}
};
}
#endif
+127
View File
@@ -0,0 +1,127 @@
#ifndef Rectangle_h__
#define Rectangle_h__
#include "math/Vector2D.h"
namespace LifeMath
{
template<typename T>
struct Rectangle
{
T x;
T y;
T width;
T height;
Rectangle()
{
x = y = width = height = 0;
}
Rectangle(T _width, T _height)
{
width = _width;
height = _height;
x = y = 0;
}
Rectangle(T _x, T _y, T _width, T _height)
{
width = _width;
height = _height;
x = _x;
y = _y;
}
bool operator ==(const Rectangle<T>& other)
{
return ((x == other.x) && (y == other.y) && (width == other.width) && (height == other.height));
}
bool operator !=(const Rectangle<T>& other)
{
return ((x != other.x) || (y != other.y) || (width != other.width) || (height != other.height));
}
//get rectangle minimum corner coordinate
Vector2D<T> GetMin() const
{
return Vector2D<T>(x, y);
}
//get rectangle maximum corner coordinate
Vector2D<T> GetMax() const
{
return Vector2D<T>(x + (width), y + (height));
}
//get rectangle maximum X
T GetMaxX() const
{
return x + (width);
}
//get rectangle maximum Y
T GetMaxY() const
{
return y + (height);
}
//get rectangle square
T GetSquare() const
{
return width * height;
}
//merge 2 rectangles into 1 bounding rectangle
void Merge(const Rectangle<T>& other)
{
int minX = std::min<T>(x, other.x);
int maxX = std::max<T>(this->GetMaxX(), other.GetMaxX());
int minY = std::min<T>(y, other.y);
int maxY = std::max<T>(this->GetMaxY(), other.GetMaxY());
this->x = minX;
this->y = minY;
this->width = maxX - minX;
this->height = maxY - minY;
}
//crop this rectangle by other rectangle
void Crop(const Rectangle<T>& other)
{
if(this->x < other.x)
{
T diff = other.x - this->x;
this->x += diff;
this->width -= diff;
}
if(this->y < other.y)
{
T diff = other.y - this->y;
this->y += diff;
this->height -= diff;
}
if(this->GetMaxX() > other.GetMaxX())
{
T diff = this->GetMaxX() - other.GetMaxX();
this->width -= diff;
}
if(this->GetMaxY() > other.GetMaxY())
{
T diff = this->GetMaxY() - other.GetMaxY();
this->height -= diff;
}
if(width < 0)
width = 0;
if(height < 0)
height = 0;
}
bool InRect(const T x, const T y)
{
return (x >= this->x && y >= this->y && x <= (this->x + width) && y <=(this->y + height));
}
bool InRect(const Vector2D<T>& point)
{
return InRect(point.X, point.Y);
}
};
typedef Rectangle<int> Rect2i;
typedef Rectangle<float> Rect2f;
typedef Rectangle<double> Rect2d;
}
#endif // Rectangle_h__
+22
View File
@@ -0,0 +1,22 @@
#ifndef Spline_h__
#define Spline_h__
namespace LifeCore
{
template<typename T>
static inline T LinearBezier(float t, const T& v1, const T& v2)
{
return (v1 * (1-t)) + (v2 * t);
}
template<typename T>
static inline T QuadraticBezier(float t, const T& v1, const T& v2, const T& v3)
{
return (LinearBezier<T>(t, v1, v2) * (1 - t)) + (LinearBezier<T>(t, v2, v3) * (t));
}
template<typename T>
static inline T CubicBezier(float t, const T& v1, const T& v2, const T& v3, const T& v4)
{
return (QuadraticBezier<T>(t, v1, v2, v3) * (1 - t)) + (QuadraticBezier<T>(t, v2, v3, v4) * (t));
}
}
#endif // Spline_h__
+175
View File
@@ -0,0 +1,175 @@
#ifndef __Vector2D__
#define __Vector2D__
#include "Math.h"
namespace LifeMath
{
#undef INLINE
#ifdef _WIN32
#ifdef _MSC_VER
#define INLINE __forceinline
#endif
#else
#ifdef __GNUC__
#define INLINE __attribute__((always_inline))
#endif
#endif
#ifndef INLINE
#define INLINE inline
#endif
template<typename T>
struct Vector2D
{
public:
T X, Y;
INLINE Vector2D(T x, T y)
{
this->X = x;
this->Y = y;
}
INLINE void Set(T x, T y)
{
this->X = x;
this->Y = y;
}
INLINE Vector2D(void)
{
this->X = this->Y = 0;
}
INLINE Vector2D(T val)
{
this->X = val;
this->Y = val;
}
INLINE Vector2D& operator=(const Vector2D& other)
{
X = other.X;
Y = other.Y;
return *this;
}
//unary operators
INLINE Vector2D operator -() const
{
return Vector2D(-X, -Y);
}
INLINE Vector2D operator +() const
{
return *this;
}
//binary operators
INLINE Vector2D<T> operator +(const LifeMath::Vector2D<T> &other) const
{
return Vector2D<T>(X + other.X, Y + other.Y);
}
INLINE Vector2D<T> operator -(const LifeMath::Vector2D<T> &other) const
{
return Vector2D<T>(X - other.X, Y - other.Y);
}
INLINE Vector2D<T> operator *(T other) const
{
return Vector2D<T>(X * other, Y * other);
}
INLINE Vector2D<T> operator /(T other) const
{
return Vector2D<T>(X / other, Y / other);
}
INLINE operator T * ()
{
return &X;
}
INLINE operator const T * () const
{
return &X;
}
INLINE bool operator == (const Vector2D& vector) const
{
return (X == vector.X && Y == vector.Y);
}
INLINE bool operator != (const Vector2D& vector) const
{
return (X != vector.X || Y != vector.Y);
}
INLINE Vector2D<T>& operator += (const Vector2D& Vector)
{
X += Vector.X;
Y += Vector.Y;
return *this;
}
INLINE Vector2D<T>& operator -= (const Vector2D& Vector)
{
X -= Vector.X;
Y -= Vector.Y;
return *this;
}
INLINE Vector2D<T>& operator *= (T Value)
{
X *= Value;
Y *= Value;
return *this;
}
INLINE Vector2D<T>& operator /= (T Value)
{
//assert(Value && "Zero Value");
//*this *= (1.0f / Value);
this->X /= Value;
this->Y /= Value;
return *this;
}
INLINE Vector2D<T>& operator += (T Value)
{
X += Value;
Y += Value;
return *this;
}
INLINE Vector2D<T>& operator -= (T Value)
{
X -= Value;
Y -= Value;
return *this;
}
INLINE Vector2D<T>& operator /= (const Vector2D<T>& vector)
{
X /= vector.X;
Y /= vector.Y;
return *this;
}
INLINE Vector2D<T>& operator *= (const Vector2D<T>& vector)
{
X *= vector.X;
Y *= vector.Y;
return *this;
}
INLINE float& operator [](int index)
{
//assert(index < 3 && "Out Of Range");
return *(index + (&X));
}
INLINE float operator [] (int index) const
{
//assert(index < 2 && "Out Of Range");
return * (index + (&X));
}
INLINE bool operator > (const Vector2D<T>& v) const
{
return X > v.X && Y > v.Y;
}
INLINE bool operator < (const Vector2D<T>& v) const
{
return X < v.X && Y < v.Y;
}
};
typedef Vector2D<float> Vec2f;
typedef Vector2D<int> Vec2i;
typedef Vector2D<float> float2;
}
#endif
+180
View File
@@ -0,0 +1,180 @@
#ifndef __VECTOR3D__
#define __VECTOR3D__
#include "Math.h"
namespace LifeMath
{
#undef INLINE
#ifdef _WIN32
#ifdef _MSC_VER
#define INLINE __forceinline
#endif
#else
#ifdef __GNUC__
#define INLINE __attribute__((always_inline))
#endif
#endif
#ifndef INLINE
#define INLINE inline
#endif
template<typename T>
struct Vector3D
{
public:
T X, Y, Z;
INLINE Vector3D<T>(T x, T y, T z)
{
this->X = x;
this->Y = y;
this->Z = z;
}
INLINE Vector3D<T>(void)
{
this->X = 0.0f;
this->Y = 0.0f;
this->Z = 0.0f;
}
INLINE Vector3D<T>(T val)
{
this->X = val;
this->Y = val;
this->Z = val;
}
INLINE Vector3D<T>& operator=(const Vector3D<T>& other)
{
X = other.X;
Y = other.Y;
Z = other.Z;
return *this;
}
//unary operators
INLINE Vector3D<T> operator -() const
{
return Vector3D<T>(-X, -Y, -Z);
}
INLINE Vector3D<T> operator +() const
{
return *this;
}
//binary operators
INLINE Vector3D<T> operator +(const Vector3D<T> &other) const
{
return Vector3D<T>(X + other.X, Y + other.Y, Z + other.Z);
}
INLINE Vector3D<T> operator -(const Vector3D<T> &other) const
{
return Vector3D<T>(X - other.X, Y - other.Y, Z - other.Z);
}
INLINE Vector3D<T> operator *(T other) const
{
return Vector3D<T>(X * other, Y * other, Z * other);
}
INLINE Vector3D<T> operator /(T other) const
{
return Vector3D<T>(X / other, Y / other, Z / other);
}
INLINE operator T * ()
{
return &X;
}
INLINE operator const T * () const
{
return &X;
}
INLINE bool operator == (const Vector3D<T>& vector) const
{
return (X == vector.X && Y == vector.Y && Z == vector.Z);
}
INLINE bool operator != (const Vector3D<T>& vector) const
{
return (X != vector.X || Y != vector.Y || Z != vector.Z);
}
INLINE Vector3D<T>& operator += (const Vector3D<T>& Vector)
{
X += Vector.X;
Y += Vector.Y;
Z += Vector.Z;
return *this;
}
INLINE Vector3D<T>& operator -= (const Vector3D<T>& Vector)
{
X -= Vector.X;
Y -= Vector.Y;
Z -= Vector.Z;
return *this;
}
INLINE Vector3D<T>& operator *= (T Value)
{
X *= Value;
Y *= Value;
Z *= Value;
return *this;
}
INLINE Vector3D<T>& operator /= (T Value)
{
//assert(Value && "Zero Value");
*this *= (1.0f / Value);
return *this;
}
INLINE Vector3D<T>& operator += (T Value)
{
X += Value;
Y += Value;
Z += Value;
return *this;
}
INLINE Vector3D<T>& operator -= (T Value)
{
X -= Value;
Y -= Value;
Z -= Value;
return *this;
}
INLINE Vector3D<T>& operator /= (const Vector3D<T>& vector)
{
X /= vector.X;
Y /= vector.Y;
Z /= vector.Z;
return *this;
}
INLINE Vector3D<T>& operator *= (const Vector3D<T>& vector)
{
X *= vector.X;
Y *= vector.Y;
Z *= vector.Z;
return *this;
}
INLINE T& operator [](int index)
{
//assert(index < 3 && "Out Of Range");
return *(index + (&X));
}
INLINE T operator [] (int index) const
{
//assert(index < 2 && "Out Of Range");
return * (index + (&X));
}
INLINE bool operator > (const Vector3D<T>& v) const
{
return X > v.X && Y > v.Y && Z > v.Z;
}
INLINE bool operator < (const Vector3D<T>& v) const
{
return X < v.X && Y < v.Y && Z < v.Z;
}
};
typedef Vector3D<float> Vec3f;
typedef Vector3D<int> Vec3i;
typedef Vector3D<float> float3;
}
#endif
+192
View File
@@ -0,0 +1,192 @@
#ifndef __VECTOR4D__
#define __VECTOR4D__
#include "Math.h"
namespace LifeMath
{
#undef INLINE
#ifdef _WIN32
#ifdef _MSC_VER
#define INLINE __forceinline
#endif
#else
#ifdef __GNUC__
#define INLINE __attribute__((always_inline))
#endif
#endif
#ifndef INLINE
#define INLINE inline
#endif
// struct Vector4D;
// struct Vector4D;
template<typename T>
struct Vector4D
{
public:
T X, Y, Z, W;
INLINE Vector4D<T>(T x, T y, T z, T w)
{
this->X = x;
this->Y = y;
this->Z = z;
this->W = w;
}
INLINE Vector4D<T>(void)
{
this->X = 0;
this->Y = 0;
this->Z = 0;
this->W = 0;
}
INLINE Vector4D<T>(T val)
{
this->X = val;
this->Y = val;
this->Z = val;
this->W = val;
}
//unary operators
INLINE Vector4D<T> operator -() const
{
return Vector4D<T>(-X, -Y, -Z, -W);
}
INLINE Vector4D<T> operator +() const
{
return *this;
}
INLINE Vector4D<T>& operator=(const Vector4D<T>& other)
{
X = other.X;
Y = other.Y;
Z = other.Z;
W = other.W;
return *this;
}
//binary operators
INLINE Vector4D<T> operator +(const Vector4D<T> &other) const
{
return Vector4D<T>(X + other.X, Y + other.Y, Z + other.Z, W + other.W);
}
INLINE Vector4D<T> operator -(const Vector4D<T> &other) const
{
return Vector4D<T>(X - other.X, Y - other.Y, Z - other.Z, W - other.W);
}
INLINE Vector4D<T> operator *(T other) const
{
return Vector4D<T>(X * other, Y * other, Z * other, W * other);
}
INLINE Vector4D<T> operator /(T other) const
{
return Vector4D<T>(X / other, Y / other, Z / other, W / other);
}
INLINE operator T * ()
{
return &X;
}
INLINE operator const T * () const
{
return &X;
}
INLINE bool operator == (const Vector4D<T>& vector) const
{
return (X == vector.X && Y == vector.Y && Z == vector.Z && W == vector.W);
}
INLINE bool operator != (const Vector4D<T>& vector) const
{
return (X != vector.X || Y != vector.Y || Z != vector.Z || W != vector.W);
}
INLINE Vector4D<T>& operator += (const Vector4D<T>& Vector)
{
X += Vector.X;
Y += Vector.Y;
Z += Vector.Z;
W += Vector.W;
return *this;
}
INLINE Vector4D<T>& operator -= (const Vector4D<T>& Vector)
{
X -= Vector.X;
Y -= Vector.Y;
Z -= Vector.Z;
W -= Vector.W;
return *this;
}
INLINE Vector4D<T>& operator *= (T Value)
{
X *= Value;
Y *= Value;
Z *= Value;
W *= Value;
return *this;
}
INLINE Vector4D<T>& operator /= (T Value)
{
//assert(Value && "Zero Value");
*this *= (1.0f / Value);
return *this;
}
INLINE Vector4D<T>& operator += (T Value)
{
X += Value;
Y += Value;
Z += Value;
W += Value;
return *this;
}
INLINE Vector4D<T>& operator -= (T Value)
{
X -= Value;
Y -= Value;
Z -= Value;
W -= Value;
return *this;
}
INLINE Vector4D<T>& operator /= (const Vector4D<T>& vector)
{
X /= vector.X;
Y /= vector.Y;
Z /= vector.Z;
W /= vector.W;
return *this;
}
INLINE Vector4D<T>& operator *= (const Vector4D<T>& vector)
{
X *= vector.X;
Y *= vector.Y;
Z *= vector.Z;
W *= vector.W;
return *this;
}
INLINE T& operator [](int index)
{
//assert(index < 3 && "Out Of Range");
return *(index + (&X));
}
INLINE T operator [] (int index) const
{
//assert(index < 2 && "Out Of Range");
return * (index + (&X));
}
INLINE bool operator > (const Vector4D<T>& v) const
{
return X > v.X && Y > v.Y && Z > v.Z && W > v.W;
}
INLINE bool operator < (const Vector4D<T>& v) const
{
return X < v.X && Y < v.Y && Z < v.Z && W < v.W;
}
};
typedef Vector4D<float> Vec4f;
typedef Vector4D<int> Vec4i;
typedef Vector4D<float> float4;
}
#endif
+17
View File
@@ -0,0 +1,17 @@
#ifndef vector_base_h__
#define vector_base_h__
namespace LifeMath
{
template<typename T_val, int Size>
class vector_base
{
public:
vector_base();
~vector_base();
private:
};
}
#endif // vector_base_h__