test_projection.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. /**************************************************************************/
  2. /* test_projection.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef TEST_PROJECTION_H
  31. #define TEST_PROJECTION_H
  32. #include "core/math/aabb.h"
  33. #include "core/math/plane.h"
  34. #include "core/math/projection.h"
  35. #include "core/math/rect2.h"
  36. #include "core/math/transform_3d.h"
  37. #include "thirdparty/doctest/doctest.h"
  38. namespace TestProjection {
  39. TEST_CASE("[Projection] Construction") {
  40. Projection default_proj;
  41. CHECK(default_proj[0].is_equal_approx(Vector4(1, 0, 0, 0)));
  42. CHECK(default_proj[1].is_equal_approx(Vector4(0, 1, 0, 0)));
  43. CHECK(default_proj[2].is_equal_approx(Vector4(0, 0, 1, 0)));
  44. CHECK(default_proj[3].is_equal_approx(Vector4(0, 0, 0, 1)));
  45. Projection from_vec4(
  46. Vector4(1, 2, 3, 4),
  47. Vector4(5, 6, 7, 8),
  48. Vector4(9, 10, 11, 12),
  49. Vector4(13, 14, 15, 16));
  50. CHECK(from_vec4[0].is_equal_approx(Vector4(1, 2, 3, 4)));
  51. CHECK(from_vec4[1].is_equal_approx(Vector4(5, 6, 7, 8)));
  52. CHECK(from_vec4[2].is_equal_approx(Vector4(9, 10, 11, 12)));
  53. CHECK(from_vec4[3].is_equal_approx(Vector4(13, 14, 15, 16)));
  54. Transform3D transform(
  55. Basis(
  56. Vector3(1, 0, 0),
  57. Vector3(0, 2, 0),
  58. Vector3(0, 0, 3)),
  59. Vector3(4, 5, 6));
  60. Projection from_transform(transform);
  61. CHECK(from_transform[0].is_equal_approx(Vector4(1, 0, 0, 0)));
  62. CHECK(from_transform[1].is_equal_approx(Vector4(0, 2, 0, 0)));
  63. CHECK(from_transform[2].is_equal_approx(Vector4(0, 0, 3, 0)));
  64. CHECK(from_transform[3].is_equal_approx(Vector4(4, 5, 6, 1)));
  65. }
  66. TEST_CASE("[Projection] set_zero()") {
  67. Projection proj;
  68. proj.set_zero();
  69. for (int i = 0; i < 4; i++) {
  70. for (int j = 0; j < 4; j++) {
  71. CHECK(proj.columns[i][j] == 0);
  72. }
  73. }
  74. }
  75. TEST_CASE("[Projection] set_identity()") {
  76. Projection proj;
  77. proj.set_identity();
  78. for (int i = 0; i < 4; i++) {
  79. for (int j = 0; j < 4; j++) {
  80. CHECK(proj.columns[i][j] == (i == j ? 1 : 0));
  81. }
  82. }
  83. }
  84. TEST_CASE("[Projection] determinant()") {
  85. Projection proj(
  86. Vector4(1, 5, 9, 13),
  87. Vector4(2, 6, 11, 15),
  88. Vector4(4, 7, 11, 15),
  89. Vector4(4, 8, 12, 16));
  90. CHECK(proj.determinant() == -12);
  91. }
  92. TEST_CASE("[Projection] Inverse and invert") {
  93. SUBCASE("[Projection] Arbitrary projection matrix inversion") {
  94. Projection proj(
  95. Vector4(1, 5, 9, 13),
  96. Vector4(2, 6, 11, 15),
  97. Vector4(4, 7, 11, 15),
  98. Vector4(4, 8, 12, 16));
  99. Projection inverse_truth(
  100. Vector4(-4.0 / 12, 0, 1, -8.0 / 12),
  101. Vector4(8.0 / 12, -1, -1, 16.0 / 12),
  102. Vector4(-20.0 / 12, 2, -1, 5.0 / 12),
  103. Vector4(1, -1, 1, -0.75));
  104. Projection inverse = proj.inverse();
  105. CHECK(inverse[0].is_equal_approx(inverse_truth[0]));
  106. CHECK(inverse[1].is_equal_approx(inverse_truth[1]));
  107. CHECK(inverse[2].is_equal_approx(inverse_truth[2]));
  108. CHECK(inverse[3].is_equal_approx(inverse_truth[3]));
  109. proj.invert();
  110. CHECK(proj[0].is_equal_approx(inverse_truth[0]));
  111. CHECK(proj[1].is_equal_approx(inverse_truth[1]));
  112. CHECK(proj[2].is_equal_approx(inverse_truth[2]));
  113. CHECK(proj[3].is_equal_approx(inverse_truth[3]));
  114. }
  115. SUBCASE("[Projection] Orthogonal projection matrix inversion") {
  116. Projection p = Projection::create_orthogonal(-125.0f, 125.0f, -125.0f, 125.0f, 0.01f, 25.0f);
  117. p = p.inverse() * p;
  118. CHECK(p[0].is_equal_approx(Vector4(1, 0, 0, 0)));
  119. CHECK(p[1].is_equal_approx(Vector4(0, 1, 0, 0)));
  120. CHECK(p[2].is_equal_approx(Vector4(0, 0, 1, 0)));
  121. CHECK(p[3].is_equal_approx(Vector4(0, 0, 0, 1)));
  122. }
  123. SUBCASE("[Projection] Perspective projection matrix inversion") {
  124. Projection p = Projection::create_perspective(90.0f, 1.77777f, 0.05f, 4000.0f);
  125. p = p.inverse() * p;
  126. CHECK(p[0].is_equal_approx(Vector4(1, 0, 0, 0)));
  127. CHECK(p[1].is_equal_approx(Vector4(0, 1, 0, 0)));
  128. CHECK(p[2].is_equal_approx(Vector4(0, 0, 1, 0)));
  129. CHECK(p[3].is_equal_approx(Vector4(0, 0, 0, 1)));
  130. }
  131. }
  132. TEST_CASE("[Projection] Matrix product") {
  133. Projection proj1(
  134. Vector4(1, 5, 9, 13),
  135. Vector4(2, 6, 11, 15),
  136. Vector4(4, 7, 11, 15),
  137. Vector4(4, 8, 12, 16));
  138. Projection proj2(
  139. Vector4(0, 1, 2, 3),
  140. Vector4(10, 11, 12, 13),
  141. Vector4(20, 21, 22, 23),
  142. Vector4(30, 31, 32, 33));
  143. Projection prod = proj1 * proj2;
  144. CHECK(prod[0].is_equal_approx(Vector4(22, 44, 69, 93)));
  145. CHECK(prod[1].is_equal_approx(Vector4(132, 304, 499, 683)));
  146. CHECK(prod[2].is_equal_approx(Vector4(242, 564, 929, 1273)));
  147. CHECK(prod[3].is_equal_approx(Vector4(352, 824, 1359, 1863)));
  148. }
  149. TEST_CASE("[Projection] Vector transformation") {
  150. Projection proj(
  151. Vector4(1, 5, 9, 13),
  152. Vector4(2, 6, 11, 15),
  153. Vector4(4, 7, 11, 15),
  154. Vector4(4, 8, 12, 16));
  155. Projection inverse(
  156. Vector4(-4.0 / 12, 0, 1, -8.0 / 12),
  157. Vector4(8.0 / 12, -1, -1, 16.0 / 12),
  158. Vector4(-20.0 / 12, 2, -1, 5.0 / 12),
  159. Vector4(1, -1, 1, -0.75));
  160. Vector4 vec4(1, 2, 3, 4);
  161. CHECK(proj.xform(vec4).is_equal_approx(Vector4(33, 70, 112, 152)));
  162. CHECK(proj.xform_inv(vec4).is_equal_approx(Vector4(90, 107, 111, 120)));
  163. Vector3 vec3(1, 2, 3);
  164. CHECK(proj.xform(vec3).is_equal_approx(Vector3(21, 46, 76) / 104));
  165. }
  166. TEST_CASE("[Projection] Plane transformation") {
  167. Projection proj(
  168. Vector4(1, 5, 9, 13),
  169. Vector4(2, 6, 11, 15),
  170. Vector4(4, 7, 11, 15),
  171. Vector4(4, 8, 12, 16));
  172. Plane plane(1, 2, 3, 4);
  173. CHECK(proj.xform4(plane).is_equal_approx(Plane(33, 70, 112, 152)));
  174. }
  175. TEST_CASE("[Projection] Values access") {
  176. Projection proj(
  177. Vector4(00, 01, 02, 03),
  178. Vector4(10, 11, 12, 13),
  179. Vector4(20, 21, 22, 23),
  180. Vector4(30, 31, 32, 33));
  181. CHECK(proj[0] == Vector4(00, 01, 02, 03));
  182. CHECK(proj[1] == Vector4(10, 11, 12, 13));
  183. CHECK(proj[2] == Vector4(20, 21, 22, 23));
  184. CHECK(proj[3] == Vector4(30, 31, 32, 33));
  185. }
  186. TEST_CASE("[Projection] flip_y() and flipped_y()") {
  187. Projection proj(
  188. Vector4(00, 01, 02, 03),
  189. Vector4(10, 11, 12, 13),
  190. Vector4(20, 21, 22, 23),
  191. Vector4(30, 31, 32, 33));
  192. Projection flipped = proj.flipped_y();
  193. CHECK(flipped[0] == proj[0]);
  194. CHECK(flipped[1] == -proj[1]);
  195. CHECK(flipped[2] == proj[2]);
  196. CHECK(flipped[3] == proj[3]);
  197. proj.flip_y();
  198. CHECK(proj[0] == flipped[0]);
  199. CHECK(proj[1] == flipped[1]);
  200. CHECK(proj[2] == flipped[2]);
  201. CHECK(proj[3] == flipped[3]);
  202. }
  203. TEST_CASE("[Projection] Jitter offset") {
  204. Projection proj(
  205. Vector4(00, 01, 02, 03),
  206. Vector4(10, 11, 12, 13),
  207. Vector4(20, 21, 22, 23),
  208. Vector4(30, 31, 32, 33));
  209. Projection offsetted = proj.jitter_offseted(Vector2(1, 2));
  210. CHECK(offsetted[0] == proj[0]);
  211. CHECK(offsetted[1] == proj[1]);
  212. CHECK(offsetted[2] == proj[2]);
  213. CHECK(offsetted[3] == proj[3] + Vector4(1, 2, 0, 0));
  214. proj.add_jitter_offset(Vector2(1, 2));
  215. CHECK(proj[0] == offsetted[0]);
  216. CHECK(proj[1] == offsetted[1]);
  217. CHECK(proj[2] == offsetted[2]);
  218. CHECK(proj[3] == offsetted[3]);
  219. }
  220. TEST_CASE("[Projection] Adjust znear") {
  221. Projection persp = Projection::create_perspective(90, 0.5, 1, 50, false);
  222. Projection adjusted = persp.perspective_znear_adjusted(2);
  223. CHECK(adjusted[0] == persp[0]);
  224. CHECK(adjusted[1] == persp[1]);
  225. CHECK(adjusted[2].is_equal_approx(Vector4(persp[2][0], persp[2][1], -1.083333, persp[2][3])));
  226. CHECK(adjusted[3].is_equal_approx(Vector4(persp[3][0], persp[3][1], -4.166666, persp[3][3])));
  227. persp.adjust_perspective_znear(2);
  228. CHECK(persp[0] == adjusted[0]);
  229. CHECK(persp[1] == adjusted[1]);
  230. CHECK(persp[2] == adjusted[2]);
  231. CHECK(persp[3] == adjusted[3]);
  232. }
  233. TEST_CASE("[Projection] Set light bias") {
  234. Projection proj;
  235. proj.set_light_bias();
  236. CHECK(proj[0] == Vector4(0.5, 0, 0, 0));
  237. CHECK(proj[1] == Vector4(0, 0.5, 0, 0));
  238. CHECK(proj[2] == Vector4(0, 0, 0.5, 0));
  239. CHECK(proj[3] == Vector4(0.5, 0.5, 0.5, 1));
  240. }
  241. TEST_CASE("[Projection] Depth correction") {
  242. Projection corrected = Projection::create_depth_correction(true);
  243. CHECK(corrected[0] == Vector4(1, 0, 0, 0));
  244. CHECK(corrected[1] == Vector4(0, -1, 0, 0));
  245. CHECK(corrected[2] == Vector4(0, 0, -0.5, 0));
  246. CHECK(corrected[3] == Vector4(0, 0, 0.5, 1));
  247. Projection proj;
  248. proj.set_depth_correction(true, true, true);
  249. CHECK(proj[0] == corrected[0]);
  250. CHECK(proj[1] == corrected[1]);
  251. CHECK(proj[2] == corrected[2]);
  252. CHECK(proj[3] == corrected[3]);
  253. proj.set_depth_correction(false, true, true);
  254. CHECK(proj[0] == Vector4(1, 0, 0, 0));
  255. CHECK(proj[1] == Vector4(0, 1, 0, 0));
  256. CHECK(proj[2] == Vector4(0, 0, -0.5, 0));
  257. CHECK(proj[3] == Vector4(0, 0, 0.5, 1));
  258. proj.set_depth_correction(false, false, true);
  259. CHECK(proj[0] == Vector4(1, 0, 0, 0));
  260. CHECK(proj[1] == Vector4(0, 1, 0, 0));
  261. CHECK(proj[2] == Vector4(0, 0, 0.5, 0));
  262. CHECK(proj[3] == Vector4(0, 0, 0.5, 1));
  263. proj.set_depth_correction(false, false, false);
  264. CHECK(proj[0] == Vector4(1, 0, 0, 0));
  265. CHECK(proj[1] == Vector4(0, 1, 0, 0));
  266. CHECK(proj[2] == Vector4(0, 0, 1, 0));
  267. CHECK(proj[3] == Vector4(0, 0, 0, 1));
  268. proj.set_depth_correction(true, true, false);
  269. CHECK(proj[0] == Vector4(1, 0, 0, 0));
  270. CHECK(proj[1] == Vector4(0, -1, 0, 0));
  271. CHECK(proj[2] == Vector4(0, 0, -1, 0));
  272. CHECK(proj[3] == Vector4(0, 0, 0, 1));
  273. }
  274. TEST_CASE("[Projection] Light atlas rect") {
  275. Projection rect = Projection::create_light_atlas_rect(Rect2(1, 2, 30, 40));
  276. CHECK(rect[0] == Vector4(30, 0, 0, 0));
  277. CHECK(rect[1] == Vector4(0, 40, 0, 0));
  278. CHECK(rect[2] == Vector4(0, 0, 1, 0));
  279. CHECK(rect[3] == Vector4(1, 2, 0, 1));
  280. Projection proj;
  281. proj.set_light_atlas_rect(Rect2(1, 2, 30, 40));
  282. CHECK(proj[0] == rect[0]);
  283. CHECK(proj[1] == rect[1]);
  284. CHECK(proj[2] == rect[2]);
  285. CHECK(proj[3] == rect[3]);
  286. }
  287. TEST_CASE("[Projection] Make scale") {
  288. Projection proj;
  289. proj.make_scale(Vector3(2, 3, 4));
  290. CHECK(proj[0] == Vector4(2, 0, 0, 0));
  291. CHECK(proj[1] == Vector4(0, 3, 0, 0));
  292. CHECK(proj[2] == Vector4(0, 0, 4, 0));
  293. CHECK(proj[3] == Vector4(0, 0, 0, 1));
  294. }
  295. TEST_CASE("[Projection] Scale translate to fit aabb") {
  296. Projection fit = Projection::create_fit_aabb(AABB(Vector3(), Vector3(0.1, 0.2, 0.4)));
  297. CHECK(fit[0] == Vector4(20, 0, 0, 0));
  298. CHECK(fit[1] == Vector4(0, 10, 0, 0));
  299. CHECK(fit[2] == Vector4(0, 0, 5, 0));
  300. CHECK(fit[3] == Vector4(-1, -1, -1, 1));
  301. Projection proj;
  302. proj.scale_translate_to_fit(AABB(Vector3(), Vector3(0.1, 0.2, 0.4)));
  303. CHECK(proj[0] == fit[0]);
  304. CHECK(proj[1] == fit[1]);
  305. CHECK(proj[2] == fit[2]);
  306. CHECK(proj[3] == fit[3]);
  307. }
  308. TEST_CASE("[Projection] Perspective") {
  309. Projection persp = Projection::create_perspective(90, 0.5, 5, 15, false);
  310. CHECK(persp[0].is_equal_approx(Vector4(2, 0, 0, 0)));
  311. CHECK(persp[1].is_equal_approx(Vector4(0, 1, 0, 0)));
  312. CHECK(persp[2].is_equal_approx(Vector4(0, 0, -2, -1)));
  313. CHECK(persp[3].is_equal_approx(Vector4(0, 0, -15, 0)));
  314. Projection proj;
  315. proj.set_perspective(90, 0.5, 5, 15, false);
  316. CHECK(proj[0] == persp[0]);
  317. CHECK(proj[1] == persp[1]);
  318. CHECK(proj[2] == persp[2]);
  319. CHECK(proj[3] == persp[3]);
  320. }
  321. TEST_CASE("[Projection] Frustum") {
  322. Projection frustum = Projection::create_frustum(15, 20, 10, 12, 5, 15);
  323. CHECK(frustum[0].is_equal_approx(Vector4(2, 0, 0, 0)));
  324. CHECK(frustum[1].is_equal_approx(Vector4(0, 5, 0, 0)));
  325. CHECK(frustum[2].is_equal_approx(Vector4(7, 11, -2, -1)));
  326. CHECK(frustum[3].is_equal_approx(Vector4(0, 0, -15, 0)));
  327. Projection proj;
  328. proj.set_frustum(15, 20, 10, 12, 5, 15);
  329. CHECK(proj[0] == frustum[0]);
  330. CHECK(proj[1] == frustum[1]);
  331. CHECK(proj[2] == frustum[2]);
  332. CHECK(proj[3] == frustum[3]);
  333. }
  334. TEST_CASE("[Projection] Ortho") {
  335. Projection ortho = Projection::create_orthogonal(15, 20, 10, 12, 5, 15);
  336. CHECK(ortho[0].is_equal_approx(Vector4(0.4, 0, 0, 0)));
  337. CHECK(ortho[1].is_equal_approx(Vector4(0, 1, 0, 0)));
  338. CHECK(ortho[2].is_equal_approx(Vector4(0, 0, -0.2, 0)));
  339. CHECK(ortho[3].is_equal_approx(Vector4(-7, -11, -2, 1)));
  340. Projection proj;
  341. proj.set_orthogonal(15, 20, 10, 12, 5, 15);
  342. CHECK(proj[0] == ortho[0]);
  343. CHECK(proj[1] == ortho[1]);
  344. CHECK(proj[2] == ortho[2]);
  345. CHECK(proj[3] == ortho[3]);
  346. }
  347. TEST_CASE("[Projection] get_fovy()") {
  348. double fov = Projection::get_fovy(90, 0.5);
  349. CHECK(fov == doctest::Approx(53.1301));
  350. }
  351. TEST_CASE("[Projection] Perspective values extraction") {
  352. Projection persp = Projection::create_perspective(90, 0.5, 1, 50, true);
  353. double znear = persp.get_z_near();
  354. double zfar = persp.get_z_far();
  355. double aspect = persp.get_aspect();
  356. double fov = persp.get_fov();
  357. CHECK(znear == doctest::Approx(1));
  358. CHECK(zfar == doctest::Approx(50));
  359. CHECK(aspect == doctest::Approx(0.5));
  360. CHECK(fov == doctest::Approx(90));
  361. }
  362. TEST_CASE("[Projection] Orthographic check") {
  363. Projection persp = Projection::create_perspective(90, 0.5, 1, 50, false);
  364. Projection ortho = Projection::create_orthogonal(15, 20, 10, 12, 5, 15);
  365. CHECK(!persp.is_orthogonal());
  366. CHECK(ortho.is_orthogonal());
  367. }
  368. TEST_CASE("[Projection] Planes extraction") {
  369. Projection persp = Projection::create_perspective(90, 1, 1, 40, false);
  370. Vector<Plane> planes = persp.get_projection_planes(Transform3D());
  371. CHECK(planes[Projection::PLANE_NEAR].normalized().is_equal_approx(Plane(0, 0, 1, -1)));
  372. CHECK(planes[Projection::PLANE_FAR].normalized().is_equal_approx(Plane(0, 0, -1, 40)));
  373. CHECK(planes[Projection::PLANE_LEFT].normalized().is_equal_approx(Plane(-0.707107, 0, 0.707107, 0)));
  374. CHECK(planes[Projection::PLANE_TOP].normalized().is_equal_approx(Plane(0, 0.707107, 0.707107, 0)));
  375. CHECK(planes[Projection::PLANE_RIGHT].normalized().is_equal_approx(Plane(0.707107, 0, 0.707107, 0)));
  376. CHECK(planes[Projection::PLANE_BOTTOM].normalized().is_equal_approx(Plane(0, -0.707107, 0.707107, 0)));
  377. Plane plane_array[6]{
  378. persp.get_projection_plane(Projection::PLANE_NEAR),
  379. persp.get_projection_plane(Projection::PLANE_FAR),
  380. persp.get_projection_plane(Projection::PLANE_LEFT),
  381. persp.get_projection_plane(Projection::PLANE_TOP),
  382. persp.get_projection_plane(Projection::PLANE_RIGHT),
  383. persp.get_projection_plane(Projection::PLANE_BOTTOM)
  384. };
  385. CHECK(plane_array[Projection::PLANE_NEAR].normalized().is_equal_approx(planes[Projection::PLANE_NEAR].normalized()));
  386. CHECK(plane_array[Projection::PLANE_FAR].normalized().is_equal_approx(planes[Projection::PLANE_FAR].normalized()));
  387. CHECK(plane_array[Projection::PLANE_LEFT].normalized().is_equal_approx(planes[Projection::PLANE_LEFT].normalized()));
  388. CHECK(plane_array[Projection::PLANE_TOP].normalized().is_equal_approx(planes[Projection::PLANE_TOP].normalized()));
  389. CHECK(plane_array[Projection::PLANE_RIGHT].normalized().is_equal_approx(planes[Projection::PLANE_RIGHT].normalized()));
  390. CHECK(plane_array[Projection::PLANE_BOTTOM].normalized().is_equal_approx(planes[Projection::PLANE_BOTTOM].normalized()));
  391. }
  392. TEST_CASE("[Projection] Half extents") {
  393. Projection persp = Projection::create_perspective(90, 1, 1, 40, false);
  394. Vector2 ne = persp.get_viewport_half_extents();
  395. Vector2 fe = persp.get_far_plane_half_extents();
  396. CHECK(ne.is_equal_approx(Vector2(1, 1) * 1));
  397. CHECK(fe.is_equal_approx(Vector2(1, 1) * 40));
  398. }
  399. TEST_CASE("[Projection] Endpoints") {
  400. Projection persp = Projection::create_perspective(90, 1, 1, 40, false);
  401. Vector3 ep[8];
  402. persp.get_endpoints(Transform3D(), ep);
  403. CHECK(ep[0].is_equal_approx(Vector3(-1, 1, -1) * 40));
  404. CHECK(ep[1].is_equal_approx(Vector3(-1, -1, -1) * 40));
  405. CHECK(ep[2].is_equal_approx(Vector3(1, 1, -1) * 40));
  406. CHECK(ep[3].is_equal_approx(Vector3(1, -1, -1) * 40));
  407. CHECK(ep[4].is_equal_approx(Vector3(-1, 1, -1) * 1));
  408. CHECK(ep[5].is_equal_approx(Vector3(-1, -1, -1) * 1));
  409. CHECK(ep[6].is_equal_approx(Vector3(1, 1, -1) * 1));
  410. CHECK(ep[7].is_equal_approx(Vector3(1, -1, -1) * 1));
  411. }
  412. } //namespace TestProjection
  413. #endif // TEST_PROJECTION_H