wip card clicking
This commit is contained in:
BIN
assets/blender/tablet.blend
LFS
Normal file
BIN
assets/blender/tablet.blend
LFS
Normal file
Binary file not shown.
BIN
assets/textures/w straight.png
LFS
Normal file
BIN
assets/textures/w straight.png
LFS
Normal file
Binary file not shown.
@@ -171,3 +171,9 @@ Mat4 Mat4::Transpose()
|
||||
bx::mtxTranspose(result.M, M);
|
||||
return result;
|
||||
}
|
||||
Vec4 Mat4::Mul(const Vec4& vec)
|
||||
{
|
||||
Vec4 out;
|
||||
bx::vec4MulMtx(&out.x, &vec.x, &M[0]);
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,19 @@ struct Vec2
|
||||
return lhs;
|
||||
}
|
||||
|
||||
Vec2& operator+=(const float& rhs)
|
||||
{
|
||||
x += rhs;
|
||||
y += rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
friend Vec2 operator+(Vec2 lhs, const float& rhs)
|
||||
{
|
||||
lhs += rhs;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
Vec2& operator-=(const Vec2& rhs)
|
||||
{
|
||||
x -= rhs.x;
|
||||
@@ -34,6 +47,19 @@ struct Vec2
|
||||
return lhs;
|
||||
}
|
||||
|
||||
Vec2& operator-=(const float& rhs)
|
||||
{
|
||||
x -= rhs;
|
||||
y -= rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
friend Vec2 operator-(Vec2 lhs, const float& rhs)
|
||||
{
|
||||
lhs -= rhs;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
Vec2& operator*=(const float rhs)
|
||||
{
|
||||
x *= rhs;
|
||||
@@ -180,6 +206,7 @@ struct Mat4
|
||||
|
||||
Mat4 Inverse();
|
||||
Mat4 Transpose();
|
||||
Vec4 Mul(const Vec4& vec);
|
||||
};
|
||||
|
||||
inline int32_t SetFlags(int32_t in, int32_t flags)
|
||||
|
||||
@@ -56,4 +56,9 @@ namespace Game
|
||||
if (!IsMouseAllowed()) return {};
|
||||
return {GetShared().Window.MouseDeltaX, GetShared().Window.MouseDeltaY};
|
||||
}
|
||||
Vec2 GetMousePos()
|
||||
{
|
||||
ImVec2 pos = ImGui::GetMousePos();
|
||||
return {pos.x, pos.y};
|
||||
}
|
||||
} // namespace Game
|
||||
|
||||
@@ -394,4 +394,5 @@ namespace Game
|
||||
bool GetMouseButtonPressedNow(MouseButton button);
|
||||
bool GetMouseButtonReleasedNow(MouseButton button);
|
||||
Vec2 GetMouseMovement();
|
||||
Vec2 GetMousePos();
|
||||
} // namespace Game
|
||||
|
||||
@@ -28,12 +28,14 @@ namespace Game
|
||||
|
||||
struct PlayerData
|
||||
{
|
||||
Transform PlayerCamTransform;
|
||||
Transform FreeflyCamTransform;
|
||||
Mat4 Projection;
|
||||
Mat4 ProjectionInverse;
|
||||
float FreeflyXRot = 0.0f;
|
||||
float FreeflyYRot = 0.0f;
|
||||
float WalkXRot = 0.0f;
|
||||
float WalkYRot = 0.0f;
|
||||
Transform PlayerCamTransform;
|
||||
CameraMode CameraM = CameraMode::Freefly;
|
||||
InputMode InputM = InputMode::Game;
|
||||
float MouseSensitivity = 1.0f;
|
||||
|
||||
@@ -58,6 +58,8 @@ namespace Game
|
||||
{
|
||||
sampler = textures[TextureHandle.TextureIdx].SamplerHandle;
|
||||
tex = textures[TextureHandle.TextureIdx].RenderHandle;
|
||||
texInfo[0] = textures[TextureHandle.TextureIdx].Info.width;
|
||||
texInfo[1] = textures[TextureHandle.TextureIdx].Info.height;
|
||||
}
|
||||
|
||||
bgfx::setTexture(0, sampler, tex);
|
||||
@@ -93,8 +95,6 @@ namespace Game
|
||||
needReset |= PuzzleTiles.Setup(storagePtr, needReset);
|
||||
needReset |= UIQuads.Setup(storagePtr, needReset);
|
||||
|
||||
Tests.IsEnabled = false;
|
||||
|
||||
Puzzle::Setup();
|
||||
|
||||
bx::Error err;
|
||||
@@ -250,27 +250,27 @@ namespace Game
|
||||
{
|
||||
ZoneScopedN("Level Render");
|
||||
auto& shared = GetShared();
|
||||
auto& player = GetInstance().Player;
|
||||
|
||||
float proj[16];
|
||||
bx::mtxProj(proj,
|
||||
bx::mtxProj(&player.Projection.M[0],
|
||||
75.0f,
|
||||
float(shared.Window.WindowWidth) / float(shared.Window.WindowHeight),
|
||||
0.1f,
|
||||
1000.0f,
|
||||
bgfx::getCaps()->homogeneousDepth);
|
||||
bx::mtxInverse(&player.ProjectionInverse.M[0], &player.Projection.M[0]);
|
||||
|
||||
auto& player = GetInstance().Player;
|
||||
bool isFreefly = player.CameraM == CameraMode::Freefly;
|
||||
Cubes.Get(PlayerOutsideViewCube).EData.Visible = isFreefly;
|
||||
if (isFreefly)
|
||||
{
|
||||
player.FreeflyCamTransform.UpdateMatrix();
|
||||
bgfx::setViewTransform(viewId, player.FreeflyCamTransform.MI.M, proj);
|
||||
bgfx::setViewTransform(viewId, player.FreeflyCamTransform.MI.M, &player.Projection.M[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.PlayerCamTransform.UpdateMatrix();
|
||||
bgfx::setViewTransform(viewId, player.PlayerCamTransform.MI.M, proj);
|
||||
bgfx::setViewTransform(viewId, player.PlayerCamTransform.MI.M, &player.Projection.M[0]);
|
||||
}
|
||||
|
||||
bgfx::touch(viewId);
|
||||
@@ -297,9 +297,7 @@ namespace Game
|
||||
void TestEntity::Setup()
|
||||
{
|
||||
EData.MaterialHandle = EMaterial::Default;
|
||||
EData.ModelH = GameRendering::Get().GetModelHandleFromPath("models/zurg.gltf");
|
||||
|
||||
EData.Transform.Position = {0.0f, 0.0f, 0.0f};
|
||||
EData.ModelH = GameRendering::Get().GetModelHandleFromPath("models/cube.gltf");
|
||||
}
|
||||
|
||||
void WorldPuzzle::Setup()
|
||||
@@ -325,6 +323,7 @@ namespace Game
|
||||
void WorldPuzzle::Update()
|
||||
{
|
||||
Level& level = GetInstance().GameLevel;
|
||||
auto& window = GetShared().Window;
|
||||
auto& staticCards = Puzzle::GetStaticPuzzleData().Cards;
|
||||
|
||||
Transform& camTransform = GetInstance().Player.PlayerCamTransform;
|
||||
@@ -335,24 +334,42 @@ namespace Game
|
||||
boardTransform.Rotation = camTransform.Rotation;
|
||||
Vec3 fw = {camTransform.M.M[8], camTransform.M.M[9], camTransform.M.M[10]};
|
||||
Vec3 pos = cameraPos;
|
||||
pos += fw;
|
||||
pos += fw * 10.0f;
|
||||
boardTransform.SetPosition(pos);
|
||||
|
||||
bool clicked = GetMouseButtonPressedNow(MouseButton::Left);
|
||||
Vec2 mousePos = GetMousePos();
|
||||
mousePos.x = mousePos.x / window.WindowWidth;
|
||||
mousePos.y = mousePos.y / window.WindowHeight;
|
||||
mousePos *= 2.0f;
|
||||
mousePos -= 1.0f;
|
||||
Vec4 mousePosView = {mousePos.x, -mousePos.y, 0.0f, 1.0f};
|
||||
Vec4 mousePosCam = GetInstance().Player.ProjectionInverse.Mul(mousePosView);
|
||||
mousePosCam.x /= mousePosCam.w;
|
||||
mousePosCam.y /= mousePosCam.w;
|
||||
mousePosCam.z /= mousePosCam.w;
|
||||
mousePosCam.w = 1.0f;
|
||||
Vec4 mousePosWorld = camTransform.M.Mul(mousePosCam);
|
||||
|
||||
auto& t = level.Tests.Get({0});
|
||||
t.EData.ModelH = GameRendering::Get().GetModelHandleFromPath("models/cube.gltf");
|
||||
t.EData.Transform.Position = {mousePosWorld.x, mousePosWorld.y, mousePosWorld.z};
|
||||
t.EData.Transform.Scale = {0.01f, 0.01f, 0.01f};
|
||||
|
||||
for (int8_t y = 0; y < Data.HeightTiles / Puzzle::Config::CardSize; ++y)
|
||||
{
|
||||
for (int8_t x = 0; x < Data.WidthTiles / Puzzle::Config::CardSize; ++x)
|
||||
{
|
||||
Generated::PlacedPuzzleCard& card = Data.PlacedCards[y * Puzzle::Config::MaxPuzzleSizeCards + x];
|
||||
auto& tile = level.PuzzleTiles.Get(TileHandles[y * Puzzle::Config::MaxPuzzleSizeCards + x]);
|
||||
auto& quad = level.UIQuads.Get(UIPlacedCards[y * Puzzle::Config::MaxPuzzleSizeCards + x]);
|
||||
int32_t cardIdx = y * Puzzle::Config::MaxPuzzleSizeCards + x;
|
||||
Generated::PlacedPuzzleCard& card = Data.PlacedCards[cardIdx];
|
||||
auto& tile = level.PuzzleTiles.Get(TileHandles[cardIdx]);
|
||||
auto& quad = level.UIQuads.Get(UIPlacedCards[cardIdx]);
|
||||
|
||||
bool IsValid = Puzzle::IsValid(card.RefCard);
|
||||
tile.EData.Visible = true;
|
||||
quad.EData.Visible = IsValid;
|
||||
|
||||
tile.EData.Visible = true;
|
||||
tile.EData.ModelH = IsValid ? staticCards[card.RefCard.Idx].ModelHandle : staticCards[0].ModelHandle;
|
||||
quad.EData.TextureHandle =
|
||||
IsValid ? staticCards[card.RefCard.Idx].BoardTextureHandle : Generated::TextureHandle{};
|
||||
|
||||
Vec3 cardPos = {
|
||||
(float)card.Position.X * Puzzle::Config::CardScaleWorld,
|
||||
-5.0f,
|
||||
@@ -365,10 +382,45 @@ namespace Game
|
||||
tile.EData.Transform.SetPosition(cardPos);
|
||||
bx::mtxRotateY(tile.EData.Transform.Rotation.M, card.Rotation * bx::kPi * 0.5f);
|
||||
|
||||
quad.EData.Visible = IsValid;
|
||||
quad.EData.TextureHandle =
|
||||
IsValid ? staticCards[card.RefCard.Idx].BoardTextureHandle : Generated::TextureHandle{};
|
||||
|
||||
quad.EData.Transform = boardTransform;
|
||||
quad.EData.Transform.TranslateLocal(Vec3{(float)card.Position.X, (float)card.Position.Y, 0.0f} * 0.21f);
|
||||
quad.EData.Transform.Scale = {0.1f, 0.1f, 0.1f};
|
||||
quad.EData.Transform.TranslateLocal(Vec3{(float)card.Position.X, (float)card.Position.Y, 0.0f} * 3.0f);
|
||||
quad.EData.Transform.Scale = {1.0f, 1.0f, 1.0f};
|
||||
// quad.EData.Transform.Scale = {0.1f, 0.1f, 0.1f};
|
||||
quad.EData.Transform.Rotate(Vec3{bx::kPi * 0.5f, 0.0f, bx::kPi});
|
||||
|
||||
if (clicked && IsValid && x == 1 && y == 1)
|
||||
{
|
||||
quad.EData.Transform.UpdateMatrix();
|
||||
// boardTransform.UpdateMatrix();
|
||||
Vec4 posInQuad = quad.EData.Transform.MI.Mul(mousePosWorld);
|
||||
// Vec4 posInQuad = boardTransform.MI.Mul(mousePosWorld);
|
||||
// if (posInQuad.x >= -1.0f && posInQuad.x <= 1.0f && posInQuad.z >= -1.0f && posInQuad.z <= 1.0f)
|
||||
{
|
||||
LOG("---");
|
||||
LOG("%.03f %.03f: Click", mousePos.x, mousePos.y);
|
||||
LOG("%.03f %.03f %.03f %.03f: Cam", mousePosCam.x, mousePosCam.y, mousePosCam.z, mousePosCam.w);
|
||||
LOG("%.03f %.03f %.03f %.03f: World",
|
||||
mousePosWorld.x,
|
||||
mousePosWorld.y,
|
||||
mousePosWorld.z,
|
||||
mousePosWorld.w);
|
||||
LOG("%.03f %.03f %.03f %.03f: Card (%u %u)",
|
||||
posInQuad.x,
|
||||
posInQuad.y,
|
||||
posInQuad.z,
|
||||
posInQuad.w,
|
||||
x,
|
||||
y);
|
||||
LOG("%.03f %.03f %.03f: Player",
|
||||
camTransform.Position.x,
|
||||
camTransform.Position.y,
|
||||
camTransform.Position.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BIN
src/game/data/puzzles/0.pzl
LFS
BIN
src/game/data/puzzles/0.pzl
LFS
Binary file not shown.
Binary file not shown.
BIN
src/models/tablet.glb
LFS
Normal file
BIN
src/models/tablet.glb
LFS
Normal file
Binary file not shown.
BIN
src/textures/w straight.ktx
LFS
Normal file
BIN
src/textures/w straight.ktx
LFS
Normal file
Binary file not shown.
Reference in New Issue
Block a user