From 467a4a049134947c5b743c2b394a3de301ea9128 Mon Sep 17 00:00:00 2001 From: Asuro Date: Sat, 1 Mar 2025 14:52:28 +0100 Subject: [PATCH] wip --- src/game/Global.cpp | 3 ++- src/game/Global.h | 15 +++++++++++++++ src/game/Level.cpp | 11 ++++++----- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/game/Global.cpp b/src/game/Global.cpp index 9337959..40579ad 100644 --- a/src/game/Global.cpp +++ b/src/game/Global.cpp @@ -141,7 +141,8 @@ Vec3 Transform::LocalToGlobalDirection(Vec3 local) UpdateMatrix(); float in[4]{local.x, local.y, local.z, 0.0f}; float out[4]{0.0f}; - bx::vec4MulMtx(out, in, M.M); + Mat4 test = M.Transpose(); + bx::vec4MulMtx(out, in, test.M); return {out[0], out[1], out[2]}; } bx::Vec3 Transform::LocalToGlobalPoint(bx::Vec3 local) diff --git a/src/game/Global.h b/src/game/Global.h index 88e6dc0..49016b6 100644 --- a/src/game/Global.h +++ b/src/game/Global.h @@ -1,6 +1,7 @@ #pragma once #include "bx/math.h" +#include struct Vec2 { @@ -63,6 +64,13 @@ struct Vec2 { return bx::sqrt(x * x + y * y); } + + Vec2 Normalize() + { + float mag = Magnitude(); + if (mag < FLT_EPSILON) return {}; + return {x / mag, y / mag}; + } }; struct Vec3 @@ -131,6 +139,13 @@ struct Vec3 { return bx::sqrt(x * x + y * y + z * z); } + + Vec3 Normalize() + { + float mag = Magnitude(); + if (mag < FLT_EPSILON) return {}; + return {x / mag, y / mag, z / mag}; + } }; struct Vec4 diff --git a/src/game/Level.cpp b/src/game/Level.cpp index 5aa949a..9a164db 100644 --- a/src/game/Level.cpp +++ b/src/game/Level.cpp @@ -195,7 +195,6 @@ namespace Game { player.FreeflyCamTransform.UpdateMatrix(); bgfx::setViewTransform(viewId, player.FreeflyCamTransform.M.M, proj); - // bgfx::dbgTextPrintf(1, 0, 0b1100, "NOCLIP"); } else { @@ -241,7 +240,7 @@ namespace Game EData.MaterialHandle = 0; EData.ModelHandle = GameRendering::Get().GetModelHandleFromPath("models/zurg.gltf"); - EData.Transform.Position = {0.0f, 0.0f, 10.0f}; + EData.Transform.Position = {0.0f, 0.0f, 0.0f}; EData.TestColor[0] = 0.0f; } @@ -272,7 +271,7 @@ namespace Game UIQuadEntity& quad = level.UIQuads.Get(UIPlacedCards[cardI]); quad.EData.MaterialHandle = 0; - quad.EData.ModelHandle = GameRendering::Get().GetModelHandleFromPath("models/plane.glb"); + quad.EData.ModelHandle = GameRendering::Get().GetModelHandleFromPath("models/cube.glb"); } } @@ -290,8 +289,10 @@ namespace Game level.PuzzleTiles.Get(TileHandles[cardI]).EData.ModelHandle = cData.ModelHandle; auto& quad = level.UIQuads.Get(UIPlacedCards[cardI]); - quad.EData.Transform.SetPosition(cameraPos + Vec3{0, -2, 0}); - quad.EData.Transform.Rotation = {}; + Vec3 fw = {0, -1, 0}; + // quad.EData.Transform.SetPosition(cameraPos + Vec3{0, -2, 0}); + quad.EData.Transform.SetPosition({}); + quad.EData.Transform.Rotation = camTransform.Rotation; } } } // namespace Game