Merge remote-tracking branch 'origin/master' into Forward+

This commit is contained in:
Tleety
2016-01-15 11:02:27 +01:00
7 changed files with 126 additions and 124 deletions
+6 -51
View File
@@ -4,59 +4,14 @@
#include "../GLM.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) {
ComponentWrapper transform = world->GetComponent(entity, "Transform");
EntityID parent = world->GetParent(entity);
position += AbsoluteOrientation(world, parent) * (glm::vec3)transform["Position"];
entity = parent;
}
glm::vec3 AbsolutePosition(World* world, EntityID entity);
glm::quat AbsoluteOrientation(World* world, EntityID entity);
glm::vec3 AbsoluteScale(World* world, EntityID entity);
glm::mat4 ModelMatrix(EntityID entity, World* world);
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
+5 -5
View File
@@ -15,22 +15,24 @@
#include "Renderer.h"
#include "PointLightJob.h"
#include "../Core/Transform.h"
#include "DebugCameraInputController.h"
class RenderSystem : public ImpureSystem
{
public:
RenderSystem(EventBroker* eventBrokerer, const IRenderer* renderer, RenderFrame* renderFrame);
~RenderSystem();
virtual void Update(World* world, double dt) override;
private:
World* m_World = nullptr;
const IRenderer* m_Renderer = nullptr;
const IRenderer* m_Renderer;
RenderFrame* m_RenderFrame;
bool m_SwitchCamera = false;
Camera* m_Camera = nullptr;
Camera* m_DefaultCamera = nullptr;
Camera* m_Camera;
DebugCameraInputController<RenderSystem>* m_DebugCameraInputController;
std::list<ComponentWrapper> m_CameraComponents;
@@ -42,8 +44,6 @@ private:
void updateCamera(World* world, double dt);
void updateProjectionMatrix(ComponentWrapper& cameraComponent);
glm::mat4 m_ViewMatrix;
glm::mat4 m_ProjectionMatrix;
void fillModels(std::list<std::shared_ptr<RenderJob>>& jobs, World* world);
void fillLight(std::list<std::shared_ptr<RenderJob>>& jobs, World* world);
+52
View File
@@ -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;
}
+3
View File
@@ -124,6 +124,9 @@ bool EditorSystem::OnMouseMove(const Events::MouseMove& e)
if (m_Selection == 0) {
return false;
}
if (m_Camera == nullptr) {
return false;
}
auto widgetTransform = m_World->GetComponent(m_Widget, "Transform");
glm::vec3 widgetOrientation = widgetTransform["Orientation"];
+3 -3
View File
@@ -109,7 +109,7 @@ void PickingPass::ClearPicking()
{
m_PickingColorsToEntity.clear();
m_EntityColors.clear();
m_ColorCounter[0] = 0;
m_ColorCounter[0] = 1;
m_ColorCounter[1] = 0;
m_PickingBuffer.Bind();
@@ -138,10 +138,10 @@ PickData PickingPass::Pick(glm::vec2 screenCoord)
pickInfo = it->second;
} else {
pickData.Entity = EntityID_Invalid;
return pickData;
}
pickData.Position = ScreenCoords::ToWorldPos(screenCoord.x, screenCoord.y, data.Depth, resolution, pickInfo.Camera->ProjectionMatrix(), pickInfo.Camera->ViewMatrix());
pickData.Entity = pickInfo.Entity;
pickData.Camera = pickInfo.Camera;
pickData.World = pickInfo.World;
+53 -59
View File
@@ -1,5 +1,4 @@
#include "Rendering/RenderSystem.h"
#include "Rendering/DebugCameraInputController.h"
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_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_DefaultCamera->SetPosition(glm::vec3(0, 0, 10));
if (m_Camera == nullptr) {
m_Camera = m_DefaultCamera;
}
m_Camera = new Camera((float)m_Renderer->Resolution().Width / m_Renderer->Resolution().Height, glm::radians(45.f), 0.01f, 5000.f);
m_DebugCameraInputController = new DebugCameraInputController<RenderSystem>(eventBrokerer, -1);
}
RenderSystem::~RenderSystem()
{
delete m_Camera;
delete m_DebugCameraInputController;
}
bool RenderSystem::OnSetCamera(const Events::SetCamera &event)
@@ -54,14 +56,11 @@ void RenderSystem::switchCamera(EntityID entity)
void RenderSystem::updateProjectionMatrix(ComponentWrapper& cameraComponent)
{
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 farClip = cameraComponent["FarClip"];
double fovY = atan(tan(glm::radians(fov)/2.0) * aspectRatio) * 2.0;
m_ProjectionMatrix = glm::perspective(fovY, aspectRatio, nearClip, farClip);
m_Camera->SetFOV(fovY);
m_Camera->SetFOV(glm::radians(fov));
m_Camera->SetAspectRatio(aspectRatio);
m_Camera->SetNearClip(nearClip);
m_Camera->SetFarClip(farClip);
@@ -153,66 +152,61 @@ void RenderSystem::Update(World* world, double dt)
void RenderSystem::updateCamera(World* world, double dt)
{
static DebugCameraInputController<RenderSystem> firstPersonInputController(m_EventBroker, -1);
if (m_SwitchCamera) {
auto cameras = world->GetComponents("Camera");
for (auto it = cameras->begin(); it != cameras->end(); it++) {
if ((*it).EntityID == m_CurrentCamera) {
it++;
if (it != cameras->end()) {
switchCamera((*it).EntityID);
} else {
switchCamera((*cameras->begin()).EntityID);
}
break;
if (m_SwitchCamera) {
auto cameras = world->GetComponents("Camera");
for (auto it = cameras->begin(); it != cameras->end(); it++) {
if ((*it).EntityID == m_CurrentCamera) {
it++;
if (it != cameras->end()) {
switchCamera((*it).EntityID);
} else {
switchCamera((*cameras->begin()).EntityID);
}
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& cameraTransform = world->GetComponent(m_CurrentCamera, "Transform");
firstPersonInputController.SetOrientation(glm::quat((glm::vec3)cameraTransform["Orientation"]));
firstPersonInputController.SetPosition(cameraTransform["Position"]);
m_DebugCameraInputController->Update(dt);
(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& cameraTransform = world->GetComponent(m_CurrentCamera, "Transform");
firstPersonInputController.Update(dt);
(glm::vec3&)cameraTransform["Orientation"] = glm::eulerAngles(firstPersonInputController.Orientation());
(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_DebugCameraInputController->SetOrientation(glm::quat((glm::vec3)cameraTransform["Orientation"]));
m_DebugCameraInputController->SetPosition(cameraTransform["Position"]);
}
}
}
m_Camera->UpdateViewMatrix();
m_Camera->UpdateViewMatrix();
}
+1 -3
View File
@@ -31,6 +31,7 @@ Game::Game(int argc, char* argv[])
));
m_Renderer->Initialize();
//m_Renderer->Camera()->SetFOV(glm::radians(m_Config->Get<float>("Video.FOV", 90.f)));
m_RenderFrame = new RenderFrame();
// Create input manager
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
m_Renderer->m_World = m_World;
m_RenderFrame = new RenderFrame();
// Create system pipeline
m_SystemPipeline = new SystemPipeline(m_EventBroker);
@@ -74,7 +73,6 @@ Game::Game(int argc, char* argv[])
++updateOrderLevel;
m_SystemPipeline->AddSystem<CollisionSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<TriggerSystem>(updateOrderLevel);
++updateOrderLevel;
m_SystemPipeline->AddSystem<RenderSystem>(updateOrderLevel, m_Renderer, m_RenderFrame);