1 ////////////////////////////////////////////////////////////
\r
3 // SFML - Simple and Fast Multimedia Library
\r
4 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
\r
6 // This software is provided 'as-is', without any express or implied warranty.
\r
7 // In no event will the authors be held liable for any damages arising from the use of this software.
\r
9 // Permission is granted to anyone to use this software for any purpose,
\r
10 // including commercial applications, and to alter it and redistribute it freely,
\r
11 // subject to the following restrictions:
\r
13 // 1. The origin of this software must not be misrepresented;
\r
14 // you must not claim that you wrote the original software.
\r
15 // If you use this software in a product, an acknowledgment
\r
16 // in the product documentation would be appreciated but is not required.
\r
18 // 2. Altered source versions must be plainly marked as such,
\r
19 // and must not be misrepresented as being the original software.
\r
21 // 3. This notice may not be removed or altered from any source distribution.
\r
23 ////////////////////////////////////////////////////////////
\r
25 #ifndef SFML_MATRIX3_HPP
\r
26 #define SFML_MATRIX3_HPP
\r
28 ////////////////////////////////////////////////////////////
\r
30 ////////////////////////////////////////////////////////////
\r
31 #include <SFML/Config.hpp>
\r
32 #include <SFML/System/Vector2.hpp>
\r
38 ////////////////////////////////////////////////////////////
\r
39 /// Utility class to manipulate 3x3 matrices representing
\r
40 /// 2D transformations
\r
41 ////////////////////////////////////////////////////////////
\r
42 class SFML_API Matrix3
\r
46 ////////////////////////////////////////////////////////////
\r
47 /// Default constructor (builds an identity matrix)
\r
49 ////////////////////////////////////////////////////////////
\r
52 ////////////////////////////////////////////////////////////
\r
53 /// Construct a matrix from its 9 elements
\r
55 ////////////////////////////////////////////////////////////
\r
56 Matrix3(float a00, float a01, float a02,
\r
57 float a10, float a11, float a12,
\r
58 float a20, float a21, float a22);
\r
60 ////////////////////////////////////////////////////////////
\r
61 /// Build a matrix from a set of transformations
\r
63 /// \param Center : Origin for the transformations
\r
64 /// \param Translation : Translation offset
\r
65 /// \param Rotation : Rotation angle in degrees
\r
66 /// \param Scale : Scaling factors
\r
68 ////////////////////////////////////////////////////////////
\r
69 void SetFromTransformations(const Vector2f& Center, const Vector2f& Translation, float Rotation, const Vector2f& Scale);
\r
71 ////////////////////////////////////////////////////////////
\r
72 /// Transform a point by the matrix
\r
74 /// \param Point : Point to transform
\r
76 /// \return Transformed point
\r
78 ////////////////////////////////////////////////////////////
\r
79 Vector2f Transform(const Vector2f& Point) const;
\r
81 ////////////////////////////////////////////////////////////
\r
82 /// Return the inverse of the matrix
\r
84 /// \return A new matrix which is the inverse of this
\r
86 ////////////////////////////////////////////////////////////
\r
87 Matrix3 GetInverse() const;
\r
89 ////////////////////////////////////////////////////////////
\r
90 /// Return the elements of the matrix as a 4x4,
\r
91 /// in an array of 16 floats
\r
93 /// \return Pointer to the 4x4 matrix elements
\r
95 ////////////////////////////////////////////////////////////
\r
96 const float* Get4x4Elements() const;
\r
98 ////////////////////////////////////////////////////////////
\r
99 /// Operator () overloads to access the matrix elements
\r
101 /// \param Row : Element row (0 based)
\r
102 /// \param Col : Element column (0 based)
\r
104 /// \return Matrix element (Row, Col)
\r
106 ////////////////////////////////////////////////////////////
\r
107 float operator ()(unsigned int Row, unsigned int Col) const;
\r
108 float& operator ()(unsigned int Row, unsigned int Col);
\r
110 ////////////////////////////////////////////////////////////
\r
111 /// Operator * overload to multiply two matrices
\r
113 /// \param Mat : Matrix to multiply
\r
115 /// \return this * Mat
\r
117 ////////////////////////////////////////////////////////////
\r
118 Matrix3 operator *(const Matrix3& Mat) const;
\r
120 ////////////////////////////////////////////////////////////
\r
121 /// Operator *= overload to multiply-assign two matrices
\r
123 /// \param Mat : Matrix to multiply
\r
125 /// \return this * Mat
\r
127 ////////////////////////////////////////////////////////////
\r
128 Matrix3& operator *=(const Matrix3& Mat);
\r
130 ////////////////////////////////////////////////////////////
\r
131 // Static member data
\r
132 ////////////////////////////////////////////////////////////
\r
133 static const Matrix3 Identity; ///< Identity matrix
\r
137 ////////////////////////////////////////////////////////////
\r
139 ////////////////////////////////////////////////////////////
\r
140 float myData[16]; /// Matrix elements (we directly store it as a 4x4 matrix for optimization purpose)
\r
143 #include <SFML/Graphics/Matrix3.inl>
\r
148 #endif // SFML_MATRIX3_HPP
\r