From 2ab9648425d922be3ebf0bb10fd408f9239350e8 Mon Sep 17 00:00:00 2001 From: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> Date: Mon, 16 Aug 2021 15:57:19 -0700 Subject: [PATCH] Gems/LyShine Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> --- .../Animation/Controls/UiTimelineCtrl.cpp | 14 +- .../Animation/UiAVCustomizeTrackColorsDlg.cpp | 2 +- .../Editor/Animation/UiAnimViewDialog.cpp | 4 +- .../Animation/UiAnimViewDopeSheetBase.cpp | 48 +++--- .../Code/Editor/Animation/UiAnimViewNodes.cpp | 144 ++++++++-------- Gems/LyShine/Code/Editor/QtHelpers.cpp | 5 +- Gems/LyShine/Code/Editor/ViewportIcon.cpp | 2 +- Gems/LyShine/Code/Editor/ViewportWidget.cpp | 8 +- Gems/LyShine/Code/Source/UiCanvasManager.cpp | 162 +++++++++--------- 9 files changed, 194 insertions(+), 195 deletions(-) diff --git a/Gems/LyShine/Code/Editor/Animation/Controls/UiTimelineCtrl.cpp b/Gems/LyShine/Code/Editor/Animation/Controls/UiTimelineCtrl.cpp index 4140cff935..3f9ba6e813 100644 --- a/Gems/LyShine/Code/Editor/Animation/Controls/UiTimelineCtrl.cpp +++ b/Gems/LyShine/Code/Editor/Animation/Controls/UiTimelineCtrl.cpp @@ -20,9 +20,9 @@ QColor InterpolateColor(const QColor& c1, const QColor& c2, float fraction) { - const int r = (c2.red() - c1.red()) * fraction + c1.red(); - const int g = (c2.green() - c1.green()) * fraction + c1.green(); - const int b = (c2.blue() - c1.blue()) * fraction + c1.blue(); + const int r = static_cast(static_cast(c2.red() - c1.red()) * fraction + c1.red()); + const int g = static_cast(static_cast(c2.green() - c1.green()) * fraction + c1.green()); + const int b = static_cast(static_cast(c2.blue() - c1.blue()) * fraction + c1.blue()); return QColor(r, g, b); } @@ -114,7 +114,7 @@ float TimelineWidget::SnapTime(float time) { double t = floor((double)time * m_ticksStep + 0.5); t = t / m_ticksStep; - return t; + return static_cast(t); } ////////////////////////////////////////////////////////////////////////// @@ -147,10 +147,10 @@ void TimelineWidget::DrawTicks(QPainter* painter) painter->setPen(redpen); int x = TimeToClient(m_fTimeMarker); painter->setBrush(Qt::NoBrush); - painter->drawRect(QRect(QPoint(x - 3, rc.top()), QPoint(x + 4, rc.bottom()))); + painter->drawRect(QRect(QPoint(x - 3, static_cast(rc.top())), QPoint(x + 4, static_cast(rc.bottom())))); painter->setPen(redpen); - painter->drawLine(x, rc.top(), x, rc.bottom()); + painter->drawLine(x, static_cast(rc.top()), x, static_cast(rc.bottom())); painter->setBrush(Qt::NoBrush); // Draw vertical line showing current time. @@ -184,7 +184,7 @@ void TimelineWidget::DrawTicks(QPainter* painter) float keyTime = (m_pKeyTimeSet ? m_pKeyTimeSet->GetKeyTime(keyTimeIndex) : 0.0f); int x2 = TimeToClient(keyTime); - painter->drawRect(QRect(QPoint(x2 - 2, rc.top()), QPoint(x2 + 3, rc.bottom()))); + painter->drawRect(QRect(QPoint(x2 - 2, static_cast(rc.top())), QPoint(x2 + 3, static_cast(rc.bottom())))); } painter->setPen(pOldPen); diff --git a/Gems/LyShine/Code/Editor/Animation/UiAVCustomizeTrackColorsDlg.cpp b/Gems/LyShine/Code/Editor/Animation/UiAVCustomizeTrackColorsDlg.cpp index 8bfb3f955d..533625c762 100644 --- a/Gems/LyShine/Code/Editor/Animation/UiAVCustomizeTrackColorsDlg.cpp +++ b/Gems/LyShine/Code/Editor/Animation/UiAVCustomizeTrackColorsDlg.cpp @@ -320,7 +320,7 @@ bool CUiAVCustomizeTrackColorsDlg::Import(const QString& fullPath) { return entry.paramType == paramType; }); - int entryIndex = pEntry - g_trackEntries; + int entryIndex = static_cast(pEntry - g_trackEntries); if (entryIndex >= arraysize(g_trackEntries)) // If not found, skip this. { continue; diff --git a/Gems/LyShine/Code/Editor/Animation/UiAnimViewDialog.cpp b/Gems/LyShine/Code/Editor/Animation/UiAnimViewDialog.cpp index 97f21e9bab..6a3afe2036 100644 --- a/Gems/LyShine/Code/Editor/Animation/UiAnimViewDialog.cpp +++ b/Gems/LyShine/Code/Editor/Animation/UiAnimViewDialog.cpp @@ -1470,7 +1470,7 @@ void CUiAnimViewDialog::OnSnapFPS() if (ok) { m_wndDopeSheet->SetSnapFPS(fps); - m_wndCurveEditor->SetFPS(fps); + m_wndCurveEditor->SetFPS(static_cast(fps)); SetCursorPosText(m_animationContext->GetTime()); } @@ -1541,7 +1541,7 @@ void CUiAnimViewDialog::ReadMiscSettings() if (settings.contains(s_kFrameSnappingFPSEntry)) { - float fps = settings.value(s_kFrameSnappingFPSEntry).toDouble(); + float fps = settings.value(s_kFrameSnappingFPSEntry).toFloat(); m_wndDopeSheet->SetSnapFPS(FloatToIntRet(fps)); m_wndCurveEditor->SetFPS(fps); } diff --git a/Gems/LyShine/Code/Editor/Animation/UiAnimViewDopeSheetBase.cpp b/Gems/LyShine/Code/Editor/Animation/UiAnimViewDopeSheetBase.cpp index 82d05a6f67..4e67fb520e 100644 --- a/Gems/LyShine/Code/Editor/Animation/UiAnimViewDopeSheetBase.cpp +++ b/Gems/LyShine/Code/Editor/Animation/UiAnimViewDopeSheetBase.cpp @@ -139,8 +139,7 @@ CUiAnimViewDopeSheetBase::~CUiAnimViewDopeSheetBase() ////////////////////////////////////////////////////////////////////////// int CUiAnimViewDopeSheetBase::TimeToClient(float time) const { - int x = m_leftOffset - m_scrollOffset.x() + (time * m_timeScale); - return x; + return static_cast(m_leftOffset - m_scrollOffset.x() + (time * m_timeScale)); } ////////////////////////////////////////////////////////////////////////// @@ -186,7 +185,7 @@ void CUiAnimViewDopeSheetBase::SetTimeRange(float start, float end) m_timeRange.Set(start, end); - SetHorizontalExtent(-m_leftOffset, m_timeRange.end * m_timeScale - m_leftOffset); + SetHorizontalExtent(-m_leftOffset, static_cast(m_timeRange.end * m_timeScale - m_leftOffset)); } ////////////////////////////////////////////////////////////////////////// @@ -255,7 +254,7 @@ void CUiAnimViewDopeSheetBase::SetTimeScale(float timeScale, float fAnchorTime) update(); - SetHorizontalExtent(-m_leftOffset, m_timeRange.end * m_timeScale); + SetHorizontalExtent(-m_leftOffset, static_cast(m_timeRange.end * m_timeScale)); ComputeFrameSteps(GetVisibleRange()); } @@ -346,15 +345,15 @@ float CUiAnimViewDopeSheetBase::TickSnap(float time) const double tickTime = GetTickTime(); double t = floor(((double)time / tickTime) + 0.5); t *= tickTime; - return t; + return static_cast(t); } ////////////////////////////////////////////////////////////////////////// float CUiAnimViewDopeSheetBase::TimeFromPoint(const QPoint& point) const { int x = point.x() - m_leftOffset + m_scrollOffset.x(); - double t = (double)x / m_timeScale; - return (float)TickSnap(t); + float t = static_cast(x) / m_timeScale; + return TickSnap(t); } ////////////////////////////////////////////////////////////////////////// @@ -362,7 +361,7 @@ float CUiAnimViewDopeSheetBase::TimeFromPointUnsnapped(const QPoint& point) cons { int x = point.x() - m_leftOffset + m_scrollOffset.x(); double t = (double)x / m_timeScale; - return t; + return static_cast(t); } void CUiAnimViewDopeSheetBase::mousePressEvent(QMouseEvent* event) @@ -1651,7 +1650,7 @@ float CUiAnimViewDopeSheetBase::FrameSnap(float time) const { double t = floor((double)time / m_snapFrameTime + 0.5); t = t * m_snapFrameTime; - return t; + return static_cast(t); } ////////////////////////////////////////////////////////////////////////// @@ -1755,9 +1754,10 @@ bool CUiAnimViewDopeSheetBase::CreateColorKey(CUiAnimViewTrack* pTrack, float ke Vec3 vColor(0, 0, 0); pTrack->GetValue(keyTime, vColor); - const AZ::Color defaultColor = AZ::Color::CreateFromRgba(clamp_tpl(FloatToIntRet(vColor.x), 0, 255), - clamp_tpl(FloatToIntRet(vColor.y), 0, 255), - clamp_tpl(FloatToIntRet(vColor.z), 0, 255), 255); + const AZ::Color defaultColor = AZ::Color::CreateFromRgba( + clamp_tpl(static_cast(FloatToIntRet(vColor.x)), AZ::u8(0), AZ::u8(255)), + clamp_tpl(static_cast(FloatToIntRet(vColor.y)), AZ::u8(0), AZ::u8(255)), + clamp_tpl(static_cast(FloatToIntRet(vColor.z)), AZ::u8(0), AZ::u8(255)), 255); AzQtComponents::ColorPicker dlg(AzQtComponents::ColorPicker::Configuration::RGB, tr("Select Color"), this); dlg.setCurrentColor(defaultColor); dlg.setSelectedColor(defaultColor); @@ -1997,12 +1997,12 @@ void CUiAnimViewDopeSheetBase::DrawTicks(QPainter* painter, const QRect& rc, Ran nNumberTicks = 8; } - double start = TickSnap(timeRange.start); - double step = 1.0 / m_ticksStep; + float start = TickSnap(timeRange.start); + float step = 1.0f / static_cast(m_ticksStep); - for (double t = 0.0f; t <= timeRange.end + step; t += step) + for (float t = 0.0f; t <= timeRange.end + step; t += step) { - double st = TickSnap(t); + float st = TickSnap(t); if (st > timeRange.end) { st = timeRange.end; @@ -2021,7 +2021,7 @@ void CUiAnimViewDopeSheetBase::DrawTicks(QPainter* painter, const QRect& rc, Ran continue; } - int k = RoundFloatToInt(st * m_ticksStep); + int k = RoundFloatToInt(st * static_cast(m_ticksStep)); if (k % nNumberTicks == 0) { if (st >= start) @@ -2743,7 +2743,7 @@ void CUiAnimViewDopeSheetBase::ComputeFrameSteps(const Range& visRange) float nBIntermediateTicks = 5; m_fFrameLabelStep = fFact * afStepTable[nStepIdx]; - if (TimeToClient(m_fFrameLabelStep) - TimeToClient(0) > 1300) + if (TimeToClient(static_cast(m_fFrameLabelStep)) - TimeToClient(0) > 1300) { nBIntermediateTicks = 10; } @@ -2755,7 +2755,7 @@ void CUiAnimViewDopeSheetBase::ComputeFrameSteps(const Range& visRange) void CUiAnimViewDopeSheetBase::DrawTimeLineInFrames(QPainter* painter, const QRect& rc, [[maybe_unused]] const QColor& lineCol, const QColor& textCol, [[maybe_unused]] double step) { float fFramesPerSec = 1.0f / m_snapFrameTime; - float fInvFrameLabelStep = 1.0f / m_fFrameLabelStep; + float fInvFrameLabelStep = 1.0f / static_cast(m_fFrameLabelStep); Range VisRange = GetVisibleRange(); const Range& timeRange = m_timeRange; @@ -2763,9 +2763,9 @@ void CUiAnimViewDopeSheetBase::DrawTimeLineInFrames(QPainter* painter, const QRe const QPen ltgray(QColor(90, 90, 90)); const QPen black(textCol); - for (double t = TickSnap(timeRange.start); t <= timeRange.end + m_fFrameTickStep; t += m_fFrameTickStep) + for (float t = TickSnap(timeRange.start); t <= timeRange.end + static_cast(m_fFrameTickStep); t += static_cast(m_fFrameTickStep)) { - double st = t; + float st = t; if (st > timeRange.end) { st = timeRange.end; @@ -2810,9 +2810,9 @@ void CUiAnimViewDopeSheetBase::DrawTimeLineInSeconds(QPainter* painter, const QR const QPen ltgray(QColor(90, 90, 90)); const QPen black(textCol); - for (double t = TickSnap(timeRange.start); t <= timeRange.end + step; t += step) + for (float t = TickSnap(timeRange.start); t <= timeRange.end + static_cast(step); t += static_cast(step)) { - double st = TickSnap(t); + float st = TickSnap(t); if (st > timeRange.end) { st = timeRange.end; @@ -2831,7 +2831,7 @@ void CUiAnimViewDopeSheetBase::DrawTimeLineInSeconds(QPainter* painter, const QR } int x = TimeToClient(st); - int k = RoundFloatToInt(st * m_ticksStep); + int k = RoundFloatToInt(st * static_cast(m_ticksStep)); if (k % nNumberTicks == 0) { painter->setPen(black); diff --git a/Gems/LyShine/Code/Editor/Animation/UiAnimViewNodes.cpp b/Gems/LyShine/Code/Editor/Animation/UiAnimViewNodes.cpp index 820849bc93..3df400ddf2 100644 --- a/Gems/LyShine/Code/Editor/Animation/UiAnimViewNodes.cpp +++ b/Gems/LyShine/Code/Editor/Animation/UiAnimViewNodes.cpp @@ -95,88 +95,88 @@ public: } protected: - void dragMoveEvent(QDragMoveEvent* event) + void dragMoveEvent([[maybe_unused]] QDragMoveEvent* event) { // For now we do not support any drag and drop in the Nodes pane return; - CUiAnimViewNodesCtrl::CRecord* pRecord = (CUiAnimViewNodesCtrl::CRecord*) itemAt(event->pos()); - if (!pRecord) - { - return; - } - CUiAnimViewNode* pTargetNode = pRecord->GetNode(); - - QTreeWidget::dragMoveEvent(event); - if (!event->isAccepted()) - { - return; - } - - if (pTargetNode && pTargetNode->IsGroupNode() /*&& !m_draggedNodes.DoesContain(pTargetNode)*/) - { - CUiAnimViewAnimNode* pDragTarget = static_cast(pTargetNode); - bool bAllValidReparenting = true; - QList nodes = draggedNodes(event); - Q_FOREACH(CUiAnimViewAnimNode * pDraggedNode, nodes) - { - if (!pDraggedNode->IsValidReparentingTo(pDragTarget)) - { - bAllValidReparenting = false; - break; - } - } - - if (!bAllValidReparenting) - { - event->ignore(); - } - - return; - } + //CUiAnimViewNodesCtrl::CRecord* pRecord = (CUiAnimViewNodesCtrl::CRecord*) itemAt(event->pos()); + //if (!pRecord) + //{ + // return; + //} + //CUiAnimViewNode* pTargetNode = pRecord->GetNode(); + // + //QTreeWidget::dragMoveEvent(event); + //if (!event->isAccepted()) + //{ + // return; + //} + // + //if (pTargetNode && pTargetNode->IsGroupNode() /*&& !m_draggedNodes.DoesContain(pTargetNode)*/) + //{ + // CUiAnimViewAnimNode* pDragTarget = static_cast(pTargetNode); + // bool bAllValidReparenting = true; + // QList nodes = draggedNodes(event); + // Q_FOREACH(CUiAnimViewAnimNode * pDraggedNode, nodes) + // { + // if (!pDraggedNode->IsValidReparentingTo(pDragTarget)) + // { + // bAllValidReparenting = false; + // break; + // } + // } + // + // if (!bAllValidReparenting) + // { + // event->ignore(); + // } + // + // return; + //} } - void dropEvent(QDropEvent* event) + void dropEvent([[maybe_unused]] QDropEvent* event) { // For now we do not support any drag and drop in the Nodes pane return; - CUiAnimViewNodesCtrl::CRecord* pRecord = (CUiAnimViewNodesCtrl::CRecord*) itemAt(event->pos()); - if (!pRecord) - { - return; - } - CUiAnimViewNode* pTargetNode = pRecord->GetNode(); - - QTreeWidget::dropEvent(event); - if (!event->isAccepted()) - { - return; - } - - if (pTargetNode && pTargetNode->IsGroupNode() /*&& !m_draggedNodes.DoesContain(pTargetNode)*/) - { - CUiAnimViewAnimNode* pDragTarget = static_cast(pTargetNode); - bool bAllValidReparenting = true; - QList nodes = draggedNodes(event); - Q_FOREACH(CUiAnimViewAnimNode * pDraggedNode, nodes) - { - if (!pDraggedNode->IsValidReparentingTo(pDragTarget)) - { - bAllValidReparenting = false; - break; - } - } - - if (bAllValidReparenting) - { - UiAnimUndo undo("Drag and Drop UiAnimView Nodes"); - Q_FOREACH(CUiAnimViewAnimNode * pDraggedNode, nodes) - { - pDraggedNode->SetNewParent(pDragTarget); - } - } - } + //CUiAnimViewNodesCtrl::CRecord* pRecord = (CUiAnimViewNodesCtrl::CRecord*) itemAt(event->pos()); + //if (!pRecord) + //{ + // return; + //} + //CUiAnimViewNode* pTargetNode = pRecord->GetNode(); + // + //QTreeWidget::dropEvent(event); + //if (!event->isAccepted()) + //{ + // return; + //} + // + //if (pTargetNode && pTargetNode->IsGroupNode() /*&& !m_draggedNodes.DoesContain(pTargetNode)*/) + //{ + // CUiAnimViewAnimNode* pDragTarget = static_cast(pTargetNode); + // bool bAllValidReparenting = true; + // QList nodes = draggedNodes(event); + // Q_FOREACH(CUiAnimViewAnimNode * pDraggedNode, nodes) + // { + // if (!pDraggedNode->IsValidReparentingTo(pDragTarget)) + // { + // bAllValidReparenting = false; + // break; + // } + // } + // + // if (bAllValidReparenting) + // { + // UiAnimUndo undo("Drag and Drop UiAnimView Nodes"); + // Q_FOREACH(CUiAnimViewAnimNode * pDraggedNode, nodes) + // { + // pDraggedNode->SetNewParent(pDragTarget); + // } + // } + //} } void keyPressEvent(QKeyEvent* event) diff --git a/Gems/LyShine/Code/Editor/QtHelpers.cpp b/Gems/LyShine/Code/Editor/QtHelpers.cpp index 8b6063a055..d9147463ed 100644 --- a/Gems/LyShine/Code/Editor/QtHelpers.cpp +++ b/Gems/LyShine/Code/Editor/QtHelpers.cpp @@ -32,8 +32,7 @@ namespace QtHelpers float GetHighDpiScaleFactor(const QWidget& widget) { - float dpiScale = QHighDpiScaling::factor(widget.windowHandle()->screen()); - return dpiScale; + return static_cast(QHighDpiScaling::factor(widget.windowHandle()->screen())); } QSize GetDpiScaledViewportSize(const QWidget& widget) @@ -41,7 +40,7 @@ namespace QtHelpers float dpiScale = GetHighDpiScaleFactor(widget); float width = ceilf(widget.size().width() * dpiScale); float height = ceilf(widget.size().height() * dpiScale); - return QSize(width, height); + return QSize(static_cast(width), static_cast(height)); } } // namespace QtHelpers diff --git a/Gems/LyShine/Code/Editor/ViewportIcon.cpp b/Gems/LyShine/Code/Editor/ViewportIcon.cpp index e4ada665d5..e3ad68922e 100644 --- a/Gems/LyShine/Code/Editor/ViewportIcon.cpp +++ b/Gems/LyShine/Code/Editor/ViewportIcon.cpp @@ -27,7 +27,7 @@ AZ::Vector2 ViewportIcon::GetTextureSize() const if (m_image) { AZ::RHI::Size size = m_image->GetDescriptor().m_size; - AZ::Vector2 scaledSize(size.m_width, size.m_height); + AZ::Vector2 scaledSize(static_cast(size.m_width), static_cast(size.m_height)); if (m_applyDpiScaleFactorToSize) { scaledSize *= m_dpiScaleFactor; diff --git a/Gems/LyShine/Code/Editor/ViewportWidget.cpp b/Gems/LyShine/Code/Editor/ViewportWidget.cpp index 1ce8f5b64d..e172d43b60 100644 --- a/Gems/LyShine/Code/Editor/ViewportWidget.cpp +++ b/Gems/LyShine/Code/Editor/ViewportWidget.cpp @@ -1001,7 +1001,7 @@ void ViewportWidget::RenderEditMode() // Render this canvas QSize scaledViewportSize = QtHelpers::GetDpiScaledViewportSize(*this); - AZ::Vector2 viewportSize(scaledViewportSize.width(), scaledViewportSize.height()); + AZ::Vector2 viewportSize(static_cast(scaledViewportSize.width()), static_cast(scaledViewportSize.height())); EBUS_EVENT_ID(canvasEntityId, UiEditorCanvasBus, RenderCanvasInEditorViewport, false, viewportSize); m_draw2d->SetSortKey(topLayerKey); @@ -1111,7 +1111,7 @@ void ViewportWidget::UpdatePreviewMode(float deltaTime) if (canvasEntityId.IsValid()) { QSize scaledViewportSize = QtHelpers::GetDpiScaledViewportSize(*this); - AZ::Vector2 viewportSize(scaledViewportSize.width(), scaledViewportSize.height()); + AZ::Vector2 viewportSize(static_cast(scaledViewportSize.width()), static_cast(scaledViewportSize.height())); // Get the canvas size AZ::Vector2 canvasSize = m_editorWindow->GetPreviewCanvasSize(); @@ -1153,7 +1153,7 @@ void ViewportWidget::RenderPreviewMode() if (canvasEntityId.IsValid()) { QSize scaledViewportSize = QtHelpers::GetDpiScaledViewportSize(*this); - AZ::Vector2 viewportSize(scaledViewportSize.width(), scaledViewportSize.height()); + AZ::Vector2 viewportSize(static_cast(scaledViewportSize.width()), static_cast(scaledViewportSize.height())); // Get the canvas size AZ::Vector2 canvasSize = m_editorWindow->GetPreviewCanvasSize(); @@ -1239,7 +1239,7 @@ void ViewportWidget::RenderViewportBackground() Draw2dHelper draw2d(m_draw2d.get()); draw2d.SetImageColor(backgroundColor.GetAsVector3()); - draw2d.DrawImage(image, AZ::Vector2(0.0f, 0.0f), AZ::Vector2(viewportSize.width(), viewportSize.height())); + draw2d.DrawImage(image, AZ::Vector2(0.0f, 0.0f), AZ::Vector2(static_cast(viewportSize.width()), static_cast(viewportSize.height()))); } void ViewportWidget::SetupShortcuts() diff --git a/Gems/LyShine/Code/Source/UiCanvasManager.cpp b/Gems/LyShine/Code/Source/UiCanvasManager.cpp index 5f2adcd20c..d13a8f5034 100644 --- a/Gems/LyShine/Code/Source/UiCanvasManager.cpp +++ b/Gems/LyShine/Code/Source/UiCanvasManager.cpp @@ -808,7 +808,7 @@ UiCanvasComponent* UiCanvasManager::FindEditorCanvasComponentByPathname(const AZ } //////////////////////////////////////////////////////////////////////////////////////////////////// -bool UiCanvasManager::HandleInputEventForInWorldCanvases(const AzFramework::InputChannel::Snapshot& inputSnapshot, const AZ::Vector2& viewportPos) +bool UiCanvasManager::HandleInputEventForInWorldCanvases([[maybe_unused]] const AzFramework::InputChannel::Snapshot& inputSnapshot, [[maybe_unused]] const AZ::Vector2& viewportPos) { // First we need to construct a ray from the either the center of the screen or the mouse position. // This requires knowledge of the camera @@ -816,86 +816,86 @@ bool UiCanvasManager::HandleInputEventForInWorldCanvases(const AzFramework::Inpu // ToDo: Re-implement by getting the camera from Atom. LYN-3680 return false; - const CCamera cam; - - // construct a ray from the camera position in the view direction of the camera - const float rayLength = 5000.0f; - Vec3 rayOrigin(cam.GetPosition()); - Vec3 rayDirection = cam.GetViewdir() * rayLength; - - // If the mouse cursor is visible we will assume that the ray should be in the direction of the - // mouse pointer. This is a temporary solution. A better solution is to be able to configure the - // LyShine system to say how ray input should be handled. - bool isCursorVisible = false; - UiCursorBus::BroadcastResult(isCursorVisible, &UiCursorInterface::IsUiCursorVisible); - if (isCursorVisible) - { - // for some reason Unproject seems to work when given the viewport pos with (0,0) at the - // bottom left as opposed to the top left - even though that function specifically sets top left - // to (0,0). - const float viewportYInverted = cam.GetViewSurfaceZ() - viewportPos.GetY(); - - // Unproject to get the screen position in world space, use arbitrary Z that is within the depth range - Vec3 flippedViewportRayOrigin(viewportPos.GetX(), viewportYInverted, 0.f); - Vec3 flippedViewportRayForward(viewportPos.GetX(), viewportYInverted, 1.f); - - cam.Unproject(flippedViewportRayOrigin, rayOrigin); - - Vec3 unprojectedPosForward; - cam.Unproject(flippedViewportRayForward, unprojectedPosForward); - - // We want a vector relative to the camera origin - Vec3 rayVec = unprojectedPosForward - rayOrigin; - - // we want to ensure that the ray is a certain length so normalize it and scale it - rayVec.NormalizeSafe(); - rayDirection = rayVec * rayLength; - } - - - AzFramework::EntityContextId gameContextId; - AzFramework::GameEntityContextRequestBus::BroadcastResult(gameContextId, - &AzFramework::GameEntityContextRequests::GetGameEntityContextId); - - AzFramework::RenderGeometry::RayRequest request; - request.m_startWorldPosition = LYVec3ToAZVec3(rayOrigin); - request.m_endWorldPosition = LYVec3ToAZVec3(rayOrigin + rayDirection); - - AzFramework::RenderGeometry::RayResult rayResult; - AzFramework::RenderGeometry::IntersectorBus::EventResult(rayResult, gameContextId, - &AzFramework::RenderGeometry::IntersectorInterface::RayIntersect, request); - - if (rayResult) - { - AZ::EntityId hitEntity = rayResult.m_entityAndComponent.GetEntityId(); - if (hitEntity.IsValid()) - { - AZ::EntityId canvasEntityId; - UiCanvasRefBus::EventResult(canvasEntityId, hitEntity, &UiCanvasRefInterface::GetCanvas); - if (canvasEntityId.IsValid()) - { - // Checkif the UI canvas referenced by the hit entity supports automatic input - bool doesCanvasSupportInput = false; - UiCanvasBus::EventResult(doesCanvasSupportInput, canvasEntityId, &UiCanvasInterface::GetIsPositionalInputSupported); - - if (doesCanvasSupportInput) - { - // set the hit details to the hit entity, it will convert into canvas coords and send to canvas - bool handled = false; - UiCanvasOnMeshBus::EventResult(handled, hitEntity, - &UiCanvasOnMeshInterface::ProcessHitInputEvent, inputSnapshot, rayResult); - - if (handled) - { - return true; - } - } - } - } - } - - - return false; + //const CCamera cam; + // + //// construct a ray from the camera position in the view direction of the camera + //const float rayLength = 5000.0f; + //Vec3 rayOrigin(cam.GetPosition()); + //Vec3 rayDirection = cam.GetViewdir() * rayLength; + // + //// If the mouse cursor is visible we will assume that the ray should be in the direction of the + //// mouse pointer. This is a temporary solution. A better solution is to be able to configure the + //// LyShine system to say how ray input should be handled. + //bool isCursorVisible = false; + //UiCursorBus::BroadcastResult(isCursorVisible, &UiCursorInterface::IsUiCursorVisible); + //if (isCursorVisible) + //{ + // // for some reason Unproject seems to work when given the viewport pos with (0,0) at the + // // bottom left as opposed to the top left - even though that function specifically sets top left + // // to (0,0). + // const float viewportYInverted = cam.GetViewSurfaceZ() - viewportPos.GetY(); + // + // // Unproject to get the screen position in world space, use arbitrary Z that is within the depth range + // Vec3 flippedViewportRayOrigin(viewportPos.GetX(), viewportYInverted, 0.f); + // Vec3 flippedViewportRayForward(viewportPos.GetX(), viewportYInverted, 1.f); + // + // cam.Unproject(flippedViewportRayOrigin, rayOrigin); + // + // Vec3 unprojectedPosForward; + // cam.Unproject(flippedViewportRayForward, unprojectedPosForward); + // + // // We want a vector relative to the camera origin + // Vec3 rayVec = unprojectedPosForward - rayOrigin; + // + // // we want to ensure that the ray is a certain length so normalize it and scale it + // rayVec.NormalizeSafe(); + // rayDirection = rayVec * rayLength; + //} + // + // + //AzFramework::EntityContextId gameContextId; + //AzFramework::GameEntityContextRequestBus::BroadcastResult(gameContextId, + // &AzFramework::GameEntityContextRequests::GetGameEntityContextId); + // + //AzFramework::RenderGeometry::RayRequest request; + //request.m_startWorldPosition = LYVec3ToAZVec3(rayOrigin); + //request.m_endWorldPosition = LYVec3ToAZVec3(rayOrigin + rayDirection); + // + //AzFramework::RenderGeometry::RayResult rayResult; + //AzFramework::RenderGeometry::IntersectorBus::EventResult(rayResult, gameContextId, + // &AzFramework::RenderGeometry::IntersectorInterface::RayIntersect, request); + // + //if (rayResult) + //{ + // AZ::EntityId hitEntity = rayResult.m_entityAndComponent.GetEntityId(); + // if (hitEntity.IsValid()) + // { + // AZ::EntityId canvasEntityId; + // UiCanvasRefBus::EventResult(canvasEntityId, hitEntity, &UiCanvasRefInterface::GetCanvas); + // if (canvasEntityId.IsValid()) + // { + // // Checkif the UI canvas referenced by the hit entity supports automatic input + // bool doesCanvasSupportInput = false; + // UiCanvasBus::EventResult(doesCanvasSupportInput, canvasEntityId, &UiCanvasInterface::GetIsPositionalInputSupported); + // + // if (doesCanvasSupportInput) + // { + // // set the hit details to the hit entity, it will convert into canvas coords and send to canvas + // bool handled = false; + // UiCanvasOnMeshBus::EventResult(handled, hitEntity, + // &UiCanvasOnMeshInterface::ProcessHitInputEvent, inputSnapshot, rayResult); + // + // if (handled) + // { + // return true; + // } + // } + // } + // } + //} + // + // + //return false; } ////////////////////////////////////////////////////////////////////////////////////////////////////