1 | #ifndef _TRANSFORMMATRIX_H_ |
---|
2 | #define _TRANSFORMMATRIX_H_ |
---|
3 | |
---|
4 | #include <QtXml> |
---|
5 | #pragma warning(disable: 4003) |
---|
6 | #include "gmtl/gmtl.h" |
---|
7 | |
---|
8 | namespace projection |
---|
9 | { |
---|
10 | |
---|
11 | /** |
---|
12 | * Transform matrix class. |
---|
13 | */ |
---|
14 | class TransformMatrix |
---|
15 | { |
---|
16 | public: |
---|
17 | |
---|
18 | /** |
---|
19 | * Constructor. |
---|
20 | * |
---|
21 | * Default transform matrix value is identity matrix. |
---|
22 | */ |
---|
23 | TransformMatrix(); |
---|
24 | |
---|
25 | /** |
---|
26 | * Destructor. |
---|
27 | */ |
---|
28 | virtual ~TransformMatrix(); |
---|
29 | |
---|
30 | /** |
---|
31 | * Set position of the transform matrix. |
---|
32 | * |
---|
33 | * @param pos Position of the transform matrix. |
---|
34 | */ |
---|
35 | void setPosition(const gmtl::Vec3f& pos) { m_pos = pos; } |
---|
36 | |
---|
37 | /** |
---|
38 | * Retrieve the position of the transform matrix. |
---|
39 | * |
---|
40 | * @return Position of the transform matrix. |
---|
41 | */ |
---|
42 | gmtl::Vec3f getPosition() const { return m_pos; } |
---|
43 | |
---|
44 | /** |
---|
45 | * Set rotation of the transform matrix. |
---|
46 | * |
---|
47 | * @param rot Rotation of the transform matrix. |
---|
48 | */ |
---|
49 | void setRotation(const gmtl::Vec3f& rot) { m_rot = rot; } |
---|
50 | |
---|
51 | /** |
---|
52 | * Retrieve the rotation of the transform matrix. |
---|
53 | * |
---|
54 | * @return Rotation of the transform matrix. |
---|
55 | */ |
---|
56 | gmtl::Vec3f getRotation() const { return m_rot; } |
---|
57 | |
---|
58 | /** |
---|
59 | * Set scaling of the transform matrix. |
---|
60 | * |
---|
61 | * @param scale Scaling of the transform matrix. |
---|
62 | */ |
---|
63 | void setScaling(const gmtl::Vec3f& scale) { m_scale = scale; } |
---|
64 | |
---|
65 | /** |
---|
66 | * Retrieve the scaling of the transform matrix. |
---|
67 | * |
---|
68 | * @return Scaling of the transform matrix. |
---|
69 | */ |
---|
70 | gmtl::Vec3f getScaling() const { return m_scale; } |
---|
71 | |
---|
72 | /** |
---|
73 | * Set whether using scale or not in the transform matrix. |
---|
74 | * |
---|
75 | * @param bUseScale True to use scaling in the transform matrix. |
---|
76 | */ |
---|
77 | void setUseScaling(bool bUseScale) { m_bUseScale = bUseScale; } |
---|
78 | |
---|
79 | /** |
---|
80 | * Check whether using scale or not in the transform matrix. |
---|
81 | * |
---|
82 | * @return True if using scale in the transform matrix. |
---|
83 | */ |
---|
84 | bool getUseScaling() const { return m_bUseScale; } |
---|
85 | |
---|
86 | /** |
---|
87 | * Retrieve the trasform matrix. |
---|
88 | * |
---|
89 | * @return Trasform matrix. |
---|
90 | */ |
---|
91 | gmtl::Matrix44f getMatrix() const; |
---|
92 | |
---|
93 | /** |
---|
94 | * Retrieve the trasform matrix without scaling. |
---|
95 | * |
---|
96 | * @return Trasform matrix without scaling. |
---|
97 | */ |
---|
98 | gmtl::Matrix44f getMatrixWOScaling() const; |
---|
99 | |
---|
100 | /** |
---|
101 | * Retrieve transform parameters like 'Rotate 45 1 0 0;'. |
---|
102 | * |
---|
103 | * @param numSpaces Number of space characters for indent. |
---|
104 | * @return Transform params. |
---|
105 | */ |
---|
106 | QString getParams(int numSpaces=0) const; |
---|
107 | |
---|
108 | /** |
---|
109 | * Assignment operator. |
---|
110 | * |
---|
111 | * @param m Assignment source transform matrix. |
---|
112 | */ |
---|
113 | TransformMatrix& operator=(const TransformMatrix& m) |
---|
114 | { |
---|
115 | m_pos = m.m_pos; |
---|
116 | m_rot = m.m_rot; |
---|
117 | m_scale = m.m_scale; |
---|
118 | return *this; |
---|
119 | } |
---|
120 | |
---|
121 | /** |
---|
122 | * Equal operator. |
---|
123 | * |
---|
124 | * @param a Operand transform matrix. |
---|
125 | * @param b Operand transform matrix. |
---|
126 | */ |
---|
127 | friend bool operator==(const TransformMatrix &a, const TransformMatrix &b) |
---|
128 | { |
---|
129 | return (a.m_pos == b.m_pos && a.m_rot == b.m_rot && a.m_scale == b.m_scale); |
---|
130 | } |
---|
131 | |
---|
132 | /** |
---|
133 | * Not equal operator. |
---|
134 | * |
---|
135 | * @param a Operand transform matrix. |
---|
136 | * @param b Operand transform matrix. |
---|
137 | */ |
---|
138 | friend bool operator!=(const TransformMatrix &a, const TransformMatrix &b) |
---|
139 | { |
---|
140 | return !(a==b); |
---|
141 | } |
---|
142 | |
---|
143 | /** |
---|
144 | * Restore the transform matrix from XML data. |
---|
145 | * |
---|
146 | * @param element Parent XML element of the transform matrix data. |
---|
147 | */ |
---|
148 | virtual void initFromDOMElement(const QDomElement& element); |
---|
149 | |
---|
150 | /** |
---|
151 | * Store the current transform matrix as XML data. |
---|
152 | * |
---|
153 | * @param name XML node name of the data. |
---|
154 | * @param doc XML document to store the data. |
---|
155 | * @return Current transform matrix data as XML data. |
---|
156 | */ |
---|
157 | virtual QDomElement domElement(const QString& name, QDomDocument& doc) const; |
---|
158 | |
---|
159 | /** |
---|
160 | * Reset the matrix. |
---|
161 | */ |
---|
162 | void reset(); |
---|
163 | |
---|
164 | private: |
---|
165 | |
---|
166 | bool m_bUseScale; |
---|
167 | |
---|
168 | gmtl::Vec3f m_pos; //!< Position of the tranform matrix. |
---|
169 | gmtl::Vec3f m_rot; //!< Rotation of the tranform matrix. |
---|
170 | gmtl::Vec3f m_scale; //!< Scaling of the tranform matrix. |
---|
171 | |
---|
172 | double m_mat[16]; //!< Matrix values. Calculated when getMatrix() called. |
---|
173 | }; |
---|
174 | |
---|
175 | }; // projection |
---|
176 | |
---|
177 | #endif // _TRANSFORMMATRIX_H_ |
---|