WhiteBoxSelectionTest.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "Viewport/WhiteBoxManipulatorBounds.h"
  9. #include "WhiteBoxTestFixtures.h"
  10. #include <AzCore/UnitTest/TestTypes.h>
  11. #include <AzCore/std/containers/array.h>
  12. #include <AzCore/std/containers/vector.h>
  13. #include <AzTest/AzTest.h>
  14. #include <AzToolsFramework/Picking/BoundInterface.h>
  15. #include <AzToolsFramework/UnitTest/AzToolsFrameworkTestHelpers.h>
  16. namespace UnitTest
  17. {
  18. TEST_F(WhiteBoxTestFixture, SelectUnitQuadFrontFaceShouldIntersect)
  19. {
  20. namespace Api = WhiteBox::Api;
  21. Api::InitializeAsUnitQuad(*m_whiteBox);
  22. auto faceHandles = Api::MeshFaceHandles(*m_whiteBox);
  23. WhiteBox::ManipulatorBoundPolygon polygonBounds(AzToolsFramework::Picking::RegisteredBoundId{});
  24. polygonBounds.m_polygonBound.m_triangles = Api::FacesPositions(*m_whiteBox, faceHandles);
  25. float distance = 0.0f;
  26. bool intersected = polygonBounds.IntersectRay(AZ::Vector3(0, -10, 0), AZ::Vector3(0, 1, 0), distance);
  27. ASSERT_TRUE(intersected);
  28. }
  29. TEST_F(WhiteBoxTestFixture, SelectUnitQuadBackFaceShouldNotIntersect)
  30. {
  31. namespace Api = WhiteBox::Api;
  32. Api::InitializeAsUnitQuad(*m_whiteBox);
  33. auto faceHandles = Api::MeshFaceHandles(*m_whiteBox);
  34. WhiteBox::ManipulatorBoundPolygon polygonBounds(AzToolsFramework::Picking::RegisteredBoundId{});
  35. polygonBounds.m_polygonBound.m_triangles = Api::FacesPositions(*m_whiteBox, faceHandles);
  36. float distance = 0.0f;
  37. bool intersected = polygonBounds.IntersectRay(AZ::Vector3(0, 10, 0), AZ::Vector3(0, -1, 0), distance);
  38. ASSERT_FALSE(intersected);
  39. }
  40. TEST_F(WhiteBoxTestFixture, SelectUnitQuadOutsideShouldNotIntersect)
  41. {
  42. namespace Api = WhiteBox::Api;
  43. Api::InitializeAsUnitQuad(*m_whiteBox);
  44. auto faceHandles = Api::MeshFaceHandles(*m_whiteBox);
  45. WhiteBox::ManipulatorBoundPolygon polygonBounds(AzToolsFramework::Picking::RegisteredBoundId{});
  46. polygonBounds.m_polygonBound.m_triangles = Api::FacesPositions(*m_whiteBox, faceHandles);
  47. float distance = 0.0f;
  48. bool intersected = polygonBounds.IntersectRay(AZ::Vector3(2, -10, 0), AZ::Vector3(0, 1, 0), distance);
  49. ASSERT_FALSE(intersected);
  50. }
  51. } // namespace UnitTest