1f9b284de2
Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> # Conflicts: # Code/Editor/Plugins/ComponentEntityEditorPlugin/ComponentEntityEditorPlugin_precompiled.h # Code/Editor/Plugins/EditorCommon/EditorCommon_precompiled.h # Code/Editor/Plugins/EditorCommon/stdafx.cpp # Code/Editor/Plugins/FFMPEGPlugin/FFMPEGPlugin_precompiled.h # Code/Editor/Plugins/PerforcePlugin/PerforcePlugin_precompiled.h # Code/Editor/Plugins/ProjectSettingsTool/ProjectSettingsTool_precompiled.h # Code/Framework/AzToolsFramework/AzToolsFramework/AzToolsFramework_precompiled.h # Code/Tools/AssetProcessor/native/precompiled.h # Code/Tools/Standalone/StandaloneTools_precompiled.h # Gems/AssetMemoryAnalyzer/Code/Source/AssetMemoryAnalyzer_precompiled.h # Gems/Atom/Asset/ImageProcessingAtom/Code/Source/ImageProcessing_precompiled.h # Gems/Atom/RHI/DX12/Code/Source/RHI/Atom_RHI_DX12_precompiled.h # Gems/Atom/RHI/Metal/Code/Include/Platform/Mac/Atom_RHI_Metal_precompiled_Platform.h # Gems/Atom/RHI/Metal/Code/Include/Platform/iOS/Atom_RHI_Metal_precompiled_Platform.h # Gems/Atom/RHI/Metal/Code/Source/Atom_RHI_Metal_precompiled.h # Gems/Atom/RHI/Metal/Code/atom_rhi_metal_common_files.cmake # Gems/Atom/RHI/Null/Code/Source/Atom_RHI_Null_precompiled.h # Gems/Atom/RHI/Null/Code/atom_rhi_null_common_files.cmake # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Android/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Linux/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Mac/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Windows/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Source/Atom_RHI_Vulkan_precompiled.h # Gems/Atom/RHI/Vulkan/Code/Source/RHI/SwapChain.cpp # Gems/Atom/RHI/Vulkan/Code/atom_rhi_vulkan_common_files.cmake # Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomFont_precompiled.h # Gems/Blast/Code/Source/StdAfx.cpp # Gems/Camera/Code/Source/Camera_precompiled.h # Gems/EMotionFX/Code/Source/EMotionFX_precompiled.h # Gems/FastNoise/Code/Source/FastNoise_precompiled.h # Gems/Gestures/Code/Source/Gestures_precompiled.h # Gems/GradientSignal/Code/Source/GradientSignal_precompiled.h # Gems/GraphCanvas/Code/precompiled.h # Gems/ImGui/Code/Source/ImGui_precompiled.h # Gems/InAppPurchases/Code/Source/InAppPurchases_precompiled.h # Gems/LmbrCentral/Code/Source/LmbrCentral_precompiled.h # Gems/LmbrCentral/Code/Tests/ShapeGeometryUtilTest.cpp # Gems/LyShine/Code/Editor/UiCanvasEditor_precompiled.h # Gems/LyShine/Code/Source/Animation/LyShine_precompiled.h # Gems/LyShine/Code/Source/LyShine_precompiled.h # Gems/LyShineExamples/Code/Source/LyShineExamples_precompiled.h # Gems/Maestro/Code/Source/Cinematics/Maestro_precompiled.h # Gems/Maestro/Code/Source/Maestro_precompiled.h # Gems/MessagePopup/Code/Source/MessagePopup_precompiled.h # Gems/Metastream/Code/Source/Metastream_precompiled.h # Gems/Microphone/Code/Source/Microphone_precompiled.h # Gems/Multiplayer/Code/Source/Multiplayer_precompiled.h # Gems/PhysX/Code/NumericalMethods/Source/NumericalMethods_precompiled.h # Gems/PhysX/Code/Source/PhysXUnsupported_precompiled.h # Gems/PhysX/Code/Source/PhysX_precompiled.h # Gems/PhysX/Code/physx_unsupported_files.cmake # Gems/PhysXDebug/Code/Source/PhysXDebugUnsupported_precompiled.h # Gems/PhysXDebug/Code/Source/PhysXDebug_precompiled.h # Gems/ScriptCanvas/Code/Editor/precompiled.h # Gems/ScriptCanvas/Code/Source/precompiled.h # Gems/ScriptCanvasDeveloper/Code/Source/precompiled.h # Gems/ScriptCanvasPhysics/Code/Source/ScriptCanvasPhysics_precompiled.h # Gems/ScriptEvents/Code/Source/precompiled.h # Gems/ScriptEvents/Code/Tests/Editor/EditorTests.cpp # Gems/ScriptedEntityTweener/Code/Source/ScriptedEntityTweener_precompiled.h # Gems/SliceFavorites/Code/Source/SliceFavorites_precompiled.h # Gems/StartingPointCamera/Code/Source/StartingPointCamera_precompiled.h # Gems/StartingPointInput/Code/Source/StartingPointInput_precompiled.h # Gems/StartingPointMovement/Code/Source/StartingPointMovement_precompiled.h # Gems/SurfaceData/Code/Source/SurfaceData_precompiled.h # Gems/TextureAtlas/Code/Source/TextureAtlas_precompiled.h # Gems/TickBusOrderViewer/Code/Source/TickBusOrderViewer_precompiled.h # Gems/Twitch/Code/Source/Twitch_precompiled.h # Gems/VirtualGamepad/Code/Source/VirtualGamepad_precompiled.h # Gems/WhiteBox/Code/Source/WhiteBoxUnsupported_precompiled.h # Gems/WhiteBox/Code/Source/WhiteBox_precompiled.h
353 lines
14 KiB
C++
353 lines
14 KiB
C++
/*
|
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*
|
|
*/
|
|
|
|
#include <AzTest/AzTest.h>
|
|
|
|
#include <AzCore/Component/ComponentApplication.h>
|
|
#include <AzCore/Math/Random.h>
|
|
#include <AzFramework/Components/TransformComponent.h>
|
|
#include <Shape/CapsuleShapeComponent.h>
|
|
#include <AzCore/UnitTest/TestTypes.h>
|
|
|
|
namespace UnitTest
|
|
{
|
|
class CapsuleShapeTest
|
|
: public AllocatorsFixture
|
|
{
|
|
AZStd::unique_ptr<AZ::SerializeContext> m_serializeContext;
|
|
AZStd::unique_ptr<AZ::ComponentDescriptor> m_transformComponentDescriptor;
|
|
AZStd::unique_ptr<AZ::ComponentDescriptor> m_capsuleShapeComponentDescriptor;
|
|
|
|
public:
|
|
void SetUp() override
|
|
{
|
|
AllocatorsFixture::SetUp();
|
|
m_serializeContext = AZStd::make_unique<AZ::SerializeContext>();
|
|
|
|
m_transformComponentDescriptor = AZStd::unique_ptr<AZ::ComponentDescriptor>(AzFramework::TransformComponent::CreateDescriptor());
|
|
m_transformComponentDescriptor->Reflect(&(*m_serializeContext));
|
|
m_capsuleShapeComponentDescriptor = AZStd::unique_ptr<AZ::ComponentDescriptor>(LmbrCentral::CapsuleShapeComponent::CreateDescriptor());
|
|
m_capsuleShapeComponentDescriptor->Reflect(&(*m_serializeContext));
|
|
}
|
|
|
|
void TearDown() override
|
|
{
|
|
m_transformComponentDescriptor.reset();
|
|
m_capsuleShapeComponentDescriptor.reset();
|
|
m_serializeContext.reset();
|
|
AllocatorsFixture::TearDown();
|
|
}
|
|
};
|
|
|
|
void CreateCapsule(const AZ::Transform& transform, const float radius, const float height, AZ::Entity& entity)
|
|
{
|
|
entity.CreateComponent<LmbrCentral::CapsuleShapeComponent>();
|
|
entity.CreateComponent<AzFramework::TransformComponent>();
|
|
|
|
entity.Init();
|
|
entity.Activate();
|
|
|
|
AZ::TransformBus::Event(entity.GetId(), &AZ::TransformBus::Events::SetWorldTM, transform);
|
|
|
|
LmbrCentral::CapsuleShapeComponentRequestsBus::Event(
|
|
entity.GetId(), &LmbrCentral::CapsuleShapeComponentRequestsBus::Events::SetHeight, height);
|
|
LmbrCentral::CapsuleShapeComponentRequestsBus::Event(
|
|
entity.GetId(), &LmbrCentral::CapsuleShapeComponentRequestsBus::Events::SetRadius, radius);
|
|
}
|
|
|
|
TEST_F(CapsuleShapeTest, GetRayIntersectCapsuleSuccess1)
|
|
{
|
|
AZ::Entity entity;
|
|
CreateCapsule(AZ::Transform::CreateFromQuaternionAndTranslation(
|
|
AZ::Quaternion::CreateIdentity(), AZ::Vector3(0.0f, 0.0f, 5.0f)),
|
|
0.5f, 5.0f, entity);
|
|
|
|
bool rayHit = false;
|
|
float distance;
|
|
LmbrCentral::ShapeComponentRequestsBus::EventResult(
|
|
rayHit, entity.GetId(), &LmbrCentral::ShapeComponentRequests::IntersectRay,
|
|
AZ::Vector3(0.0f, 5.0f, 5.0f), AZ::Vector3(0.0f, -1.0f, 0.0f), distance);
|
|
|
|
EXPECT_TRUE(rayHit);
|
|
EXPECT_NEAR(distance, 4.5f, 1e-4f);
|
|
}
|
|
|
|
TEST_F(CapsuleShapeTest, GetRayIntersectCapsuleSuccess2)
|
|
{
|
|
AZ::Entity entity;
|
|
CreateCapsule(AZ::Transform::CreateFromQuaternionAndTranslation(
|
|
AZ::Quaternion::CreateFromAxisAngle(AZ::Vector3::CreateAxisX(), AZ::Constants::HalfPi),
|
|
AZ::Vector3(-10.0f, -10.0f, 0.0f)),
|
|
1.0f, 5.0f, entity);
|
|
|
|
bool rayHit = false;
|
|
float distance;
|
|
LmbrCentral::ShapeComponentRequestsBus::EventResult(
|
|
rayHit, entity.GetId(), &LmbrCentral::ShapeComponentRequests::IntersectRay,
|
|
AZ::Vector3(-10.0f, -20.0f, 0.0f), AZ::Vector3(0.0f, 1.0f, 0.0f), distance);
|
|
|
|
EXPECT_TRUE(rayHit);
|
|
EXPECT_NEAR(distance, 7.5f, 1e-2f);
|
|
}
|
|
|
|
TEST_F(CapsuleShapeTest, GetRayIntersectCapsuleSuccess3)
|
|
{
|
|
AZ::Entity entity;
|
|
CreateCapsule(AZ::Transform::CreateFromQuaternionAndTranslation(
|
|
AZ::Quaternion::CreateFromAxisAngle(AZ::Vector3::CreateAxisX(), AZ::Constants::HalfPi),
|
|
AZ::Vector3(-10.0f, -10.0f, 0.0f)),
|
|
1.0f, 5.0f, entity);
|
|
|
|
bool rayHit = false;
|
|
float distance;
|
|
LmbrCentral::ShapeComponentRequestsBus::EventResult(
|
|
rayHit, entity.GetId(), &LmbrCentral::ShapeComponentRequests::IntersectRay,
|
|
AZ::Vector3(-10.0f, -10.0f, -10.0f), AZ::Vector3(0.0f, 0.0f, 1.0f), distance);
|
|
|
|
EXPECT_TRUE(rayHit);
|
|
EXPECT_NEAR(distance, 9.0f, 1e-2f);
|
|
}
|
|
|
|
// test sphere case
|
|
TEST_F(CapsuleShapeTest, GetRayIntersectCapsuleSuccess4)
|
|
{
|
|
AZ::Entity entity;
|
|
CreateCapsule(AZ::Transform::CreateFromQuaternionAndTranslation(
|
|
AZ::Quaternion::CreateFromAxisAngle(AZ::Vector3::CreateAxisX(), AZ::Constants::HalfPi),
|
|
AZ::Vector3(-10.0f, -10.0f, 0.0f)),
|
|
1.0f, 0.0f, entity);
|
|
|
|
bool rayHit = false;
|
|
float distance;
|
|
LmbrCentral::ShapeComponentRequestsBus::EventResult(
|
|
rayHit, entity.GetId(), &LmbrCentral::ShapeComponentRequests::IntersectRay,
|
|
AZ::Vector3(-10.0f, -10.0f, -10.0f), AZ::Vector3(0.0f, 0.0f, 1.0f), distance);
|
|
|
|
EXPECT_TRUE(rayHit);
|
|
EXPECT_NEAR(distance, 9.0f, 1e-2f);
|
|
}
|
|
|
|
// transformed scaled
|
|
TEST_F(CapsuleShapeTest, GetRayIntersectCapsuleSuccess5)
|
|
{
|
|
AZ::Entity entity;
|
|
CreateCapsule(
|
|
AZ::Transform::CreateTranslation(AZ::Vector3(-4.0f, -12.0f, -3.0f)) *
|
|
AZ::Transform::CreateRotationX(AZ::Constants::HalfPi) *
|
|
AZ::Transform::CreateUniformScale(6.0f),
|
|
0.25f, 1.5f, entity);
|
|
|
|
bool rayHit = false;
|
|
float distance;
|
|
LmbrCentral::ShapeComponentRequestsBus::EventResult(
|
|
rayHit, entity.GetId(), &LmbrCentral::ShapeComponentRequests::IntersectRay,
|
|
AZ::Vector3(-4.0f, -21.0f, -3.0f), AZ::Vector3(0.0f, 1.0f, 0.0f), distance);
|
|
|
|
EXPECT_TRUE(rayHit);
|
|
EXPECT_NEAR(distance, 4.5f, 1e-2f);
|
|
}
|
|
|
|
TEST_F(CapsuleShapeTest, GetRayIntersectCapsuleFailure)
|
|
{
|
|
AZ::Entity entity;
|
|
CreateCapsule(AZ::Transform::CreateFromQuaternionAndTranslation(
|
|
AZ::Quaternion::CreateIdentity(), AZ::Vector3(0.0f, -10.0f, 0.0f)),
|
|
5.0f, 1.0f, entity);
|
|
|
|
bool rayHit = false;
|
|
float distance;
|
|
LmbrCentral::ShapeComponentRequestsBus::EventResult(
|
|
rayHit, entity.GetId(), &LmbrCentral::ShapeComponentRequests::IntersectRay,
|
|
AZ::Vector3(0.0f, 0.0f, 0.0f), AZ::Vector3(1.0f, 0.0f, 0.0f), distance);
|
|
|
|
EXPECT_FALSE(rayHit);
|
|
}
|
|
|
|
TEST_F(CapsuleShapeTest, GetAabb1)
|
|
{
|
|
AZ::Entity entity;
|
|
CreateCapsule(AZ::Transform::CreateFromQuaternionAndTranslation(
|
|
AZ::Quaternion::CreateIdentity(), AZ::Vector3(0.0f, -10.0f, 0.0f)),
|
|
5.0f, 1.0f, entity);
|
|
|
|
AZ::Aabb aabb;
|
|
LmbrCentral::ShapeComponentRequestsBus::EventResult(
|
|
aabb, entity.GetId(), &LmbrCentral::ShapeComponentRequests::GetEncompassingAabb);
|
|
|
|
EXPECT_TRUE(aabb.GetMin().IsClose(AZ::Vector3(-5.0f, -15.0f, -5.0f)));
|
|
EXPECT_TRUE(aabb.GetMax().IsClose(AZ::Vector3(5.0f, -5.0f, 5.0f)));
|
|
}
|
|
|
|
TEST_F(CapsuleShapeTest, GetAabb2)
|
|
{
|
|
AZ::Entity entity;
|
|
CreateCapsule(AZ::Transform::CreateFromQuaternionAndTranslation(
|
|
AZ::Quaternion::CreateFromAxisAngle(AZ::Vector3::CreateAxisX(), AZ::Constants::HalfPi) *
|
|
AZ::Quaternion::CreateFromAxisAngle(AZ::Vector3::CreateAxisY(), AZ::Constants::QuarterPi), AZ::Vector3(-10.0f, -10.0f, 0.0f)),
|
|
1.0f, 5.0f, entity);
|
|
|
|
AZ::Aabb aabb;
|
|
LmbrCentral::ShapeComponentRequestsBus::EventResult(
|
|
aabb, entity.GetId(), &LmbrCentral::ShapeComponentRequests::GetEncompassingAabb);
|
|
|
|
EXPECT_TRUE(aabb.GetMin().IsClose(AZ::Vector3(-12.0606f, -12.0606f, -1.0f)));
|
|
EXPECT_TRUE(aabb.GetMax().IsClose(AZ::Vector3(-7.9393f, -7.9393f, 1.0f)));
|
|
}
|
|
|
|
// test with scale
|
|
TEST_F(CapsuleShapeTest, GetAabb3)
|
|
{
|
|
AZ::Entity entity;
|
|
CreateCapsule(AZ::Transform::CreateUniformScale(3.5f), 2.0f, 4.0f, entity);
|
|
|
|
AZ::Aabb aabb;
|
|
LmbrCentral::ShapeComponentRequestsBus::EventResult(
|
|
aabb, entity.GetId(), &LmbrCentral::ShapeComponentRequests::GetEncompassingAabb);
|
|
|
|
EXPECT_TRUE(aabb.GetMin().IsClose(AZ::Vector3(-7.0f, -7.0f, -7.0f)));
|
|
EXPECT_TRUE(aabb.GetMax().IsClose(AZ::Vector3(7.0f, 7.0f, 7.0f)));
|
|
}
|
|
|
|
// test with scale and translation
|
|
TEST_F(CapsuleShapeTest, GetAabb4)
|
|
{
|
|
AZ::Entity entity;
|
|
CreateCapsule(
|
|
AZ::Transform::CreateTranslation(AZ::Vector3(5.0f, 20.0f, 0.0f)) *
|
|
AZ::Transform::CreateUniformScale(2.5f), 1.0f, 5.0f, entity);
|
|
|
|
AZ::Aabb aabb;
|
|
LmbrCentral::ShapeComponentRequestsBus::EventResult(
|
|
aabb, entity.GetId(), &LmbrCentral::ShapeComponentRequests::GetEncompassingAabb);
|
|
|
|
EXPECT_TRUE(aabb.GetMin().IsClose(AZ::Vector3(2.5f, 17.5f, -6.25f)));
|
|
EXPECT_TRUE(aabb.GetMax().IsClose(AZ::Vector3(7.5f, 22.5f, 6.25f)));
|
|
}
|
|
|
|
TEST_F(CapsuleShapeTest, GetTransformAndLocalBounds1)
|
|
{
|
|
AZ::Entity entity;
|
|
AZ::Transform transformIn = AZ::Transform::CreateIdentity();
|
|
CreateCapsule(transformIn, 5.0f, 2.0f, entity);
|
|
|
|
AZ::Transform transformOut;
|
|
AZ::Aabb aabb;
|
|
LmbrCentral::ShapeComponentRequestsBus::Event(entity.GetId(), &LmbrCentral::ShapeComponentRequests::GetTransformAndLocalBounds, transformOut, aabb);
|
|
|
|
EXPECT_TRUE(transformOut.IsClose(transformIn));
|
|
EXPECT_TRUE(aabb.GetMin().IsClose(AZ::Vector3(-5.0f, -5.0f, -5.0f)));
|
|
EXPECT_TRUE(aabb.GetMax().IsClose(AZ::Vector3(5.0f, 5.0f, 5.0f)));
|
|
}
|
|
|
|
TEST_F(CapsuleShapeTest, GetTransformAndLocalBounds2)
|
|
{
|
|
AZ::Entity entity;
|
|
AZ::Transform transformIn = AZ::Transform::CreateFromQuaternionAndTranslation(
|
|
AZ::Quaternion::CreateFromAxisAngle(AZ::Vector3::CreateAxisX(), AZ::Constants::HalfPi) *
|
|
AZ::Quaternion::CreateFromAxisAngle(AZ::Vector3::CreateAxisY(), AZ::Constants::QuarterPi), AZ::Vector3(-10.0f, -10.0f, 0.0f));
|
|
transformIn.MultiplyByUniformScale(3.0f);
|
|
CreateCapsule(transformIn, 5.0f, 2.0f, entity);
|
|
|
|
AZ::Transform transformOut;
|
|
AZ::Aabb aabb;
|
|
LmbrCentral::ShapeComponentRequestsBus::Event(entity.GetId(), &LmbrCentral::ShapeComponentRequests::GetTransformAndLocalBounds, transformOut, aabb);
|
|
|
|
EXPECT_TRUE(transformOut.IsClose(transformIn));
|
|
EXPECT_TRUE(aabb.GetMin().IsClose(AZ::Vector3(-5.0f, -5.0f, -5.0f)));
|
|
EXPECT_TRUE(aabb.GetMax().IsClose(AZ::Vector3(5.0f, 5.0f, 5.0f)));
|
|
}
|
|
|
|
TEST_F(CapsuleShapeTest, GetTransformAndLocalBounds3)
|
|
{
|
|
AZ::Entity entity;
|
|
AZ::Transform transformIn = AZ::Transform::CreateFromQuaternionAndTranslation(
|
|
AZ::Quaternion::CreateFromAxisAngle(AZ::Vector3::CreateAxisX(), AZ::Constants::HalfPi) *
|
|
AZ::Quaternion::CreateFromAxisAngle(AZ::Vector3::CreateAxisY(), AZ::Constants::QuarterPi), AZ::Vector3(-10.0f, -10.0f, 0.0f));
|
|
transformIn.MultiplyByUniformScale(3.0f);
|
|
CreateCapsule(transformIn, 2.0f, 5.0f, entity);
|
|
|
|
AZ::Transform transformOut;
|
|
AZ::Aabb aabb;
|
|
LmbrCentral::ShapeComponentRequestsBus::Event(entity.GetId(), &LmbrCentral::ShapeComponentRequests::GetTransformAndLocalBounds, transformOut, aabb);
|
|
|
|
EXPECT_TRUE(transformOut.IsClose(transformIn));
|
|
EXPECT_TRUE(aabb.GetMin().IsClose(AZ::Vector3(-2.0f, -2.0f, -2.5f)));
|
|
EXPECT_TRUE(aabb.GetMax().IsClose(AZ::Vector3(2.0f, 2.0f, 2.5f)));
|
|
}
|
|
|
|
// point inside scaled
|
|
TEST_F(CapsuleShapeTest, IsPointInsideSuccess1)
|
|
{
|
|
AZ::Entity entity;
|
|
CreateCapsule(
|
|
AZ::Transform::CreateTranslation(AZ::Vector3(27.0f, 28.0f, 38.0f)) *
|
|
AZ::Transform::CreateUniformScale(2.5f),
|
|
0.5f, 2.0f, entity);
|
|
|
|
bool inside;
|
|
LmbrCentral::ShapeComponentRequestsBus::EventResult(
|
|
inside, entity.GetId(), &LmbrCentral::ShapeComponentRequests::IsPointInside, AZ::Vector3(27.0f, 28.5f, 40.0f));
|
|
|
|
EXPECT_TRUE(inside);
|
|
}
|
|
|
|
// point inside scaled
|
|
TEST_F(CapsuleShapeTest, IsPointInsideSuccess2)
|
|
{
|
|
AZ::Entity entity;
|
|
CreateCapsule(
|
|
AZ::Transform::CreateTranslation(AZ::Vector3(27.0f, 28.0f, 38.0f)) *
|
|
AZ::Transform::CreateRotationX(AZ::Constants::HalfPi) *
|
|
AZ::Transform::CreateRotationY(AZ::Constants::QuarterPi) *
|
|
AZ::Transform::CreateUniformScale(0.5f),
|
|
0.5f, 2.0f, entity);
|
|
|
|
bool inside;
|
|
LmbrCentral::ShapeComponentRequestsBus::EventResult(
|
|
inside, entity.GetId(), &LmbrCentral::ShapeComponentRequests::IsPointInside, AZ::Vector3(27.0f, 28.155f, 37.82f));
|
|
|
|
EXPECT_TRUE(inside);
|
|
}
|
|
|
|
// distance scaled - along length
|
|
TEST_F(CapsuleShapeTest, DistanceFromPoint1)
|
|
{
|
|
AZ::Entity entity;
|
|
CreateCapsule(
|
|
AZ::Transform::CreateTranslation(AZ::Vector3(27.0f, 28.0f, 38.0f)) *
|
|
AZ::Transform::CreateRotationX(AZ::Constants::HalfPi) *
|
|
AZ::Transform::CreateRotationY(AZ::Constants::QuarterPi) *
|
|
AZ::Transform::CreateUniformScale(2.0f),
|
|
0.5f, 4.0f, entity);
|
|
|
|
float distance;
|
|
LmbrCentral::ShapeComponentRequestsBus::EventResult(
|
|
distance, entity.GetId(), &LmbrCentral::ShapeComponentRequests::DistanceFromPoint, AZ::Vector3(27.0f, 28.0f, 41.0f));
|
|
|
|
EXPECT_NEAR(distance, 2.0f, 1e-2f);
|
|
}
|
|
|
|
// distance scaled - from end
|
|
TEST_F(CapsuleShapeTest, DistanceFromPoint2)
|
|
{
|
|
AZ::Entity entity;
|
|
CreateCapsule(
|
|
AZ::Transform::CreateTranslation(AZ::Vector3(27.0f, 28.0f, 38.0f)) *
|
|
AZ::Transform::CreateRotationX(AZ::Constants::HalfPi) *
|
|
AZ::Transform::CreateRotationY(AZ::Constants::QuarterPi) *
|
|
AZ::Transform::CreateUniformScale(2.0f),
|
|
0.5f, 4.0f, entity);
|
|
|
|
float distance;
|
|
LmbrCentral::ShapeComponentRequestsBus::EventResult(
|
|
distance, entity.GetId(), &LmbrCentral::ShapeComponentRequests::DistanceFromPoint, AZ::Vector3(22.757f, 32.243f, 38.0f));
|
|
|
|
EXPECT_NEAR(distance, 2.0f, 1e-2f);
|
|
}
|
|
}
|