1 | #ifndef _PROJECTIONMATRIX_H_ |
---|
2 | #define _PROJECTIONMATRIX_H_ |
---|
3 | |
---|
4 | #include <QtXml> |
---|
5 | #pragma warning(disable: 4003) |
---|
6 | #include "gmtl/gmtl.h" |
---|
7 | |
---|
8 | namespace projection |
---|
9 | { |
---|
10 | |
---|
11 | /** |
---|
12 | * Projection matrix class. |
---|
13 | */ |
---|
14 | class ProjectionMatrix |
---|
15 | { |
---|
16 | public: |
---|
17 | |
---|
18 | /** |
---|
19 | * Constructor. |
---|
20 | * |
---|
21 | * Default projection matrix value is : FOV=30.0, |
---|
22 | * AspectRatio=4/3, Near=0.1, Far=100.0 |
---|
23 | */ |
---|
24 | ProjectionMatrix(); |
---|
25 | |
---|
26 | /** |
---|
27 | * Destructor. |
---|
28 | */ |
---|
29 | virtual ~ProjectionMatrix(); |
---|
30 | |
---|
31 | /** |
---|
32 | * Copy constructor. |
---|
33 | * |
---|
34 | * @param matrix Copy source matrix. |
---|
35 | */ |
---|
36 | ProjectionMatrix(const ProjectionMatrix &matrix); |
---|
37 | |
---|
38 | /** |
---|
39 | * Set Field of View. |
---|
40 | * |
---|
41 | * @param fov Field of View. |
---|
42 | */ |
---|
43 | void setFOV(float fov) { m_fov = fov; } |
---|
44 | |
---|
45 | /** |
---|
46 | * Retrieve Field of View. |
---|
47 | * |
---|
48 | * @return Field of View. |
---|
49 | */ |
---|
50 | float getFOV() const { return m_fov; } |
---|
51 | |
---|
52 | /** |
---|
53 | * Set aspect ratio. |
---|
54 | * |
---|
55 | * @param ratio Aspect ratio. |
---|
56 | */ |
---|
57 | void setAspectRatio(float ratio) { m_aspectRatio = ratio; } |
---|
58 | |
---|
59 | /** |
---|
60 | * Retrieve aspect ratio. |
---|
61 | * |
---|
62 | * @return Aspect ratio. |
---|
63 | */ |
---|
64 | float getAspectRatio() const { return m_aspectRatio; } |
---|
65 | |
---|
66 | /** |
---|
67 | * Set near clip distance. |
---|
68 | * |
---|
69 | * @param Near clip distance. |
---|
70 | */ |
---|
71 | void setNear(float nearDist) { m_near = nearDist; } |
---|
72 | |
---|
73 | /** |
---|
74 | * Retrieve near clip distance. |
---|
75 | * |
---|
76 | * @return Near clip distance. |
---|
77 | */ |
---|
78 | float getNear() const { return m_near; } |
---|
79 | |
---|
80 | /** |
---|
81 | * Set far clip plane distance. |
---|
82 | * |
---|
83 | * @param Far clip plane distance. |
---|
84 | */ |
---|
85 | void setFar(float farDist) { m_far = farDist; } |
---|
86 | |
---|
87 | /** |
---|
88 | * Retrieve far clip plane distance. |
---|
89 | * |
---|
90 | * @return Far clip plane distance. |
---|
91 | */ |
---|
92 | float getFar() const { return m_far; } |
---|
93 | |
---|
94 | /** |
---|
95 | * Set vertical off-axis distane on the Z=1.0 plane. |
---|
96 | * |
---|
97 | * @param Vertical off-axis distane. |
---|
98 | */ |
---|
99 | void setOffaxisX(float offaxisX) { m_offaxisX = offaxisX; } |
---|
100 | |
---|
101 | /** |
---|
102 | * Retrieve horizontal off-axis distane on the Z=1.0 plane. |
---|
103 | * |
---|
104 | * @return Horizontal off-axis distane. |
---|
105 | */ |
---|
106 | float getOffaxisX() const { return m_offaxisX; } |
---|
107 | |
---|
108 | /** |
---|
109 | * Set horizontal off-axis distane on the Z=1.0 plane. |
---|
110 | * |
---|
111 | * @param Horizontal off-axis distane. |
---|
112 | */ |
---|
113 | void setOffaxisY(float offaxisY) { m_offaxisY = offaxisY; } |
---|
114 | |
---|
115 | /** |
---|
116 | * Retrieve vertical off-axis distane on the Z=1.0 plane. |
---|
117 | * |
---|
118 | * @return Vertical off-axis distane. |
---|
119 | */ |
---|
120 | float getOffaxisY() const { return m_offaxisY; } |
---|
121 | |
---|
122 | /** |
---|
123 | * Retrieve matrix values for glMultMatrixd(). |
---|
124 | * |
---|
125 | * @return Matrix values. |
---|
126 | */ |
---|
127 | float* getMatrix(); |
---|
128 | |
---|
129 | /** |
---|
130 | * Retrieve four corner vectors. |
---|
131 | * |
---|
132 | * @param Four corner vectors. |
---|
133 | */ |
---|
134 | void getCorners(gmtl::Vec3f vecs[4]) const; |
---|
135 | |
---|
136 | /** |
---|
137 | * Retrieve frustum parameters as 'Frustum left right bottom top near far;'. |
---|
138 | * |
---|
139 | * @param numSpaces Number of space characters for indent. |
---|
140 | * @return Frustum params. |
---|
141 | */ |
---|
142 | QString getParams(int numSpaces=0) const; |
---|
143 | |
---|
144 | /** |
---|
145 | * Assignment operator. |
---|
146 | * |
---|
147 | * @param m Assignment source projection matrix. |
---|
148 | */ |
---|
149 | ProjectionMatrix& operator=(const ProjectionMatrix& m) |
---|
150 | { |
---|
151 | if (this != &m) |
---|
152 | { |
---|
153 | m_fov = m.m_fov; |
---|
154 | m_aspectRatio = m.m_aspectRatio; |
---|
155 | m_near = m.m_near; |
---|
156 | m_far = m.m_far; |
---|
157 | m_offaxisX = m.m_offaxisX; |
---|
158 | m_offaxisY = m.m_offaxisY; |
---|
159 | } |
---|
160 | return *this; |
---|
161 | } |
---|
162 | |
---|
163 | /** |
---|
164 | * Equal operator. |
---|
165 | * |
---|
166 | * @param a Operand projection matrix. |
---|
167 | * @param b Operand projection matrix. |
---|
168 | */ |
---|
169 | friend bool operator==(const ProjectionMatrix &a, const ProjectionMatrix &b) |
---|
170 | { |
---|
171 | return (a.m_fov == b.m_fov && a.m_aspectRatio == b.m_aspectRatio && |
---|
172 | a.m_near == b.m_near && a.m_far == b.m_far && |
---|
173 | a.m_offaxisX == b.m_offaxisX && a.m_offaxisY == b.m_offaxisY); |
---|
174 | } |
---|
175 | |
---|
176 | /** |
---|
177 | * Not equal operator. |
---|
178 | * |
---|
179 | * @param a Operand projection matrix. |
---|
180 | * @param b Operand projection matrix. |
---|
181 | */ |
---|
182 | friend bool operator!=(const ProjectionMatrix &a, const ProjectionMatrix &b) |
---|
183 | { |
---|
184 | return !(a==b); |
---|
185 | } |
---|
186 | |
---|
187 | /** |
---|
188 | * Restore the projection matrix from XML data. |
---|
189 | * |
---|
190 | * @param element Parent XML element of the projection matrix data. |
---|
191 | */ |
---|
192 | virtual void initFromDOMElement(const QDomElement& element); |
---|
193 | |
---|
194 | /** |
---|
195 | * Store the current projection matrix as XML data. |
---|
196 | * |
---|
197 | * @param name XML node name of the data. |
---|
198 | * @param doc XML document to store the data. |
---|
199 | * @return Current projection matrix data as XML data. |
---|
200 | */ |
---|
201 | virtual QDomElement domElement(const QString& name, QDomDocument& doc) const; |
---|
202 | |
---|
203 | private: |
---|
204 | |
---|
205 | float m_fov; //!< Field of View (FOV). |
---|
206 | float m_aspectRatio; //!< Aspect ratio (width / height). |
---|
207 | float m_near; //!< Near clip plane distance. |
---|
208 | float m_far; //!< Far clip plane distance. |
---|
209 | float m_offaxisX; //!< Horizontal off-axis distance. |
---|
210 | float m_offaxisY; //!< Vertical off-axis distance. |
---|
211 | |
---|
212 | float m_mat[16]; //!< Matrix values. Calculated when getMatrix() called. |
---|
213 | }; |
---|
214 | |
---|
215 | }; // projection |
---|
216 | |
---|
217 | #endif // _PROJECTIONMATRIX_H_ |
---|