Merge remote-tracking branch 'origin/master' into Forward+
This commit is contained in:
@@ -4,59 +4,14 @@
|
|||||||
#include "../GLM.h"
|
#include "../GLM.h"
|
||||||
#include "World.h"
|
#include "World.h"
|
||||||
|
|
||||||
static class Transform
|
namespace Transform
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
static glm::vec3 AbsolutePosition(World* world, EntityID entity)
|
|
||||||
{
|
|
||||||
glm::vec3 position;
|
|
||||||
|
|
||||||
while (entity != EntityID_Invalid) {
|
glm::vec3 AbsolutePosition(World* world, EntityID entity);
|
||||||
ComponentWrapper transform = world->GetComponent(entity, "Transform");
|
glm::quat AbsoluteOrientation(World* world, EntityID entity);
|
||||||
EntityID parent = world->GetParent(entity);
|
glm::vec3 AbsoluteScale(World* world, EntityID entity);
|
||||||
position += AbsoluteOrientation(world, parent) * (glm::vec3)transform["Position"];
|
glm::mat4 ModelMatrix(EntityID entity, World* world);
|
||||||
entity = parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
return position;
|
}
|
||||||
};
|
|
||||||
|
|
||||||
static glm::quat AbsoluteOrientation(World* world, EntityID entity)
|
|
||||||
{
|
|
||||||
glm::quat orientation;
|
|
||||||
|
|
||||||
while (entity != EntityID_Invalid) {
|
|
||||||
ComponentWrapper transform = world->GetComponent(entity, "Transform");
|
|
||||||
orientation = glm::quat((glm::vec3)transform["Orientation"]) * orientation;
|
|
||||||
entity = world->GetParent(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
return orientation;
|
|
||||||
};
|
|
||||||
|
|
||||||
static glm::vec3 AbsoluteScale(World* world, EntityID entity)
|
|
||||||
{
|
|
||||||
glm::vec3 scale(1.f);
|
|
||||||
|
|
||||||
while (entity != EntityID_Invalid) {
|
|
||||||
ComponentWrapper transform = world->GetComponent(entity, "Transform");
|
|
||||||
scale *= (glm::vec3)transform["Scale"];
|
|
||||||
entity = world->GetParent(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
return scale;
|
|
||||||
};
|
|
||||||
|
|
||||||
static glm::mat4 ModelMatrix(EntityID entity, World* world)
|
|
||||||
{
|
|
||||||
glm::vec3 position = Transform::AbsolutePosition(world, entity);
|
|
||||||
glm::quat orientation = Transform::AbsoluteOrientation(world, entity);
|
|
||||||
glm::vec3 scale = Transform::AbsoluteScale(world, entity);
|
|
||||||
|
|
||||||
glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale);
|
|
||||||
return modelMatrix;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -15,22 +15,24 @@
|
|||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
#include "PointLightJob.h"
|
#include "PointLightJob.h"
|
||||||
#include "../Core/Transform.h"
|
#include "../Core/Transform.h"
|
||||||
|
#include "DebugCameraInputController.h"
|
||||||
|
|
||||||
class RenderSystem : public ImpureSystem
|
class RenderSystem : public ImpureSystem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RenderSystem(EventBroker* eventBrokerer, const IRenderer* renderer, RenderFrame* renderFrame);
|
RenderSystem(EventBroker* eventBrokerer, const IRenderer* renderer, RenderFrame* renderFrame);
|
||||||
|
~RenderSystem();
|
||||||
|
|
||||||
virtual void Update(World* world, double dt) override;
|
virtual void Update(World* world, double dt) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
World* m_World = nullptr;
|
World* m_World = nullptr;
|
||||||
const IRenderer* m_Renderer = nullptr;
|
const IRenderer* m_Renderer;
|
||||||
|
|
||||||
RenderFrame* m_RenderFrame;
|
RenderFrame* m_RenderFrame;
|
||||||
bool m_SwitchCamera = false;
|
bool m_SwitchCamera = false;
|
||||||
Camera* m_Camera = nullptr;
|
Camera* m_Camera;
|
||||||
Camera* m_DefaultCamera = nullptr;
|
DebugCameraInputController<RenderSystem>* m_DebugCameraInputController;
|
||||||
|
|
||||||
std::list<ComponentWrapper> m_CameraComponents;
|
std::list<ComponentWrapper> m_CameraComponents;
|
||||||
|
|
||||||
@@ -42,8 +44,6 @@ private:
|
|||||||
|
|
||||||
void updateCamera(World* world, double dt);
|
void updateCamera(World* world, double dt);
|
||||||
void updateProjectionMatrix(ComponentWrapper& cameraComponent);
|
void updateProjectionMatrix(ComponentWrapper& cameraComponent);
|
||||||
glm::mat4 m_ViewMatrix;
|
|
||||||
glm::mat4 m_ProjectionMatrix;
|
|
||||||
|
|
||||||
void fillModels(std::list<std::shared_ptr<RenderJob>>& jobs, World* world);
|
void fillModels(std::list<std::shared_ptr<RenderJob>>& jobs, World* world);
|
||||||
void fillLight(std::list<std::shared_ptr<RenderJob>>& jobs, World* world);
|
void fillLight(std::list<std::shared_ptr<RenderJob>>& jobs, World* world);
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
#include "Core/Transform.h"
|
||||||
|
|
||||||
|
glm::vec3 Transform::AbsolutePosition(World* world, EntityID entity)
|
||||||
|
{
|
||||||
|
glm::vec3 position;
|
||||||
|
|
||||||
|
while (entity != EntityID_Invalid) {
|
||||||
|
ComponentWrapper transform = world->GetComponent(entity, "Transform");
|
||||||
|
EntityID parent = world->GetParent(entity);
|
||||||
|
position += Transform::AbsoluteOrientation(world, parent) * (glm::vec3)transform["Position"];
|
||||||
|
entity = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::quat Transform::AbsoluteOrientation(World* world, EntityID entity)
|
||||||
|
{
|
||||||
|
glm::quat orientation;
|
||||||
|
|
||||||
|
while (entity != EntityID_Invalid) {
|
||||||
|
ComponentWrapper transform = world->GetComponent(entity, "Transform");
|
||||||
|
orientation = glm::quat((glm::vec3)transform["Orientation"]) * orientation;
|
||||||
|
entity = world->GetParent(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
return orientation;
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::vec3 Transform::AbsoluteScale(World* world, EntityID entity)
|
||||||
|
{
|
||||||
|
glm::vec3 scale(1.f);
|
||||||
|
|
||||||
|
while (entity != EntityID_Invalid) {
|
||||||
|
ComponentWrapper transform = world->GetComponent(entity, "Transform");
|
||||||
|
scale *= (glm::vec3)transform["Scale"];
|
||||||
|
entity = world->GetParent(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
return scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::mat4 Transform::ModelMatrix(EntityID entity, World* world)
|
||||||
|
{
|
||||||
|
glm::vec3 position = Transform::AbsolutePosition(world, entity);
|
||||||
|
glm::quat orientation = Transform::AbsoluteOrientation(world, entity);
|
||||||
|
glm::vec3 scale = Transform::AbsoluteScale(world, entity);
|
||||||
|
|
||||||
|
glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale);
|
||||||
|
return modelMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -124,6 +124,9 @@ bool EditorSystem::OnMouseMove(const Events::MouseMove& e)
|
|||||||
if (m_Selection == 0) {
|
if (m_Selection == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (m_Camera == nullptr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
auto widgetTransform = m_World->GetComponent(m_Widget, "Transform");
|
auto widgetTransform = m_World->GetComponent(m_Widget, "Transform");
|
||||||
glm::vec3 widgetOrientation = widgetTransform["Orientation"];
|
glm::vec3 widgetOrientation = widgetTransform["Orientation"];
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ void PickingPass::ClearPicking()
|
|||||||
{
|
{
|
||||||
m_PickingColorsToEntity.clear();
|
m_PickingColorsToEntity.clear();
|
||||||
m_EntityColors.clear();
|
m_EntityColors.clear();
|
||||||
m_ColorCounter[0] = 0;
|
m_ColorCounter[0] = 1;
|
||||||
m_ColorCounter[1] = 0;
|
m_ColorCounter[1] = 0;
|
||||||
|
|
||||||
m_PickingBuffer.Bind();
|
m_PickingBuffer.Bind();
|
||||||
@@ -138,10 +138,10 @@ PickData PickingPass::Pick(glm::vec2 screenCoord)
|
|||||||
pickInfo = it->second;
|
pickInfo = it->second;
|
||||||
} else {
|
} else {
|
||||||
pickData.Entity = EntityID_Invalid;
|
pickData.Entity = EntityID_Invalid;
|
||||||
|
return pickData;
|
||||||
}
|
}
|
||||||
|
|
||||||
pickData.Position = ScreenCoords::ToWorldPos(screenCoord.x, screenCoord.y, data.Depth, resolution, pickInfo.Camera->ProjectionMatrix(), pickInfo.Camera->ViewMatrix());
|
pickData.Position = ScreenCoords::ToWorldPos(screenCoord.x, screenCoord.y, data.Depth, resolution, pickInfo.Camera->ProjectionMatrix(), pickInfo.Camera->ViewMatrix());
|
||||||
|
|
||||||
|
|
||||||
pickData.Entity = pickInfo.Entity;
|
pickData.Entity = pickInfo.Entity;
|
||||||
pickData.Camera = pickInfo.Camera;
|
pickData.Camera = pickInfo.Camera;
|
||||||
pickData.World = pickInfo.World;
|
pickData.World = pickInfo.World;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#include "Rendering/RenderSystem.h"
|
#include "Rendering/RenderSystem.h"
|
||||||
#include "Rendering/DebugCameraInputController.h"
|
|
||||||
|
|
||||||
RenderSystem::RenderSystem(EventBroker* eventBrokerer, const IRenderer* renderer, RenderFrame* renderFrame) :ImpureSystem(eventBrokerer)
|
RenderSystem::RenderSystem(EventBroker* eventBrokerer, const IRenderer* renderer, RenderFrame* renderFrame) :ImpureSystem(eventBrokerer)
|
||||||
{
|
{
|
||||||
@@ -8,11 +7,14 @@ RenderSystem::RenderSystem(EventBroker* eventBrokerer, const IRenderer* renderer
|
|||||||
EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &RenderSystem::OnSetCamera);
|
EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &RenderSystem::OnSetCamera);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &RenderSystem::OnInputCommand);
|
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &RenderSystem::OnInputCommand);
|
||||||
|
|
||||||
m_DefaultCamera = new Camera((float)m_Renderer->Resolution().Width / m_Renderer->Resolution().Height, glm::radians(45.f), 0.01f, 5000.f);
|
m_Camera = new Camera((float)m_Renderer->Resolution().Width / m_Renderer->Resolution().Height, glm::radians(45.f), 0.01f, 5000.f);
|
||||||
m_DefaultCamera->SetPosition(glm::vec3(0, 0, 10));
|
m_DebugCameraInputController = new DebugCameraInputController<RenderSystem>(eventBrokerer, -1);
|
||||||
if (m_Camera == nullptr) {
|
}
|
||||||
m_Camera = m_DefaultCamera;
|
|
||||||
}
|
RenderSystem::~RenderSystem()
|
||||||
|
{
|
||||||
|
delete m_Camera;
|
||||||
|
delete m_DebugCameraInputController;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RenderSystem::OnSetCamera(const Events::SetCamera &event)
|
bool RenderSystem::OnSetCamera(const Events::SetCamera &event)
|
||||||
@@ -54,14 +56,11 @@ void RenderSystem::switchCamera(EntityID entity)
|
|||||||
void RenderSystem::updateProjectionMatrix(ComponentWrapper& cameraComponent)
|
void RenderSystem::updateProjectionMatrix(ComponentWrapper& cameraComponent)
|
||||||
{
|
{
|
||||||
double fov = cameraComponent["FOV"];
|
double fov = cameraComponent["FOV"];
|
||||||
double aspectRatio = m_Renderer->Resolution().Width / m_Renderer->Resolution().Height;
|
double aspectRatio = (float)m_Renderer->Resolution().Width / m_Renderer->Resolution().Height;
|
||||||
double nearClip = cameraComponent["NearClip"];
|
double nearClip = cameraComponent["NearClip"];
|
||||||
double farClip = cameraComponent["FarClip"];
|
double farClip = cameraComponent["FarClip"];
|
||||||
|
|
||||||
double fovY = atan(tan(glm::radians(fov)/2.0) * aspectRatio) * 2.0;
|
m_Camera->SetFOV(glm::radians(fov));
|
||||||
m_ProjectionMatrix = glm::perspective(fovY, aspectRatio, nearClip, farClip);
|
|
||||||
|
|
||||||
m_Camera->SetFOV(fovY);
|
|
||||||
m_Camera->SetAspectRatio(aspectRatio);
|
m_Camera->SetAspectRatio(aspectRatio);
|
||||||
m_Camera->SetNearClip(nearClip);
|
m_Camera->SetNearClip(nearClip);
|
||||||
m_Camera->SetFarClip(farClip);
|
m_Camera->SetFarClip(farClip);
|
||||||
@@ -153,66 +152,61 @@ void RenderSystem::Update(World* world, double dt)
|
|||||||
|
|
||||||
void RenderSystem::updateCamera(World* world, double dt)
|
void RenderSystem::updateCamera(World* world, double dt)
|
||||||
{
|
{
|
||||||
|
if (m_SwitchCamera) {
|
||||||
static DebugCameraInputController<RenderSystem> firstPersonInputController(m_EventBroker, -1);
|
auto cameras = world->GetComponents("Camera");
|
||||||
|
for (auto it = cameras->begin(); it != cameras->end(); it++) {
|
||||||
if (m_SwitchCamera) {
|
if ((*it).EntityID == m_CurrentCamera) {
|
||||||
auto cameras = world->GetComponents("Camera");
|
it++;
|
||||||
for (auto it = cameras->begin(); it != cameras->end(); it++) {
|
if (it != cameras->end()) {
|
||||||
if ((*it).EntityID == m_CurrentCamera) {
|
switchCamera((*it).EntityID);
|
||||||
it++;
|
} else {
|
||||||
if (it != cameras->end()) {
|
switchCamera((*cameras->begin()).EntityID);
|
||||||
switchCamera((*it).EntityID);
|
|
||||||
} else {
|
|
||||||
switchCamera((*cameras->begin()).EntityID);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
ComponentWrapper& cameraComponent = world->GetComponent(m_CurrentCamera, "Camera");
|
||||||
|
ComponentWrapper& cameraTransform = world->GetComponent(m_CurrentCamera, "Transform");
|
||||||
|
|
||||||
|
m_DebugCameraInputController->SetOrientation(glm::quat((glm::vec3)cameraTransform["Orientation"]));
|
||||||
|
m_DebugCameraInputController->SetPosition(cameraTransform["Position"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_World->ValidEntity(m_CurrentCamera)) {
|
||||||
|
if (world->HasComponent(m_CurrentCamera, "Camera") && world->HasComponent(m_CurrentCamera, "Transform")) {
|
||||||
ComponentWrapper& cameraComponent = world->GetComponent(m_CurrentCamera, "Camera");
|
ComponentWrapper& cameraComponent = world->GetComponent(m_CurrentCamera, "Camera");
|
||||||
ComponentWrapper& cameraTransform = world->GetComponent(m_CurrentCamera, "Transform");
|
ComponentWrapper& cameraTransform = world->GetComponent(m_CurrentCamera, "Transform");
|
||||||
|
|
||||||
firstPersonInputController.SetOrientation(glm::quat((glm::vec3)cameraTransform["Orientation"]));
|
m_DebugCameraInputController->Update(dt);
|
||||||
firstPersonInputController.SetPosition(cameraTransform["Position"]);
|
(glm::vec3&)cameraTransform["Orientation"] = glm::eulerAngles(m_DebugCameraInputController->Orientation());
|
||||||
|
(glm::vec3&)cameraTransform["Position"] = m_DebugCameraInputController->Position();
|
||||||
|
|
||||||
|
glm::vec3 position = Transform::AbsolutePosition(world, m_CurrentCamera);
|
||||||
|
glm::quat orientation = Transform::AbsoluteOrientation(world, m_CurrentCamera);
|
||||||
|
|
||||||
|
m_Camera->SetPosition(position);
|
||||||
|
m_Camera->SetOrientation(orientation);
|
||||||
|
|
||||||
|
updateProjectionMatrix(cameraComponent);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
m_Camera = m_Camera;
|
||||||
|
|
||||||
|
auto cameras = world->GetComponents("Camera");
|
||||||
|
if (cameras != nullptr) {
|
||||||
|
if (cameras->begin() != cameras->end()) {
|
||||||
|
ComponentWrapper& cameraC = *cameras->begin();
|
||||||
|
switchCamera(cameraC.EntityID);
|
||||||
|
|
||||||
if (m_World->ValidEntity(m_CurrentCamera)) {
|
|
||||||
if (world->HasComponent(m_CurrentCamera, "Camera") && world->HasComponent(m_CurrentCamera, "Transform")) {
|
|
||||||
ComponentWrapper& cameraComponent = world->GetComponent(m_CurrentCamera, "Camera");
|
ComponentWrapper& cameraComponent = world->GetComponent(m_CurrentCamera, "Camera");
|
||||||
ComponentWrapper& cameraTransform = world->GetComponent(m_CurrentCamera, "Transform");
|
ComponentWrapper& cameraTransform = world->GetComponent(m_CurrentCamera, "Transform");
|
||||||
|
|
||||||
firstPersonInputController.Update(dt);
|
m_DebugCameraInputController->SetOrientation(glm::quat((glm::vec3)cameraTransform["Orientation"]));
|
||||||
(glm::vec3&)cameraTransform["Orientation"] = glm::eulerAngles(firstPersonInputController.Orientation());
|
m_DebugCameraInputController->SetPosition(cameraTransform["Position"]);
|
||||||
(glm::vec3&)cameraTransform["Position"] = firstPersonInputController.Position();
|
|
||||||
|
|
||||||
glm::vec3 position = Transform::AbsolutePosition(world, m_CurrentCamera);
|
|
||||||
glm::quat orientation = Transform::AbsoluteOrientation(world, m_CurrentCamera);
|
|
||||||
|
|
||||||
m_Camera->SetPosition(position);
|
|
||||||
m_Camera->SetOrientation(orientation);
|
|
||||||
|
|
||||||
updateProjectionMatrix(cameraComponent);
|
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
m_Camera = m_DefaultCamera;
|
|
||||||
|
|
||||||
auto cameras = world->GetComponents("Camera");
|
|
||||||
if (cameras != nullptr) {
|
|
||||||
if (cameras->begin() != cameras->end()) {
|
|
||||||
ComponentWrapper& cameraC = *cameras->begin();
|
|
||||||
switchCamera(cameraC.EntityID);
|
|
||||||
|
|
||||||
ComponentWrapper& cameraComponent = world->GetComponent(m_CurrentCamera, "Camera");
|
|
||||||
ComponentWrapper& cameraTransform = world->GetComponent(m_CurrentCamera, "Transform");
|
|
||||||
|
|
||||||
firstPersonInputController.SetOrientation(glm::quat((glm::vec3)cameraTransform["Orientation"]));
|
|
||||||
firstPersonInputController.SetPosition(cameraTransform["Position"]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_Camera->UpdateViewMatrix();
|
m_Camera->UpdateViewMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-3
@@ -31,6 +31,7 @@ Game::Game(int argc, char* argv[])
|
|||||||
));
|
));
|
||||||
m_Renderer->Initialize();
|
m_Renderer->Initialize();
|
||||||
//m_Renderer->Camera()->SetFOV(glm::radians(m_Config->Get<float>("Video.FOV", 90.f)));
|
//m_Renderer->Camera()->SetFOV(glm::radians(m_Config->Get<float>("Video.FOV", 90.f)));
|
||||||
|
m_RenderFrame = new RenderFrame();
|
||||||
|
|
||||||
// Create input manager
|
// Create input manager
|
||||||
m_InputManager = new InputManager(m_Renderer->Window(), m_EventBroker);
|
m_InputManager = new InputManager(m_Renderer->Window(), m_EventBroker);
|
||||||
@@ -57,8 +58,6 @@ Game::Game(int argc, char* argv[])
|
|||||||
//SO MUCH TEMP PLEASE REMOVE ME OMFG VIKTOR HELP
|
//SO MUCH TEMP PLEASE REMOVE ME OMFG VIKTOR HELP
|
||||||
m_Renderer->m_World = m_World;
|
m_Renderer->m_World = m_World;
|
||||||
|
|
||||||
m_RenderFrame = new RenderFrame();
|
|
||||||
|
|
||||||
// Create system pipeline
|
// Create system pipeline
|
||||||
m_SystemPipeline = new SystemPipeline(m_EventBroker);
|
m_SystemPipeline = new SystemPipeline(m_EventBroker);
|
||||||
|
|
||||||
@@ -74,7 +73,6 @@ Game::Game(int argc, char* argv[])
|
|||||||
++updateOrderLevel;
|
++updateOrderLevel;
|
||||||
m_SystemPipeline->AddSystem<CollisionSystem>(updateOrderLevel);
|
m_SystemPipeline->AddSystem<CollisionSystem>(updateOrderLevel);
|
||||||
m_SystemPipeline->AddSystem<TriggerSystem>(updateOrderLevel);
|
m_SystemPipeline->AddSystem<TriggerSystem>(updateOrderLevel);
|
||||||
|
|
||||||
++updateOrderLevel;
|
++updateOrderLevel;
|
||||||
m_SystemPipeline->AddSystem<RenderSystem>(updateOrderLevel, m_Renderer, m_RenderFrame);
|
m_SystemPipeline->AddSystem<RenderSystem>(updateOrderLevel, m_Renderer, m_RenderFrame);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user