Merge branch 'Rendering' of github.com:teamfisk/TacticalZ into Rendering
# Conflicts: # include/Engine/Rendering/Renderer.h # src/Engine/Rendering/Renderer.cpp
This commit is contained in:
@@ -161,16 +161,15 @@ void Renderer::InputUpdate(double dt)
|
||||
static double mousePosX, mousePosY;
|
||||
glfwGetCursorPos(m_Window, &mousePosX, &mousePosY);
|
||||
if (glfwGetMouseButton(m_Window, GLFW_MOUSE_BUTTON_1) == GLFW_PRESS) {
|
||||
glm::vec3 data = GetClickedPixelData(mousePosX, m_Resolution.Height - mousePosY);
|
||||
glm::vec3 data = ScreenCoords::ToPixelData(mousePosX, m_Resolution.Height - mousePosY, m_PickingBuffer, m_DepthBuffer);
|
||||
glm::vec2 color = glm::vec2(data);
|
||||
float depth = data.z;
|
||||
|
||||
glm::vec3 viewPos = ScreenCoordsToWorldPos(glm::vec2(mousePosX, m_Resolution.Height - mousePosY), depth);
|
||||
glm::vec3 viewPos = ScreenCoords::ToWorldPos(mousePosX, m_Resolution.Height - mousePosY, depth, m_Resolution, m_Camera->ProjectionMatrix(), m_Camera->ViewMatrix());
|
||||
// glm::vec3 worldPos = glm::vec3(glm::inverse(m_Camera->ViewMatrix()) * glm::vec4(viewPos, 1.f));
|
||||
|
||||
//printf("R: %f, G: %f, Depth: %f\n", color.r, color.g, depth);
|
||||
printf("view: x: %f, y: %f z: %f, Length: %f\n", viewPos.x, viewPos.y, viewPos.z, glm::length(viewPos));
|
||||
|
||||
//printf("view: x: %f, y: %f z: %f, Length: %f\n\n", viewPos.x, viewPos.y, viewPos.z, glm::length(viewPos));
|
||||
|
||||
if (color != glm::vec2(0, 0)) {
|
||||
const Model* pickModel = m_PickingColorsToModels[color];
|
||||
@@ -200,33 +199,6 @@ void Renderer::InputUpdate(double dt)
|
||||
m_Camera->SetPosition(m_Position);
|
||||
}
|
||||
|
||||
|
||||
// Utility functions should be moved to a better place
|
||||
glm::vec3 Renderer::ScreenCoordsToWorldPos(glm::vec2 screenCoord, float depth)
|
||||
{
|
||||
glm::vec4 pos;
|
||||
float near = m_Camera->NearClip();
|
||||
float far = m_Camera->FarClip();
|
||||
|
||||
glm::vec3 ndc;
|
||||
ndc.x = screenCoord.x / m_Resolution.Width;
|
||||
ndc.y = screenCoord.y / m_Resolution.Height;
|
||||
glm::vec4 clipSpace = glm::vec4(glm::vec2(ndc.x, ndc.y) * 2.0f - 1.0f, (depth) * 2.0f - 1.0f, 1.0f);
|
||||
|
||||
glm::vec4 EyeSpace = glm::inverse(m_Camera->ProjectionMatrix()) * clipSpace;
|
||||
glm::vec4 WorldSpace = glm::inverse(m_Camera->ViewMatrix()) * EyeSpace;
|
||||
WorldSpace = glm::vec4(glm::vec3(WorldSpace) / WorldSpace.w, 1.f);
|
||||
|
||||
return glm::vec3(WorldSpace);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//EntityID Renderer::ScreenCoordsToEntityID(glm::vec2 screenCoord, float depth)
|
||||
//{
|
||||
//
|
||||
//}
|
||||
|
||||
void Renderer::Update(double dt)
|
||||
{
|
||||
InputUpdate(dt);
|
||||
@@ -352,23 +324,6 @@ void Renderer::DrawScreenQuad(GLuint textureToDraw)
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Will return a vec3 where RG is the PickColor and B is the Depth
|
||||
glm::vec3 Renderer::GetClickedPixelData(float x, float y)
|
||||
{
|
||||
m_PickingBuffer.Bind();
|
||||
glm::vec2 pixelData;
|
||||
glReadPixels(x, y, 1, 1, GL_RG, GL_FLOAT, &pixelData);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_DepthBuffer);
|
||||
float depthData;
|
||||
glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depthData);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
return glm::vec3(pixelData, depthData);
|
||||
}
|
||||
|
||||
void Renderer::InitializeTextures()
|
||||
{
|
||||
m_ErrorTexture=ResourceManager::Load<Texture>("Textures/Core/ErrorTexture.png");
|
||||
|
||||
Reference in New Issue
Block a user