aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/math
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-02-11 11:29:07 +0800
committerchai <chaifix@163.com>2020-02-11 11:29:07 +0800
commit160e1299ef3d95f8e8c48706d7f61dd3dc6c6b60 (patch)
treeabe5ae5242d9cc6caf6edf103e662c44e978fca0 /src/libjin/math
parente095043485d1d298571af6d9eca7f0db9009ea7a (diff)
*修改 tab大小HEADmaster
Diffstat (limited to 'src/libjin/math')
-rw-r--r--src/libjin/math/bbox.h36
-rw-r--r--src/libjin/math/bezier_curve.h12
-rw-r--r--src/libjin/math/math.h206
-rw-r--r--src/libjin/math/matrix.cpp370
-rw-r--r--src/libjin/math/matrix.h304
-rw-r--r--src/libjin/math/percentage.h40
-rw-r--r--src/libjin/math/quad.h36
-rw-r--r--src/libjin/math/random.cpp94
-rw-r--r--src/libjin/math/random.h32
-rw-r--r--src/libjin/math/ranged_value.cpp116
-rw-r--r--src/libjin/math/ranged_value.h68
-rw-r--r--src/libjin/math/transform.cpp198
-rw-r--r--src/libjin/math/transform.h58
-rw-r--r--src/libjin/math/vector2.hpp122
-rw-r--r--src/libjin/math/vector3.hpp86
-rw-r--r--src/libjin/math/vector4.hpp98
16 files changed, 938 insertions, 938 deletions
diff --git a/src/libjin/math/bbox.h b/src/libjin/math/bbox.h
index ce88080..97b67cb 100644
--- a/src/libjin/math/bbox.h
+++ b/src/libjin/math/bbox.h
@@ -3,28 +3,28 @@
namespace JinEngine
{
- namespace Math
- {
+ namespace Math
+ {
- ///
- ///
- ///
- struct BBox
- {
- BBox()
- : l(0), r(0), t(0), b(0)
- {
- }
+ ///
+ ///
+ ///
+ struct BBox
+ {
+ BBox()
+ : l(0), r(0), t(0), b(0)
+ {
+ }
- BBox(float _l, float _r, float _t, float _b)
- : l(+l), r(_r), t(_t), b(_b)
- {
- }
+ BBox(float _l, float _r, float _t, float _b)
+ : l(+l), r(_r), t(_t), b(_b)
+ {
+ }
- float l, r, t, b;
- };
+ float l, r, t, b;
+ };
- } // namespace Math
+ } // namespace Math
} // namespace JinEngine
#endif // __JE_BBOX_H__ \ No newline at end of file
diff --git a/src/libjin/math/bezier_curve.h b/src/libjin/math/bezier_curve.h
index 6925baf..a84d856 100644
--- a/src/libjin/math/bezier_curve.h
+++ b/src/libjin/math/bezier_curve.h
@@ -3,15 +3,15 @@
namespace JinEngine
{
- namespace Math
- {
+ namespace Math
+ {
- class BezierCurve
- {
+ class BezierCurve
+ {
- };
+ };
- } // namespace Math
+ } // namespace Math
} // namespace JinEngine
#endif \ No newline at end of file
diff --git a/src/libjin/math/math.h b/src/libjin/math/math.h
index 79ed4c8..5197f6d 100644
--- a/src/libjin/math/math.h
+++ b/src/libjin/math/math.h
@@ -7,109 +7,109 @@
namespace JinEngine
{
- namespace Math
- {
-
- #ifdef min
- #undef min
- #endif // min
- #ifdef max
- #undef max
- #endif // max
-
- template<typename T>
- inline T min(T a, T b)
- {
- return a < b ? a : b;
- }
-
- template<typename T>
- inline T max(T a, T b)
- {
- return a > b ? a : b;
- }
-
- template<typename T>
- inline T clamp(T a, T mi, T ma)
- {
- return min<T>(max<T>(a, mi), ma);
- }
-
- template<typename T>
- inline bool within(T a, T mi, T ma)
- {
- return a >= mi && a <= ma;
- }
-
- template<typename T>
- inline bool without(T a, T mi, T ma)
- {
- return a < mi || a > ma;
- }
-
- template<typename T>
- inline T lowerBound(T a, T lower)
- {
- return a < lower ? lower : a;
- }
-
- template<typename T>
- inline T upperBound(T a, T upper)
- {
- return a > upper ? upper : a;
- }
-
- inline float lerp(float a, float b, float f)
- {
- f = clamp<float>(f, 0, 1);
- return a + f * (b - a);
- }
-
- template<typename T>
- inline T abs(T a)
- {
- return a > 0 ? a : -a;
- }
-
- template<typename T>
- inline T reverse(T a)
- {
- return -a;
- }
-
- template<typename T>
- inline T lerp(T a, T b, float t)
- {
- return a + t * (b - a);
- }
-
- template<typename T>
- inline T slerp(T start, T end, float percent)
- {
- // Dot product - the cosine of the angle between 2 vectors.
- float dot = start * end;
- // Clamp it to be in the range of Acos()
- // This may be unnecessary, but floating point
- // precision can be a fickle mistress.
- dot = clamp<float>(dot, -1.0f, 1.0f);
- // Acos(dot) returns the angle between start and end,
- // And multiplying that by percent returns the angle between
- // start and the final result.
- float theta = Mathf.Acos(dot)*percent;
- Vector3 RelativeVec = end - start * dot;
- RelativeVec.Normalize();
- // Orthonormal basis
- // The final result.
- return ((start*Mathf.Cos(theta)) + (RelativeVec*Mathf.Sin(theta)));
- }
-
- template<typename T>
- inline T nlerp(T a, T b, float t)
- {
-
- }
-
- } // namespace Math
+ namespace Math
+ {
+
+ #ifdef min
+ #undef min
+ #endif // min
+ #ifdef max
+ #undef max
+ #endif // max
+
+ template<typename T>
+ inline T min(T a, T b)
+ {
+ return a < b ? a : b;
+ }
+
+ template<typename T>
+ inline T max(T a, T b)
+ {
+ return a > b ? a : b;
+ }
+
+ template<typename T>
+ inline T clamp(T a, T mi, T ma)
+ {
+ return min<T>(max<T>(a, mi), ma);
+ }
+
+ template<typename T>
+ inline bool within(T a, T mi, T ma)
+ {
+ return a >= mi && a <= ma;
+ }
+
+ template<typename T>
+ inline bool without(T a, T mi, T ma)
+ {
+ return a < mi || a > ma;
+ }
+
+ template<typename T>
+ inline T lowerBound(T a, T lower)
+ {
+ return a < lower ? lower : a;
+ }
+
+ template<typename T>
+ inline T upperBound(T a, T upper)
+ {
+ return a > upper ? upper : a;
+ }
+
+ inline float lerp(float a, float b, float f)
+ {
+ f = clamp<float>(f, 0, 1);
+ return a + f * (b - a);
+ }
+
+ template<typename T>
+ inline T abs(T a)
+ {
+ return a > 0 ? a : -a;
+ }
+
+ template<typename T>
+ inline T reverse(T a)
+ {
+ return -a;
+ }
+
+ template<typename T>
+ inline T lerp(T a, T b, float t)
+ {
+ return a + t * (b - a);
+ }
+
+ template<typename T>
+ inline T slerp(T start, T end, float percent)
+ {
+ // Dot product - the cosine of the angle between 2 vectors.
+ float dot = start * end;
+ // Clamp it to be in the range of Acos()
+ // This may be unnecessary, but floating point
+ // precision can be a fickle mistress.
+ dot = clamp<float>(dot, -1.0f, 1.0f);
+ // Acos(dot) returns the angle between start and end,
+ // And multiplying that by percent returns the angle between
+ // start and the final result.
+ float theta = Mathf.Acos(dot)*percent;
+ Vector3 RelativeVec = end - start * dot;
+ RelativeVec.Normalize();
+ // Orthonormal basis
+ // The final result.
+ return ((start*Mathf.Cos(theta)) + (RelativeVec*Mathf.Sin(theta)));
+ }
+
+ template<typename T>
+ inline T nlerp(T a, T b, float t)
+ {
+
+ }
+
+ } // namespace Math
} // namespace JinEngine
#endif // __JE_UTILS_MATH_H__ \ No newline at end of file
diff --git a/src/libjin/math/matrix.cpp b/src/libjin/math/matrix.cpp
index 9d1c77b..52d4f74 100644
--- a/src/libjin/math/matrix.cpp
+++ b/src/libjin/math/matrix.cpp
@@ -7,189 +7,189 @@
namespace JinEngine
{
- namespace Math
- {
-
- const Matrix Matrix::Identity;
-
- // | e0 e4 e8 e12 |
- // | e1 e5 e9 e13 |
- // | e2 e6 e10 e14 |
- // | e3 e7 e11 e15 |
-
- Matrix::Matrix()
- {
- setIdentity();
- }
-
- Matrix::~Matrix()
- {
- }
-
- void Matrix::setOrtho(float l, float r, float b, float t, float n, float f)
- {
- setIdentity();
- float w = r - l;
- float h = t - b;
- float z = f - n;
- e[0] = 2 / w;
- e[5] = 2 / h;
- e[10] = -2 / z;
- e[12] = -(r + l) / w;
- e[13] = -(t + b) / h;
- e[14] = -(f + n) / z;
- e[15] = 1;
- }
-
- // | e0 e4 e8 e12 |
- // | e1 e5 e9 e13 |
- // | e2 e6 e10 e14 |
- // | e3 e7 e11 e15 |
- // | e0 e4 e8 e12 |
- // | e1 e5 e9 e13 |
- // | e2 e6 e10 e14 |
- // | e3 e7 e11 e15 |
-
- Matrix Matrix::operator * (const Matrix & m) const
- {
- Matrix t;
-
- t.e[0] = (e[0] * m.e[0]) + (e[4] * m.e[1]) + (e[8] * m.e[2]) + (e[12] * m.e[3]);
- t.e[4] = (e[0] * m.e[4]) + (e[4] * m.e[5]) + (e[8] * m.e[6]) + (e[12] * m.e[7]);
- t.e[8] = (e[0] * m.e[8]) + (e[4] * m.e[9]) + (e[8] * m.e[10]) + (e[12] * m.e[11]);
- t.e[12] = (e[0] * m.e[12]) + (e[4] * m.e[13]) + (e[8] * m.e[14]) + (e[12] * m.e[15]);
-
- t.e[1] = (e[1] * m.e[0]) + (e[5] * m.e[1]) + (e[9] * m.e[2]) + (e[13] * m.e[3]);
- t.e[5] = (e[1] * m.e[4]) + (e[5] * m.e[5]) + (e[9] * m.e[6]) + (e[13] * m.e[7]);
- t.e[9] = (e[1] * m.e[8]) + (e[5] * m.e[9]) + (e[9] * m.e[10]) + (e[13] * m.e[11]);
- t.e[13] = (e[1] * m.e[12]) + (e[5] * m.e[13]) + (e[9] * m.e[14]) + (e[13] * m.e[15]);
-
- t.e[2] = (e[2] * m.e[0]) + (e[6] * m.e[1]) + (e[10] * m.e[2]) + (e[14] * m.e[3]);
- t.e[6] = (e[2] * m.e[4]) + (e[6] * m.e[5]) + (e[10] * m.e[6]) + (e[14] * m.e[7]);
- t.e[10] = (e[2] * m.e[8]) + (e[6] * m.e[9]) + (e[10] * m.e[10]) + (e[14] * m.e[11]);
- t.e[14] = (e[2] * m.e[12]) + (e[6] * m.e[13]) + (e[10] * m.e[14]) + (e[14] * m.e[15]);
-
- t.e[3] = (e[3] * m.e[0]) + (e[7] * m.e[1]) + (e[11] * m.e[2]) + (e[15] * m.e[3]);
- t.e[7] = (e[3] * m.e[4]) + (e[7] * m.e[5]) + (e[11] * m.e[6]) + (e[15] * m.e[7]);
- t.e[11] = (e[3] * m.e[8]) + (e[7] * m.e[9]) + (e[11] * m.e[10]) + (e[15] * m.e[11]);
- t.e[15] = (e[3] * m.e[12]) + (e[7] * m.e[13]) + (e[11] * m.e[14]) + (e[15] * m.e[15]);
-
- return t;
- }
-
- void Matrix::operator *= (const Matrix & m)
- {
- Matrix t = (*this) * m;
- memcpy((void*)this->e, (void*)t.e, sizeof(float) * 16);
- }
-
- const float * Matrix::getElements() const
- {
- return e;
- }
-
- void Matrix::setIdentity()
- {
- memset(e, 0, sizeof(float) * 16);
- e[0] = e[5] = e[10] = e[15] = 1;
- }
-
- void Matrix::setTranslation(float x, float y)
- {
- setIdentity();
- e[12] = x;
- e[13] = y;
- }
-
- void Matrix::setRotation(float rad)
- {
- setIdentity();
- float c = cos(rad), s = sin(rad);
- e[0] = c; e[4] = -s;
- e[1] = s; e[5] = c;
- }
-
- void Matrix::setScale(float sx, float sy)
- {
- setIdentity();
- e[0] = sx;
- e[5] = sy;
- }
-
- void Matrix::setShear(float kx, float ky)
- {
- setIdentity();
- e[1] = ky;
- e[4] = kx;
- }
-
- void Matrix::setTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy)
- {
- memset(e, 0, sizeof(float) * 16); // zero out matrix
- float c = cos(angle), s = sin(angle);
- // matrix multiplication carried out on paper:
- // |1 x| |c -s | |sx | |1 -ox|
- // | 1 y| |s c | | sy | | 1 -oy|
- // | 1 | | 1 | | 1 | | 1 |
- // | 1| | 1| | 1| | 1 |
- // move rotate scale origin
- e[10] = e[15] = 1.0f;
- e[0] = c * sx ; // = a
- e[1] = s * sx ; // = b
- e[4] = - s * sy; // = c
- e[5] = c * sy; // = d
- e[12] = x - ox * e[0] - oy * e[4];
- e[13] = y - ox * e[1] - oy * e[5];
- }
-
- void Matrix::translate(float x, float y)
- {
- Matrix t;
- t.setTranslation(x, y);
- this->operator *=(t);
- }
-
- void Matrix::rotate(float rad)
- {
- Matrix t;
- t.setRotation(rad);
- this->operator *=(t);
- }
-
- void Matrix::scale(float sx, float sy)
- {
- Matrix t;
- t.setScale(sx, sy);
- this->operator *=(t);
- }
-
- void Matrix::shear(float kx, float ky)
- {
- Matrix t;
- t.setShear(kx, ky);
- this->operator *=(t);
- }
-
- // | x |
- // | y |
- // | 0 |
- // | 1 |
- // | e0 e4 e8 e12 |
- // | e1 e5 e9 e13 |
- // | e2 e6 e10 e14 |
- // | e3 e7 e11 e15 |
-
- void Matrix::transform(Graphics::Vertex* dst, const Graphics::Vertex* src, int size) const
- {
- for (int i = 0; i<size; ++i)
- {
- // Store in temp variables in case src = dst
- float x = (e[0] * src[i].xy.x()) + (e[4] * src[i].xy.y()) + (0) + (e[12]);
- float y = (e[1] * src[i].xy.x()) + (e[5] * src[i].xy.y()) + (0) + (e[13]);
-
- dst[i].xy.set(x, y);
- }
- }
-
- }
+ namespace Math
+ {
+
+ const Matrix Matrix::Identity;
+
+ // | e0 e4 e8 e12 |
+ // | e1 e5 e9 e13 |
+ // | e2 e6 e10 e14 |
+ // | e3 e7 e11 e15 |
+
+ Matrix::Matrix()
+ {
+ setIdentity();
+ }
+
+ Matrix::~Matrix()
+ {
+ }
+
+ void Matrix::setOrtho(float l, float r, float b, float t, float n, float f)
+ {
+ setIdentity();
+ float w = r - l;
+ float h = t - b;
+ float z = f - n;
+ e[0] = 2 / w;
+ e[5] = 2 / h;
+ e[10] = -2 / z;
+ e[12] = -(r + l) / w;
+ e[13] = -(t + b) / h;
+ e[14] = -(f + n) / z;
+ e[15] = 1;
+ }
+
+ // | e0 e4 e8 e12 |
+ // | e1 e5 e9 e13 |
+ // | e2 e6 e10 e14 |
+ // | e3 e7 e11 e15 |
+ // | e0 e4 e8 e12 |
+ // | e1 e5 e9 e13 |
+ // | e2 e6 e10 e14 |
+ // | e3 e7 e11 e15 |
+
+ Matrix Matrix::operator * (const Matrix & m) const
+ {
+ Matrix t;
+
+ t.e[0] = (e[0] * m.e[0]) + (e[4] * m.e[1]) + (e[8] * m.e[2]) + (e[12] * m.e[3]);
+ t.e[4] = (e[0] * m.e[4]) + (e[4] * m.e[5]) + (e[8] * m.e[6]) + (e[12] * m.e[7]);
+ t.e[8] = (e[0] * m.e[8]) + (e[4] * m.e[9]) + (e[8] * m.e[10]) + (e[12] * m.e[11]);
+ t.e[12] = (e[0] * m.e[12]) + (e[4] * m.e[13]) + (e[8] * m.e[14]) + (e[12] * m.e[15]);
+
+ t.e[1] = (e[1] * m.e[0]) + (e[5] * m.e[1]) + (e[9] * m.e[2]) + (e[13] * m.e[3]);
+ t.e[5] = (e[1] * m.e[4]) + (e[5] * m.e[5]) + (e[9] * m.e[6]) + (e[13] * m.e[7]);
+ t.e[9] = (e[1] * m.e[8]) + (e[5] * m.e[9]) + (e[9] * m.e[10]) + (e[13] * m.e[11]);
+ t.e[13] = (e[1] * m.e[12]) + (e[5] * m.e[13]) + (e[9] * m.e[14]) + (e[13] * m.e[15]);
+
+ t.e[2] = (e[2] * m.e[0]) + (e[6] * m.e[1]) + (e[10] * m.e[2]) + (e[14] * m.e[3]);
+ t.e[6] = (e[2] * m.e[4]) + (e[6] * m.e[5]) + (e[10] * m.e[6]) + (e[14] * m.e[7]);
+ t.e[10] = (e[2] * m.e[8]) + (e[6] * m.e[9]) + (e[10] * m.e[10]) + (e[14] * m.e[11]);
+ t.e[14] = (e[2] * m.e[12]) + (e[6] * m.e[13]) + (e[10] * m.e[14]) + (e[14] * m.e[15]);
+
+ t.e[3] = (e[3] * m.e[0]) + (e[7] * m.e[1]) + (e[11] * m.e[2]) + (e[15] * m.e[3]);
+ t.e[7] = (e[3] * m.e[4]) + (e[7] * m.e[5]) + (e[11] * m.e[6]) + (e[15] * m.e[7]);
+ t.e[11] = (e[3] * m.e[8]) + (e[7] * m.e[9]) + (e[11] * m.e[10]) + (e[15] * m.e[11]);
+ t.e[15] = (e[3] * m.e[12]) + (e[7] * m.e[13]) + (e[11] * m.e[14]) + (e[15] * m.e[15]);
+
+ return t;
+ }
+
+ void Matrix::operator *= (const Matrix & m)
+ {
+ Matrix t = (*this) * m;
+ memcpy((void*)this->e, (void*)t.e, sizeof(float) * 16);
+ }
+
+ const float * Matrix::getElements() const
+ {
+ return e;
+ }
+
+ void Matrix::setIdentity()
+ {
+ memset(e, 0, sizeof(float) * 16);
+ e[0] = e[5] = e[10] = e[15] = 1;
+ }
+
+ void Matrix::setTranslation(float x, float y)
+ {
+ setIdentity();
+ e[12] = x;
+ e[13] = y;
+ }
+
+ void Matrix::setRotation(float rad)
+ {
+ setIdentity();
+ float c = cos(rad), s = sin(rad);
+ e[0] = c; e[4] = -s;
+ e[1] = s; e[5] = c;
+ }
+
+ void Matrix::setScale(float sx, float sy)
+ {
+ setIdentity();
+ e[0] = sx;
+ e[5] = sy;
+ }
+
+ void Matrix::setShear(float kx, float ky)
+ {
+ setIdentity();
+ e[1] = ky;
+ e[4] = kx;
+ }
+
+ void Matrix::setTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy)
+ {
+ memset(e, 0, sizeof(float) * 16); // zero out matrix
+ float c = cos(angle), s = sin(angle);
+ // matrix multiplication carried out on paper:
+ // |1 x| |c -s | |sx | |1 -ox|
+ // | 1 y| |s c | | sy | | 1 -oy|
+ // | 1 | | 1 | | 1 | | 1 |
+ // | 1| | 1| | 1| | 1 |
+ // move rotate scale origin
+ e[10] = e[15] = 1.0f;
+ e[0] = c * sx ; // = a
+ e[1] = s * sx ; // = b
+ e[4] = - s * sy; // = c
+ e[5] = c * sy; // = d
+ e[12] = x - ox * e[0] - oy * e[4];
+ e[13] = y - ox * e[1] - oy * e[5];
+ }
+
+ void Matrix::translate(float x, float y)
+ {
+ Matrix t;
+ t.setTranslation(x, y);
+ this->operator *=(t);
+ }
+
+ void Matrix::rotate(float rad)
+ {
+ Matrix t;
+ t.setRotation(rad);
+ this->operator *=(t);
+ }
+
+ void Matrix::scale(float sx, float sy)
+ {
+ Matrix t;
+ t.setScale(sx, sy);
+ this->operator *=(t);
+ }
+
+ void Matrix::shear(float kx, float ky)
+ {
+ Matrix t;
+ t.setShear(kx, ky);
+ this->operator *=(t);
+ }
+
+ // | x |
+ // | y |
+ // | 0 |
+ // | 1 |
+ // | e0 e4 e8 e12 |
+ // | e1 e5 e9 e13 |
+ // | e2 e6 e10 e14 |
+ // | e3 e7 e11 e15 |
+
+ void Matrix::transform(Graphics::Vertex* dst, const Graphics::Vertex* src, int size) const
+ {
+ for (int i = 0; i<size; ++i)
+ {
+ // Store in temp variables in case src = dst
+ float x = (e[0] * src[i].xy.x()) + (e[4] * src[i].xy.y()) + (0) + (e[12]);
+ float y = (e[1] * src[i].xy.x()) + (e[5] * src[i].xy.y()) + (0) + (e[13]);
+
+ dst[i].xy.set(x, y);
+ }
+ }
+
+ }
} \ No newline at end of file
diff --git a/src/libjin/math/matrix.h b/src/libjin/math/matrix.h
index 7955de1..c92a293 100644
--- a/src/libjin/math/matrix.h
+++ b/src/libjin/math/matrix.h
@@ -3,158 +3,158 @@
namespace JinEngine
{
-
- // Forward declarations.
- namespace Graphics
- {
- struct Vertex;
- }
-
- namespace Math
- {
-
- ///
- /// This class is the basis for all transformations in LOVE. Althought not
- /// really needed for 2D, it contains 4x4 elements to be compatible with
- /// OpenGL without conversions.
- /// ҪתõOpenGL
- /// https://blog.csdn.net/candycat1992/article/details/8830894
- ///
- class Matrix
- {
- private:
-
- ///
- /// | e0 e4 e8 e12 |
- /// | e1 e5 e9 e13 |
- /// | e2 e6 e10 e14 |
- /// | e3 e7 e11 e15 |
- ///
- float e[16];
-
- public:
-
- static const Matrix Identity;
-
- ///
- /// Creates a new identity matrix.
- ///
- Matrix();
-
- ///
- /// Destructor.
- ///
- ~Matrix();
-
- void setOrtho(float _left, float _right, float _bottom, float _top, float _near, float _far);
-
- ///
- /// Multiplies this Matrix with another Matrix, changing neither.
- /// @param m The Matrix to multiply with this Matrix.
- /// @return The combined matrix.
- ///
- Matrix operator * (const Matrix & m) const;
-
- ///
- /// Multiplies a Matrix into this Matrix.
- /// @param m The Matrix to combine into this Matrix.
- ///
- void operator *= (const Matrix & m);
-
- ///
- /// Gets a pointer to the 16 array elements.
- /// @return The array elements.
- ///
- const float* getElements() const;
-
- ///
- /// Resets this Matrix to the identity matrix.
- ///
- void setIdentity();
-
- ///
- /// Resets this Matrix to a translation.
- /// @param x Translation along x-axis.
- /// @param y Translation along y-axis.
- ///
- void setTranslation(float x, float y);
-
- ///
- /// Resets this Matrix to a rotation.
- /// @param r The angle in radians.
- ///
- void setRotation(float r);
-
- ///
- /// Resets this Matrix to a scale transformation.
- /// @param sx Scale factor along the x-axis.
- /// @param sy Scale factor along the y-axis.
- ///
- void setScale(float sx, float sy);
-
- ///
- /// Resets this Matrix to a shear transformation.
- /// @param kx Shear along x-axis.
- /// @param ky Shear along y-axis.
- ///
- void setShear(float kx, float ky);
-
- ///
- /// Creates a transformation with a certain position, orientation, scale
- /// and offset. Perfect for Drawables -- what a coincidence!
- ///
- /// @param x The translation along the x-axis.
- /// @param y The translation along the y-axis.
- /// @param angle The rotation (rad) around the center with offset (ox,oy).
- /// @param sx Scale along x-axis.
- /// @param sy Scale along y-axis.
- /// @param ox The offset for rotation along the x-axis.
- /// @param oy The offset for rotation along the y-axis.
- /// @param kx Shear along x-axis
- /// @param ky Shear along y-axis
- ///
- void setTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy);
-
- ///
- /// Multiplies this Matrix with a translation.
- /// @param x Translation along x-axis.
- /// @param y Translation along y-axis.
- ///
- void translate(float x, float y);
-
- ///
- /// Multiplies this Matrix with a rotation.
- /// @param r Angle in radians.
- ///
- void rotate(float r);
-
- ///
- /// Multiplies this Matrix with a scale transformation.
- /// @param sx Scale factor along the x-axis.
- /// @param sy Scale factor along the y-axis.
- ///
- void scale(float sx, float sy);
-
- ///
- /// Multiplies this Matrix with a shear transformation.
- /// @param kx Shear along the x-axis.
- /// @param ky Shear along the y-axis.
- ///
- void shear(float kx, float ky);
-
- ///
- /// Transforms an array of vertices by this Matrix. The sources and
- /// destination arrays may be the same.
- ///
- /// @param dst Storage for the transformed vertices.
- /// @param src The source vertices.
- /// @param size The number of vertices.
- ///
- void transform(Graphics::Vertex* dst, const Graphics::Vertex * src, int size) const;
-
- };
-
- } // namespace Math
+
+ // Forward declarations.
+ namespace Graphics
+ {
+ struct Vertex;
+ }
+
+ namespace Math
+ {
+
+ ///
+ /// This class is the basis for all transformations in LOVE. Althought not
+ /// really needed for 2D, it contains 4x4 elements to be compatible with
+ /// OpenGL without conversions.
+ /// ҪתõOpenGL
+ /// https://blog.csdn.net/candycat1992/article/details/8830894
+ ///
+ class Matrix
+ {
+ private:
+
+ ///
+ /// | e0 e4 e8 e12 |
+ /// | e1 e5 e9 e13 |
+ /// | e2 e6 e10 e14 |
+ /// | e3 e7 e11 e15 |
+ ///
+ float e[16];
+
+ public:
+
+ static const Matrix Identity;
+
+ ///
+ /// Creates a new identity matrix.
+ ///
+ Matrix();
+
+ ///
+ /// Destructor.
+ ///
+ ~Matrix();
+
+ void setOrtho(float _left, float _right, float _bottom, float _top, float _near, float _far);
+
+ ///
+ /// Multiplies this Matrix with another Matrix, changing neither.
+ /// @param m The Matrix to multiply with this Matrix.
+ /// @return The combined matrix.
+ ///
+ Matrix operator * (const Matrix & m) const;
+
+ ///
+ /// Multiplies a Matrix into this Matrix.
+ /// @param m The Matrix to combine into this Matrix.
+ ///
+ void operator *= (const Matrix & m);
+
+ ///
+ /// Gets a pointer to the 16 array elements.
+ /// @return The array elements.
+ ///
+ const float* getElements() const;
+
+ ///
+ /// Resets this Matrix to the identity matrix.
+ ///
+ void setIdentity();
+
+ ///
+ /// Resets this Matrix to a translation.
+ /// @param x Translation along x-axis.
+ /// @param y Translation along y-axis.
+ ///
+ void setTranslation(float x, float y);
+
+ ///
+ /// Resets this Matrix to a rotation.
+ /// @param r The angle in radians.
+ ///
+ void setRotation(float r);
+
+ ///
+ /// Resets this Matrix to a scale transformation.
+ /// @param sx Scale factor along the x-axis.
+ /// @param sy Scale factor along the y-axis.
+ ///
+ void setScale(float sx, float sy);
+
+ ///
+ /// Resets this Matrix to a shear transformation.
+ /// @param kx Shear along x-axis.
+ /// @param ky Shear along y-axis.
+ ///
+ void setShear(float kx, float ky);
+
+ ///
+ /// Creates a transformation with a certain position, orientation, scale
+ /// and offset. Perfect for Drawables -- what a coincidence!
+ ///
+ /// @param x The translation along the x-axis.
+ /// @param y The translation along the y-axis.
+ /// @param angle The rotation (rad) around the center with offset (ox,oy).
+ /// @param sx Scale along x-axis.
+ /// @param sy Scale along y-axis.
+ /// @param ox The offset for rotation along the x-axis.
+ /// @param oy The offset for rotation along the y-axis.
+ /// @param kx Shear along x-axis
+ /// @param ky Shear along y-axis
+ ///
+ void setTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy);
+
+ ///
+ /// Multiplies this Matrix with a translation.
+ /// @param x Translation along x-axis.
+ /// @param y Translation along y-axis.
+ ///
+ void translate(float x, float y);
+
+ ///
+ /// Multiplies this Matrix with a rotation.
+ /// @param r Angle in radians.
+ ///
+ void rotate(float r);
+
+ ///
+ /// Multiplies this Matrix with a scale transformation.
+ /// @param sx Scale factor along the x-axis.
+ /// @param sy Scale factor along the y-axis.
+ ///
+ void scale(float sx, float sy);
+
+ ///
+ /// Multiplies this Matrix with a shear transformation.
+ /// @param kx Shear along the x-axis.
+ /// @param ky Shear along the y-axis.
+ ///
+ void shear(float kx, float ky);
+
+ ///
+ /// Transforms an array of vertices by this Matrix. The sources and
+ /// destination arrays may be the same.
+ ///
+ /// @param dst Storage for the transformed vertices.
+ /// @param src The source vertices.
+ /// @param size The number of vertices.
+ ///
+ void transform(Graphics::Vertex* dst, const Graphics::Vertex * src, int size) const;
+
+ };
+
+ } // namespace Math
} // namespace JinEngine
#endif // __JE_MATRIX_H__
diff --git a/src/libjin/math/percentage.h b/src/libjin/math/percentage.h
index a9fdc4e..41b311a 100644
--- a/src/libjin/math/percentage.h
+++ b/src/libjin/math/percentage.h
@@ -5,32 +5,32 @@
namespace JinEngine
{
- namespace Math
- {
+ namespace Math
+ {
- class Percentage
- {
- public:
- Percentage(float v)
- {
- value = clamp<float>(v, 0, 1);
- }
+ class Percentage
+ {
+ public:
+ Percentage(float v)
+ {
+ value = clamp<float>(v, 0, 1);
+ }
- Percentage(const Percentage& p)
- {
- value = p.value;
- }
+ Percentage(const Percentage& p)
+ {
+ value = p.value;
+ }
- void operator = (const Percentage& p)
- {
- value = p.value;
- }
+ void operator = (const Percentage& p)
+ {
+ value = p.value;
+ }
- float value;
+ float value;
- };
+ };
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin/math/quad.h b/src/libjin/math/quad.h
index 5bda125..4c4246e 100644
--- a/src/libjin/math/quad.h
+++ b/src/libjin/math/quad.h
@@ -3,29 +3,29 @@
namespace JinEngine
{
- namespace Math
- {
+ namespace Math
+ {
- ///
- ///
- ///
- struct Quad
- {
- Quad()
- : x(0), y(0), w(0), h(0)
- {
- }
+ ///
+ ///
+ ///
+ struct Quad
+ {
+ Quad()
+ : x(0), y(0), w(0), h(0)
+ {
+ }
- Quad(float _x, float _y, float _w, float _h)
- : x(_x), y(_y), w(_w), h(_h)
- {
- }
+ Quad(float _x, float _y, float _w, float _h)
+ : x(_x), y(_y), w(_w), h(_h)
+ {
+ }
- float x, y, w, h;
+ float x, y, w, h;
- };
+ };
- } // namespace Math
+ } // namespace Math
} // namespace JinEngine
#endif // __JE_QUAD_H__ \ No newline at end of file
diff --git a/src/libjin/math/random.cpp b/src/libjin/math/random.cpp
index 5f3b28c..288f6c8 100644
--- a/src/libjin/math/random.cpp
+++ b/src/libjin/math/random.cpp
@@ -4,51 +4,51 @@
namespace JinEngine
{
- namespace Math
- {
-
- RandomGenerator::RandomGenerator(uint32 seed)
- : mSeed(seed)
- {
- }
-
- uint32 RandomGenerator::rand()
- {
- unsigned int next = mSeed;
- uint32 result;
-
- next *= 1103515245;
- next += 12345;
- result = (unsigned int)(next / 65536) % 2048;
-
- next *= 1103515245;
- next += 12345;
- result <<= 10;
- result ^= (unsigned int)(next / 65536) % 1024;
-
- next *= 1103515245;
- next += 12345;
- result <<= 10;
- result ^= (unsigned int)(next / 65536) % 1024;
-
- mSeed = next;
-
- return result;
- }
-
- uint32 RandomGenerator::rand(uint32 min, uint32 max)
- {
- uint32 n = rand();
- return n % (max - min + 1) + min;
- }
-
- float RandomGenerator::randf(float min, float max, int ac)
- {
- float floor = 0, ceil = max + reverse<float>(min);
- uint32 a = pow(10.f, ac);
- uint32 n = rand(floor*a, ceil*a);
- return (float)n / a + min;
- }
-
- }
+ namespace Math
+ {
+
+ RandomGenerator::RandomGenerator(uint32 seed)
+ : mSeed(seed)
+ {
+ }
+
+ uint32 RandomGenerator::rand()
+ {
+ unsigned int next = mSeed;
+ uint32 result;
+
+ next *= 1103515245;
+ next += 12345;
+ result = (unsigned int)(next / 65536) % 2048;
+
+ next *= 1103515245;
+ next += 12345;
+ result <<= 10;
+ result ^= (unsigned int)(next / 65536) % 1024;
+
+ next *= 1103515245;
+ next += 12345;
+ result <<= 10;
+ result ^= (unsigned int)(next / 65536) % 1024;
+
+ mSeed = next;
+
+ return result;
+ }
+
+ uint32 RandomGenerator::rand(uint32 min, uint32 max)
+ {
+ uint32 n = rand();
+ return n % (max - min + 1) + min;
+ }
+
+ float RandomGenerator::randf(float min, float max, int ac)
+ {
+ float floor = 0, ceil = max + reverse<float>(min);
+ uint32 a = pow(10.f, ac);
+ uint32 n = rand(floor*a, ceil*a);
+ return (float)n / a + min;
+ }
+
+ }
} \ No newline at end of file
diff --git a/src/libjin/math/random.h b/src/libjin/math/random.h
index 1eb22c4..f2fbe22 100644
--- a/src/libjin/math/random.h
+++ b/src/libjin/math/random.h
@@ -5,29 +5,29 @@
namespace JinEngine
{
- namespace Math
- {
+ namespace Math
+ {
- ///
- /// A random number generator.
- ///
- class RandomGenerator
- {
- public:
- RandomGenerator(uint32 seed);
+ ///
+ /// A random number generator.
+ ///
+ class RandomGenerator
+ {
+ public:
+ RandomGenerator(uint32 seed);
- uint32 rand();
+ uint32 rand();
- uint32 rand(uint32 min, uint32 max);
+ uint32 rand(uint32 min, uint32 max);
- float randf(float min, float max, int ac);
+ float randf(float min, float max, int ac);
- private:
- uint32 mSeed;
+ private:
+ uint32 mSeed;
- };
+ };
- } // namespace Math
+ } // namespace Math
} // namespace JinEngine
#endif \ No newline at end of file
diff --git a/src/libjin/math/ranged_value.cpp b/src/libjin/math/ranged_value.cpp
index 1a14467..1c8b2ff 100644
--- a/src/libjin/math/ranged_value.cpp
+++ b/src/libjin/math/ranged_value.cpp
@@ -2,70 +2,70 @@
namespace JinEngine
{
- namespace Math
- {
+ namespace Math
+ {
- RangedValue::RangedValue()
- : mCount(0)
- {
- }
+ RangedValue::RangedValue()
+ : mCount(0)
+ {
+ }
- RangedValue::RangedValue(float* points, uint n)
- : mCount(n)
- {
- for (uint i = 0; i < n; ++i)
- {
- float x = points[2*i];
- float y = points[2*i + 1];
- mXAxis.push_back(x);
- mYAxis.push_back(y);
- }
- }
+ RangedValue::RangedValue(float* points, uint n)
+ : mCount(n)
+ {
+ for (uint i = 0; i < n; ++i)
+ {
+ float x = points[2*i];
+ float y = points[2*i + 1];
+ mXAxis.push_back(x);
+ mYAxis.push_back(y);
+ }
+ }
- void RangedValue::addPoint(float x, float y)
- {
- mXAxis.push_back(x);
- mYAxis.push_back(y);
- ++mCount;
- }
+ void RangedValue::addPoint(float x, float y)
+ {
+ mXAxis.push_back(x);
+ mYAxis.push_back(y);
+ ++mCount;
+ }
- void RangedValue::removePoint(uint i)
- {
- mXAxis.erase(mXAxis.begin() + i);
- mYAxis.erase(mYAxis.begin() + i);
- --mCount;
- }
+ void RangedValue::removePoint(uint i)
+ {
+ mXAxis.erase(mXAxis.begin() + i);
+ mYAxis.erase(mYAxis.begin() + i);
+ --mCount;
+ }
- void RangedValue::insertPoint(uint i, float x, float y)
- {
- mXAxis.insert(mXAxis.begin() + i, x);
- mYAxis.insert(mYAxis.begin() + i, y);
- ++mCount;
- }
+ void RangedValue::insertPoint(uint i, float x, float y)
+ {
+ mXAxis.insert(mXAxis.begin() + i, x);
+ mYAxis.insert(mYAxis.begin() + i, y);
+ ++mCount;
+ }
- float RangedValue::getValue(float x)
- {
- int endIndex = -1;
- int n = mCount;
- for (int i = 1; i < n; i++) {
- float t = mXAxis[i];
- if (t > x) {
- endIndex = i;
- break;
- }
- }
- if (endIndex == -1) return mYAxis[n - 1];
- int startIndex = endIndex - 1;
- float startValue = mYAxis[startIndex];
- float startX = mXAxis[startIndex];
- return startValue + (mYAxis[endIndex] - startValue) * ((x - startX) / (mXAxis[endIndex] - startX));
- }
+ float RangedValue::getValue(float x)
+ {
+ int endIndex = -1;
+ int n = mCount;
+ for (int i = 1; i < n; i++) {
+ float t = mXAxis[i];
+ if (t > x) {
+ endIndex = i;
+ break;
+ }
+ }
+ if (endIndex == -1) return mYAxis[n - 1];
+ int startIndex = endIndex - 1;
+ float startValue = mYAxis[startIndex];
+ float startX = mXAxis[startIndex];
+ return startValue + (mYAxis[endIndex] - startValue) * ((x - startX) / (mXAxis[endIndex] - startX));
+ }
- void RangedValue::clear()
- {
- mXAxis.clear();
- mYAxis.clear();
- }
+ void RangedValue::clear()
+ {
+ mXAxis.clear();
+ mYAxis.clear();
+ }
- }
+ }
} \ No newline at end of file
diff --git a/src/libjin/math/ranged_value.h b/src/libjin/math/ranged_value.h
index 5a4c35d..abcca29 100644
--- a/src/libjin/math/ranged_value.h
+++ b/src/libjin/math/ranged_value.h
@@ -7,51 +7,51 @@
namespace JinEngine
{
- namespace Math
- {
- /*
- * y ^
- * |-------- _
- * | \ / \
- * | --- \
- * | \
- * | \
- * +----------------------> x
- */
- class RangedValue
- {
- public:
- RangedValue();
+ namespace Math
+ {
+ /*
+ * y ^
+ * |-------- _
+ * | \ / \
+ * | --- \
+ * | \
+ * | \
+ * +----------------------> x
+ */
+ class RangedValue
+ {
+ public:
+ RangedValue();
- ///
- /// Points of ranged value.
- ///
- /// @param points Points.
- /// @param n Number of points.
- ///
- RangedValue(float* points, uint n);
+ ///
+ /// Points of ranged value.
+ ///
+ /// @param points Points.
+ /// @param n Number of points.
+ ///
+ RangedValue(float* points, uint n);
- virtual ~RangedValue() {}
+ virtual ~RangedValue() {}
- virtual void addPoint(float x, float y);
+ virtual void addPoint(float x, float y);
- virtual void removePoint(uint i);
+ virtual void removePoint(uint i);
- virtual void insertPoint(uint i, float x, float y);
+ virtual void insertPoint(uint i, float x, float y);
- virtual float getValue(float x);
+ virtual float getValue(float x);
- virtual void clear();
+ virtual void clear();
- private:
- std::vector<float> mXAxis;
- std::vector<float> mYAxis;
+ private:
+ std::vector<float> mXAxis;
+ std::vector<float> mYAxis;
- uint mCount;
+ uint mCount;
- };
+ };
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin/math/transform.cpp b/src/libjin/math/transform.cpp
index 84c8327..71e83e5 100644
--- a/src/libjin/math/transform.cpp
+++ b/src/libjin/math/transform.cpp
@@ -2,103 +2,103 @@
namespace JinEngine
{
- namespace Math
- {
-
- Transform::Transform()
- : mScale(1, 1)
- , mPosition(0, 0)
- , mOrigin(0, 0)
- , mRotation(0)
- {
- }
-
- Transform::Transform(float x, float y, float sx, float sy, float r, float ox, float oy)
- {
- set(x, y, sx, sy, r, ox, oy);
- }
-
- void Transform::set(float x, float y, float sx, float sy, float r, float ox, float oy)
- {
- setPosition(x, y);
- setScale(sx, sy);
- setRotation(r);
- setOrigin(ox, oy);
- }
-
- void Transform::setScale(float sx, float sy)
- {
- mScale.set(sx, sy);
- }
-
- Vector2<float> Transform::getScale() const
- {
- return mScale;
- }
-
- void Transform::scale(float sx, float sy)
- {
- mScale.x() *= sx;
- mScale.y() *= sy;
- }
-
- void Transform::setPosition(const Vector2<float>& p)
- {
- setPosition(p.x(), p.y());
- }
-
- void Transform::setPosition(float x, float y)
- {
- mPosition.set(x, y);
- }
-
- Vector2<float> Transform::getPosition() const
- {
- return mPosition;
- }
-
- void Transform::move(float x, float y)
- {
- mPosition.x() += x;
- mPosition.y() += y;
- }
-
- void Transform::move(const Vector2<float>& v)
- {
- move(v.x(), v.y());
- }
-
- void Transform::setOrigin(float x, float y)
- {
- mOrigin.set(x, y);
- }
-
- Vector2<float> Transform::getOrigin() const
- {
- return mOrigin;
- }
-
- void Transform::setRotation(float r)
- {
- mRotation = r;
- }
-
- float Transform::getRotation() const
- {
- return mRotation;
- }
-
- void Transform::rotate(float r)
- {
- mRotation += r;
- }
-
- Matrix Transform::getMatrix() const
- {
- Matrix m;
- m.setTransformation(mPosition.x(), mPosition.y(), mRotation, mScale.x(), mScale.y(), mOrigin.x(), mOrigin.y());
- return m;
- }
-
- }
+ namespace Math
+ {
+
+ Transform::Transform()
+ : mScale(1, 1)
+ , mPosition(0, 0)
+ , mOrigin(0, 0)
+ , mRotation(0)
+ {
+ }
+
+ Transform::Transform(float x, float y, float sx, float sy, float r, float ox, float oy)
+ {
+ set(x, y, sx, sy, r, ox, oy);
+ }
+
+ void Transform::set(float x, float y, float sx, float sy, float r, float ox, float oy)
+ {
+ setPosition(x, y);
+ setScale(sx, sy);
+ setRotation(r);
+ setOrigin(ox, oy);
+ }
+
+ void Transform::setScale(float sx, float sy)
+ {
+ mScale.set(sx, sy);
+ }
+
+ Vector2<float> Transform::getScale() const
+ {
+ return mScale;
+ }
+
+ void Transform::scale(float sx, float sy)
+ {
+ mScale.x() *= sx;
+ mScale.y() *= sy;
+ }
+
+ void Transform::setPosition(const Vector2<float>& p)
+ {
+ setPosition(p.x(), p.y());
+ }
+
+ void Transform::setPosition(float x, float y)
+ {
+ mPosition.set(x, y);
+ }
+
+ Vector2<float> Transform::getPosition() const
+ {
+ return mPosition;
+ }
+
+ void Transform::move(float x, float y)
+ {
+ mPosition.x() += x;
+ mPosition.y() += y;
+ }
+
+ void Transform::move(const Vector2<float>& v)
+ {
+ move(v.x(), v.y());
+ }
+
+ void Transform::setOrigin(float x, float y)
+ {
+ mOrigin.set(x, y);
+ }
+
+ Vector2<float> Transform::getOrigin() const
+ {
+ return mOrigin;
+ }
+
+ void Transform::setRotation(float r)
+ {
+ mRotation = r;
+ }
+
+ float Transform::getRotation() const
+ {
+ return mRotation;
+ }
+
+ void Transform::rotate(float r)
+ {
+ mRotation += r;
+ }
+
+ Matrix Transform::getMatrix() const
+ {
+ Matrix m;
+ m.setTransformation(mPosition.x(), mPosition.y(), mRotation, mScale.x(), mScale.y(), mOrigin.x(), mOrigin.y());
+ return m;
+ }
+
+ }
} \ No newline at end of file
diff --git a/src/libjin/math/transform.h b/src/libjin/math/transform.h
index 3f3c199..0a0fa0a 100644
--- a/src/libjin/math/transform.h
+++ b/src/libjin/math/transform.h
@@ -6,45 +6,45 @@
namespace JinEngine
{
- namespace Math
- {
+ namespace Math
+ {
- class Transform
- {
- public:
- Transform();
- Transform(float x, float y, float sx, float sy, float r, float ox, float oy);
+ class Transform
+ {
+ public:
+ Transform();
+ Transform(float x, float y, float sx, float sy, float r, float ox, float oy);
- void set(float x, float y, float sx, float sy, float r, float ox, float oy);
+ void set(float x, float y, float sx, float sy, float r, float ox, float oy);
- void setScale(float sx, float sy);
- Vector2<float> getScale() const;
- void scale(float sx, float sy);
+ void setScale(float sx, float sy);
+ Vector2<float> getScale() const;
+ void scale(float sx, float sy);
- void setPosition(float x, float y);
- void setPosition(const Vector2<float>& p);
- Vector2<float> getPosition() const;
- void move(float x, float y);
- void move(const Vector2<float>& v);
+ void setPosition(float x, float y);
+ void setPosition(const Vector2<float>& p);
+ Vector2<float> getPosition() const;
+ void move(float x, float y);
+ void move(const Vector2<float>& v);
- void setOrigin(float x, float y);
- Vector2<float> getOrigin() const;
+ void setOrigin(float x, float y);
+ Vector2<float> getOrigin() const;
- void setRotation(float r);
- float getRotation() const;
- void rotate(float r);
+ void setRotation(float r);
+ float getRotation() const;
+ void rotate(float r);
- Matrix getMatrix() const;
+ Matrix getMatrix() const;
- private:
- Vector2<float> mPosition;
- Vector2<float> mOrigin;
- Vector2<float> mScale;
- float mRotation;
+ private:
+ Vector2<float> mPosition;
+ Vector2<float> mOrigin;
+ Vector2<float> mScale;
+ float mRotation;
- };
+ };
- }
+ }
}
#endif \ No newline at end of file
diff --git a/src/libjin/math/vector2.hpp b/src/libjin/math/vector2.hpp
index 6115a63..b61205b 100644
--- a/src/libjin/math/vector2.hpp
+++ b/src/libjin/math/vector2.hpp
@@ -3,80 +3,80 @@
namespace JinEngine
{
- namespace Math
- {
+ namespace Math
+ {
- template<typename T>
- class Vector2
- {
- public:
- Vector2()
- {
- data[0] = data[1] = 0;
- }
- Vector2(T _x, T _y)
- {
- data[0] = _x;
- data[1] = _y;
- }
- Vector2(const Vector2<T>& v)
- {
- data[0] = v.data[0];
- data[1] = v.data[1];
- }
+ template<typename T>
+ class Vector2
+ {
+ public:
+ Vector2()
+ {
+ data[0] = data[1] = 0;
+ }
+ Vector2(T _x, T _y)
+ {
+ data[0] = _x;
+ data[1] = _y;
+ }
+ Vector2(const Vector2<T>& v)
+ {
+ data[0] = v.data[0];
+ data[1] = v.data[1];
+ }
- void operator = (const Vector2<T>& v)
- {
- data[0] = v.data[0];
- data[1] = v.data[1];
- }
+ void operator = (const Vector2<T>& v)
+ {
+ data[0] = v.data[0];
+ data[1] = v.data[1];
+ }
- Vector2<T> operator * (float n)
- {
- return Vector2<T>(data[0]*n, data[1]*n);
- }
+ Vector2<T> operator * (float n)
+ {
+ return Vector2<T>(data[0]*n, data[1]*n);
+ }
- void operator +=(const Vector2<T> v)
- {
- data[0] += v.data[0];
- data[1] += v.data[1];
- }
+ void operator +=(const Vector2<T> v)
+ {
+ data[0] += v.data[0];
+ data[1] += v.data[1];
+ }
- Vector2<T> operator +(const Vector2<T>& v)
- {
- return Vector2<T>(data[0] + v.data[0], data[1] + v.data[1]);
- }
+ Vector2<T> operator +(const Vector2<T>& v)
+ {
+ return Vector2<T>(data[0] + v.data[0], data[1] + v.data[1]);
+ }
- void set(T _x, T _y)
- {
- data[0] = _x;
- data[1] = _y;
- }
+ void set(T _x, T _y)
+ {
+ data[0] = _x;
+ data[1] = _y;
+ }
- bool isZero()
- {
- return data[0] == 0 && data[1] == 0;
- }
+ bool isZero()
+ {
+ return data[0] == 0 && data[1] == 0;
+ }
- #define _aliases(A, B) \
- inline T& A() { return data[0]; }\
- inline T& B() { return data[1]; }\
- inline T A() const { return data[0]; }\
- inline T B() const { return data[1]; }
+ #define _aliases(A, B) \
+ inline T& A() { return data[0]; }\
+ inline T& B() { return data[1]; }\
+ inline T A() const { return data[0]; }\
+ inline T B() const { return data[1]; }
- _aliases(x, y);
- _aliases(w, h);
- _aliases(u, v);
- _aliases(colum, row);
+ _aliases(x, y);
+ _aliases(w, h);
+ _aliases(u, v);
+ _aliases(colum, row);
- #undef _aliases
+ #undef _aliases
- private:
- T data[2];
+ private:
+ T data[2];
- };
+ };
- } // namespace Math
+ } // namespace Math
} // namespace JinEngine
#endif \ No newline at end of file
diff --git a/src/libjin/math/vector3.hpp b/src/libjin/math/vector3.hpp
index 3c800b6..85babf5 100644
--- a/src/libjin/math/vector3.hpp
+++ b/src/libjin/math/vector3.hpp
@@ -3,49 +3,49 @@
namespace JinEngine
{
- namespace Math
- {
-
- template<typename T>
- class Vector3
- {
- public:
- Vector3()
- {
- data[0] = data[1] = data[2] = 0;
- }
- Vector3(T _x, T _y, T _z)
- {
- data[0] = _x;
- data[1] = _y;
- data[2] = _z;
- }
- Vector3(const Vector3<T>& v)
- {
- data[0] = v.data[0];
- data[1] = v.data[1];
- data[2] = v.data[2];
- }
-
- #define _aliases(A, B, C) \
- inline T& A() { return data[0]; }\
- inline T& B() { return data[1]; }\
- inline T& C() { return data[2]; }\
- inline T A() const { return data[0]; }\
- inline T B() const { return data[1]; }\
- inline T C() const { return data[2]; }
-
- _aliases(x, y, z);
- _aliases(r, g, b);
-
- #undef _aliases
-
- private:
- T data[3];
-
- };
-
- } // namespace Math
+ namespace Math
+ {
+
+ template<typename T>
+ class Vector3
+ {
+ public:
+ Vector3()
+ {
+ data[0] = data[1] = data[2] = 0;
+ }
+ Vector3(T _x, T _y, T _z)
+ {
+ data[0] = _x;
+ data[1] = _y;
+ data[2] = _z;
+ }
+ Vector3(const Vector3<T>& v)
+ {
+ data[0] = v.data[0];
+ data[1] = v.data[1];
+ data[2] = v.data[2];
+ }
+
+ #define _aliases(A, B, C) \
+ inline T& A() { return data[0]; }\
+ inline T& B() { return data[1]; }\
+ inline T& C() { return data[2]; }\
+ inline T A() const { return data[0]; }\
+ inline T B() const { return data[1]; }\
+ inline T C() const { return data[2]; }
+
+ _aliases(x, y, z);
+ _aliases(r, g, b);
+
+ #undef _aliases
+
+ private:
+ T data[3];
+
+ };
+
+ } // namespace Math
} // namespace JinEngine
#endif \ No newline at end of file
diff --git a/src/libjin/math/vector4.hpp b/src/libjin/math/vector4.hpp
index b544126..01a2309 100644
--- a/src/libjin/math/vector4.hpp
+++ b/src/libjin/math/vector4.hpp
@@ -3,55 +3,55 @@
namespace JinEngine
{
- namespace Math
- {
-
- template<typename T>
- class Vector4
- {
- public:
- Vector4()
- {
- data[0] = data[1] = data[2] = data[3] = 0;
- }
- Vector4(T _x, T _y, T _z, T _t)
- {
- data[0] = _x;
- data[1] = _y;
- data[2] = _z;
- data[3] = _t;
- }
- Vector4(const Vector4<T>& v)
- {
- data[0] = v.data[0];
- data[1] = v.data[1];
- data[2] = v.data[2];
- data[3] = v.data[3];
- }
-
- #define _aliases(A, B, C, D) \
- inline T& A() { return data[0]; } \
- inline T& B() { return data[1]; } \
- inline T& C() { return data[2]; } \
- inline T& D() { return data[3]; } \
- inline T A() const { return data[0]; } \
- inline T B() const { return data[1]; } \
- inline T C() const { return data[2]; } \
- inline T D() const { return data[3]; }
-
- _aliases(x, y, z, t);
- _aliases(x1, y1, w, h);
- _aliases(r, g, b, a);
- _aliases(left, right, top, bottom);
-
- #undef _aliases
-
- private:
- T data[4];
-
- };
-
- } // namespace Math
+ namespace Math
+ {
+
+ template<typename T>
+ class Vector4
+ {
+ public:
+ Vector4()
+ {
+ data[0] = data[1] = data[2] = data[3] = 0;
+ }
+ Vector4(T _x, T _y, T _z, T _t)
+ {
+ data[0] = _x;
+ data[1] = _y;
+ data[2] = _z;
+ data[3] = _t;
+ }
+ Vector4(const Vector4<T>& v)
+ {
+ data[0] = v.data[0];
+ data[1] = v.data[1];
+ data[2] = v.data[2];
+ data[3] = v.data[3];
+ }
+
+ #define _aliases(A, B, C, D) \
+ inline T& A() { return data[0]; } \
+ inline T& B() { return data[1]; } \
+ inline T& C() { return data[2]; } \
+ inline T& D() { return data[3]; } \
+ inline T A() const { return data[0]; } \
+ inline T B() const { return data[1]; } \
+ inline T C() const { return data[2]; } \
+ inline T D() const { return data[3]; }
+
+ _aliases(x, y, z, t);
+ _aliases(x1, y1, w, h);
+ _aliases(r, g, b, a);
+ _aliases(left, right, top, bottom);
+
+ #undef _aliases
+
+ private:
+ T data[4];
+
+ };
+
+ } // namespace Math
} // namespace JinEngine
#endif \ No newline at end of file