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:
viktorljung
2016-01-14 11:12:02 +01:00
parent 0f17f9a888
commit e7f02f14a0
16 changed files with 135 additions and 133 deletions
+62
View File
@@ -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
+1 -1
View File
@@ -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"
+1 -1
View File
@@ -17,7 +17,7 @@ public:
void InitializeFrameBuffers();
void InitializeShaderPrograms();
void Draw(RenderFrame& rf);
void Draw(RenderScene& scene);
//Getters
+1 -1
View File
@@ -19,7 +19,7 @@ public:
void InitializeFrameBuffers();
void InitializeShaderPrograms();
void Draw(RenderFrame& rf);
void Draw(RenderScene& scene);
//Getters
+1 -1
View File
@@ -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()
{
+1 -8
View File
@@ -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;
+1 -1
View File
@@ -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;