make aabb shape component incompatible with non-uniform scale component
Signed-off-by: greerdv <greerdv@amazon.com>
This commit is contained in:
@@ -27,6 +27,7 @@ namespace LmbrCentral
|
||||
{
|
||||
incompatible.push_back(AZ_CRC_CE("ShapeService"));
|
||||
incompatible.push_back(AZ_CRC_CE("AxisAlignedBoxShapeService"));
|
||||
incompatible.push_back(AZ_CRC_CE("NonUniformScaleService"));
|
||||
}
|
||||
|
||||
void AxisAlignedBoxShapeComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
|
||||
@@ -34,11 +35,6 @@ namespace LmbrCentral
|
||||
required.push_back(AZ_CRC_CE("TransformService"));
|
||||
}
|
||||
|
||||
void AxisAlignedBoxShapeComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
|
||||
{
|
||||
dependent.push_back(AZ_CRC_CE("NonUniformScaleService"));
|
||||
}
|
||||
|
||||
void AxisAlignedBoxShapeDebugDisplayComponent::Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
|
||||
@@ -54,8 +50,6 @@ namespace LmbrCentral
|
||||
{
|
||||
EntityDebugDisplayComponent::Activate();
|
||||
ShapeComponentNotificationsBus::Handler::BusConnect(GetEntityId());
|
||||
m_nonUniformScale = AZ::Vector3::CreateOne();
|
||||
AZ::NonUniformScaleRequestBus::EventResult(m_nonUniformScale, GetEntityId(), &AZ::NonUniformScaleRequests::GetScale);
|
||||
}
|
||||
|
||||
void AxisAlignedBoxShapeDebugDisplayComponent::Deactivate()
|
||||
@@ -74,7 +68,7 @@ namespace LmbrCentral
|
||||
transform.SetRotation(AZ::Quaternion::CreateIdentity());
|
||||
saveMatrix = debugDisplay.PopPremultipliedMatrix();
|
||||
debugDisplay.PushMatrix(transform);
|
||||
DrawBoxShape(drawParams, m_boxShapeConfig, debugDisplay, m_nonUniformScale);
|
||||
DrawBoxShape(drawParams, m_boxShapeConfig, debugDisplay);
|
||||
debugDisplay.PopMatrix();
|
||||
debugDisplay.PushPremultipliedMatrix(saveMatrix);
|
||||
}
|
||||
@@ -104,7 +98,6 @@ namespace LmbrCentral
|
||||
if (changeReason == ShapeChangeReasons::ShapeChanged)
|
||||
{
|
||||
BoxShapeComponentRequestsBus::EventResult(m_boxShapeConfig, GetEntityId(), &BoxShapeComponentRequests::GetBoxConfiguration);
|
||||
AZ::NonUniformScaleRequestBus::EventResult(m_nonUniformScale, GetEntityId(), &AZ::NonUniformScaleRequests::GetScale);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@ namespace LmbrCentral
|
||||
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
|
||||
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
|
||||
static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
|
||||
static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
|
||||
|
||||
AxisAlignedBoxShape m_aaboxShape; ///< Stores underlying box type for this component.
|
||||
};
|
||||
@@ -65,6 +64,5 @@ namespace LmbrCentral
|
||||
void OnShapeChanged(ShapeChangeReasons changeReason) override;
|
||||
|
||||
BoxShapeConfig m_boxShapeConfig; ///< Stores configuration data for box shape.
|
||||
AZ::Vector3 m_nonUniformScale = AZ::Vector3::CreateOne(); ///< Caches non-uniform scale for this entity.
|
||||
};
|
||||
} // namespace LmbrCentral
|
||||
|
||||
@@ -89,9 +89,10 @@ namespace LmbrCentral
|
||||
provided.push_back(AZ_CRC_CE("AxisAlignedBoxShapeService"));
|
||||
}
|
||||
|
||||
void EditorAxisAlignedBoxShapeComponent::GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent)
|
||||
void EditorAxisAlignedBoxShapeComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
|
||||
{
|
||||
dependent.push_back(AZ_CRC_CE("NonUniformScaleService"));
|
||||
EditorBaseShapeComponent::GetIncompatibleServices(incompatible);
|
||||
incompatible.push_back(AZ_CRC_CE("NonUniformScaleService"));
|
||||
}
|
||||
|
||||
void EditorAxisAlignedBoxShapeComponent::DisplayEntityViewport(
|
||||
@@ -104,7 +105,7 @@ namespace LmbrCentral
|
||||
{
|
||||
DrawBoxShape(
|
||||
{ m_aaboxShape.GetBoxConfiguration().GetDrawColor(), m_shapeWireColor, m_aaboxShape.GetBoxConfiguration().IsFilled() },
|
||||
m_aaboxShape.GetBoxConfiguration(), debugDisplay, m_aaboxShape.GetCurrentNonUniformScale());
|
||||
m_aaboxShape.GetBoxConfiguration(), debugDisplay);
|
||||
},
|
||||
m_aaboxShape.GetCurrentTransform());
|
||||
}
|
||||
@@ -163,6 +164,6 @@ namespace LmbrCentral
|
||||
|
||||
AZ::Vector3 EditorAxisAlignedBoxShapeComponent::GetBoxScale()
|
||||
{
|
||||
return AZ::Vector3(m_aaboxShape.GetCurrentTransform().GetUniformScale() * m_aaboxShape.GetCurrentNonUniformScale());
|
||||
return AZ::Vector3(m_aaboxShape.GetCurrentTransform().GetUniformScale());
|
||||
}
|
||||
} // namespace LmbrCentral
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace LmbrCentral
|
||||
|
||||
protected:
|
||||
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
|
||||
static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
|
||||
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
|
||||
|
||||
// EditorComponentBase
|
||||
void BuildGameEntity(AZ::Entity* gameEntity) override;
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#include <AzCore/Math/Matrix3x3.h>
|
||||
#include <AzCore/Math/Random.h>
|
||||
#include <AzCore/UnitTest/TestTypes.h>
|
||||
#include <AzFramework/Components/NonUniformScaleComponent.h>
|
||||
#include <AzFramework/Components/TransformComponent.h>
|
||||
#include <AzFramework/UnitTest/TestDebugDisplayRequests.h>
|
||||
#include <Shape/AxisAlignedBoxShapeComponent.h>
|
||||
@@ -26,7 +25,6 @@ namespace UnitTest
|
||||
AZStd::unique_ptr<AZ::ComponentDescriptor> m_transformComponentDescriptor;
|
||||
AZStd::unique_ptr<AZ::ComponentDescriptor> m_axisAlignedBoxShapeComponentDescriptor;
|
||||
AZStd::unique_ptr<AZ::ComponentDescriptor> m_axisAlignedBoxShapeDebugDisplayComponentDescriptor;
|
||||
AZStd::unique_ptr<AZ::ComponentDescriptor> m_nonUniformScaleComponentDescriptor;
|
||||
|
||||
public:
|
||||
void SetUp() override
|
||||
@@ -43,9 +41,6 @@ namespace UnitTest
|
||||
m_axisAlignedBoxShapeDebugDisplayComponentDescriptor =
|
||||
AZStd::unique_ptr<AZ::ComponentDescriptor>(LmbrCentral::AxisAlignedBoxShapeDebugDisplayComponent::CreateDescriptor());
|
||||
m_axisAlignedBoxShapeDebugDisplayComponentDescriptor->Reflect(&(*m_serializeContext));
|
||||
m_nonUniformScaleComponentDescriptor =
|
||||
AZStd::unique_ptr<AZ::ComponentDescriptor>(AzFramework::NonUniformScaleComponent::CreateDescriptor());
|
||||
m_nonUniformScaleComponentDescriptor->Reflect(&(*m_serializeContext));
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
@@ -53,7 +48,6 @@ namespace UnitTest
|
||||
m_transformComponentDescriptor.reset();
|
||||
m_axisAlignedBoxShapeComponentDescriptor.reset();
|
||||
m_axisAlignedBoxShapeDebugDisplayComponentDescriptor.reset();
|
||||
m_nonUniformScaleComponentDescriptor.reset();
|
||||
m_serializeContext.reset();
|
||||
AllocatorsFixture::TearDown();
|
||||
}
|
||||
@@ -73,23 +67,6 @@ namespace UnitTest
|
||||
entity.GetId(), &LmbrCentral::BoxShapeComponentRequestsBus::Events::SetBoxDimensions, dimensions);
|
||||
}
|
||||
|
||||
void CreateAxisAlignedBoxWithNonUniformScale(
|
||||
const AZ::Transform& transform, const AZ::Vector3& nonUniformScale, const AZ::Vector3& dimensions, AZ::Entity& entity)
|
||||
{
|
||||
entity.CreateComponent<LmbrCentral::AxisAlignedBoxShapeComponent>();
|
||||
entity.CreateComponent<LmbrCentral::AxisAlignedBoxShapeDebugDisplayComponent>();
|
||||
entity.CreateComponent<AzFramework::TransformComponent>();
|
||||
entity.CreateComponent<AzFramework::NonUniformScaleComponent>();
|
||||
|
||||
entity.Init();
|
||||
entity.Activate();
|
||||
|
||||
AZ::TransformBus::Event(entity.GetId(), &AZ::TransformBus::Events::SetWorldTM, transform);
|
||||
LmbrCentral::BoxShapeComponentRequestsBus::Event(
|
||||
entity.GetId(), &LmbrCentral::BoxShapeComponentRequestsBus::Events::SetBoxDimensions, dimensions);
|
||||
AZ::NonUniformScaleRequestBus::Event(entity.GetId(), &AZ::NonUniformScaleRequests::SetScale, nonUniformScale);
|
||||
}
|
||||
|
||||
void CreateDefaultAxisAlignedBox(const AZ::Transform& transform, AZ::Entity& entity)
|
||||
{
|
||||
CreateAxisAlignedBox(transform, AZ::Vector3(10.0f, 10.0f, 10.0f), entity);
|
||||
@@ -187,52 +164,4 @@ namespace UnitTest
|
||||
EXPECT_TRUE(rayHit);
|
||||
EXPECT_NEAR(distance, 4.0f, 1e-2f);
|
||||
}
|
||||
|
||||
TEST_F(AxisAlignedBoxShapeTest, RayIntersectWithBoxRotatedNonUniformScale)
|
||||
{
|
||||
AZ::Entity entity;
|
||||
CreateAxisAlignedBoxWithNonUniformScale(
|
||||
AZ::Transform(
|
||||
AZ::Vector3(2.0f, -5.0f, 3.0f), AZ::Quaternion::CreateFromAxisAngle(AZ::Vector3::CreateAxisY(), AZ::Constants::QuarterPi),
|
||||
0.5f),
|
||||
AZ::Vector3(2.2f, 1.8f, 0.4f), AZ::Vector3(0.2f, 2.6f, 1.2f), entity);
|
||||
|
||||
// This test creates a box of dimensions (2.2, 1.8, 0.4) centered on (2.0, -5, 3) and rotated about the Y axis by 45 degrees.
|
||||
// The box is tested for axis-alignment by firing various rays and ensuring they either hit or miss the box. Any failure here
|
||||
// would show the box has been rotated.
|
||||
|
||||
// Ray should just miss the box
|
||||
bool rayHit = false;
|
||||
float distance = AZ::Constants::FloatMax;
|
||||
LmbrCentral::ShapeComponentRequestsBus::EventResult(
|
||||
rayHit, entity.GetId(), &LmbrCentral::ShapeComponentRequests::IntersectRay, AZ::Vector3(1.8f, -6.2f, 3.0f),
|
||||
AZ::Vector3(1.0f, 0.0f, 0.0f), distance);
|
||||
EXPECT_FALSE(rayHit);
|
||||
|
||||
// Ray should just hit the box
|
||||
rayHit = false;
|
||||
distance = AZ::Constants::FloatMax;
|
||||
LmbrCentral::ShapeComponentRequestsBus::EventResult(
|
||||
rayHit, entity.GetId(), &LmbrCentral::ShapeComponentRequests::IntersectRay, AZ::Vector3(1.8f, -6.1f, 3.0f),
|
||||
AZ::Vector3(1.0f, 0.0f, 0.0f), distance);
|
||||
EXPECT_TRUE(rayHit);
|
||||
EXPECT_NEAR(distance, 0.09f, 1e-3f);
|
||||
|
||||
// Ray should just miss the box
|
||||
rayHit = false;
|
||||
distance = AZ::Constants::FloatMax;
|
||||
LmbrCentral::ShapeComponentRequestsBus::EventResult(
|
||||
rayHit, entity.GetId(), &LmbrCentral::ShapeComponentRequests::IntersectRay, AZ::Vector3(2.2f, -6.2f, 3.0f),
|
||||
AZ::Vector3(0.0f, 1.0f, 0.0f), distance);
|
||||
EXPECT_FALSE(rayHit);
|
||||
|
||||
// Ray should just hit the box
|
||||
rayHit = false;
|
||||
distance = AZ::Constants::FloatMax;
|
||||
LmbrCentral::ShapeComponentRequestsBus::EventResult(
|
||||
rayHit, entity.GetId(), &LmbrCentral::ShapeComponentRequests::IntersectRay, AZ::Vector3(2.1f, -6.2f, 3.0f),
|
||||
AZ::Vector3(0.0f, 1.0f, 0.0f), distance);
|
||||
EXPECT_TRUE(rayHit);
|
||||
EXPECT_NEAR(distance, 0.03f, 1e-3f);
|
||||
}
|
||||
} // namespace UnitTest
|
||||
|
||||
Reference in New Issue
Block a user