Progress towards finding transform corruption when drawing after loading scene

This commit is contained in:
Antoine Pilote
2023-07-12 01:21:47 -04:00
parent 9ad09ff749
commit a466065ac6
8 changed files with 117 additions and 28 deletions

File diff suppressed because one or more lines are too long

View File

@@ -259,7 +259,7 @@ void GizmoDrawer::DrawGizmos(Ref<Scene> scene)
flatShader->SetUniformVec4("u_Color", Vector4(0.0f, 1.0f, 0.4f, 1.0f));
const auto scaledTransform = glm::scale(transformComponent.GetGlobalTransform(), Vector3(0.25f, 0.25f, 0.25f));
renderList.AddToRenderList(_gizmos["player"]->GetMeshes()[0], scaledTransform);
//renderList.AddToRenderList(_gizmos["player"]->GetMeshes()[0], scaledTransform);
renderList.Flush(flatShader, true);
}

View File

@@ -215,7 +215,7 @@ namespace Nuake {
ImGuizmo::DecomposeMatrixToComponents(glm::value_ptr(localTransform), glm::value_ptr(pos), glm::value_ptr(rotation), glm::value_ptr(scale));
tc.Translation = pos;
//tc.Rotation = rotation;
tc.Rotation = rotation;
tc.Scale = scale;
tc.LocalTransform = localTransform;

View File

@@ -370,17 +370,16 @@ namespace Nuake
transformComponent.SetLocalPosition(pos);
transformComponent.SetLocalRotation(Quat(bodyRotation.GetW(), bodyRotation.GetX(), bodyRotation.GetY(), bodyRotation.GetZ()));
transformComponent.SetLocalTransform(transform);
transformComponent.Dirty = false;
transformComponent.Dirty = true;
}
}
void DynamicWorld::SyncCharactersTransforms()
{
// TODO(ANTO): Finish this to connect updated jolt transforms back to the entity.
// The problem was that I dont know yet how to go from jolt body ptr to the entity
// Combinations of find and iterators etc. I do not have the brain power rn zzz.
// const auto& bodyInterface = _JoltPhysicsSystem->GetBodyInterface();
for (const auto& e : _registeredCharacters)
{
Entity entity { (entt::entity)e.first, Engine::GetCurrentScene().get()};
@@ -407,7 +406,7 @@ namespace Nuake
transformComponent.SetLocalPosition(pos);
transformComponent.SetLocalRotation(Quat(bodyRotation.GetW(), bodyRotation.GetX(), bodyRotation.GetY(), bodyRotation.GetZ()));
transformComponent.SetLocalTransform(transform);
transformComponent.Dirty = false;
transformComponent.Dirty = true;
}
}

View File

@@ -55,6 +55,20 @@ namespace Nuake
//Up = glm::normalize(glm::cross(Direction, Right));
}
void Camera::SetDirection(const Quat& direction)
{
//cam->cameraDirection.x = cos(glm::radians(Yaw)) * cos(glm::radians(Pitch));
//cam->cameraDirection.y = sin(glm::radians(Pitch));
//cam->cameraDirection.z = sin(glm::radians(Yaw)) * cos(glm::radians(Pitch));
//cam->cameraFront = glm::normalize(cam->cameraDirection);
//cam->cameraRight = glm::normalize(glm::cross(cam->up, cam->cameraFront));
//glm::quatLookAt();
//Direction = glm::normalize(direction);
//Right = glm::normalize(glm::cross(Vector3(0, 1, 0), Direction));
//Up = glm::normalize(glm::cross(Direction, Right));
}
Vector3 Camera::GetTranslation() {
return Translation;
}
@@ -72,7 +86,7 @@ namespace Nuake
Matrix4 Camera::GetTransform()
{
glm::mat4 tr = lookAt(Translation, Translation + Direction, Vector3(0, 1, 0));
glm::mat4 tr = lookAt(Translation, Translation + glm::normalize(Direction), Vector3(0, 1, 0));
return tr;
}
@@ -98,6 +112,8 @@ namespace Nuake
BEGIN_SERIALIZE();
SERIALIZE_VAL(m_Type);
SERIALIZE_VAL(AspectRatio);
SERIALIZE_VEC3(Translation)
SERIALIZE_VEC3(Direction)
SERIALIZE_VAL(Fov);
SERIALIZE_VAL(Exposure);
SERIALIZE_VAL(Speed);
@@ -109,6 +125,12 @@ namespace Nuake
BEGIN_DESERIALIZE();
j = j["CameraInstance"];
this->m_Type = (CAMERA_TYPE)j["m_Type"];
if(j.contains("Translation"))
DESERIALIZE_VEC3(j["Translation"], Translation);
if (j.contains("Direction"))
DESERIALIZE_VEC3(j["Direction"], Direction);
this->AspectRatio = j["AspectRatio"];
this->Fov = j["Fov"];
this->Exposure = j["Exposure"];

