Fixed quaternion for transforms
This commit is contained in:
@@ -215,7 +215,6 @@ namespace Nuake
|
||||
//m_DebugShader->SetUniform4f("u_Color", color.r, color.g, color.b, color.a);
|
||||
}
|
||||
|
||||
// TODO: Maybe have a debug primitive draw list
|
||||
void Renderer::DrawCube(TransformComponent transform, glm::vec4 color)
|
||||
{
|
||||
//glDisable(GL_DEPTH_TEST);
|
||||
@@ -226,7 +225,7 @@ namespace Nuake
|
||||
RenderCommand::DrawArrays(0, 36);
|
||||
}
|
||||
|
||||
// TODO: See above
|
||||
|
||||
void Renderer::DrawSphere(TransformComponent transform, glm::vec4 color)
|
||||
{
|
||||
|
||||
|
||||
@@ -7,10 +7,15 @@ namespace Nuake
|
||||
{
|
||||
GlobalTranslation = Vector3(0, 0, 0);
|
||||
Translation = Vector3(0, 0, 0);
|
||||
Orientation = Quat(0, 0, 0, 0);
|
||||
GlobalOrientation = Orientation;
|
||||
//Rotation = Vector3(0, 0, 0);
|
||||
Scale = Vector3(1, 1, 1);
|
||||
|
||||
Rotation = Quat(0, 0, 0, 1);
|
||||
GlobalRotation = Rotation;
|
||||
|
||||
GlobalScale = Vector3(1, 1, 1);
|
||||
Scale = GlobalScale;
|
||||
|
||||
LocalTransform = Matrix4(1);
|
||||
GlobalTransform = Matrix4(1);
|
||||
}
|
||||
|
||||
void TransformComponent::SetRotation(float x, float y, float z)
|
||||
@@ -19,12 +24,12 @@ namespace Nuake
|
||||
Quat QuatAroundY = Quat(0.0, 1.0, 0.0, y);
|
||||
Quat QuatAroundZ = Quat(0.0, 0.0, 1.0, z);
|
||||
Quat finalOrientation = QuatAroundX * QuatAroundY * QuatAroundZ;
|
||||
Orientation = finalOrientation;
|
||||
Rotation = finalOrientation;
|
||||
}
|
||||
|
||||
Matrix4 TransformComponent::GetGlobalTransform() const
|
||||
{
|
||||
return LocalTransform;
|
||||
return GlobalTransform;
|
||||
}
|
||||
|
||||
Matrix4 TransformComponent::GetLocalTransform() const
|
||||
|
||||
@@ -7,14 +7,13 @@ namespace Nuake
|
||||
class TransformComponent {
|
||||
public:
|
||||
bool Dirty = true;
|
||||
|
||||
Vector3 Translation;
|
||||
Quat Orientation;
|
||||
//Vector3 Rotation; // TODO: Should use quaternions.
|
||||
Quat Rotation;
|
||||
Vector3 Scale;
|
||||
|
||||
Vector3 GlobalTranslation;
|
||||
//Vector3 GlobalRotation;
|
||||
Quat GlobalOrientation;
|
||||
Quat GlobalRotation;
|
||||
Vector3 GlobalScale;
|
||||
|
||||
Matrix4 LocalTransform;
|
||||
|
||||
@@ -382,11 +382,11 @@ namespace Nuake {
|
||||
m_Scene->DestroyEntity(e);
|
||||
}
|
||||
|
||||
map_parser_load(std::string(FileSystem::Root + quakeMapC.Path).c_str());
|
||||
map_parser_load((FileSystem::Root + quakeMapC.Path).c_str());
|
||||
geo_generator_run();
|
||||
|
||||
DefaultMaterial = MaterialManager::Get()->GetMaterial("resources/Textures/default/Default.png");
|
||||
for (int e = 0; e < entity_count; ++e)
|
||||
DefaultMaterial = MaterialManager::Get()->GetMaterial("default");
|
||||
for (uint32_t e = 0; e < entity_count; ++e)
|
||||
{
|
||||
entity* entity_inst = &entities[e];
|
||||
entity_geometry* entity_geo_inst = &entity_geo[e];
|
||||
|
||||
@@ -51,14 +51,12 @@ namespace Nuake {
|
||||
|
||||
if (transform.Dirty)
|
||||
{
|
||||
Vector3 dum;
|
||||
Vector4 dum2;
|
||||
glm::decompose(transform.LocalTransform, transform.Scale, transform.Orientation, transform.Translation, dum, dum2);
|
||||
|
||||
transform.LocalTransform = Matrix4(1);
|
||||
transform.LocalTransform = glm::translate(transform.LocalTransform, transform.Translation);
|
||||
|
||||
transform.Dirty = false;
|
||||
Matrix4 localTransform = Matrix4(1);
|
||||
localTransform = glm::translate(transform.LocalTransform, transform.Translation);
|
||||
localTransform = localTransform * glm::toMat4(transform.Rotation);
|
||||
localTransform = glm::scale(transform.LocalTransform, transform.Scale);
|
||||
|
||||
transform.LocalTransform = localTransform;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +77,7 @@ namespace Nuake {
|
||||
|
||||
Matrix4 globalTransform = transform.LocalTransform;
|
||||
Vector3 globalPosition = transform.Translation;
|
||||
Quat globalOrientation = transform.Orientation;
|
||||
Quat globalOrientation = transform.Rotation;
|
||||
Vector3 globalScale = transform.Scale;
|
||||
|
||||
ParentComponent parentComponent = currentParent.GetComponent<ParentComponent>();
|
||||
@@ -90,14 +88,14 @@ namespace Nuake {
|
||||
globalTransform = transformComponent.LocalTransform * globalTransform;
|
||||
|
||||
globalPosition += transformComponent.Translation;
|
||||
globalOrientation *= transformComponent.Orientation;
|
||||
globalOrientation *= transformComponent.Rotation;
|
||||
globalScale *= transformComponent.Scale;
|
||||
|
||||
parentComponent = parentComponent.Parent.GetComponent<ParentComponent>();
|
||||
}
|
||||
|
||||
transform.GlobalTranslation = globalPosition;
|
||||
transform.GlobalOrientation = globalOrientation;
|
||||
transform.GlobalRotation = globalOrientation;
|
||||
transform.GlobalScale = globalScale;
|
||||
|
||||
transform.GlobalTransform = globalTransform;
|
||||
|
||||
Reference in New Issue
Block a user