parent to camera

This commit is contained in:
Asuro
2025-03-27 22:38:31 +01:00
parent 90d4c3df1b
commit 26ba03b7fe
4 changed files with 29 additions and 27 deletions

View File

@@ -37,7 +37,7 @@ void Transform::TranslateLocal(Vec3 offset)
Position = bx::add(Position, {localOffset.x, localOffset.y, localOffset.z}); Position = bx::add(Position, {localOffset.x, localOffset.y, localOffset.z});
} }
void Transform::Rotate(bx::Vec3 rotation) void Transform::Rotate(Vec3 rotation)
{ {
float rot[16]{0}; float rot[16]{0};
bx::mtxRotateXYZ(rot, rotation.x, rotation.y, rotation.z); bx::mtxRotateXYZ(rot, rotation.x, rotation.y, rotation.z);
@@ -46,7 +46,7 @@ void Transform::Rotate(bx::Vec3 rotation)
bx::memCopy(Rotation.M, temp, sizeof(temp)); bx::memCopy(Rotation.M, temp, sizeof(temp));
} }
void Transform::RotateLocal(bx::Vec3 rotation) void Transform::RotateLocal(Vec3 rotation)
{ {
float rot[16]{0}; float rot[16]{0};
bx::mtxRotateXYZ(rot, rotation.x, rotation.y, rotation.z); bx::mtxRotateXYZ(rot, rotation.x, rotation.y, rotation.z);
@@ -135,7 +135,7 @@ Vec3 Transform::GlobalToLocalDirection(Vec3 global)
bx::vec4MulMtx(out, in, MI.M); bx::vec4MulMtx(out, in, MI.M);
return {out[0], out[1], out[2]}; return {out[0], out[1], out[2]};
} }
bx::Vec3 Transform::GlobalToLocalPoint(bx::Vec3 global) bx::Vec3 Transform::GlobalToLocalPoint(Vec3 global)
{ {
UpdateMatrix(); UpdateMatrix();
float in[4]{global.x, global.y, global.z, 1.0f}; float in[4]{global.x, global.y, global.z, 1.0f};
@@ -152,7 +152,7 @@ Vec3 Transform::LocalToGlobalDirection(Vec3 local)
bx::vec4MulMtx(out, in, test.M); bx::vec4MulMtx(out, in, test.M);
return {out[0], out[1], out[2]}; return {out[0], out[1], out[2]};
} }
bx::Vec3 Transform::LocalToGlobalPoint(bx::Vec3 local) bx::Vec3 Transform::LocalToGlobalPoint(Vec3 local)
{ {
UpdateMatrix(); UpdateMatrix();
float in[4]{local.x, local.y, local.z, 1.0f}; float in[4]{local.x, local.y, local.z, 1.0f};

View File

@@ -214,11 +214,11 @@ struct Transform
static void CreateTransform(float* out, bx::Vec3 pos, bx::Quaternion rot, bx::Vec3 scale); static void CreateTransform(float* out, bx::Vec3 pos, bx::Quaternion rot, bx::Vec3 scale);
void Translate(Vec3 offset); void Translate(Vec3 offset);
void TranslateLocal(Vec3 offset); void TranslateLocal(Vec3 offset);
void Rotate(bx::Vec3 rotation); void Rotate(Vec3 rotation);
void RotateLocal(bx::Vec3 rotation); void RotateLocal(Vec3 rotation);
bx::Vec3 LocalToGlobalPoint(bx::Vec3 local); bx::Vec3 LocalToGlobalPoint(Vec3 local);
Vec3 LocalToGlobalDirection(Vec3 local); Vec3 LocalToGlobalDirection(Vec3 local);
bx::Vec3 GlobalToLocalPoint(bx::Vec3 global); bx::Vec3 GlobalToLocalPoint(Vec3 global);
Vec3 GlobalToLocalDirection(Vec3 global); Vec3 GlobalToLocalDirection(Vec3 global);
Vec3 Right() const; Vec3 Right() const;
Vec3 Up() const; Vec3 Up() const;

View File

@@ -364,12 +364,13 @@ namespace Game
tile.EData.Transform.SetPosition(cardPos); tile.EData.Transform.SetPosition(cardPos);
bx::mtxRotateY(tile.EData.Transform.Rotation.M, card.Rotation * bx::kPi * 0.5f); bx::mtxRotateY(tile.EData.Transform.Rotation.M, card.Rotation * bx::kPi * 0.5f);
Mat4 tp = camTransform.M.Transpose(); camTransform.UpdateMatrixForCam();
Vec3 fw = {tp.M[8], tp.M[9], tp.M[10]}; Vec3 fw = {camTransform.M.M[2], camTransform.M.M[6], camTransform.M.M[10]};
Vec3 pos = camTransform.GetPosition() * -1; Vec3 pos = camTransform.GetPosition() * -1;
pos += fw; pos += fw;
quad.EData.Transform.SetPosition(pos); quad.EData.Transform.SetPosition(pos);
quad.EData.Transform.Rotation = {}; quad.EData.Transform.Rotation = camTransform.Rotation.Inverse();
quad.EData.Transform.Rotate(Vec3{bx::kPi * 0.5f, 0.0f, 0.0f});
} }
} }
} }

