Merge fixes
This commit is contained in:
@@ -11,7 +11,7 @@
|
|||||||
#include "../Core/Ray.h"
|
#include "../Core/Ray.h"
|
||||||
#include "../Core/AABB.h"
|
#include "../Core/AABB.h"
|
||||||
#include "../Rendering/RawModel.h"
|
#include "../Rendering/RawModel.h"
|
||||||
#include "../Rendering/RenderQueueFactory.h"
|
#include "../Core/Transform.h"
|
||||||
#include "../Core/Entity.h"
|
#include "../Core/Entity.h"
|
||||||
#include "../Core/EntityWrapper.h"
|
#include "../Core/EntityWrapper.h"
|
||||||
|
|
||||||
|
|||||||
@@ -14,22 +14,24 @@
|
|||||||
#include "ModelJob.h"
|
#include "ModelJob.h"
|
||||||
#include "Renderer.h"
|
#include "Renderer.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;
|
||||||
|
|
||||||
@@ -41,8 +43,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);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<c:Camera>
|
<c:Camera>
|
||||||
<Name>cam</Name>
|
<Name>cam</Name>
|
||||||
<FOV>60.0</FOV>
|
<FOV>45</FOV>
|
||||||
<NearClip>0.01</NearClip>
|
<NearClip>0.01</NearClip>
|
||||||
<FarClip>5000</FarClip>
|
<FarClip>5000</FarClip>
|
||||||
</c:Camera>
|
</c:Camera>
|
||||||
@@ -10,7 +10,9 @@
|
|||||||
<xs:complexType>
|
<xs:complexType>
|
||||||
<xs:all>
|
<xs:all>
|
||||||
<xs:element name="Name" type="t:string" minOccurs="0"/>
|
<xs:element name="Name" type="t:string" minOccurs="0"/>
|
||||||
<xs:element name="FOV" type="t:double" minOccurs="0"/>
|
<xs:element name="FOV" type="t:double" minOccurs="0">
|
||||||
|
<xs:annotation><xs:documentation>Vertical Field of View in degrees</xs:documentation></xs:annotation>
|
||||||
|
</xs:element>
|
||||||
<xs:element name="NearClip" type="t:double" minOccurs="0"/>
|
<xs:element name="NearClip" type="t:double" minOccurs="0"/>
|
||||||
<xs:element name="FarClip" type="t:double" minOccurs="0"/>
|
<xs:element name="FarClip" type="t:double" minOccurs="0"/>
|
||||||
</xs:all>
|
</xs:all>
|
||||||
|
|||||||
@@ -6,6 +6,13 @@
|
|||||||
</Components>
|
</Components>
|
||||||
|
|
||||||
<Children>
|
<Children>
|
||||||
|
<Entity>
|
||||||
|
<Components>
|
||||||
|
<c:Camera/>
|
||||||
|
<c:Transform/>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
<Entity>
|
<Entity>
|
||||||
<Components>
|
<Components>
|
||||||
<c:AABB/>
|
<c:AABB/>
|
||||||
|
|||||||
@@ -290,8 +290,8 @@ boost::optional<AABB> EntityAbsoluteAABB(EntityWrapper& entity)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ComponentWrapper& cAABB = entity["AABB"];
|
ComponentWrapper& cAABB = entity["AABB"];
|
||||||
glm::vec3 absPosition = RenderQueueFactory::AbsolutePosition(entity.World, entity.ID);
|
glm::vec3 absPosition = Transform::AbsolutePosition(entity.World, entity.ID);
|
||||||
glm::vec3 absScale = RenderQueueFactory::AbsoluteScale(entity.World, entity.ID);
|
glm::vec3 absScale = Transform::AbsoluteScale(entity.World, entity.ID);
|
||||||
glm::vec3 origin = absPosition + (glm::vec3)cAABB["Origin"];
|
glm::vec3 origin = absPosition + (glm::vec3)cAABB["Origin"];
|
||||||
glm::vec3 size = (glm::vec3)cAABB["Size"] * absScale;
|
glm::vec3 size = (glm::vec3)cAABB["Size"] * absScale;
|
||||||
return AABB::FromOriginSize(origin, size);
|
return AABB::FromOriginSize(origin, size);
|
||||||
|
|||||||
@@ -125,6 +125,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,18 +1,21 @@
|
|||||||
#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* eventBroker, const IRenderer* renderer, RenderFrame* renderFrame)
|
||||||
|
: System(eventBroker)
|
||||||
|
, m_Renderer(renderer)
|
||||||
|
, m_RenderFrame(renderFrame)
|
||||||
{
|
{
|
||||||
m_Renderer = renderer;
|
|
||||||
m_RenderFrame = renderFrame;
|
|
||||||
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>(eventBroker, -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 +57,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);
|
||||||
@@ -129,66 +129,62 @@ 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
@@ -35,6 +35,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);
|
||||||
@@ -59,8 +60,6 @@ Game::Game(int argc, char* argv[])
|
|||||||
fp.MergeEntities(m_World);
|
fp.MergeEntities(m_World);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_RenderFrame = new RenderFrame();
|
|
||||||
|
|
||||||
// Create Octrees
|
// Create Octrees
|
||||||
m_OctreeCollision = new Octree(AABB(glm::vec3(-100), glm::vec3(100)), 4);
|
m_OctreeCollision = new Octree(AABB(glm::vec3(-100), glm::vec3(100)), 4);
|
||||||
m_OctreeFrustrumCulling = new Octree(AABB(glm::vec3(-100), glm::vec3(100)), 4);
|
m_OctreeFrustrumCulling = new Octree(AABB(glm::vec3(-100), glm::vec3(100)), 4);
|
||||||
@@ -82,7 +81,6 @@ Game::Game(int argc, char* argv[])
|
|||||||
++updateOrderLevel;
|
++updateOrderLevel;
|
||||||
m_SystemPipeline->AddSystem<CollisionSystem>(updateOrderLevel, m_OctreeCollision);
|
m_SystemPipeline->AddSystem<CollisionSystem>(updateOrderLevel, m_OctreeCollision);
|
||||||
m_SystemPipeline->AddSystem<TriggerSystem>(updateOrderLevel, m_OctreeCollision);
|
m_SystemPipeline->AddSystem<TriggerSystem>(updateOrderLevel, m_OctreeCollision);
|
||||||
|
|
||||||
++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