test_projection.h 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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/projection.h"
  33. #include "core/string/print_string.h"
  34. #include "tests/test_macros.h"
  35. namespace TestProjection {
  36. TEST_CASE("[Projection] Default construct") {
  37. Projection p;
  38. CHECK(p.columns[0][0] == 1.0);
  39. CHECK(p.columns[0][1] == 0.0);
  40. CHECK(p.columns[0][2] == 0.0);
  41. CHECK(p.columns[0][3] == 0.0);
  42. CHECK(p.columns[1][0] == 0.0);
  43. CHECK(p.columns[1][1] == 1.0);
  44. CHECK(p.columns[1][2] == 0.0);
  45. CHECK(p.columns[1][3] == 0.0);
  46. CHECK(p.columns[2][0] == 0.0);
  47. CHECK(p.columns[2][1] == 0.0);
  48. CHECK(p.columns[2][2] == 1.0);
  49. CHECK(p.columns[2][3] == 0.0);
  50. CHECK(p.columns[3][0] == 0.0);
  51. CHECK(p.columns[3][1] == 0.0);
  52. CHECK(p.columns[3][2] == 0.0);
  53. CHECK(p.columns[3][3] == 1.0);
  54. }
  55. bool projection_is_equal_approx(const Projection &p_a, const Projection &p_b) {
  56. for (int i = 0; i < 4; i++) {
  57. for (int j = 0; j < 4; j++) {
  58. if (!Math::is_equal_approx(p_a.columns[i][j], p_b.columns[i][j])) {
  59. return false;
  60. }
  61. }
  62. }
  63. return true;
  64. }
  65. TEST_CASE("[Projection] Orthogonal projection matrix inversion") {
  66. Projection p = Projection::create_orthogonal(-125.0f, 125.0f, -125.0f, 125.0f, 0.01f, 25.0f);
  67. CHECK(projection_is_equal_approx(p.inverse() * p, Projection()));
  68. }
  69. TEST_CASE("[Projection] Perspective projection matrix inversion") {
  70. Projection p = Projection::create_perspective(90.0f, 1.77777f, 0.05f, 4000.0f);
  71. CHECK(projection_is_equal_approx(p.inverse() * p, Projection()));
  72. }
  73. } //namespace TestProjection
  74. #endif // TEST_PROJECTION_H