View File

@@ -44,6 +44,7 @@ namespace Nuake
void OnWindowResize(float x, float y);
void SetDirection(Vector3 direction);
void SetDirection(const Quat& direction);
Vector3 GetTranslation();
Vector3 GetDirection();

View File

@@ -46,11 +46,13 @@ namespace Nuake
json Serialize()
{
Rotation = glm::normalize(Rotation);
BEGIN_SERIALIZE();
SERIALIZE_VAL_LBL("Type", "TransformComponent");
SERIALIZE_VEC3(Translation);
SERIALIZE_VEC3(GlobalTranslation);
SERIALIZE_VEC4(Rotation);
SERIALIZE_VEC4(GlobalRotation);
SERIALIZE_VEC3(GlobalScale);
SERIALIZE_VEC3(Scale);
END_SERIALIZE();
}
@@ -59,6 +61,16 @@ namespace Nuake
{
BEGIN_DESERIALIZE();
this->Translation = Vector3(j["Translation"]["x"], j["Translation"]["y"], j["Translation"]["z"]);
if (j.contains("GlobalTranslation"))
{
float x = j["GlobalTranslation"]["x"];
float y = j["GlobalTranslation"]["y"];
float z = j["GlobalTranslation"]["z"];
this->GlobalTranslation = Vector3(x, y, z);
}
if (j.contains("Rotation"))
{
float w = j["Rotation"]["w"];
@@ -68,6 +80,25 @@ namespace Nuake
this->Rotation = Quat(w, x, y, z);
}
if (j.contains("GlobalRotation"))
{
float w = j["GlobalRotation"]["w"];
float x = j["GlobalRotation"]["x"];
float y = j["GlobalRotation"]["y"];
float z = j["GlobalRotation"]["z"];
this->GlobalRotation = Quat(w, x, y, z);
}
if (j.contains("GlobalScale"))
{
float x = j["GlobalScale"]["x"];
float y = j["GlobalScale"]["y"];
float z = j["GlobalScale"]["z"];
this->GlobalScale = Vector3(x, y, z);
}
this->Scale = Vector3(j["Scale"]["x"], j["Scale"]["y"], j["Scale"]["z"]);

View File

@@ -109,10 +109,13 @@ namespace Nuake
Matrix4 cameraTransform = camera.CameraInstance->GetTransformRotation();
camera.CameraInstance->Translation = transform.GlobalTranslation;
const auto& globalRotation = transform.GetGlobalRotation();
auto& forward = QuatToDirection(globalRotation);
const auto& globalTransform = transform.GetGlobalTransform();
const auto& forwardTransform = Vector3(globalTransform[0][2], globalTransform[1][2], globalTransform[2][2]);
//const auto& globalRotation = transform.GetGlobalRotation();
//auto& forward = QuatToDirection(globalRotation);
//forward *= -1.0;
camera.CameraInstance->SetDirection(forward);
//f/orward.z *= -1.0f;
camera.CameraInstance->SetDirection(forwardTransform);
}
}
}