test_transform_3d.h 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*************************************************************************/
  2. /* test_transform_3d.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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_TRANSFORM_3D_H
  31. #define TEST_TRANSFORM_3D_H
  32. #include "core/math/transform_3d.h"
  33. #include "tests/test_macros.h"
  34. namespace TestTransform3D {
  35. Transform3D create_dummy_transform() {
  36. return Transform3D(Basis(Vector3(1, 2, 3), Vector3(4, 5, 6), Vector3(7, 8, 9)), Vector3(10, 11, 12));
  37. }
  38. Transform3D identity() {
  39. return Transform3D();
  40. }
  41. TEST_CASE("[Transform3D] translation") {
  42. Vector3 offset = Vector3(1, 2, 3);
  43. // Both versions should give the same result applied to identity.
  44. CHECK(identity().translated(offset) == identity().translated_local(offset));
  45. // Check both versions against left and right multiplications.
  46. Transform3D orig = create_dummy_transform();
  47. Transform3D T = identity().translated(offset);
  48. CHECK(orig.translated(offset) == T * orig);
  49. CHECK(orig.translated_local(offset) == orig * T);
  50. }
  51. TEST_CASE("[Transform3D] scaling") {
  52. Vector3 scaling = Vector3(1, 2, 3);
  53. // Both versions should give the same result applied to identity.
  54. CHECK(identity().scaled(scaling) == identity().scaled_local(scaling));
  55. // Check both versions against left and right multiplications.
  56. Transform3D orig = create_dummy_transform();
  57. Transform3D S = identity().scaled(scaling);
  58. CHECK(orig.scaled(scaling) == S * orig);
  59. CHECK(orig.scaled_local(scaling) == orig * S);
  60. }
  61. TEST_CASE("[Transform3D] rotation") {
  62. Vector3 axis = Vector3(1, 2, 3).normalized();
  63. real_t phi = 1.0;
  64. // Both versions should give the same result applied to identity.
  65. CHECK(identity().rotated(axis, phi) == identity().rotated_local(axis, phi));
  66. // Check both versions against left and right multiplications.
  67. Transform3D orig = create_dummy_transform();
  68. Transform3D R = identity().rotated(axis, phi);
  69. CHECK(orig.rotated(axis, phi) == R * orig);
  70. CHECK(orig.rotated_local(axis, phi) == orig * R);
  71. }
  72. } // namespace TestTransform3D
  73. #endif // TEST_TRANSFORM_3D_H