Merge branch 'master' into PlayerMovement
# Conflicts: # src/Engine/Rendering/RenderSystem.cpp # src/Game/Game.cpp
This commit is contained in:
@@ -4,59 +4,14 @@
|
|||||||
#include "../GLM.h"
|
#include "../GLM.h"
|
||||||
#include "World.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) {
|
glm::vec3 AbsolutePosition(World* world, EntityID entity);
|
||||||
ComponentWrapper transform = world->GetComponent(entity, "Transform");
|
glm::quat AbsoluteOrientation(World* world, EntityID entity);
|
||||||
EntityID parent = world->GetParent(entity);
|
glm::vec3 AbsoluteScale(World* world, EntityID entity);
|
||||||
position += AbsoluteOrientation(world, parent) * (glm::vec3)transform["Position"];
|
glm::mat4 ModelMatrix(EntityID entity, World* world);
|
||||||
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
|
#endif
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -186,5 +186,4 @@ void RenderSystem::updateCamera(World* world, double dt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_Camera->UpdateViewMatrix();
|
m_Camera->UpdateViewMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +63,6 @@ Game::Game(int argc, char* argv[])
|
|||||||
// 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);
|
||||||
|
|
||||||
// Create system pipeline
|
// Create system pipeline
|
||||||
m_SystemPipeline = new SystemPipeline(m_EventBroker);
|
m_SystemPipeline = new SystemPipeline(m_EventBroker);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user