Fixed picking event

This commit is contained in:
2015-12-14 14:19:45 +01:00
parent 3a9577c9fb
commit 797036c204
2 changed files with 7 additions and 2 deletions
+3 -1
View File
@@ -40,6 +40,8 @@ public:
{ {
PickData pickData; PickData pickData;
// Invert screen y coordinate
screenCoord.y = Resolution.Height - screenCoord.y;
ScreenCoords::PixelData data = ScreenCoords::ToPixelData(screenCoord, PickingBuffer, *DepthBuffer); ScreenCoords::PixelData data = ScreenCoords::ToPixelData(screenCoord, PickingBuffer, *DepthBuffer);
auto it = PickingColorsToEntity->find(glm::vec2(data.Color[0], data.Color[1])); auto it = PickingColorsToEntity->find(glm::vec2(data.Color[0], data.Color[1]));
@@ -48,7 +50,7 @@ public:
} else { } else {
pickData.Entity = 0; 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; return pickData;
} }
+4 -1
View File
@@ -93,12 +93,15 @@ void PickingPass::Draw(RenderQueueCollection& rq)
GLERROR("PickingPass Error"); GLERROR("PickingPass Error");
//Publish pick event every frame with the pick data that can be picked by the event //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( Events::Picking pickEvent = Events::Picking(
&m_PickingBuffer, &m_PickingBuffer,
&m_DepthBuffer, &m_DepthBuffer,
m_Renderer->Camera()->ProjectionMatrix(), m_Renderer->Camera()->ProjectionMatrix(),
m_Renderer->Camera()->ViewMatrix(), m_Renderer->Camera()->ViewMatrix(),
m_Renderer->Resolution(), Rectangle(fbWidth, fbHeight),
&m_PickingColorsToEntity); &m_PickingColorsToEntity);
m_EventBroker->Publish(pickEvent); m_EventBroker->Publish(pickEvent);