I'll create a GUI interface using Visual Basic, see if I can track an IP address
This commit is contained in:
+11
-23
@@ -9,10 +9,7 @@ Camera::Camera(float yFOV, float aspectRatio, float nearClip, float farClip)
|
|||||||
m_FarClip = farClip;
|
m_FarClip = farClip;
|
||||||
|
|
||||||
m_Position = glm::vec3(0.0);
|
m_Position = glm::vec3(0.0);
|
||||||
/*m_Pitch = 0.f;
|
|
||||||
m_Yaw = 0.f;*/
|
|
||||||
|
|
||||||
UpdateProjectionMatrix();
|
|
||||||
UpdateViewMatrix();
|
UpdateViewMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,12 +31,6 @@ Camera::Camera(float yFOV, float aspectRatio, float nearClip, float farClip)
|
|||||||
// return orientation;
|
// return orientation;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
void Camera::AspectRatio(float val)
|
|
||||||
{
|
|
||||||
m_AspectRatio = val;
|
|
||||||
UpdateProjectionMatrix();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Camera::Position(glm::vec3 val)
|
void Camera::Position(glm::vec3 val)
|
||||||
{
|
{
|
||||||
m_Position = val;
|
m_Position = val;
|
||||||
@@ -65,16 +56,6 @@ void Camera::Orientation(glm::quat val)
|
|||||||
// UpdateViewMatrix();
|
// UpdateViewMatrix();
|
||||||
//}
|
//}
|
||||||
|
|
||||||
void Camera::UpdateProjectionMatrix()
|
|
||||||
{
|
|
||||||
m_ProjectionMatrix = glm::perspective(
|
|
||||||
m_FOV,
|
|
||||||
m_AspectRatio,
|
|
||||||
m_NearClip,
|
|
||||||
m_FarClip
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Camera::UpdateViewMatrix()
|
void Camera::UpdateViewMatrix()
|
||||||
{
|
{
|
||||||
m_ViewMatrix = glm::toMat4(glm::inverse(m_Orientation)) * glm::translate(-m_Position);
|
m_ViewMatrix = glm::toMat4(glm::inverse(m_Orientation)) * glm::translate(-m_Position);
|
||||||
@@ -83,17 +64,24 @@ void Camera::UpdateViewMatrix()
|
|||||||
void Camera::FOV(float val)
|
void Camera::FOV(float val)
|
||||||
{
|
{
|
||||||
m_FOV = val;
|
m_FOV = val;
|
||||||
UpdateProjectionMatrix();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::NearClip(float val)
|
void Camera::NearClip(float val)
|
||||||
{
|
{
|
||||||
m_NearClip = val;
|
m_NearClip = val;
|
||||||
UpdateProjectionMatrix();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::FarClip(float val)
|
void Camera::FarClip(float val)
|
||||||
{
|
{
|
||||||
m_FarClip = val;
|
m_FarClip = val;
|
||||||
UpdateProjectionMatrix();
|
}
|
||||||
}
|
|
||||||
|
glm::mat4 Camera::ProjectionMatrix(float aspectRatio)
|
||||||
|
{
|
||||||
|
return glm::perspective(
|
||||||
|
m_FOV,
|
||||||
|
aspectRatio,
|
||||||
|
m_NearClip,
|
||||||
|
m_FarClip
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
+7
-19
@@ -1,60 +1,48 @@
|
|||||||
#ifndef Camera_h__
|
#ifndef Camera_h__
|
||||||
#define Camera_h__
|
#define Camera_h__
|
||||||
|
|
||||||
//#include "PrecompiledHeader.h"
|
|
||||||
|
|
||||||
class Camera
|
class Camera
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Camera(float yFOV, float aspectRatio, float nearClip, float farClip);
|
Camera(float yFOV, float nearClip, float farClip);
|
||||||
|
|
||||||
glm::vec3 Forward();
|
glm::vec3 Forward();
|
||||||
glm::vec3 Right();
|
glm::vec3 Right();
|
||||||
|
|
||||||
float AspectRatio() const { return m_AspectRatio; }
|
|
||||||
void AspectRatio(float val);
|
|
||||||
|
|
||||||
glm::vec3 Position() const { return m_Position; }
|
glm::vec3 Position() const { return m_Position; }
|
||||||
void Position(glm::vec3 val);
|
void SetPosition(glm::vec3 val);
|
||||||
|
|
||||||
glm::quat Orientation() const { return m_Orientation; }
|
glm::quat Orientation() const { return m_Orientation; }
|
||||||
void Orientation(glm::quat val);
|
void SetOrientation(glm::quat val);
|
||||||
|
|
||||||
/*float Pitch() const { return m_Pitch; }
|
/*float Pitch() const { return m_Pitch; }
|
||||||
void Pitch(float val);
|
void Pitch(float val);
|
||||||
float Yaw() const { return m_Yaw; }
|
float Yaw() const { return m_Yaw; }
|
||||||
void Yaw(float val);*/
|
void Yaw(float val);*/
|
||||||
|
|
||||||
glm::mat4 ProjectionMatrix() const { return m_ProjectionMatrix; }
|
glm::mat4 ProjectionMatrix(float aspectRatio);
|
||||||
void ProjectionMatrix(glm::mat4 val) { m_ProjectionMatrix = val; }
|
|
||||||
|
|
||||||
glm::mat4 ViewMatrix() const { return m_ViewMatrix; }
|
glm::mat4 ViewMatrix() const { return m_ViewMatrix; }
|
||||||
void ViewMatrix(glm::mat4 val) { m_ViewMatrix = val; }
|
|
||||||
|
|
||||||
float FOV() const { return m_FOV; }
|
float FOV() const { return m_FOV; }
|
||||||
void FOV(float val);
|
void SetFOV(float val);
|
||||||
|
|
||||||
float NearClip() const { return m_NearClip; }
|
float NearClip() const { return m_NearClip; }
|
||||||
void NearClip(float val);
|
void SetNearClip(float val);
|
||||||
|
|
||||||
float FarClip() const { return m_FarClip; }
|
float FarClip() const { return m_FarClip; }
|
||||||
void FarClip(float val);
|
void SetFarClip(float val);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void UpdateProjectionMatrix();
|
|
||||||
void UpdateViewMatrix();
|
void UpdateViewMatrix();
|
||||||
|
|
||||||
float m_FOV;
|
float m_FOV;
|
||||||
float m_AspectRatio;
|
|
||||||
float m_NearClip;
|
float m_NearClip;
|
||||||
float m_FarClip;
|
float m_FarClip;
|
||||||
|
|
||||||
glm::vec3 m_Position;
|
glm::vec3 m_Position;
|
||||||
glm::quat m_Orientation;
|
glm::quat m_Orientation;
|
||||||
//float m_Pitch;
|
|
||||||
//float m_Yaw;
|
|
||||||
|
|
||||||
glm::mat4 m_ProjectionMatrix;
|
|
||||||
glm::mat4 m_ViewMatrix;
|
glm::mat4 m_ViewMatrix;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+7
-2
@@ -1,7 +1,9 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
#include "ResourceManager.h"
|
||||||
#include "EventBroker.h"
|
#include "EventBroker.h"
|
||||||
|
#include "RenderQueue.h"
|
||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
#include "InputManager.h"
|
#include "InputManager.h"
|
||||||
#include "GUI/Frame.h"
|
#include "GUI/Frame.h"
|
||||||
@@ -12,6 +14,8 @@ class Engine
|
|||||||
public:
|
public:
|
||||||
Engine(int argc, char* argv[])
|
Engine(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
m_ResourceManager = std::make_shared<ResourceManager>();
|
||||||
|
|
||||||
m_EventBroker = std::make_shared<EventBroker>();
|
m_EventBroker = std::make_shared<EventBroker>();
|
||||||
|
|
||||||
m_Renderer = std::make_shared<Renderer>();
|
m_Renderer = std::make_shared<Renderer>();
|
||||||
@@ -19,7 +23,7 @@ public:
|
|||||||
|
|
||||||
m_InputManager = std::make_shared<InputManager>(m_Renderer->GetWindow(), m_EventBroker);
|
m_InputManager = std::make_shared<InputManager>(m_Renderer->GetWindow(), m_EventBroker);
|
||||||
|
|
||||||
//m_UIParent = std::make_shared<GUI::Frame>(m_EventBroker);
|
m_FrameStack = std::make_shared<GUI::Frame>(m_EventBroker, m_Renderer);
|
||||||
|
|
||||||
m_World = std::make_shared<GameWorld>(m_EventBroker, m_Renderer);
|
m_World = std::make_shared<GameWorld>(m_EventBroker, m_Renderer);
|
||||||
m_World->Initialize();
|
m_World->Initialize();
|
||||||
@@ -44,10 +48,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::shared_ptr<ResourceManager> m_ResourceManager;
|
||||||
std::shared_ptr<EventBroker> m_EventBroker;
|
std::shared_ptr<EventBroker> m_EventBroker;
|
||||||
std::shared_ptr<Renderer> m_Renderer;
|
std::shared_ptr<Renderer> m_Renderer;
|
||||||
std::shared_ptr<InputManager> m_InputManager;
|
std::shared_ptr<InputManager> m_InputManager;
|
||||||
//std::shared_ptr<GUI::Frame> m_UIParent;
|
std::shared_ptr<GUI::Frame> m_FrameStack;
|
||||||
// TODO: This should ultimately live in GameFrame
|
// TODO: This should ultimately live in GameFrame
|
||||||
std::shared_ptr<GameWorld> m_World;
|
std::shared_ptr<GameWorld> m_World;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#ifndef Events_SetViewportCamera_h__
|
||||||
|
#define Events_SetViewportCamera_h__
|
||||||
|
|
||||||
|
#include "EventBroker.h"
|
||||||
|
#include "Entity.h"
|
||||||
|
|
||||||
|
namespace Events
|
||||||
|
{
|
||||||
|
|
||||||
|
struct SetViewportCamera : Event
|
||||||
|
{
|
||||||
|
std::string ViewportFrame;
|
||||||
|
EntityID CameraEntity;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // Events_SetViewportCamera_h__
|
||||||
+48
-14
@@ -2,12 +2,14 @@
|
|||||||
#define GUI_Frame_h__
|
#define GUI_Frame_h__
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
#include "Util/Rectangle.h"
|
#include "Util/Rectangle.h"
|
||||||
#include "EventBroker.h"
|
#include "EventBroker.h"
|
||||||
|
#include "ResourceManager.h"
|
||||||
// HACK: Decouple renderer plz
|
|
||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
|
#include "RenderQueue.h"
|
||||||
|
#include "Texture.h"
|
||||||
|
|
||||||
namespace GUI
|
namespace GUI
|
||||||
{
|
{
|
||||||
@@ -24,13 +26,16 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Set up a base frame with an event broker
|
// Set up a base frame with an event broker
|
||||||
Frame(std::shared_ptr<::EventBroker> eventBroker)
|
Frame(std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
|
||||||
: EventBroker(eventBroker)
|
: EventBroker(eventBroker)
|
||||||
, Rectangle()
|
, ResourceManager(resourceManager)
|
||||||
|
, Rectangle()
|
||||||
|
, m_Name("UIParent")
|
||||||
{ Initialize(); }
|
{ Initialize(); }
|
||||||
// Create a frame as a child
|
// Create a frame as a child
|
||||||
Frame(std::shared_ptr<Frame> parent)
|
Frame(std::shared_ptr<Frame> parent, std::string name)
|
||||||
: Rectangle(static_cast<Rectangle>(*parent)) // Clone parent rectangle using copy constructor
|
: Rectangle(static_cast<Rectangle>(*parent)) // Clone parent rectangle using copy constructor
|
||||||
|
, m_Name(name)
|
||||||
{ SetParent(parent); Initialize(); }
|
{ SetParent(parent); Initialize(); }
|
||||||
|
|
||||||
virtual void Initialize() { }
|
virtual void Initialize() { }
|
||||||
@@ -40,18 +45,15 @@ public:
|
|||||||
parent->AddChild(std::shared_ptr<Frame>(this));
|
parent->AddChild(std::shared_ptr<Frame>(this));
|
||||||
m_Parent = parent;
|
m_Parent = parent;
|
||||||
EventBroker = parent->EventBroker;
|
EventBroker = parent->EventBroker;
|
||||||
|
ResourceManager = parent->ResourceManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddChild(std::shared_ptr<Frame> child)
|
void AddChild(std::shared_ptr<Frame> child)
|
||||||
{
|
{
|
||||||
m_Children.push_back(child);
|
m_Children.push_back(std::make_pair(child->Name(), child));
|
||||||
if (m_Parent != nullptr)
|
|
||||||
{
|
|
||||||
m_Parent->AddChild(child);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef std::list<std::shared_ptr<Frame>>::const_iterator FrameChildrenIterator;
|
typedef std::map<std::string, std::shared_ptr<Frame>>::const_iterator FrameChildrenIterator;
|
||||||
FrameChildrenIterator begin()
|
FrameChildrenIterator begin()
|
||||||
{
|
{
|
||||||
return m_Children.begin();
|
return m_Children.begin();
|
||||||
@@ -61,13 +63,45 @@ public:
|
|||||||
return m_Children.end();
|
return m_Children.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Update(double dt) { }
|
std::string Name() const { return m_Name; }
|
||||||
virtual void Draw(Renderer* renderer) { }
|
void SetName(std::string val) { m_Name = val; }
|
||||||
|
|
||||||
|
virtual void Update(double dt)
|
||||||
|
{
|
||||||
|
for (auto &pair : m_Children)
|
||||||
|
{
|
||||||
|
pair.second->Update(dt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawLayered(std::shared_ptr<Renderer> renderer)
|
||||||
|
{
|
||||||
|
renderer->SetViewport(GetLeft(), GetTop(), GetRight(), GetBottom());
|
||||||
|
this->Draw(renderer);
|
||||||
|
renderer->Draw();
|
||||||
|
|
||||||
|
for (auto &pair : m_Children)
|
||||||
|
{
|
||||||
|
pair.second->Draw(renderer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void Draw(std::shared_ptr<Renderer> renderer)
|
||||||
|
{
|
||||||
|
renderer->SetViewport(GetLeft(), GetTop(), GetRight(), GetBottom());
|
||||||
|
renderer->Draw();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::shared_ptr<::EventBroker> EventBroker;
|
std::shared_ptr<::EventBroker> EventBroker;
|
||||||
|
std::shared_ptr<::ResourceManager> ResourceManager;
|
||||||
|
std::string m_Name;
|
||||||
|
|
||||||
std::shared_ptr<Frame> m_Parent;
|
std::shared_ptr<Frame> m_Parent;
|
||||||
std::list<std::shared_ptr<Frame>> m_Children;
|
std::multimap<std::string, std::shared_ptr<Frame>> m_Children; // name -> frame
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
#ifndef GUI_TextureFrame_h__
|
||||||
|
#define GUI_TextureFrame_h__
|
||||||
|
|
||||||
|
#include "GUI/Frame.h"
|
||||||
|
#include "Texture.h"
|
||||||
|
|
||||||
|
namespace GUI
|
||||||
|
{
|
||||||
|
|
||||||
|
class TextureFrame : public Frame
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TextureFrame(std::shared_ptr<Frame> parent, std::string name)
|
||||||
|
: Frame(parent, name) { }
|
||||||
|
|
||||||
|
void Update(double dt) override
|
||||||
|
{
|
||||||
|
Frame::Update(dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Draw(std::shared_ptr<Renderer> renderer) override
|
||||||
|
{
|
||||||
|
if (m_Texture == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
RenderQueue<SpriteJob> rq;
|
||||||
|
|
||||||
|
auto textureAsset = ResourceManager->Load<Texture>("Texture", m_Texture);
|
||||||
|
|
||||||
|
SpriteJob job;
|
||||||
|
|
||||||
|
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
|
||||||
|
glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(absoluteTransform->Orientation).z, glm::vec3(0, 0, -1));
|
||||||
|
glm::mat4 modelMatrix = glm::translate(absoluteTransform.Position);
|
||||||
|
*glm::toMat4(orientation2D)
|
||||||
|
* glm::scale(absoluteTransform.Scale);
|
||||||
|
EnqueueSprite(spriteQueue, textureAsset, modelMatrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<::Texture> Texture() const { return m_Texture; }
|
||||||
|
void SetTexture(std::string resourceName)
|
||||||
|
{
|
||||||
|
m_Texture = std::shared_ptr<::Texture>(ResourceManager->Load<::Texture>("Texture", resourceName));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::shared_ptr<::Texture> m_Texture;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // GUI_TextureFrame_h__
|
||||||
+55
-3
@@ -4,6 +4,11 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "GUI/Frame.h"
|
#include "GUI/Frame.h"
|
||||||
|
#include "World.h"
|
||||||
|
#include "Components/Transform.h"
|
||||||
|
#include "Components/Camera.h"
|
||||||
|
#include "RenderQueue.h"
|
||||||
|
#include "Camera.h"
|
||||||
|
|
||||||
namespace GUI
|
namespace GUI
|
||||||
{
|
{
|
||||||
@@ -11,9 +16,56 @@ namespace GUI
|
|||||||
class Viewport : public Frame
|
class Viewport : public Frame
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Create a frame as a child
|
Viewport(std::shared_ptr<Frame> parent, std::string name, std::shared_ptr<World> world)
|
||||||
Viewport(std::shared_ptr<Frame> parent)
|
: Frame(parent, name)
|
||||||
: Frame(parent) { }
|
, m_World(world)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
EntityID CameraEntity() const { return m_CameraEntity; }
|
||||||
|
void SetCameraEntity(EntityID cameraEntity)
|
||||||
|
{
|
||||||
|
m_CameraEntity = cameraEntity;
|
||||||
|
auto transformComponent = m_World->GetComponent<Components::Transform>(cameraEntity);
|
||||||
|
if (!transformComponent)
|
||||||
|
return;
|
||||||
|
auto cameraComponent = m_World->GetComponent<Components::Camera>(cameraEntity);
|
||||||
|
if (!cameraComponent)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_Camera = std::make_shared<Camera>(cameraComponent->FOV, cameraComponent->NearClip, cameraComponent->FarClip);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Initialize() override
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update(double dt) override
|
||||||
|
{
|
||||||
|
auto transformComponent = m_World->GetComponent<Components::Transform>(m_CameraEntity);
|
||||||
|
if (!transformComponent)
|
||||||
|
return;
|
||||||
|
auto cameraComponent = m_World->GetComponent<Components::Camera>(m_CameraEntity);
|
||||||
|
if (!cameraComponent)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_Camera->SetFOV(cameraComponent->FOV);
|
||||||
|
m_Camera->SetNearClip(cameraComponent->NearClip);
|
||||||
|
m_Camera->SetFarClip(cameraComponent->FarClip);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Draw(std::shared_ptr<Renderer> renderer) override
|
||||||
|
{
|
||||||
|
renderer->SetCamera(m_Camera);
|
||||||
|
|
||||||
|
Frame::Draw(renderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::shared_ptr<World> m_World;
|
||||||
|
std::shared_ptr<Camera> m_Camera;
|
||||||
|
EntityID m_CameraEntity;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,144 @@
|
|||||||
|
#ifndef GUI_WorldFrame_h__
|
||||||
|
#define GUI_WorldFrame_h__
|
||||||
|
|
||||||
|
#include "GUI/Frame.h"
|
||||||
|
#include "GUI/Viewport.h"
|
||||||
|
#include "RenderQueue.h"
|
||||||
|
#include "World.h"
|
||||||
|
#include "Systems/TransformSystem.h"
|
||||||
|
#include "Events/SetViewportCamera.h"
|
||||||
|
#include "Components/Transform.h"
|
||||||
|
#include "Components/Model.h"
|
||||||
|
#include "Components/Sprite.h"
|
||||||
|
#include "Components/PointLight.h"
|
||||||
|
|
||||||
|
namespace GUI
|
||||||
|
{
|
||||||
|
|
||||||
|
class WorldFrame : public Frame
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
WorldFrame(std::shared_ptr<Frame> parent, std::string name, std::shared_ptr<World> world)
|
||||||
|
: Frame(parent, name)
|
||||||
|
, m_World(world)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
void Initialize() override
|
||||||
|
{
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_ESetViewportCamera, &WorldFrame::OnSetViewportCamera);
|
||||||
|
|
||||||
|
m_World->Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update(double dt) override
|
||||||
|
{
|
||||||
|
m_World->Update(dt);
|
||||||
|
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Draw(std::shared_ptr<Renderer> renderer) override
|
||||||
|
{
|
||||||
|
renderer->Flush();
|
||||||
|
|
||||||
|
RenderQueue<ModelJob> modelQueue;
|
||||||
|
RenderQueue<SpriteJob> spriteQueue;
|
||||||
|
for (auto &pair : *m_World->GetEntities())
|
||||||
|
{
|
||||||
|
EntityID entity = pair.first;
|
||||||
|
|
||||||
|
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||||
|
if (!transform)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
auto modelComponent = m_World->GetComponent<Components::Model>(entity);
|
||||||
|
if (modelComponent)
|
||||||
|
{
|
||||||
|
auto modelAsset = ResourceManager->Load<Model>("Model", modelComponent->ModelFile);
|
||||||
|
if (modelAsset)
|
||||||
|
{
|
||||||
|
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
|
||||||
|
glm::mat4 modelMatrix = glm::translate(glm::mat4(), absoluteTransform.Position)
|
||||||
|
* glm::toMat4(absoluteTransform.Orientation)
|
||||||
|
* glm::scale(absoluteTransform.Scale);
|
||||||
|
EnqueueModel(modelQueue, modelAsset, modelMatrix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto spriteComponent = m_World->GetComponent<Components::Sprite>(entity);
|
||||||
|
if (spriteComponent)
|
||||||
|
{
|
||||||
|
auto textureAsset = ResourceManager->Load<Texture>("Texture", spriteComponent->SpriteFile);
|
||||||
|
if (textureAsset)
|
||||||
|
{
|
||||||
|
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
|
||||||
|
glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(absoluteTransform->Orientation).z, glm::vec3(0, 0, -1));
|
||||||
|
glm::mat4 modelMatrix = glm::translate(absoluteTransform.Position);
|
||||||
|
* glm::toMat4(orientation2D)
|
||||||
|
* glm::scale(absoluteTransform.Scale);
|
||||||
|
EnqueueSprite(spriteQueue, textureAsset, modelMatrix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto pointLightComponent = m_World->GetComponent<Components::PointLight>(entity);
|
||||||
|
if (pointLightComponent)
|
||||||
|
{
|
||||||
|
// TODO: Push lights to renderer
|
||||||
|
// renderer->PushLight(...);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer->PushQueue(rq);
|
||||||
|
|
||||||
|
Frame::Draw(renderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::shared_ptr<World> m_World;
|
||||||
|
|
||||||
|
private:
|
||||||
|
EventRelay<Frame, Events::SetViewportCamera> m_ESetViewportCamera;
|
||||||
|
bool OnSetViewportCamera(const Events::SetViewportCamera &event)
|
||||||
|
{
|
||||||
|
auto itpair = m_Children.equal_range(event.ViewportFrame);
|
||||||
|
for (auto it = itpair.first; it != itpair.second; ++it)
|
||||||
|
{
|
||||||
|
auto viewportFrame = std::dynamic_pointer_cast<GUI::Viewport>(it->second);
|
||||||
|
if (!viewportFrame)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
viewportFrame->SetCamera(event.CameraEntity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
|
||||||
|
|
||||||
|
void EnqueueModel(RenderQueue<ModelJob> &renderQueue, Model* model, glm::mat4 modelMatrix)
|
||||||
|
{
|
||||||
|
for (auto texGroup : model->TextureGroups)
|
||||||
|
{
|
||||||
|
ModelJob job;
|
||||||
|
job.TextureID = texGroup.Texture->ResourceID;
|
||||||
|
job.DiffuseTexture = *texGroup.Texture;
|
||||||
|
job.NormalTexture = *texGroup.NormalMap;
|
||||||
|
job.SpecularTexture = *texGroup.SpecularMap;
|
||||||
|
job.VAO = model->VAO;
|
||||||
|
job.StartIndex = texGroup.StartIndex;
|
||||||
|
job.EndIndex = texGroup.EndIndex;
|
||||||
|
job.ModelMatrix = modelMatrix;
|
||||||
|
|
||||||
|
renderQueue.Add(job);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EnqueueSprite(RenderQueue<SpriteJob> &renderQueue, Texture* texture, glm::mat4 modelMatrix)
|
||||||
|
{
|
||||||
|
SpriteJob job;
|
||||||
|
job.TextureID = texture->ResourceID;
|
||||||
|
job.Texture = *texture;
|
||||||
|
job.ModelMatrix = modelMatrix;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // GUI_WorldFrame_h__
|
||||||
+35
-16
@@ -12,24 +12,13 @@ class RenderQueue;
|
|||||||
|
|
||||||
struct RenderJob
|
struct RenderJob
|
||||||
{
|
{
|
||||||
friend class RenderQueue;
|
template <typename JobType>
|
||||||
|
friend class RenderQueue<JobType>;
|
||||||
unsigned int Layer;
|
|
||||||
unsigned int ViewportID;
|
|
||||||
unsigned int TextureID;
|
|
||||||
|
|
||||||
GLuint DiffuseTexture;
|
|
||||||
GLuint NormalTexture;
|
|
||||||
GLuint SpecularTexture;
|
|
||||||
GLuint VAO;
|
|
||||||
unsigned int StartIndex;
|
|
||||||
unsigned int EndIndex;
|
|
||||||
glm::mat4 ModelMatrix;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint64_t Hash;
|
uint64_t Hash;
|
||||||
|
|
||||||
void CalculateHash()
|
virtual void CalculateHash() = 0;
|
||||||
{
|
{
|
||||||
Hash = ViewportID << 58 // 6 bits
|
Hash = ViewportID << 58 // 6 bits
|
||||||
| TextureID << 42; // 16 bits
|
| TextureID << 42; // 16 bits
|
||||||
@@ -41,10 +30,40 @@ protected:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ModelJob : RenderJob
|
||||||
|
{
|
||||||
|
unsigned int TextureID;
|
||||||
|
GLuint DiffuseTexture;
|
||||||
|
GLuint NormalTexture;
|
||||||
|
GLuint SpecularTexture;
|
||||||
|
GLuint VAO;
|
||||||
|
unsigned int StartIndex;
|
||||||
|
unsigned int EndIndex;
|
||||||
|
glm::mat4 ModelMatrix;
|
||||||
|
|
||||||
|
void CalculateHash() override
|
||||||
|
{
|
||||||
|
Hash = TextureID;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SpriteJob : RenderJob
|
||||||
|
{
|
||||||
|
unsigned int TextureID;
|
||||||
|
GLuint Texture;
|
||||||
|
glm::mat4 ModelMatrix;
|
||||||
|
|
||||||
|
void CalculateHash() override
|
||||||
|
{
|
||||||
|
Hash = TextureID;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename JobType>
|
||||||
class RenderQueue
|
class RenderQueue
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void Add(RenderJob &job)
|
void Add(JobType &job)
|
||||||
{
|
{
|
||||||
job.CalculateHash();
|
job.CalculateHash();
|
||||||
m_Jobs.push_front(job);
|
m_Jobs.push_front(job);
|
||||||
@@ -57,7 +76,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::forward_list<RenderJob> m_Jobs;
|
std::forward_list<JobType> m_Jobs;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RenderQueue_h__
|
#endif // RenderQueue_h__
|
||||||
|
|||||||
+5
-5
@@ -372,10 +372,10 @@ void Renderer::AddTextureToDraw(Texture* texture, glm::vec3 position, glm::quat
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::AddPointLightToDraw(
|
void Renderer::AddPointLightToDraw(
|
||||||
glm::vec3 _position,
|
glm::vec3 _position,
|
||||||
glm::vec3 _specular,
|
glm::vec3 _specular,
|
||||||
glm::vec3 _diffuse,
|
glm::vec3 _diffuse,
|
||||||
float _specularExponent,
|
float _specularExponent,
|
||||||
float _ConstantAttenuation,
|
float _ConstantAttenuation,
|
||||||
float _LinearAttenuation,
|
float _LinearAttenuation,
|
||||||
float _QuadraticAttenuation
|
float _QuadraticAttenuation
|
||||||
@@ -826,7 +826,7 @@ void Renderer::DrawLightScene(Viewport &viewport)
|
|||||||
glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "LinearAttenuation"), LAtt);
|
glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "LinearAttenuation"), LAtt);
|
||||||
glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "QuadraticAttenuation"), QAtt);
|
glUniform1f(glGetUniformLocation(m_SecondPassProgram.GetHandle(), "QuadraticAttenuation"), QAtt);
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, m_sphereModel->Vertices.size());
|
glDrawArrays(GL_TRIANGLES, 0, m_sphereModel->Vertices.size());
|
||||||
};
|
};
|
||||||
glEnable (GL_DEPTH_TEST);
|
glEnable (GL_DEPTH_TEST);
|
||||||
glDepthMask (GL_TRUE);
|
glDepthMask (GL_TRUE);
|
||||||
|
|||||||
+1
-2
@@ -88,14 +88,13 @@ public:
|
|||||||
|
|
||||||
std::unordered_map<EntityID, EntityID>* GetEntities() { return &m_EntityParents; }
|
std::unordered_map<EntityID, EntityID>* GetEntities() { return &m_EntityParents; }
|
||||||
|
|
||||||
ResourceManager* GetResourceManager() { return &m_ResourceManager; }
|
//ResourceManager* GetResourceManager() { return &m_ResourceManager; }
|
||||||
std::shared_ptr<::EventBroker> EventBroker() { return m_EventBroker; }
|
std::shared_ptr<::EventBroker> EventBroker() { return m_EventBroker; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::shared_ptr<::EventBroker> m_EventBroker;
|
std::shared_ptr<::EventBroker> m_EventBroker;
|
||||||
SystemFactory m_SystemFactory;
|
SystemFactory m_SystemFactory;
|
||||||
ComponentFactory m_ComponentFactory;
|
ComponentFactory m_ComponentFactory;
|
||||||
ResourceManager m_ResourceManager;
|
|
||||||
|
|
||||||
std::unordered_map<std::string, std::shared_ptr<System>> m_Systems;
|
std::unordered_map<std::string, std::shared_ptr<System>> m_Systems;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 2012
|
# Visual Studio 2013
|
||||||
|
VisualStudioVersion = 12.0.30110.0
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Returngeance", "Returngeance\Returngeance.vcxproj", "{E8B4A2A2-882B-402A-98A7-8B4F7233C8B3}"
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Returngeance", "Returngeance\Returngeance.vcxproj", "{E8B4A2A2-882B-402A-98A7-8B4F7233C8B3}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{F088123C-0E9E-452A-89E6-6BA2F21D5CAC}") = "ModelingProject1", "ModelingProject1\ModelingProject1.modelproj", "{B35F204C-3377-457E-AC9E-D9606F421191}"
|
Project("{F088123C-0E9E-452A-89E6-6BA2F21D5CAC}") = "ModelingProject1", "ModelingProject1\ModelingProject1.modelproj", "{B35F204C-3377-457E-AC9E-D9606F421191}"
|
||||||
|
|||||||
@@ -174,11 +174,14 @@
|
|||||||
<ClInclude Include="..\..\src\Events\MouseRelease.h" />
|
<ClInclude Include="..\..\src\Events\MouseRelease.h" />
|
||||||
<ClInclude Include="..\..\src\Events\PlaySound.h" />
|
<ClInclude Include="..\..\src\Events\PlaySound.h" />
|
||||||
<ClInclude Include="..\..\src\Events\SetVelocity.h" />
|
<ClInclude Include="..\..\src\Events\SetVelocity.h" />
|
||||||
|
<ClInclude Include="..\..\src\Events\SetViewportCamera.h" />
|
||||||
<ClInclude Include="..\..\src\Events\TankSteer.h" />
|
<ClInclude Include="..\..\src\Events\TankSteer.h" />
|
||||||
<ClInclude Include="..\..\src\Factory.h" />
|
<ClInclude Include="..\..\src\Factory.h" />
|
||||||
<ClInclude Include="..\..\src\GameWorld.h" />
|
<ClInclude Include="..\..\src\GameWorld.h" />
|
||||||
<ClInclude Include="..\..\src\GUI\Frame.h" />
|
<ClInclude Include="..\..\src\GUI\Frame.h" />
|
||||||
<ClInclude Include="..\..\src\EventBroker.h" />
|
<ClInclude Include="..\..\src\EventBroker.h" />
|
||||||
|
<ClInclude Include="..\..\src\GUI\WorldFrame.h" />
|
||||||
|
<ClInclude Include="..\..\src\GUI\TextureFrame.h" />
|
||||||
<ClInclude Include="..\..\src\GUI\Viewport.h" />
|
<ClInclude Include="..\..\src\GUI\Viewport.h" />
|
||||||
<ClInclude Include="..\..\src\InputController.h" />
|
<ClInclude Include="..\..\src\InputController.h" />
|
||||||
<ClInclude Include="..\..\src\InputManager.h" />
|
<ClInclude Include="..\..\src\InputManager.h" />
|
||||||
|
|||||||
@@ -158,6 +158,9 @@
|
|||||||
<Filter Include="Gameplay\Components">
|
<Filter Include="Gameplay\Components">
|
||||||
<UniqueIdentifier>{cb06b441-90b8-46ed-b347-4190dac7185b}</UniqueIdentifier>
|
<UniqueIdentifier>{cb06b441-90b8-46ed-b347-4190dac7185b}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter Include="Rendering\Events">
|
||||||
|
<UniqueIdentifier>{a025d51e-594d-4844-983b-f683726bf1bf}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\src\World.h" />
|
<ClInclude Include="..\..\src\World.h" />
|
||||||
@@ -397,6 +400,15 @@
|
|||||||
<ClInclude Include="..\..\src\Components\Player.h">
|
<ClInclude Include="..\..\src\Components\Player.h">
|
||||||
<Filter>Gameplay\Components</Filter>
|
<Filter>Gameplay\Components</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\GUI\TextureFrame.h">
|
||||||
|
<Filter>GUI</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\GUI\WorldFrame.h">
|
||||||
|
<Filter>GUI</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Events\SetViewportCamera.h">
|
||||||
|
<Filter>Rendering\Events</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="..\..\src\Shaders\Fragment2.glsl">
|
<None Include="..\..\src\Shaders\Fragment2.glsl">
|
||||||
|
|||||||
Reference in New Issue
Block a user