Update intersect behavior for positioning entities in the viewport (#5906)
* update intersect behavior for positioning entities in the viewport and restore SurfaceManipulator Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com> * tests for surface manipulator from EditorTransformComponentSelection Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com> * update comments in tests and remove #pragma optimize('', off)@ Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com> * add new file for FindClosestPickIntersection tests Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com> * add remaining tests for surface manipulator and snap fixes Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com> * some small updates and polish before PR Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com> * small updates following PR feedback Signed-off-by: Tom Hulton-Harrop <82228511+hultonha@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
75d6cb2527
commit
6908a3e945
@@ -8,6 +8,8 @@
|
||||
|
||||
#include <Tests/BoundsTestComponent.h>
|
||||
|
||||
#include <AzCore/Math/Obb.h>
|
||||
#include <AzCore/Math/IntersectSegment.h>
|
||||
#include <AzToolsFramework/ViewportSelection/EditorSelectionUtil.h>
|
||||
|
||||
namespace UnitTest
|
||||
@@ -62,4 +64,51 @@ namespace UnitTest
|
||||
{
|
||||
return m_localBounds;
|
||||
}
|
||||
|
||||
void RenderGeometryIntersectionTestComponent::Reflect(AZ::ReflectContext* context)
|
||||
{
|
||||
if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
|
||||
{
|
||||
serializeContext->Class<RenderGeometryIntersectionTestComponent, BoundsTestComponent>()->Version(1);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderGeometryIntersectionTestComponent::Activate()
|
||||
{
|
||||
BoundsTestComponent::Activate();
|
||||
|
||||
const AZ::EntityId entityId = GetEntityId();
|
||||
AzFramework::EntityContextId contextId = AzFramework::EntityContextId::CreateNull();
|
||||
AzFramework::EntityIdContextQueryBus::EventResult(contextId, entityId, &AzFramework::EntityIdContextQueries::GetOwningContextId);
|
||||
AzFramework::RenderGeometry::IntersectionRequestBus::Handler::BusConnect({entityId, contextId});
|
||||
}
|
||||
|
||||
void RenderGeometryIntersectionTestComponent::Deactivate()
|
||||
{
|
||||
AzFramework::RenderGeometry::IntersectionRequestBus::Handler::BusDisconnect();
|
||||
BoundsTestComponent::Deactivate();
|
||||
}
|
||||
|
||||
AzFramework::RenderGeometry::RayResult RenderGeometryIntersectionTestComponent::RenderGeometryIntersect(
|
||||
const AzFramework::RenderGeometry::RayRequest& ray)
|
||||
{
|
||||
AZ::Transform worldFromLocal = AZ::Transform::CreateIdentity();
|
||||
AZ::TransformBus::EventResult(worldFromLocal, GetEntityId(), &AZ::TransformBus::Events::GetWorldTM);
|
||||
|
||||
AzFramework::RenderGeometry::RayResult rayResult;
|
||||
|
||||
float t = 0.0f;
|
||||
const AZ::Obb obb = GetLocalBounds().GetTransformedObb(worldFromLocal);
|
||||
const AZ::Vector3 rayDirection = ray.m_endWorldPosition - ray.m_startWorldPosition;
|
||||
if (AZ::Intersect::IntersectRayObb(ray.m_startWorldPosition, rayDirection, obb, t))
|
||||
{
|
||||
rayResult.m_worldPosition = ray.m_startWorldPosition + rayDirection * t;
|
||||
rayResult.m_entityAndComponent = AZ::EntityComponentIdPair(GetEntityId(), GetId());
|
||||
rayResult.m_distance = t;
|
||||
rayResult.m_uv = AZ::Vector2::CreateZero();
|
||||
rayResult.m_worldNormal = AZ::Vector3::CreateZero();
|
||||
}
|
||||
|
||||
return rayResult;
|
||||
}
|
||||
} // namespace UnitTest
|
||||
|
||||
Reference in New Issue
Block a user