matrix_clip_space.inl 20 KB

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