diff --git a/assets/blender/plane.blend b/assets/blender/plane.blend index 95489f8..5879eb6 100644 --- a/assets/blender/plane.blend +++ b/assets/blender/plane.blend @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:981ced151e6b052264dc7081422e6a4c0afaa65fbd19de9aa3d4c9207a520510 -size 926632 +oid sha256:2e0e7cc42595c0ae508bf26f919468d81310ac8e88698d68bbf10ef6f20d8057 +size 893120 diff --git a/src/game/Global.cpp b/src/game/Global.cpp index 5ab0a52..9337959 100644 --- a/src/game/Global.cpp +++ b/src/game/Global.cpp @@ -27,15 +27,15 @@ void Transform::CreateTransform(float* out, bx::Vec3 pos, bx::Quaternion rot, bx bx::mtxMul(out, buf, tMat); } -void Transform::Translate(bx::Vec3 offset) +void Transform::Translate(Vec3 offset) { - Position = bx::add(Position, offset); + Position = bx::add(Position, {offset.x, offset.y, offset.z}); } -void Transform::TranslateLocal(bx::Vec3 offset) +void Transform::TranslateLocal(Vec3 offset) { - bx::Vec3 localOffset = GlobalToLocalDirection(offset); - Position = bx::add(Position, localOffset); + Vec3 localOffset = GlobalToLocalDirection(offset); + Position = bx::add(Position, {localOffset.x, localOffset.y, localOffset.z}); } void Transform::Rotate(bx::Vec3 rotation) @@ -56,17 +56,17 @@ void Transform::RotateLocal(bx::Vec3 rotation) bx::memCopy(Rotation.M, temp, sizeof(temp)); } -bx::Vec3 Transform::Right() const +Vec3 Transform::Right() const { return {M.M[0], M.M[1], M.M[2]}; } -bx::Vec3 Transform::Up() const +Vec3 Transform::Up() const { return {M.M[4], M.M[5], M.M[6]}; } -bx::Vec3 Transform::Forward() const +Vec3 Transform::Forward() const { return {M.M[8], M.M[9], M.M[10]}; } @@ -120,7 +120,7 @@ namespace Game return reinterpret_cast(ptrAligned); } } // namespace Game -bx::Vec3 Transform::GlobalToLocalDirection(bx::Vec3 global) +Vec3 Transform::GlobalToLocalDirection(Vec3 global) { UpdateMatrix(); float in[4]{global.x, global.y, global.z, 0.0f}; @@ -136,7 +136,7 @@ bx::Vec3 Transform::GlobalToLocalPoint(bx::Vec3 global) bx::vec4MulMtx(out, in, MI.M); return {out[0], out[1], out[2]}; } -bx::Vec3 Transform::LocalToGlobalDirection(bx::Vec3 local) +Vec3 Transform::LocalToGlobalDirection(Vec3 local) { UpdateMatrix(); float in[4]{local.x, local.y, local.z, 0.0f}; @@ -152,3 +152,23 @@ bx::Vec3 Transform::LocalToGlobalPoint(bx::Vec3 local) bx::vec4MulMtx(out, in, M.M); return {out[0], out[1], out[2]}; } +void Transform::SetPosition(Vec3 pos) +{ + Position = {pos.x, pos.y, pos.z}; +} +Vec3 Transform::GetPosition() +{ + return {Position.x, Position.y, Position.z}; +} +Mat4 Mat4::Inverse() +{ + Mat4 result; + bx::mtxInverse(result.M, M); + return result; +} +Mat4 Mat4::Transpose() +{ + Mat4 result; + bx::mtxTranspose(result.M, M); + return result; +} diff --git a/src/game/Global.h b/src/game/Global.h index 77df6c3..88e6dc0 100644 --- a/src/game/Global.h +++ b/src/game/Global.h @@ -70,6 +70,67 @@ struct Vec3 float x = 0.0f; float y = 0.0f; float z = 0.0f; + + Vec3& operator+=(const Vec3& rhs) + { + x += rhs.x; + y += rhs.y; + z += rhs.z; + return *this; + } + + friend Vec3 operator+(Vec3 lhs, const Vec3& rhs) + { + lhs += rhs; + return lhs; + } + + Vec3& operator-=(const Vec3& rhs) + { + x -= rhs.x; + y -= rhs.y; + z -= rhs.z; + return *this; + } + + friend Vec3 operator-(Vec3 lhs, const Vec3& rhs) + { + lhs -= rhs; + return lhs; + } + + Vec3& operator*=(const float rhs) + { + x *= rhs; + y *= rhs; + z *= rhs; + return *this; + } + + friend Vec3 operator*(Vec3 lhs, const float rhs) + { + lhs *= rhs; + return lhs; + } + + Vec3& operator/=(const float rhs) + { + x /= rhs; + y /= rhs; + z /= rhs; + return *this; + } + + friend Vec3 operator/(Vec3 lhs, const float rhs) + { + lhs /= rhs; + return lhs; + } + + float Magnitude() + { + return bx::sqrt(x * x + y * y + z * z); + } }; struct Vec4 @@ -101,6 +162,9 @@ struct Mat4 0.0, 0.0, 0.0, 1.0, }; // clang-format on + + Mat4 Inverse(); + Mat4 Transpose(); }; inline int32_t SetFlags(int32_t in, int32_t flags) @@ -133,17 +197,19 @@ struct Transform bx::Vec3 Scale{1.0f, 1.0f, 1.0f}; static void CreateTransform(float* out, bx::Vec3 pos, bx::Quaternion rot, bx::Vec3 scale); - void Translate(bx::Vec3 offset); - void TranslateLocal(bx::Vec3 offset); + void Translate(Vec3 offset); + void TranslateLocal(Vec3 offset); void Rotate(bx::Vec3 rotation); void RotateLocal(bx::Vec3 rotation); bx::Vec3 LocalToGlobalPoint(bx::Vec3 local); - bx::Vec3 LocalToGlobalDirection(bx::Vec3 local); + Vec3 LocalToGlobalDirection(Vec3 local); bx::Vec3 GlobalToLocalPoint(bx::Vec3 global); - bx::Vec3 GlobalToLocalDirection(bx::Vec3 global); - bx::Vec3 Right() const; - bx::Vec3 Up() const; - bx::Vec3 Forward() const; + Vec3 GlobalToLocalDirection(Vec3 global); + Vec3 Right() const; + Vec3 Up() const; + Vec3 Forward() const; + void SetPosition(Vec3 pos); + Vec3 GetPosition(); const float* GetPtr(); void UpdateMatrix(); }; diff --git a/src/game/Level.cpp b/src/game/Level.cpp index 1840282..5aa949a 100644 --- a/src/game/Level.cpp +++ b/src/game/Level.cpp @@ -206,7 +206,8 @@ namespace Game // Cubes.Render(models, materials); Tests.Render(models, materials); - PuzzleTiles.Render(models, materials); + // PuzzleTiles.Render(models, materials); + UIQuads.Render(models, materials); } void Cube::Setup() @@ -256,7 +257,7 @@ namespace Game for (uint32_t cardI = 0; cardI < Data.PlacedCardCount; ++cardI) { const Puzzle::PlacedPuzzleCard& card = Data.PlacedCards[cardI]; - auto& level = GetInstance().GameLevel; + Level& level = GetInstance().GameLevel; TileHandles[cardI] = level.PuzzleTiles.New(); UIPlacedCards[cardI] = level.UIQuads.New(); @@ -265,24 +266,32 @@ namespace Game WorldPosition.y, WorldPosition.z + card.Position.Y * WorldCardSize.y, }; - auto& tile = level.PuzzleTiles.Get(TileHandles[cardI]); + PuzzleTileEntity& tile = level.PuzzleTiles.Get(TileHandles[cardI]); tile.EData.Transform.Position = Pos; tile.EData.MaterialHandle = 0; - auto& quad = level.UIQuads.Get(UIPlacedCards[cardI]); - // quad.EData.Transform.Position.something; + UIQuadEntity& quad = level.UIQuads.Get(UIPlacedCards[cardI]); + quad.EData.MaterialHandle = 0; + quad.EData.ModelHandle = GameRendering::Get().GetModelHandleFromPath("models/plane.glb"); } } void WorldPuzzle::Update() { + Transform& camTransform = GetInstance().Player.PlayerCamTransform; + Vec3 cameraPos = camTransform.GetPosition() * -1; + Level& level = GetInstance().GameLevel; + for (int32_t cardI = 0; cardI < Data.PlacedCardCount; ++cardI) { Puzzle::PlacedPuzzleCard& card = Data.PlacedCards[cardI]; if (!card.RefCard.IsValid()) continue; const Puzzle::StaticPuzzleCard& cData = Puzzle::StaticPuzzleData::Get().GetCard(card.RefCard); - GetInstance().GameLevel.PuzzleTiles.Get(TileHandles[cardI]).EData.ModelHandle = cData.ModelHandle; - GetInstance().GameLevel.UIQuads.Get(UIPlacedCards[cardI]).EData.Transform.Position = {0, 0, 0}; + 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 = {}; } } } // namespace Game diff --git a/src/game/Level.h b/src/game/Level.h index 01b2df0..22fb859 100644 --- a/src/game/Level.h +++ b/src/game/Level.h @@ -145,7 +145,6 @@ namespace Game EntityManager PuzzleTiles; EntityManager UIQuads; - public: Puzzle::StaticPuzzleData PuzzleData; WorldPuzzle Puzzles[1]; diff --git a/src/game/Log.cpp b/src/game/Log.cpp index d32e0b6..be3fb4b 100644 --- a/src/game/Log.cpp +++ b/src/game/Log.cpp @@ -5,18 +5,30 @@ #include +#define ESC "\x1B[" +#define YELLOW ESC "33m" +#define RED ESC "31m" +#define END ESC "39m" + namespace { char LineBuffer[1024]{0}; char OutBuffer[1024]{0}; bx::HandleHashMapT<1024> OnceMap; + constexpr char LogFormat[]{"%s\n"}; + constexpr char WarnFormat[]{YELLOW "%s" END "\n"}; + constexpr char ErrorFormat[]{RED "%s" END "\n"}; } // namespace void Log(ELogType logType, const char* file, uint32_t line, const char* format, ...) { + const char* LineFormat = LogFormat; + if (logType == ELogType::Warn) LineFormat = WarnFormat; + if (logType == ELogType::Error) LineFormat = ErrorFormat; + va_list args; va_start(args, format); - bx::snprintf(LineBuffer, sizeof(LineBuffer), "%s\n", format); + bx::snprintf(LineBuffer, sizeof(LineBuffer), LineFormat, format); bx::vprintf(LineBuffer, args); bx::vsnprintf(OutBuffer, sizeof(OutBuffer), LineBuffer, args); va_end(args); diff --git a/src/game/Setup.cpp b/src/game/Setup.cpp index 97e0a67..b2bae47 100644 --- a/src/game/Setup.cpp +++ b/src/game/Setup.cpp @@ -42,7 +42,7 @@ namespace Game GameInstance& instance = *reinterpret_cast(shared.Game.PermanentStorage); if (sizeof(GameInstance) != instance.Size) { - LOG_ERROR("Game instance size changed, resetting!"); + LOG_WARN("Game instance size changed, resetting!"); instance = {}; } instance.UsedScratchAmount = 0; diff --git a/src/game/rendering/Rendering.cpp b/src/game/rendering/Rendering.cpp index 5101198..e5ea765 100644 --- a/src/game/rendering/Rendering.cpp +++ b/src/game/rendering/Rendering.cpp @@ -500,6 +500,8 @@ namespace Game { ImGui::Image(DitherTextures.RampTex.idx, {BX_COUNTOF(DitherTextures.BrightnessRamp), 8}); } + Vec3 quadPos = GetInstance().GameLevel.UIQuads.Get({0}).EData.Transform.GetPosition(); + ImGui::Text("%f %f %f", quadPos.x, quadPos.y, quadPos.z); ImGui::Text("Shader log:"); ImGui::TextWrapped("%s", GetShared().Dev.ShaderLog); } diff --git a/src/models/plane.glb b/src/models/plane.glb index d3814f8..61932b7 100644 --- a/src/models/plane.glb +++ b/src/models/plane.glb @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e47d024c30089d49d6836a129467c800065dcc3b392362c4a5688967c65d1919 -size 132 +oid sha256:ba22bfdf1a3273a838969a87ce3e446595078f7a89dc8619ab8ae639ac469dea +size 1220