diff options
author | chai <chaifix@163.com> | 2020-02-11 11:29:07 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2020-02-11 11:29:07 +0800 |
commit | 160e1299ef3d95f8e8c48706d7f61dd3dc6c6b60 (patch) | |
tree | abe5ae5242d9cc6caf6edf103e662c44e978fca0 /src/libjin/math/matrix.h | |
parent | e095043485d1d298571af6d9eca7f0db9009ea7a (diff) |
Diffstat (limited to 'src/libjin/math/matrix.h')
-rw-r--r-- | src/libjin/math/matrix.h | 304 |
1 files changed, 152 insertions, 152 deletions
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__ |