Merge pull request #3094 from aws-lumberyard-dev/cgalvan/CreateEntitiesInViewportCorrectPosition
Fixed creating entities in the viewport logic to use hit test detection.
This commit is contained in:
@@ -2697,8 +2697,7 @@ void EditorViewportWidget::RestoreViewportAfterGameMode()
|
||||
QString(
|
||||
tr("When leaving \" Game Mode \" the engine will automatically restore your camera position to the default position before you "
|
||||
"had entered Game mode.<br/><br/><small>If you dislike this setting you can always change this anytime in the global "
|
||||
"preferences.</small><br/><br/>"))
|
||||
.arg(EditorPreferencesGeneralRestoreViewportCameraSettingName);
|
||||
"preferences.</small><br/><br/>"));
|
||||
QString restoreOnExitGameModePopupDisabledRegKey("Editor/AutoHide/ViewportCameraRestoreOnExitGameMode");
|
||||
|
||||
// Read the popup disabled registry value
|
||||
|
||||
@@ -1452,7 +1452,7 @@ void SandboxIntegrationManager::ContextMenu_NewEntity()
|
||||
if (view)
|
||||
{
|
||||
const QPoint viewPoint(m_contextMenuViewPoint.GetX(), m_contextMenuViewPoint.GetY());
|
||||
worldPosition = LYVec3ToAZVec3(view->SnapToGrid(view->ViewToWorld(viewPoint)));
|
||||
worldPosition = view->GetHitLocation(viewPoint);
|
||||
}
|
||||
|
||||
CreateNewEntityAtPosition(worldPosition);
|
||||
|
||||
+24
-18
@@ -46,24 +46,7 @@ void QtViewport::BuildDragDropContext(AzQtComponents::ViewportDragContext& conte
|
||||
|
||||
PreWidgetRendering(); // required so that the current render cam is set.
|
||||
|
||||
Vec3 pos = Vec3(ZERO);
|
||||
HitContext hit;
|
||||
if (HitTest(pt, hit))
|
||||
{
|
||||
pos = hit.raySrc + hit.rayDir * hit.dist;
|
||||
pos = SnapToGrid(pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
bool hitTerrain;
|
||||
pos = ViewToWorld(pt, &hitTerrain);
|
||||
if (hitTerrain)
|
||||
{
|
||||
pos.z = GetIEditor()->GetTerrainElevation(pos.x, pos.y);
|
||||
}
|
||||
pos = SnapToGrid(pos);
|
||||
}
|
||||
context.m_hitLocation = AZ::Vector3(pos.x, pos.y, pos.z);
|
||||
context.m_hitLocation = GetHitLocation(pt);
|
||||
|
||||
PostWidgetRendering();
|
||||
}
|
||||
@@ -1154,6 +1137,29 @@ bool QtViewport::HitTest(const QPoint& point, HitContext& hitInfo)
|
||||
return false;
|
||||
}
|
||||
|
||||
AZ::Vector3 QtViewport::GetHitLocation(const QPoint& point)
|
||||
{
|
||||
Vec3 pos = Vec3(ZERO);
|
||||
HitContext hit;
|
||||
if (HitTest(point, hit))
|
||||
{
|
||||
pos = hit.raySrc + hit.rayDir * hit.dist;
|
||||
pos = SnapToGrid(pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
bool hitTerrain;
|
||||
pos = ViewToWorld(point, &hitTerrain);
|
||||
if (hitTerrain)
|
||||
{
|
||||
pos.z = GetIEditor()->GetTerrainElevation(pos.x, pos.y);
|
||||
}
|
||||
pos = SnapToGrid(pos);
|
||||
}
|
||||
|
||||
return AZ::Vector3(pos.x, pos.y, pos.z);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void QtViewport::SetZoomFactor(float fZoomFactor)
|
||||
{
|
||||
|
||||
@@ -201,6 +201,7 @@ public:
|
||||
|
||||
//! Performs hit testing of 2d point in view to find which object hit.
|
||||
virtual bool HitTest(const QPoint& point, HitContext& hitInfo) = 0;
|
||||
virtual AZ::Vector3 GetHitLocation(const QPoint& point) = 0;
|
||||
|
||||
virtual void MakeConstructionPlane(int axis) = 0;
|
||||
|
||||
@@ -436,6 +437,7 @@ public:
|
||||
|
||||
//! Performs hit testing of 2d point in view to find which object hit.
|
||||
bool HitTest(const QPoint& point, HitContext& hitInfo) override;
|
||||
AZ::Vector3 GetHitLocation(const QPoint& point) override;
|
||||
|
||||
//! Do 2D hit testing of line in world space.
|
||||
// pToCameraDistance is an optional output parameter in which distance from the camera to the line is returned.
|
||||
|
||||
Reference in New Issue
Block a user