@@ -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
|
||||
@@ -14,22 +14,24 @@
|
||||
#include "ModelJob.h"
|
||||
#include "Renderer.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;
|
||||
|
||||
@@ -41,8 +43,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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user