Merge branch 'master' into PlayerMovement

# Conflicts:
#	src/Engine/Rendering/RenderSystem.cpp
#	src/Game/Game.cpp
This commit is contained in:
2016-01-14 18:21:32 +01:00
4 changed files with 59 additions and 54 deletions
+6 -51
View File
@@ -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
+52
View File
@@ -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;
}
+1 -2
View File
@@ -186,5 +186,4 @@ void RenderSystem::updateCamera(World* world, double dt)
}
m_Camera->UpdateViewMatrix();
}
}
-1
View File
@@ -63,7 +63,6 @@ Game::Game(int argc, char* argv[])
// Create Octrees
m_OctreeCollision = 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
m_SystemPipeline = new SystemPipeline(m_EventBroker);