Removed picking event and added a pick function to renderer

This commit is contained in:
viktorljung
2016-01-12 11:45:50 +01:00
parent 3feee7fd35
commit d469fe6e9a
15 changed files with 82 additions and 137 deletions
+2 -3
View File
@@ -7,7 +7,6 @@
#include "../Core/ConfigFile.h"
#include "../Input/EInputCommand.h"
#include "../Rendering/IRenderer.h"
#include "../Rendering/EPicking.h"
#include "../Rendering/RenderSystem.h"
class EditorSystem : public ImpureSystem
@@ -59,8 +58,8 @@ private:
bool OnMousePress(const Events::MousePress& e);
EventRelay<EditorSystem, Events::MouseMove> m_EMouseMove;
bool OnMouseMove(const Events::MouseMove& e);
EventRelay<EditorSystem, Events::Picking> m_EPicking;
bool OnPicking(const Events::Picking& e);
void Picking();
void updateWidget();
void setWidgetMode(WidgetMode newMode);
-74
View File
@@ -1,74 +0,0 @@
#ifndef Events_Picking_h__
#define Events_Picking_h__
#include "../OpenGL.h"
#include "../GLM.h"
#include "../Core/EventBroker.h"
#include "Util/ScreenCoords.h"
#include "FrameBuffer.h"
#include "../Core/Entity.h"
#include "Util/UnorderedMapVec2.h"
namespace Events
{
/** Thrown Every frame, use functions to pick*/
struct Picking : Event
{
public:
Picking(FrameBuffer* pickingBuffer, GLuint* depthBuffer, glm::mat4 projectionMatrix, glm::mat4 viewMatrix, Rectangle resolution, const std::unordered_map<glm::vec2, EntityID>* pickingColorsToEntity)
: PickingBuffer(pickingBuffer)
, DepthBuffer(depthBuffer)
, ProjectionMatrix(projectionMatrix)
, ViewMatrix(viewMatrix)
, Resolution(resolution)
, PickingColorsToEntity(pickingColorsToEntity)
{ }
struct PickData
{
//Picked Entity
EntityID Entity;
//World position of the "pick"
glm::vec3 Position;
// Depth
float Depth;
};
PickData Pick(glm::vec2 screenCoord) const
{
PickData pickData;
// Invert screen y coordinate
screenCoord.y = Resolution.Height - screenCoord.y;
ScreenCoords::PixelData data = ScreenCoords::ToPixelData(screenCoord, PickingBuffer, *DepthBuffer);
pickData.Depth = data.Depth;
auto it = PickingColorsToEntity->find(glm::vec2(data.Color[0], data.Color[1]));
if (it != PickingColorsToEntity->end()) {
pickData.Entity = it->second;
} else {
pickData.Entity = 0;
}
pickData.Position = ScreenCoords::ToWorldPos(screenCoord.x, screenCoord.y, data.Depth, Resolution, ProjectionMatrix, ViewMatrix);
return pickData;
}
private:
FrameBuffer* PickingBuffer;
GLuint* DepthBuffer;
const glm::mat4 ProjectionMatrix;
const glm::mat4 ViewMatrix;
const Rectangle Resolution;
const std::unordered_map<glm::vec2, EntityID>* PickingColorsToEntity;
};
}
#endif
+8
View File
@@ -10,6 +10,13 @@
#include "RenderQueue.h"
#include "Model.h"
struct PickData
{
EntityID Entity;
glm::vec3 Position; //World position
float Depth;
};
class IRenderer
{
public:
@@ -32,6 +39,7 @@ public:
virtual void Initialize() = 0;
virtual void Update(double dt) = 0;
virtual void Draw(RenderFrame& rq) = 0;
virtual PickData Pick(glm::vec2 screenCord) = 0;
protected:
Rectangle m_Resolution = Rectangle(1280, 720);
+4 -1
View File
@@ -7,7 +7,8 @@
#include "ShaderProgram.h"
#include "Util/UnorderedMapVec2.h"
#include "../Core/EventBroker.h"
#include "EPicking.h"
class PickingPass
{
@@ -28,6 +29,8 @@ public:
GLuint DepthBuffer() const { return m_DepthBuffer; }
const FrameBuffer& PickingBuffer() const { return m_PickingBuffer; }
PickData Pick(glm::vec2 screenCoord);
private:
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const;
+3 -7
View File
@@ -12,11 +12,8 @@
#include "RenderJob.h"
#include "ModelJob.h"
class Model;
class Skeleton;
class Texture;
//TODO: Render: Remove obsolete RenderJobs and fix standard values on variables.
/*
@@ -88,7 +85,7 @@ struct RenderScene
::Camera* Camera;
std::list<std::shared_ptr<RenderJob>> ForwardJobs;
std::list<std::shared_ptr<RenderJob>> LightJobs;
Rectangle ViewPort;
void Clear()
{
@@ -125,8 +122,7 @@ public:
}
std::list<std::shared_ptr<RenderScene>> RenderScenes;
private:
int m_Size = 0;
};
+4 -2
View File
@@ -12,12 +12,12 @@
#include "../Input/EInputCommand.h"
#include "Camera.h"
#include "ModelJob.h"
#include "Renderer.h"
class RenderSystem : public ImpureSystem
{
public:
RenderSystem(EventBroker* eventBrokerer, RenderFrame* renderFrame);
RenderSystem(EventBroker* eventBrokerer, const IRenderer* renderer, RenderFrame* renderFrame);
virtual void Update(World* world, double dt) override;
@@ -29,6 +29,7 @@ public:
private:
World* m_World = nullptr;
const IRenderer* m_Renderer = nullptr;
RenderFrame* m_RenderFrame;
bool m_SwitchCamera = false;
@@ -44,6 +45,7 @@ private:
void SwitchCamera(EntityID entity);
void Initialize();
void UpdateCamera(World* world, double dt);
void UpdateProjectionMatrix(ComponentWrapper& cameraComponent);
glm::mat4 m_ViewMatrix;
glm::mat4 m_ProjectionMatrix;
+2 -1
View File
@@ -13,7 +13,6 @@
#include "PickingPass.h"
#include "DrawScenePass.h"
#include "../Core/EventBroker.h"
#include "EPicking.h"
#include "ImGuiRenderPass.h"
#include "Camera.h"
@@ -29,6 +28,8 @@ public:
virtual void Update(double dt) override;
virtual void Draw(RenderFrame& rf) override;
virtual PickData Pick(glm::vec2 screenCoord) override;
private:
//----------------------Variables----------------------//
EventBroker* m_EventBroker;