Linked picking to entities

This commit is contained in:
viktorljung
2015-12-07 17:26:42 +01:00
parent 9c589a0dc6
commit 9e1a4b83ae
4 changed files with 14 additions and 4 deletions
+4
View File
@@ -7,6 +7,7 @@
#include "../Common.h" #include "../Common.h"
#include "../GLM.h" #include "../GLM.h"
#include "../Core/Util/Rectangle.h" #include "../Core/Util/Rectangle.h"
#include "../Core/EntityWrapper.h"
class Model; class Model;
class Skeleton; class Skeleton;
@@ -37,6 +38,9 @@ struct ModelJob : RenderJob
unsigned int ShaderID = 0; unsigned int ShaderID = 0;
unsigned int TextureID = 0; unsigned int TextureID = 0;
//TODO: RENDERER: Not sure if the best solution for pickingColor to entity link is this
EntityID Entity;
glm::mat4 ModelMatrix; glm::mat4 ModelMatrix;
const Texture* DiffuseTexture; const Texture* DiffuseTexture;
const Texture* NormalTexture; const Texture* NormalTexture;
+2 -1
View File
@@ -9,6 +9,7 @@
#include "../Core/ResourceManager.h" #include "../Core/ResourceManager.h"
#include "Util/UnorderedMapVec2.h" #include "Util/UnorderedMapVec2.h"
#include "Util/FrameBuffer.h" #include "Util/FrameBuffer.h"
#include "../Core/World.h"
class Renderer : public IRenderer class Renderer : public IRenderer
{ {
@@ -32,7 +33,7 @@ private:
std::unordered_map<glm::vec2, const Model*> m_PickingColorsToModels; std::unordered_map<glm::vec2, EntityID> m_PickingColorsToEntity;
//----------------------Functions----------------------// //----------------------Functions----------------------//
void InitializeWindow(); void InitializeWindow();
@@ -53,6 +53,9 @@ void RenderQueueFactory::FillModels(World* world, RenderQueue* renderQueue)
job.ModelMatrix = model->m_Matrix * ModelMatrix(world, modelC.EntityID); job.ModelMatrix = model->m_Matrix * ModelMatrix(world, modelC.EntityID);
job.Color = color; job.Color = color;
//TODO: RENDERER: Not sure if the best solution for pickingColor to entity link is this
job.Entity = modelC.EntityID;
renderQueue->Add(job); renderQueue->Add(job);
} }
} }
+5 -3
View File
@@ -125,10 +125,11 @@ void Renderer::InputUpdate(double dt)
// glm::vec3 worldPos = glm::vec3(glm::inverse(m_Camera->ViewMatrix()) * glm::vec4(viewPos, 1.f)); // 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("R: %f, G: %f, Depth: %f\n", color.r, color.g, depth);
printf("view: x: %f, y: %f z: %f, Length: %f\n\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)) { if (color != glm::vec2(0, 0)) {
const Model* pickModel = m_PickingColorsToModels[color]; EntityID pickedEntity = m_PickingColorsToEntity[color];
printf("Picked Entity: %i", pickedEntity);
} }
} }
@@ -237,7 +238,8 @@ void Renderer::PickingPass(RenderQueueCollection& rq)
if (modelJob) { if (modelJob) {
glm::vec2 pickColor = glm::vec2(r/255.f, g/255.f); glm::vec2 pickColor = glm::vec2(r/255.f, g/255.f);
m_PickingColorsToModels[pickColor] = modelJob->Model; m_PickingColorsToEntity[pickColor] = modelJob->Entity;
//Render picking stuff //Render picking stuff
//TODO: Kolla upp "header/include/common" shader saken så man slipper skicka in asmycket uniforms //TODO: Kolla upp "header/include/common" shader saken så man slipper skicka in asmycket uniforms