From 797036c20474acb9d97bf78bde298966767b2c11 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Mon, 14 Dec 2015 14:19:45 +0100 Subject: [PATCH] Fixed picking event --- include/Engine/Rendering/EPicking.h | 4 +++- src/Engine/Rendering/PickingPass.cpp | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/Engine/Rendering/EPicking.h b/include/Engine/Rendering/EPicking.h index 66530a01..044a944b 100644 --- a/include/Engine/Rendering/EPicking.h +++ b/include/Engine/Rendering/EPicking.h @@ -40,6 +40,8 @@ public: { PickData pickData; + // Invert screen y coordinate + screenCoord.y = Resolution.Height - screenCoord.y; ScreenCoords::PixelData data = ScreenCoords::ToPixelData(screenCoord, PickingBuffer, *DepthBuffer); auto it = PickingColorsToEntity->find(glm::vec2(data.Color[0], data.Color[1])); @@ -48,7 +50,7 @@ public: } else { pickData.Entity = 0; } - pickData.Position = ScreenCoords::ToWorldPos(screenCoord.x, Resolution.Width - screenCoord.y, data.Depth, Resolution, ProjectionMatrix, ViewMatrix); + pickData.Position = ScreenCoords::ToWorldPos(screenCoord.x, screenCoord.y, data.Depth, Resolution, ProjectionMatrix, ViewMatrix); return pickData; } diff --git a/src/Engine/Rendering/PickingPass.cpp b/src/Engine/Rendering/PickingPass.cpp index 7d4cb66f..d45c0322 100644 --- a/src/Engine/Rendering/PickingPass.cpp +++ b/src/Engine/Rendering/PickingPass.cpp @@ -93,12 +93,15 @@ void PickingPass::Draw(RenderQueueCollection& rq) GLERROR("PickingPass Error"); //Publish pick event every frame with the pick data that can be picked by the event + int fbWidth; + int fbHeight; + glfwGetFramebufferSize(m_Renderer->Window(), &fbWidth, &fbHeight); Events::Picking pickEvent = Events::Picking( &m_PickingBuffer, &m_DepthBuffer, m_Renderer->Camera()->ProjectionMatrix(), m_Renderer->Camera()->ViewMatrix(), - m_Renderer->Resolution(), + Rectangle(fbWidth, fbHeight), &m_PickingColorsToEntity); m_EventBroker->Publish(pickEvent);