diff options
Diffstat (limited to 'src/libjin/math')
-rw-r--r-- | src/libjin/math/je_math.h | 98 | ||||
-rw-r--r-- | src/libjin/math/je_matrix.cpp | 372 | ||||
-rw-r--r-- | src/libjin/math/je_matrix.h | 300 | ||||
-rw-r--r-- | src/libjin/math/je_quad.h | 14 | ||||
-rw-r--r-- | src/libjin/math/je_vector2.hpp | 54 | ||||
-rw-r--r-- | src/libjin/math/je_vector3.hpp | 56 | ||||
-rw-r--r-- | src/libjin/math/je_vector4.hpp | 64 |
7 files changed, 479 insertions, 479 deletions
diff --git a/src/libjin/math/je_math.h b/src/libjin/math/je_math.h index ed46e58..f0a0a4c 100644 --- a/src/libjin/math/je_math.h +++ b/src/libjin/math/je_math.h @@ -7,63 +7,63 @@ namespace JinEngine { - namespace Math - { + namespace Math + { - #ifdef min - #undef min - #endif // min - #ifdef max - #undef max - #endif // max + #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 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 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 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 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 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 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; - } + template<typename T> + inline T upperBound(T a, T upper) + { + return a > upper ? upper : a; + } - template<typename T> - inline T lerp(T a, T b, float t) - { - return a + t * (b - a); - } + template<typename T> + inline T lerp(T a, T b, float t) + { + return a + t * (b - a); + } inline float lerp(float a, float b, float f) { @@ -83,7 +83,7 @@ namespace JinEngine return -a; } - } // namespace Math + } // namespace Math } // namespace JinEngine #endif // __JE_UTILS_MATH_H__
\ No newline at end of file diff --git a/src/libjin/math/je_matrix.cpp b/src/libjin/math/je_matrix.cpp index bc1fcea..f51ef5d 100644 --- a/src/libjin/math/je_matrix.cpp +++ b/src/libjin/math/je_matrix.cpp @@ -5,190 +5,190 @@ 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(vertex * dst, const 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].x) + (e[4] * src[i].y) + (0) + (e[12]); - float y = (e[1] * src[i].x) + (e[5] * src[i].y) + (0) + (e[13]); - - dst[i].x = x; - dst[i].y = y; - } - } - - } // namespace Math + 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(vertex * dst, const 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].x) + (e[4] * src[i].y) + (0) + (e[12]); + float y = (e[1] * src[i].x) + (e[5] * src[i].y) + (0) + (e[13]); + + dst[i].x = x; + dst[i].y = y; + } + } + + } // namespace Math } // namespace JinEngine
\ No newline at end of file diff --git a/src/libjin/math/je_matrix.h b/src/libjin/math/je_matrix.h index bbc831d..f35b88b 100644 --- a/src/libjin/math/je_matrix.h +++ b/src/libjin/math/je_matrix.h @@ -3,157 +3,157 @@ namespace JinEngine { - namespace Math - { - - struct vertex - { - unsigned char r, g, b, a; - float x, y; - float s, t; - }; - /// - /// 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. - /// Ҫתõľ - /// 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(); - - /// + namespace Math + { + + struct vertex + { + unsigned char r, g, b, a; + float x, y; + float s, t; + }; + /// + /// 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. + /// Ҫתõľ + /// 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(vertex * dst, const vertex * src, int size) const; - - }; - - } // namespace Math + /// + ~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(vertex * dst, const vertex * src, int size) const; + + }; + + } // namespace Math } // namespace JinEngine #endif // __JE_MATRIX_H__ diff --git a/src/libjin/math/je_quad.h b/src/libjin/math/je_quad.h index b07b5f6..e62f370 100644 --- a/src/libjin/math/je_quad.h +++ b/src/libjin/math/je_quad.h @@ -3,14 +3,14 @@ namespace JinEngine { - namespace Math - { + namespace Math + { /// /// /// - struct Quad - { + struct Quad + { Quad() : x(0), y(0), w(0), h(0) { @@ -21,10 +21,10 @@ namespace JinEngine { } - 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/je_vector2.hpp b/src/libjin/math/je_vector2.hpp index 406b756..4d76987 100644 --- a/src/libjin/math/je_vector2.hpp +++ b/src/libjin/math/je_vector2.hpp @@ -3,27 +3,27 @@ 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) { @@ -58,16 +58,16 @@ namespace JinEngine return data[0] == 0 && data[1] == 0; } - T &x = data[0], &y = data[1]; // xy - T &w = data[0], &h = data[1]; // wh - T &colum = data[0], &row = data[1]; // colum row + T &x = data[0], &y = data[1]; // xy + T &w = data[0], &h = data[1]; // wh + T &colum = data[0], &row = data[1]; // colum row - 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/je_vector3.hpp b/src/libjin/math/je_vector3.hpp index fdab2d0..1e8f86d 100644 --- a/src/libjin/math/je_vector3.hpp +++ b/src/libjin/math/je_vector3.hpp @@ -3,39 +3,39 @@ namespace JinEngine { - 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]; - } + 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]; + } - T &x = data[0], &y = data[1], &z = data[2]; // xyz - T &r = data[0], &g = data[1], &b = data[2]; // rgb + T &x = data[0], &y = data[1], &z = data[2]; // xyz + T &r = data[0], &g = data[1], &b = data[2]; // rgb - private: - T data[3]; + private: + T data[3]; - }; + }; - } // namespace Math + } // namespace Math } // namespace JinEngine #endif
\ No newline at end of file diff --git a/src/libjin/math/je_vector4.hpp b/src/libjin/math/je_vector4.hpp index 5cd5b35..02675dd 100644 --- a/src/libjin/math/je_vector4.hpp +++ b/src/libjin/math/je_vector4.hpp @@ -3,43 +3,43 @@ namespace JinEngine { - 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]; - } + 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]; + } - T &x = data[0], &y = data[1], &z = data[2], &t = data[3]; // xyzt - T &w = data[2], &h = data[3]; // xywh - T &r = data[0], &g = data[1], &b = data[2], &a = data[3]; // rgb - T &left = data[0], &right = data[1], &top = data[2], &bottom = data[3]; // lrtb + T &x = data[0], &y = data[1], &z = data[2], &t = data[3]; // xyzt + T &w = data[2], &h = data[3]; // xywh + T &r = data[0], &g = data[1], &b = data[2], &a = data[3]; // rgb + T &left = data[0], &right = data[1], &top = data[2], &bottom = data[3]; // lrtb - private: - T data[4]; + private: + T data[4]; - }; + }; - } // namespace Math + } // namespace Math } // namespace JinEngine #endif
\ No newline at end of file |