View File

@@ -476,22 +476,6 @@ namespace Game
debug.DebugCardRotation++; debug.DebugCardRotation++;
if (debug.DebugCardRotation >= 4) debug.DebugCardRotation = 0; if (debug.DebugCardRotation >= 4) debug.DebugCardRotation = 0;
} }
ImGui::SetNextWindowPos({0, 0});
if (ImGui::Begin("Stats",
nullptr,
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoInputs |
ImGuiWindowFlags_AlwaysAutoResize))
{
if (GetInstance().Player.CameraM == CameraMode::Freefly)
{
ImGui::PushStyleColor(ImGuiCol_Text, {0.8f, 0.1f, 0.1f, 1.0f});
ImGui::Text("NOCLIP");
ImGui::PopStyleColor();
}
ImGui::Text("Delta: %.01fms", time.Delta * 1000);
ImGui::Text("FPS: %.0f", 1.0 / time.Delta);
}
ImGui::End();
if (ImGui::Begin("Log")) if (ImGui::Begin("Log"))
{ {
ImGui::Checkbox("Shorten File Names", &GetInstance().DebugData.ShortenLogFileNames); ImGui::Checkbox("Shorten File Names", &GetInstance().DebugData.ShortenLogFileNames);
@@ -717,6 +701,7 @@ namespace Game
{ {
ZoneScopedN("Rendering"); ZoneScopedN("Rendering");
SharedData& shared = GetShared(); SharedData& shared = GetShared();
auto& time = GetInstance().Time;
HandleEvents(); HandleEvents();
@@ -732,6 +717,22 @@ namespace Game
{ {
RenderDebugUI(); RenderDebugUI();
} }
ImGui::SetNextWindowPos({0, 0});
if (ImGui::Begin("Stats",
nullptr,
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoInputs |
ImGuiWindowFlags_AlwaysAutoResize))
{
if (GetInstance().Player.CameraM == CameraMode::Freefly)
{
ImGui::PushStyleColor(ImGuiCol_Text, {0.8f, 0.1f, 0.1f, 1.0f});
ImGui::Text("NOCLIP");
ImGui::PopStyleColor();
}
ImGui::Text("Delta: %.01fms", time.Delta * 1000);
ImGui::Text("FPS: %.0f", 1.0 / time.Delta);
}
ImGui::End();
GetInstance().GameLevel.Update(); GetInstance().GameLevel.Update();
GetInstance().GameLevel.Render(MainViewID, Models, Materials); GetInstance().GameLevel.Render(MainViewID, Models, Materials);