Added Transform.h that holds all the AbsoluteTransformation functions. Camera now working better with scenes. Changed Modeljob Matrix to only hold the model matrix instad of all matrix info
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
#ifndef Transform_h__
|
||||
#define Transform_h__
|
||||
|
||||
#include "../GLM.h"
|
||||
#include "World.h"
|
||||
|
||||
static class 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;
|
||||
}
|
||||
|
||||
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
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "../Core/ConfigFile.h"
|
||||
#include "../Input/EInputCommand.h"
|
||||
#include "../Rendering/IRenderer.h"
|
||||
#include "../Rendering/RenderSystem.h"
|
||||
#include "../Core/Transform.h"
|
||||
#include "../Core/EFileDropped.h"
|
||||
#include "../Core/EntityFilePreprocessor.h"
|
||||
#include "../Core/EntityFileParser.h"
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
void InitializeFrameBuffers();
|
||||
void InitializeShaderPrograms();
|
||||
|
||||
void Draw(RenderFrame& rf);
|
||||
void Draw(RenderScene& scene);
|
||||
|
||||
//Getters
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
void InitializeFrameBuffers();
|
||||
void InitializeShaderPrograms();
|
||||
|
||||
void Draw(RenderFrame& rf);
|
||||
void Draw(RenderScene& scene);
|
||||
|
||||
|
||||
//Getters
|
||||
|
||||
@@ -52,7 +52,7 @@ struct RenderScene
|
||||
::Camera* Camera;
|
||||
std::list<std::shared_ptr<RenderJob>> ForwardJobs;
|
||||
std::list<std::shared_ptr<RenderJob>> LightJobs;
|
||||
Rectangle ViewPort;
|
||||
Rectangle Viewport;
|
||||
|
||||
void Clear()
|
||||
{
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "Camera.h"
|
||||
#include "ModelJob.h"
|
||||
#include "Renderer.h"
|
||||
#include "../Core/Transform.h"
|
||||
|
||||
class RenderSystem : public ImpureSystem
|
||||
{
|
||||
@@ -21,12 +22,6 @@ public:
|
||||
|
||||
virtual void Update(World* world, double dt) override;
|
||||
|
||||
static glm::vec3 AbsolutePosition(World* world, EntityID entity);
|
||||
static glm::quat AbsoluteOrientation(World* world, EntityID entity);
|
||||
static glm::vec3 AbsoluteScale(World* world, EntityID entity);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
World* m_World = nullptr;
|
||||
const IRenderer* m_Renderer = nullptr;
|
||||
@@ -44,13 +39,11 @@ 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;
|
||||
|
||||
glm::mat4 ModelMatrix(EntityID entity, World* world);
|
||||
void fillModels(std::list<std::shared_ptr<RenderJob>>& jobs, World* world);
|
||||
|
||||
EventRelay<RenderSystem, Events::InputCommand> m_EInputCommand;
|
||||
|
||||
@@ -26,7 +26,7 @@ public:
|
||||
|
||||
virtual void Initialize() override;
|
||||
virtual void Update(double dt) override;
|
||||
virtual void Draw(RenderFrame& rf) override;
|
||||
virtual void Draw(RenderFrame& frame) override;
|
||||
|
||||
virtual PickData Pick(glm::vec2 screenCoord) override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user