master
ブランチ master
ShaderPlayground / deps / glm / glm / ext / matrix_clip_space.inl
19.4 KB、534行 生 Blame 履歴
1namespace glm
2{
3 template<typename T>
4 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> ortho(T left, T right, T bottom, T top)
5 {
6 mat<4, 4, T, defaultp> Result(static_cast<T>(1));
7 Result[0][0] = static_cast<T>(2) / (right - left);
8 Result[1][1] = static_cast<T>(2) / (top - bottom);
9 Result[2][2] = - static_cast<T>(1);
10 Result[3][0] = - (right + left) / (right - left);
11 Result[3][1] = - (top + bottom) / (top - bottom);
12 return Result;
13 }
14
15 template<typename T>
16 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> orthoLH_ZO(T left, T right, T bottom, T top, T zNear, T zFar)
17 {
18 mat<4, 4, T, defaultp> Result(1);
19 Result[0][0] = static_cast<T>(2) / (right - left);
20 Result[1][1] = static_cast<T>(2) / (top - bottom);
21 Result[2][2] = static_cast<T>(1) / (zFar - zNear);
22 Result[3][0] = - (right + left) / (right - left);
23 Result[3][1] = - (top + bottom) / (top - bottom);
24 Result[3][2] = - zNear / (zFar - zNear);
25 return Result;
26 }
27
28 template<typename T>
29 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> orthoLH_NO(T left, T right, T bottom, T top, T zNear, T zFar)
30 {
31 mat<4, 4, T, defaultp> Result(1);
32 Result[0][0] = static_cast<T>(2) / (right - left);
33 Result[1][1] = static_cast<T>(2) / (top - bottom);
34 Result[2][2] = static_cast<T>(2) / (zFar - zNear);
35 Result[3][0] = - (right + left) / (right - left);
36 Result[3][1] = - (top + bottom) / (top - bottom);
37 Result[3][2] = - (zFar + zNear) / (zFar - zNear);
38 return Result;
39 }
40
41 template<typename T>
42 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> orthoRH_ZO(T left, T right, T bottom, T top, T zNear, T zFar)
43 {
44 mat<4, 4, T, defaultp> Result(1);
45 Result[0][0] = static_cast<T>(2) / (right - left);
46 Result[1][1] = static_cast<T>(2) / (top - bottom);
47 Result[2][2] = - static_cast<T>(1) / (zFar - zNear);
48 Result[3][0] = - (right + left) / (right - left);
49 Result[3][1] = - (top + bottom) / (top - bottom);
50 Result[3][2] = - zNear / (zFar - zNear);
51 return Result;
52 }
53
54 template<typename T>
55 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> orthoRH_NO(T left, T right, T bottom, T top, T zNear, T zFar)
56 {
57 mat<4, 4, T, defaultp> Result(1);
58 Result[0][0] = static_cast<T>(2) / (right - left);
59 Result[1][1] = static_cast<T>(2) / (top - bottom);
60 Result[2][2] = - static_cast<T>(2) / (zFar - zNear);
61 Result[3][0] = - (right + left) / (right - left);
62 Result[3][1] = - (top + bottom) / (top - bottom);
63 Result[3][2] = - (zFar + zNear) / (zFar - zNear);
64 return Result;
65 }
66
67 template<typename T>
68 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> orthoZO(T left, T right, T bottom, T top, T zNear, T zFar)
69 {
70 if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_LH_BIT)
71 return orthoLH_ZO(left, right, bottom, top, zNear, zFar);
72 else
73 return orthoRH_ZO(left, right, bottom, top, zNear, zFar);
74 }
75
76 template<typename T>
77 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> orthoNO(T left, T right, T bottom, T top, T zNear, T zFar)
78 {
79 if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_LH_BIT)
80 return orthoLH_NO(left, right, bottom, top, zNear, zFar);
81 else
82 return orthoRH_NO(left, right, bottom, top, zNear, zFar);
83 }
84
85 template<typename T>
86 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> orthoLH(T left, T right, T bottom, T top, T zNear, T zFar)
87 {
88 if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_ZO_BIT)
89 return orthoLH_ZO(left, right, bottom, top, zNear, zFar);
90 else
91 return orthoLH_NO(left, right, bottom, top, zNear, zFar);
92
93 }
94
95 template<typename T>
96 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> orthoRH(T left, T right, T bottom, T top, T zNear, T zFar)
97 {
98 if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_ZO_BIT)
99 return orthoRH_ZO(left, right, bottom, top, zNear, zFar);
100 else
101 return orthoRH_NO(left, right, bottom, top, zNear, zFar);
102 }
103
104 template<typename T>
105 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> ortho(T left, T right, T bottom, T top, T zNear, T zFar)
106 {
107 if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_LH_ZO)
108 return orthoLH_ZO(left, right, bottom, top, zNear, zFar);
109 else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_LH_NO)
110 return orthoLH_NO(left, right, bottom, top, zNear, zFar);
111 else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_RH_ZO)
112 return orthoRH_ZO(left, right, bottom, top, zNear, zFar);
113 else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_RH_NO)
114 return orthoRH_NO(left, right, bottom, top, zNear, zFar);
115 }
116
117 template<typename T>
118 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> frustumLH_ZO(T left, T right, T bottom, T top, T nearVal, T farVal)
119 {
120 mat<4, 4, T, defaultp> Result(0);
121 Result[0][0] = (static_cast<T>(2) * nearVal) / (right - left);
122 Result[1][1] = (static_cast<T>(2) * nearVal) / (top - bottom);
123 Result[2][0] = (right + left) / (right - left);
124 Result[2][1] = (top + bottom) / (top - bottom);
125 Result[2][2] = farVal / (farVal - nearVal);
126 Result[2][3] = static_cast<T>(1);
127 Result[3][2] = -(farVal * nearVal) / (farVal - nearVal);
128 return Result;
129 }
130
131 template<typename T>
132 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> frustumLH_NO(T left, T right, T bottom, T top, T nearVal, T farVal)
133 {
134 mat<4, 4, T, defaultp> Result(0);
135 Result[0][0] = (static_cast<T>(2) * nearVal) / (right - left);
136 Result[1][1] = (static_cast<T>(2) * nearVal) / (top - bottom);
137 Result[2][0] = (right + left) / (right - left);
138 Result[2][1] = (top + bottom) / (top - bottom);
139 Result[2][2] = (farVal + nearVal) / (farVal - nearVal);
140 Result[2][3] = static_cast<T>(1);
141 Result[3][2] = - (static_cast<T>(2) * farVal * nearVal) / (farVal - nearVal);
142 return Result;
143 }
144
145 template<typename T>
146 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> frustumRH_ZO(T left, T right, T bottom, T top, T nearVal, T farVal)
147 {
148 mat<4, 4, T, defaultp> Result(0);
149 Result[0][0] = (static_cast<T>(2) * nearVal) / (right - left);
150 Result[1][1] = (static_cast<T>(2) * nearVal) / (top - bottom);
151 Result[2][0] = (right + left) / (right - left);
152 Result[2][1] = (top + bottom) / (top - bottom);
153 Result[2][2] = farVal / (nearVal - farVal);
154 Result[2][3] = static_cast<T>(-1);
155 Result[3][2] = -(farVal * nearVal) / (farVal - nearVal);
156 return Result;
157 }
158
159 template<typename T>
160 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> frustumRH_NO(T left, T right, T bottom, T top, T nearVal, T farVal)
161 {
162 mat<4, 4, T, defaultp> Result(0);
163 Result[0][0] = (static_cast<T>(2) * nearVal) / (right - left);
164 Result[1][1] = (static_cast<T>(2) * nearVal) / (top - bottom);
165 Result[2][0] = (right + left) / (right - left);
166 Result[2][1] = (top + bottom) / (top - bottom);
167 Result[2][2] = - (farVal + nearVal) / (farVal - nearVal);
168 Result[2][3] = static_cast<T>(-1);
169 Result[3][2] = - (static_cast<T>(2) * farVal * nearVal) / (farVal - nearVal);
170 return Result;
171 }
172
173 template<typename T>
174 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> frustumZO(T left, T right, T bottom, T top, T nearVal, T farVal)
175 {
176 if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_LH_BIT)
177 return frustumLH_ZO(left, right, bottom, top, nearVal, farVal);
178 else
179 return frustumRH_ZO(left, right, bottom, top, nearVal, farVal);
180 }
181
182 template<typename T>
183 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> frustumNO(T left, T right, T bottom, T top, T nearVal, T farVal)
184 {
185 if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_LH_BIT)
186 return frustumLH_NO(left, right, bottom, top, nearVal, farVal);
187 else
188 return frustumRH_NO(left, right, bottom, top, nearVal, farVal);
189 }
190
191 template<typename T>
192 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> frustumLH(T left, T right, T bottom, T top, T nearVal, T farVal)
193 {
194 if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_ZO_BIT)
195 return frustumLH_ZO(left, right, bottom, top, nearVal, farVal);
196 else
197 return frustumLH_NO(left, right, bottom, top, nearVal, farVal);
198 }
199
200 template<typename T>
201 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> frustumRH(T left, T right, T bottom, T top, T nearVal, T farVal)
202 {
203 if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_ZO_BIT)
204 return frustumRH_ZO(left, right, bottom, top, nearVal, farVal);
205 else
206 return frustumRH_NO(left, right, bottom, top, nearVal, farVal);
207 }
208
209 template<typename T>
210 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> frustum(T left, T right, T bottom, T top, T nearVal, T farVal)
211 {
212 if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_LH_ZO)
213 return frustumLH_ZO(left, right, bottom, top, nearVal, farVal);
214 else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_LH_NO)
215 return frustumLH_NO(left, right, bottom, top, nearVal, farVal);
216 else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_RH_ZO)
217 return frustumRH_ZO(left, right, bottom, top, nearVal, farVal);
218 else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_RH_NO)
219 return frustumRH_NO(left, right, bottom, top, nearVal, farVal);
220 }
221
222 template<typename T>
223 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveRH_ZO(T fovy, T aspect, T zNear, T zFar)
224 {
225 assert(abs(aspect - std::numeric_limits<T>::epsilon()) > static_cast<T>(0));
226
227 T const tanHalfFovy = tan(fovy / static_cast<T>(2));
228
229 mat<4, 4, T, defaultp> Result(static_cast<T>(0));
230 Result[0][0] = static_cast<T>(1) / (aspect * tanHalfFovy);
231 Result[1][1] = static_cast<T>(1) / (tanHalfFovy);
232 Result[2][2] = zFar / (zNear - zFar);
233 Result[2][3] = - static_cast<T>(1);
234 Result[3][2] = -(zFar * zNear) / (zFar - zNear);
235 return Result;
236 }
237
238 template<typename T>
239 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveRH_NO(T fovy, T aspect, T zNear, T zFar)
240 {
241 assert(abs(aspect - std::numeric_limits<T>::epsilon()) > static_cast<T>(0));
242
243 T const tanHalfFovy = tan(fovy / static_cast<T>(2));
244
245 mat<4, 4, T, defaultp> Result(static_cast<T>(0));
246 Result[0][0] = static_cast<T>(1) / (aspect * tanHalfFovy);
247 Result[1][1] = static_cast<T>(1) / (tanHalfFovy);
248 Result[2][2] = - (zFar + zNear) / (zFar - zNear);
249 Result[2][3] = - static_cast<T>(1);
250 Result[3][2] = - (static_cast<T>(2) * zFar * zNear) / (zFar - zNear);
251 return Result;
252 }
253
254 template<typename T>
255 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveLH_ZO(T fovy, T aspect, T zNear, T zFar)
256 {
257 assert(abs(aspect - std::numeric_limits<T>::epsilon()) > static_cast<T>(0));
258
259 T const tanHalfFovy = tan(fovy / static_cast<T>(2));
260
261 mat<4, 4, T, defaultp> Result(static_cast<T>(0));
262 Result[0][0] = static_cast<T>(1) / (aspect * tanHalfFovy);
263 Result[1][1] = static_cast<T>(1) / (tanHalfFovy);
264 Result[2][2] = zFar / (zFar - zNear);
265 Result[2][3] = static_cast<T>(1);
266 Result[3][2] = -(zFar * zNear) / (zFar - zNear);
267 return Result;
268 }
269
270 template<typename T>
271 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveLH_NO(T fovy, T aspect, T zNear, T zFar)
272 {
273 assert(abs(aspect - std::numeric_limits<T>::epsilon()) > static_cast<T>(0));
274
275 T const tanHalfFovy = tan(fovy / static_cast<T>(2));
276
277 mat<4, 4, T, defaultp> Result(static_cast<T>(0));
278 Result[0][0] = static_cast<T>(1) / (aspect * tanHalfFovy);
279 Result[1][1] = static_cast<T>(1) / (tanHalfFovy);
280 Result[2][2] = (zFar + zNear) / (zFar - zNear);
281 Result[2][3] = static_cast<T>(1);
282 Result[3][2] = - (static_cast<T>(2) * zFar * zNear) / (zFar - zNear);
283 return Result;
284 }
285
286 template<typename T>
287 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveZO(T fovy, T aspect, T zNear, T zFar)
288 {
289 if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_LH_BIT)
290 return perspectiveLH_ZO(fovy, aspect, zNear, zFar);
291 else
292 return perspectiveRH_ZO(fovy, aspect, zNear, zFar);
293 }
294
295 template<typename T>
296 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveNO(T fovy, T aspect, T zNear, T zFar)
297 {
298 if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_LH_BIT)
299 return perspectiveLH_NO(fovy, aspect, zNear, zFar);
300 else
301 return perspectiveRH_NO(fovy, aspect, zNear, zFar);
302 }
303
304 template<typename T>
305 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveLH(T fovy, T aspect, T zNear, T zFar)
306 {
307 if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_ZO_BIT)
308 return perspectiveLH_ZO(fovy, aspect, zNear, zFar);
309 else
310 return perspectiveLH_NO(fovy, aspect, zNear, zFar);
311
312 }
313
314 template<typename T>
315 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveRH(T fovy, T aspect, T zNear, T zFar)
316 {
317 if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_ZO_BIT)
318 return perspectiveRH_ZO(fovy, aspect, zNear, zFar);
319 else
320 return perspectiveRH_NO(fovy, aspect, zNear, zFar);
321 }
322
323 template<typename T>
324 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspective(T fovy, T aspect, T zNear, T zFar)
325 {
326 if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_LH_ZO)
327 return perspectiveLH_ZO(fovy, aspect, zNear, zFar);
328 else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_LH_NO)
329 return perspectiveLH_NO(fovy, aspect, zNear, zFar);
330 else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_RH_ZO)
331 return perspectiveRH_ZO(fovy, aspect, zNear, zFar);
332 else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_RH_NO)
333 return perspectiveRH_NO(fovy, aspect, zNear, zFar);
334 }
335
336 template<typename T>
337 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveFovRH_ZO(T fov, T width, T height, T zNear, T zFar)
338 {
339 assert(width > static_cast<T>(0));
340 assert(height > static_cast<T>(0));
341 assert(fov > static_cast<T>(0));
342
343 T const rad = fov;
344 T const h = glm::cos(static_cast<T>(0.5) * rad) / glm::sin(static_cast<T>(0.5) * rad);
345 T const w = h * height / width; ///todo max(width , Height) / min(width , Height)?
346
347 mat<4, 4, T, defaultp> Result(static_cast<T>(0));
348 Result[0][0] = w;
349 Result[1][1] = h;
350 Result[2][2] = zFar / (zNear - zFar);
351 Result[2][3] = - static_cast<T>(1);
352 Result[3][2] = -(zFar * zNear) / (zFar - zNear);
353 return Result;
354 }
355
356 template<typename T>
357 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveFovRH_NO(T fov, T width, T height, T zNear, T zFar)
358 {
359 assert(width > static_cast<T>(0));
360 assert(height > static_cast<T>(0));
361 assert(fov > static_cast<T>(0));
362
363 T const rad = fov;
364 T const h = glm::cos(static_cast<T>(0.5) * rad) / glm::sin(static_cast<T>(0.5) * rad);
365 T const w = h * height / width; ///todo max(width , Height) / min(width , Height)?
366
367 mat<4, 4, T, defaultp> Result(static_cast<T>(0));
368 Result[0][0] = w;
369 Result[1][1] = h;
370 Result[2][2] = - (zFar + zNear) / (zFar - zNear);
371 Result[2][3] = - static_cast<T>(1);
372 Result[3][2] = - (static_cast<T>(2) * zFar * zNear) / (zFar - zNear);
373 return Result;
374 }
375
376 template<typename T>
377 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveFovLH_ZO(T fov, T width, T height, T zNear, T zFar)
378 {
379 assert(width > static_cast<T>(0));
380 assert(height > static_cast<T>(0));
381 assert(fov > static_cast<T>(0));
382
383 T const rad = fov;
384 T const h = glm::cos(static_cast<T>(0.5) * rad) / glm::sin(static_cast<T>(0.5) * rad);
385 T const w = h * height / width; ///todo max(width , Height) / min(width , Height)?
386
387 mat<4, 4, T, defaultp> Result(static_cast<T>(0));
388 Result[0][0] = w;
389 Result[1][1] = h;
390 Result[2][2] = zFar / (zFar - zNear);
391 Result[2][3] = static_cast<T>(1);
392 Result[3][2] = -(zFar * zNear) / (zFar - zNear);
393 return Result;
394 }
395
396 template<typename T>
397 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveFovLH_NO(T fov, T width, T height, T zNear, T zFar)
398 {
399 assert(width > static_cast<T>(0));
400 assert(height > static_cast<T>(0));
401 assert(fov > static_cast<T>(0));
402
403 T const rad = fov;
404 T const h = glm::cos(static_cast<T>(0.5) * rad) / glm::sin(static_cast<T>(0.5) * rad);
405 T const w = h * height / width; ///todo max(width , Height) / min(width , Height)?
406
407 mat<4, 4, T, defaultp> Result(static_cast<T>(0));
408 Result[0][0] = w;
409 Result[1][1] = h;
410 Result[2][2] = (zFar + zNear) / (zFar - zNear);
411 Result[2][3] = static_cast<T>(1);
412 Result[3][2] = - (static_cast<T>(2) * zFar * zNear) / (zFar - zNear);
413 return Result;
414 }
415
416 template<typename T>
417 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveFovZO(T fov, T width, T height, T zNear, T zFar)
418 {
419 if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_LH_BIT)
420 return perspectiveFovLH_ZO(fov, width, height, zNear, zFar);
421 else
422 return perspectiveFovRH_ZO(fov, width, height, zNear, zFar);
423 }
424
425 template<typename T>
426 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveFovNO(T fov, T width, T height, T zNear, T zFar)
427 {
428 if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_LH_BIT)
429 return perspectiveFovLH_NO(fov, width, height, zNear, zFar);
430 else
431 return perspectiveFovRH_NO(fov, width, height, zNear, zFar);
432 }
433
434 template<typename T>
435 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveFovLH(T fov, T width, T height, T zNear, T zFar)
436 {
437 if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_ZO_BIT)
438 return perspectiveFovLH_ZO(fov, width, height, zNear, zFar);
439 else
440 return perspectiveFovLH_NO(fov, width, height, zNear, zFar);
441 }
442
443 template<typename T>
444 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveFovRH(T fov, T width, T height, T zNear, T zFar)
445 {
446 if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_ZO_BIT)
447 return perspectiveFovRH_ZO(fov, width, height, zNear, zFar);
448 else
449 return perspectiveFovRH_NO(fov, width, height, zNear, zFar);
450 }
451
452 template<typename T>
453 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> perspectiveFov(T fov, T width, T height, T zNear, T zFar)
454 {
455 if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_LH_ZO)
456 return perspectiveFovLH_ZO(fov, width, height, zNear, zFar);
457 else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_LH_NO)
458 return perspectiveFovLH_NO(fov, width, height, zNear, zFar);
459 else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_RH_ZO)
460 return perspectiveFovRH_ZO(fov, width, height, zNear, zFar);
461 else if(GLM_CONFIG_CLIP_CONTROL == GLM_CLIP_CONTROL_RH_NO)
462 return perspectiveFovRH_NO(fov, width, height, zNear, zFar);
463 }
464
465 template<typename T>
466 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> infinitePerspectiveRH(T fovy, T aspect, T zNear)
467 {
468 T const range = tan(fovy / static_cast<T>(2)) * zNear;
469 T const left = -range * aspect;
470 T const right = range * aspect;
471 T const bottom = -range;
472 T const top = range;
473
474 mat<4, 4, T, defaultp> Result(static_cast<T>(0));
475 Result[0][0] = (static_cast<T>(2) * zNear) / (right - left);
476 Result[1][1] = (static_cast<T>(2) * zNear) / (top - bottom);
477 Result[2][2] = - static_cast<T>(1);
478 Result[2][3] = - static_cast<T>(1);
479 Result[3][2] = - static_cast<T>(2) * zNear;
480 return Result;
481 }
482
483 template<typename T>
484 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> infinitePerspectiveLH(T fovy, T aspect, T zNear)
485 {
486 T const range = tan(fovy / static_cast<T>(2)) * zNear;
487 T const left = -range * aspect;
488 T const right = range * aspect;
489 T const bottom = -range;
490 T const top = range;
491
492 mat<4, 4, T, defaultp> Result(T(0));
493 Result[0][0] = (static_cast<T>(2) * zNear) / (right - left);
494 Result[1][1] = (static_cast<T>(2) * zNear) / (top - bottom);
495 Result[2][2] = static_cast<T>(1);
496 Result[2][3] = static_cast<T>(1);
497 Result[3][2] = - static_cast<T>(2) * zNear;
498 return Result;
499 }
500
501 template<typename T>
502 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> infinitePerspective(T fovy, T aspect, T zNear)
503 {
504 if(GLM_CONFIG_CLIP_CONTROL & GLM_CLIP_CONTROL_LH_BIT)
505 return infinitePerspectiveLH(fovy, aspect, zNear);
506 else
507 return infinitePerspectiveRH(fovy, aspect, zNear);
508 }
509
510 // Infinite projection matrix: http://www.terathon.com/gdc07_lengyel.pdf
511 template<typename T>
512 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> tweakedInfinitePerspective(T fovy, T aspect, T zNear, T ep)
513 {
514 T const range = tan(fovy / static_cast<T>(2)) * zNear;
515 T const left = -range * aspect;
516 T const right = range * aspect;
517 T const bottom = -range;
518 T const top = range;
519
520 mat<4, 4, T, defaultp> Result(static_cast<T>(0));
521 Result[0][0] = (static_cast<T>(2) * zNear) / (right - left);
522 Result[1][1] = (static_cast<T>(2) * zNear) / (top - bottom);
523 Result[2][2] = ep - static_cast<T>(1);
524 Result[2][3] = static_cast<T>(-1);
525 Result[3][2] = (ep - static_cast<T>(2)) * zNear;
526 return Result;
527 }
528
529 template<typename T>
530 GLM_FUNC_QUALIFIER mat<4, 4, T, defaultp> tweakedInfinitePerspective(T fovy, T aspect, T zNear)
531 {
532 return tweakedInfinitePerspective(fovy, aspect, zNear, epsilon<T>());
533 }
534}//namespace glm