• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 ///////////////////////////////////////////////////////////////////////////////////
2 /// OpenGL Mathematics (glm.g-truc.net)
3 ///
4 /// Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net)
5 /// Permission is hereby granted, free of charge, to any person obtaining a copy
6 /// of this software and associated documentation files (the "Software"), to deal
7 /// in the Software without restriction, including without limitation the rights
8 /// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 /// copies of the Software, and to permit persons to whom the Software is
10 /// furnished to do so, subject to the following conditions:
11 ///
12 /// The above copyright notice and this permission notice shall be included in
13 /// all copies or substantial portions of the Software.
14 ///
15 /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 /// THE SOFTWARE.
22 ///
23 /// @ref gtc_matrix_transform
24 /// @file glm/gtc/matrix_transform.hpp
25 /// @date 2009-04-29 / 2011-05-16
26 /// @author Christophe Riccio
27 ///
28 /// @see core (dependence)
29 /// @see gtx_transform
30 /// @see gtx_transform2
31 ///
32 /// @defgroup gtc_matrix_transform GLM_GTC_matrix_transform
33 /// @ingroup gtc
34 ///
35 /// @brief Defines functions that generate common transformation matrices.
36 ///
37 /// The matrices generated by this extension use standard OpenGL fixed-function
38 /// conventions. For example, the lookAt function generates a transform from world
39 /// space into the specific eye space that the projective matrix functions
40 /// (perspective, ortho, etc) are designed to expect. The OpenGL compatibility
41 /// specifications defines the particular layout of this eye space.
42 ///
43 /// <glm/gtc/matrix_transform.hpp> need to be included to use these functionalities.
44 ///////////////////////////////////////////////////////////////////////////////////
45 
46 #ifndef GLM_GTC_matrix_transform
47 #define GLM_GTC_matrix_transform
48 
49 // Dependency:
50 #include "../mat4x4.hpp"
51 #include "../vec2.hpp"
52 #include "../vec3.hpp"
53 #include "../vec4.hpp"
54 
55 #if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
56 #	pragma message("GLM: GLM_GTC_matrix_transform extension included")
57 #endif
58 
59 namespace glm
60 {
61 	/// @addtogroup gtc_matrix_transform
62 	/// @{
63 
64 	/// Builds a translation 4 * 4 matrix created from a vector of 3 components.
65 	///
66 	/// @param m Input matrix multiplied by this translation matrix.
67 	/// @param v Coordinates of a translation vector.
68 	/// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double.
69 	/// @code
70 	/// #include <glm/glm.hpp>
71 	/// #include <glm/gtc/matrix_transform.hpp>
72 	/// ...
73 	/// glm::mat4 m = glm::translate(glm::mat4(1.0f), glm::vec3(1.0f));
74 	/// // m[0][0] == 1.0f, m[0][1] == 0.0f, m[0][2] == 0.0f, m[0][3] == 0.0f
75 	/// // m[1][0] == 0.0f, m[1][1] == 1.0f, m[1][2] == 0.0f, m[1][3] == 0.0f
76 	/// // m[2][0] == 0.0f, m[2][1] == 0.0f, m[2][2] == 1.0f, m[2][3] == 0.0f
77 	/// // m[3][0] == 1.0f, m[3][1] == 1.0f, m[3][2] == 1.0f, m[3][3] == 1.0f
78 	/// @endcode
79 	/// @see gtc_matrix_transform
80 	/// @see gtx_transform
81 	/// @see - translate(T x, T y, T z)
82 	/// @see - translate(detail::tmat4x4<T, P> const & m, T x, T y, T z)
83 	/// @see - translate(detail::tvec3<T, P> const & v)
84 	template <typename T, precision P>
85 	GLM_FUNC_DECL detail::tmat4x4<T, P> translate(
86 		detail::tmat4x4<T, P> const & m,
87 		detail::tvec3<T, P> const & v);
88 
89 	/// Builds a rotation 4 * 4 matrix created from an axis vector and an angle.
90 	///
91 	/// @param m Input matrix multiplied by this rotation matrix.
92 	/// @param angle Rotation angle expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise.
93 	/// @param axis Rotation axis, recommanded to be normalized.
94 	/// @tparam T Value type used to build the matrix. Supported: half, float or double.
95 	/// @see gtc_matrix_transform
96 	/// @see gtx_transform
97 	/// @see - rotate(T angle, T x, T y, T z)
98 	/// @see - rotate(detail::tmat4x4<T, P> const & m, T angle, T x, T y, T z)
99 	/// @see - rotate(T angle, detail::tvec3<T, P> const & v)
100 	template <typename T, precision P>
101 	GLM_FUNC_DECL detail::tmat4x4<T, P> rotate(
102 		detail::tmat4x4<T, P> const & m,
103 		T const & angle,
104 		detail::tvec3<T, P> const & axis);
105 
106 	/// Builds a scale 4 * 4 matrix created from 3 scalars.
107 	///
108 	/// @param m Input matrix multiplied by this scale matrix.
109 	/// @param v Ratio of scaling for each axis.
110 	/// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double.
111 	/// @see gtc_matrix_transform
112 	/// @see gtx_transform
113 	/// @see - scale(T x, T y, T z) scale(T const & x, T const & y, T const & z)
114 	/// @see - scale(detail::tmat4x4<T, P> const & m, T x, T y, T z)
115 	/// @see - scale(detail::tvec3<T, P> const & v)
116 	template <typename T, precision P>
117 	GLM_FUNC_DECL detail::tmat4x4<T, P> scale(
118 		detail::tmat4x4<T, P> const & m,
119 		detail::tvec3<T, P> const & v);
120 
121 	/// Creates a matrix for an orthographic parallel viewing volume.
122 	///
123 	/// @param left
124 	/// @param right
125 	/// @param bottom
126 	/// @param top
127 	/// @param zNear
128 	/// @param zFar
129 	/// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double.
130 	/// @see gtc_matrix_transform
131 	/// @see - glm::ortho(T const & left, T const & right, T const & bottom, T const & top)
132 	template <typename T>
133 	GLM_FUNC_DECL detail::tmat4x4<T, defaultp> ortho(
134 		T const & left,
135 		T const & right,
136 		T const & bottom,
137 		T const & top,
138 		T const & zNear,
139 		T const & zFar);
140 
141 	/// Creates a matrix for projecting two-dimensional coordinates onto the screen.
142 	///
143 	/// @param left
144 	/// @param right
145 	/// @param bottom
146 	/// @param top
147 	/// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double.
148 	/// @see gtc_matrix_transform
149 	/// @see - glm::ortho(T const & left, T const & right, T const & bottom, T const & top, T const & zNear, T const & zFar)
150 	template <typename T>
151 	GLM_FUNC_DECL detail::tmat4x4<T, defaultp> ortho(
152 		T const & left,
153 		T const & right,
154 		T const & bottom,
155 		T const & top);
156 
157 	/// Creates a frustum matrix.
158 	///
159 	/// @param left
160 	/// @param right
161 	/// @param bottom
162 	/// @param top
163 	/// @param near
164 	/// @param far
165 	/// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double.
166 	/// @see gtc_matrix_transform
167 	template <typename T, precision P>
168 	GLM_FUNC_DECL detail::tmat4x4<T, P> frustum(
169 		T const & left,
170 		T const & right,
171 		T const & bottom,
172 		T const & top,
173 		T const & near,
174 		T const & far);
175 
176 	/// Creates a matrix for a symetric perspective-view frustum.
177 	///
178 	/// @param fovy Expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise.
179 	/// @param aspect
180 	/// @param near
181 	/// @param far
182 	/// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double.
183 	/// @see gtc_matrix_transform
184 	template <typename T, precision P>
185 	GLM_FUNC_DECL detail::tmat4x4<T, P> perspective(
186 		T const & fovy,
187 		T const & aspect,
188 		T const & near,
189 		T const & far);
190 
191 	/// Builds a perspective projection matrix based on a field of view.
192 	///
193 	/// @param fov Expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise.
194 	/// @param width
195 	/// @param height
196 	/// @param near
197 	/// @param far
198 	/// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double.
199 	/// @see gtc_matrix_transform
200 	template <typename T, precision P>
201 	GLM_FUNC_DECL detail::tmat4x4<T, P> perspectiveFov(
202 		T const & fov,
203 		T const & width,
204 		T const & height,
205 		T const & near,
206 		T const & far);
207 
208 	/// Creates a matrix for a symmetric perspective-view frustum with far plane at infinite.
209 	///
210 	/// @param fovy Expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise.
211 	/// @param aspect
212 	/// @param near
213 	/// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double.
214 	/// @see gtc_matrix_transform
215 	template <typename T, precision P>
216 	GLM_FUNC_DECL detail::tmat4x4<T, P> infinitePerspective(
217 		T fovy, T aspect, T near);
218 
219 	/// Creates a matrix for a symmetric perspective-view frustum with far plane at infinite for graphics hardware that doesn't support depth clamping.
220 	///
221 	/// @param fovy Expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise.
222 	/// @param aspect
223 	/// @param near
224 	/// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double.
225 	/// @see gtc_matrix_transform
226 	template <typename T, precision P>
227 	GLM_FUNC_DECL detail::tmat4x4<T, P> tweakedInfinitePerspective(
228 		T fovy, T aspect, T near);
229 
230 	/// Map the specified object coordinates (obj.x, obj.y, obj.z) into window coordinates.
231 	///
232 	/// @param obj
233 	/// @param model
234 	/// @param proj
235 	/// @param viewport
236 	/// @tparam T Native type used for the computation. Currently supported: half (not recommanded), float or double.
237 	/// @tparam U Currently supported: Floating-point types and integer types.
238 	/// @see gtc_matrix_transform
239 	template <typename T, typename U, precision P>
240 	GLM_FUNC_DECL detail::tvec3<T, P> project(
241 		detail::tvec3<T, P> const & obj,
242 		detail::tmat4x4<T, P> const & model,
243 		detail::tmat4x4<T, P> const & proj,
244 		detail::tvec4<U, P> const & viewport);
245 
246 	/// Map the specified window coordinates (win.x, win.y, win.z) into object coordinates.
247 	///
248 	/// @param win
249 	/// @param model
250 	/// @param proj
251 	/// @param viewport
252 	/// @tparam T Native type used for the computation. Currently supported: half (not recommanded), float or double.
253 	/// @tparam U Currently supported: Floating-point types and integer types.
254 	/// @see gtc_matrix_transform
255 	template <typename T, typename U, precision P>
256 	GLM_FUNC_DECL detail::tvec3<T, P> unProject(
257 		detail::tvec3<T, P> const & win,
258 		detail::tmat4x4<T, P> const & model,
259 		detail::tmat4x4<T, P> const & proj,
260 		detail::tvec4<U, P> const & viewport);
261 
262 	/// Define a picking region
263 	///
264 	/// @param center
265 	/// @param delta
266 	/// @param viewport
267 	/// @tparam T Native type used for the computation. Currently supported: half (not recommanded), float or double.
268 	/// @tparam U Currently supported: Floating-point types and integer types.
269 	/// @see gtc_matrix_transform
270 	template <typename T, precision P, typename U>
271 	GLM_FUNC_DECL detail::tmat4x4<T, P> pickMatrix(
272 		detail::tvec2<T, P> const & center,
273 		detail::tvec2<T, P> const & delta,
274 		detail::tvec4<U, P> const & viewport);
275 
276 	/// Build a look at view matrix.
277 	///
278 	/// @param eye Position of the camera
279 	/// @param center Position where the camera is looking at
280 	/// @param up Normalized up vector, how the camera is oriented. Typically (0, 0, 1)
281 	/// @see gtc_matrix_transform
282 	/// @see - frustum(T const & left, T const & right, T const & bottom, T const & top, T const & nearVal, T const & farVal) frustum(T const & left, T const & right, T const & bottom, T const & top, T const & nearVal, T const & farVal)
283 	template <typename T, precision P>
284 	GLM_FUNC_DECL detail::tmat4x4<T, P> lookAt(
285 		detail::tvec3<T, P> const & eye,
286 		detail::tvec3<T, P> const & center,
287 		detail::tvec3<T, P> const & up);
288 
289 	/// @}
290 }//namespace glm
291 
292 #include "matrix_transform.inl"
293 
294 #endif//GLM_GTC_matrix_transform
295