mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-09 20:08:57 +03:00
Work but still broken
This commit is contained in:
@@ -212,23 +212,39 @@ namespace Nuake {
|
||||
Vector3 scale = Vector3();
|
||||
Quat rotation = Quat();
|
||||
Vector3 pos = Vector3();
|
||||
ImGuizmo::DecomposeMatrixToComponents(glm::value_ptr(localTransform), glm::value_ptr(pos), glm::value_ptr(rotation), glm::value_ptr(scale));
|
||||
|
||||
Vector3 skew = Vector3();
|
||||
Vector4 pesp = Vector4();
|
||||
glm::decompose(localTransform, scale, rotation, pos, skew, pesp);
|
||||
|
||||
tc.Translation = pos;
|
||||
tc.Rotation = rotation;
|
||||
tc.Scale = scale;
|
||||
tc.LocalTransform = localTransform;
|
||||
tc.Dirty = true;
|
||||
|
||||
const Matrix4& translationMatrix = glm::translate(Matrix4(1.0f), pos);
|
||||
const Matrix4& rotationMatrix = glm::mat4_cast(rotation);
|
||||
const Matrix4& scaleMatrix = glm::scale(Matrix4(1.0f), scale);
|
||||
const Matrix4& newLocalTransform = translationMatrix * rotationMatrix * scaleMatrix;
|
||||
|
||||
//tc.SetLocalPosition(pos);
|
||||
//tc.SetLocalRotation(-rotationQuaternion);
|
||||
//tc.SetLocalScale(scale);
|
||||
//tc.SetLocalTransform(localTransform);
|
||||
|
||||
// Decompose global trasnform
|
||||
Vector3 gscale = Vector3();
|
||||
Quat grotation = Quat();
|
||||
Vector3 gpos = Vector3();
|
||||
ImGuizmo::DecomposeMatrixToComponents(glm::value_ptr(transform), glm::value_ptr(gpos), glm::value_ptr(grotation), glm::value_ptr(gscale));
|
||||
|
||||
Vector3 gskew = Vector3();
|
||||
Vector4 gpesp = Vector4();
|
||||
glm::decompose(transform, gscale, grotation, gpos, gskew, gpesp);
|
||||
|
||||
//glm::quat rotationQuaternionG = glm::quat_cast(transform);
|
||||
tc.SetGlobalPosition(gpos);
|
||||
tc.SetGlobalRotation(grotation);
|
||||
tc.SetGlobalScale(gscale);
|
||||
tc.SetGlobalTransform(transform);
|
||||
tc.SetGlobalTransform(localTransform);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,14 @@ Quat Nuake::CreateFromAxisAngle(Vector3 axis, float angle)
|
||||
|
||||
Quat Nuake::QuatFromEuler(float x, float y, float z)
|
||||
{
|
||||
return Quat(Vector3(Rad(z), Rad(y), Rad(x)));
|
||||
glm::quat yawQuat = glm::angleAxis(Rad(y), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
glm::quat rollQuat = glm::angleAxis(Rad(z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
glm::quat pitchQuat = glm::angleAxis(Rad(x), glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
glm::quat orientation = yawQuat * pitchQuat * rollQuat;
|
||||
|
||||
return glm::normalize(orientation);
|
||||
|
||||
return Quat(Vector3(Rad(x), Rad(y), Rad(z)));
|
||||
|
||||
Quat q;
|
||||
|
||||
@@ -57,6 +64,6 @@ Quat Nuake::QuatFromEuler(float x, float y, float z)
|
||||
|
||||
Vector3 Nuake::QuatToDirection(const Quat& quat)
|
||||
{
|
||||
//return quat * Vector3(0, 0, -1);
|
||||
return glm::rotate(glm::inverse(quat), glm::vec3(-1.0, 0.0, 0.0));
|
||||
return glm::normalize(quat * Vector3(0, 0, -1));
|
||||
//return glm::normalize(glm::rotate(glm::inverse(quat), glm::vec3(-1.0, 0.0, 0.0)));
|
||||
}
|
||||
@@ -52,6 +52,8 @@ namespace Nuake
|
||||
//cam->cameraRight = glm::normalize(glm::cross(cam->up, cam->cameraFront));
|
||||
Direction = glm::normalize(direction);
|
||||
Right = glm::normalize(glm::cross(Vector3(0, 1, 0), Direction));
|
||||
m_View = lookAt(Translation, Translation + glm::normalize(Direction), Vector3(0, 1, 0));
|
||||
|
||||
//Up = glm::normalize(glm::cross(Direction, Right));
|
||||
}
|
||||
|
||||
@@ -84,8 +86,14 @@ namespace Nuake
|
||||
return m_Perspective;
|
||||
}
|
||||
|
||||
void Camera::SetTransform(const Matrix4& transform)
|
||||
{
|
||||
m_View = transform;
|
||||
}
|
||||
|
||||
Matrix4 Camera::GetTransform()
|
||||
{
|
||||
return m_View;
|
||||
glm::mat4 tr = lookAt(Translation, Translation + glm::normalize(Direction), Vector3(0, 1, 0));
|
||||
return tr;
|
||||
}
|
||||
@@ -94,7 +102,7 @@ namespace Nuake
|
||||
{
|
||||
return lookAt(glm::vec3(), Direction, Up);
|
||||
}
|
||||
|
||||
|
||||
bool Camera::BoxFrustumCheck(const AABB& aabb)
|
||||
{
|
||||
m_Frustum = Frustum(GetPerspective() * GetTransform());
|
||||
@@ -128,8 +136,8 @@ namespace Nuake
|
||||
if(j.contains("Translation"))
|
||||
DESERIALIZE_VEC3(j["Translation"], Translation);
|
||||
|
||||
if (j.contains("Direction"))
|
||||
DESERIALIZE_VEC3(j["Direction"], Direction);
|
||||
//if (j.contains("Direction"))
|
||||
// DESERIALIZE_VEC3(j["Direction"], Direction);
|
||||
|
||||
this->AspectRatio = j["AspectRatio"];
|
||||
this->Fov = j["Fov"];
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace Nuake
|
||||
Vector3 Up = Vector3(0, 1, 0);
|
||||
Vector3 Right = Vector3(1, 0, 0);
|
||||
Matrix4 m_Perspective;
|
||||
Matrix4 m_View;
|
||||
|
||||
public:
|
||||
float AspectRatio = 16.0f / 9.0f;
|
||||
@@ -51,6 +52,7 @@ namespace Nuake
|
||||
Matrix4 GetPerspective();
|
||||
Matrix4 GetTransform();
|
||||
Matrix4 GetTransformRotation();
|
||||
void SetTransform(const Matrix4& transform);
|
||||
inline Vector3 GetRight() const { return Right; }
|
||||
inline Vector3 GetUp() const { return glm::cross(Direction, Right); }
|
||||
bool BoxFrustumCheck(const AABB& aabb);
|
||||
|
||||
@@ -148,7 +148,8 @@ namespace Nuake
|
||||
Direction.x = cos(glm::radians(Yaw)) * cos(glm::radians(Pitch));
|
||||
Direction.y = sin(glm::radians(Pitch));
|
||||
Direction.z = sin(glm::radians(Yaw)) * cos(glm::radians(Pitch));
|
||||
Direction = glm::normalize(Direction);
|
||||
|
||||
SetDirection(glm::normalize(Direction));
|
||||
Right = glm::normalize(glm::cross(Up, Direction));
|
||||
}
|
||||
else if (Input::IsMouseButtonDown(2))
|
||||
|
||||
@@ -43,15 +43,20 @@ namespace Nuake
|
||||
TransformComponent& transform = localTransformView.get<TransformComponent>(tv);
|
||||
if (transform.Dirty)
|
||||
{
|
||||
Matrix4 localTransform = Matrix4(1.0f);
|
||||
auto& localTranslate = transform.GetLocalPosition();
|
||||
auto& localRot = transform.GetLocalRotation();
|
||||
auto& localScale = transform.GetLocalScale();
|
||||
localRot.w *= -1.0;
|
||||
localTransform = glm::translate(localTransform, localTranslate);
|
||||
localTransform = localTransform * glm::toMat4(localRot);
|
||||
localTransform = glm::scale(localTransform, localScale);
|
||||
transform.SetLocalTransform(localTransform);
|
||||
|
||||
const Matrix4& translationMatrix = glm::translate(Matrix4(1.0f), localTranslate);
|
||||
localRot.w *= -1.0f;
|
||||
const Matrix4& rotationMatrix = glm::mat4_cast(localRot);
|
||||
const Matrix4& scaleMatrix = glm::scale(Matrix4(1.0f), localScale);
|
||||
const Matrix4& newLocalTransform = translationMatrix * rotationMatrix * scaleMatrix;
|
||||
|
||||
//if(localRot.y != 0)
|
||||
// assert(newLocalTransform == transform.GetLocalTransform());
|
||||
|
||||
transform.SetLocalTransform(newLocalTransform);
|
||||
transform.Dirty = false;
|
||||
}
|
||||
}
|
||||
@@ -63,7 +68,7 @@ namespace Nuake
|
||||
auto [parent, transform] = transformView.get<ParentComponent, TransformComponent>(e);
|
||||
|
||||
if (!parent.HasParent)
|
||||
{
|
||||
{
|
||||
// If no parents, then globalTransform is local transform.
|
||||
transform.SetGlobalTransform(transform.GetLocalTransform());
|
||||
transform.SetGlobalPosition(transform.GetLocalPosition());
|
||||
@@ -84,14 +89,13 @@ namespace Nuake
|
||||
{
|
||||
TransformComponent& transformComponent = parentComponent.Parent.GetComponent<TransformComponent>();
|
||||
|
||||
globalPosition = transformComponent.GetLocalPosition() + (transformComponent.GetLocalRotation() * globalPosition);
|
||||
globalPosition = transformComponent.GetLocalPosition() + (globalPosition);
|
||||
|
||||
globalScale *= transformComponent.GetLocalScale();
|
||||
globalOrientation = transformComponent.GetLocalRotation() * globalOrientation;
|
||||
globalTransform = transformComponent.GetLocalTransform() * globalTransform;
|
||||
|
||||
globalOrientation = transformComponent.GetLocalRotation() * globalOrientation;
|
||||
globalScale *= transformComponent.GetLocalScale();
|
||||
|
||||
NameComponent& nameComponent = parentComponent.Parent.GetComponent<NameComponent>();
|
||||
|
||||
parentComponent = parentComponent.Parent.GetComponent<ParentComponent>();
|
||||
}
|
||||
|
||||
@@ -106,15 +110,13 @@ namespace Nuake
|
||||
{
|
||||
auto [transform, camera] = camView.get<TransformComponent, CameraComponent>(e);
|
||||
Matrix4 cameraTransform = camera.CameraInstance->GetTransformRotation();
|
||||
|
||||
camera.CameraInstance->Translation = transform.GlobalTranslation;
|
||||
|
||||
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;
|
||||
//f/orward.z *= -1.0f;
|
||||
camera.CameraInstance->SetDirection(forwardTransform);
|
||||
auto globalRotation = transform.GetGlobalRotation();
|
||||
auto& trnaslationMatrix = glm::translate(Matrix4(1.0f), transform.GetGlobalPosition());
|
||||
const Matrix4& rotationMatrix = glm::mat4_cast(globalRotation);
|
||||
camera.CameraInstance->SetTransform(glm::inverse(trnaslationMatrix * rotationMatrix));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user