working collision!
This commit is contained in:
@@ -212,6 +212,44 @@ namespace Game
|
||||
UpdatePlayerInputMode();
|
||||
}
|
||||
|
||||
bool IsOnGround(Level& level, Vec3 worldPos)
|
||||
{
|
||||
for (auto& puz : level.Puzzles)
|
||||
{
|
||||
Vec3 offsetToPuzzle =
|
||||
worldPos - puz.WorldPosition + (Vec3{0.5f, 0.0f, 0.5f} * Puzzle::Config::CardScaleWorld);
|
||||
Vec3 scaledOffset = offsetToPuzzle / Puzzle::Config::CardScaleWorld;
|
||||
int32_t offsetX = (int32_t)bx::floor(scaledOffset.x);
|
||||
int32_t offsetY = (int32_t)bx::floor(scaledOffset.z);
|
||||
if (offsetX >= 0 && offsetX < puz.Data.WidthTiles / 2 && offsetY >= 0 && offsetY < puz.Data.HeightTiles / 2)
|
||||
{
|
||||
auto& card = puz.Data.PlacedCards[offsetY * Puzzle::Config::MaxPuzzleSizeCards + offsetX];
|
||||
if (card.RefCard.Idx == UINT16_MAX)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
auto& refCard = Puzzle::GetStaticPuzzleData().Cards[card.RefCard.Idx];
|
||||
if (!IsValid(refCard.BaseModelHandle))
|
||||
{
|
||||
LOG_WARN("missing base model! @ %i %i", offsetX, offsetY);
|
||||
return true;
|
||||
}
|
||||
|
||||
auto& heightmap = GameRendering::Get().Models[refCard.BaseModelHandle.ModelIdx].Height;
|
||||
float fracOffsetX = scaledOffset.x - offsetX;
|
||||
float fracOffsetY = scaledOffset.z - offsetY;
|
||||
int32_t xPos = (int32_t)(fracOffsetX * heightmap.Width);
|
||||
int32_t yPos = (int32_t)(fracOffsetY * heightmap.Height);
|
||||
uint8_t height = heightmap.Values[yPos * heightmap.Width + xPos];
|
||||
|
||||
LOG("Height: %u", height);
|
||||
return height > 230;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Level::Update()
|
||||
{
|
||||
ZoneScopedN("Level update");
|
||||
@@ -263,9 +301,15 @@ namespace Game
|
||||
}
|
||||
else if (player.CameraM == CameraMode::Walk)
|
||||
{
|
||||
TranslateLocal(player.PlayerCamTransform, {0.0f, 0.0f, inputVec.z});
|
||||
TranslateLocal(player.PlayerCamTransform, {inputVec.x, 0.0f, 0.0f});
|
||||
player.PlayerCamTransform.Position.y = 3.0f;
|
||||
auto newTransform = player.PlayerCamTransform;
|
||||
TranslateLocal(newTransform, {0.0f, 0.0f, inputVec.z});
|
||||
TranslateLocal(newTransform, {inputVec.x, 0.0f, 0.0f});
|
||||
newTransform.Position.y = 3.0f;
|
||||
|
||||
if (IsOnGround(*this, newTransform.Position))
|
||||
{
|
||||
player.PlayerCamTransform = newTransform;
|
||||
}
|
||||
|
||||
player.WalkXRot += rotInput.x;
|
||||
player.WalkYRot += rotInput.y;
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#include "rendering/Rendering.h"
|
||||
|
||||
#include "Instance.h"
|
||||
#include <cfloat>
|
||||
#include <cstdint>
|
||||
|
||||
#define TINYGLTF_IMPLEMENTATION
|
||||
@@ -129,8 +128,8 @@ namespace Game
|
||||
{
|
||||
float uPos = mesh.MinPos.x + (float)u / HeightMap::Width * mesh.Size.x;
|
||||
|
||||
Gen::Vec3 rayStart = {uPos, mesh.MinPos.y, vPos};
|
||||
Gen::Vec3 rayEnd = {uPos, mesh.MaxPos.y, vPos};
|
||||
Gen::Vec3 rayStart = {uPos, -100.0f, vPos};
|
||||
Gen::Vec3 rayEnd = {uPos, 100.0f, vPos};
|
||||
Gen::Vec3 ptOut;
|
||||
|
||||
for (int16_t i = 0; i < indexBufferView.byteLength; i += indexStride * 3)
|
||||
@@ -148,7 +147,7 @@ namespace Game
|
||||
reinterpret_cast<Gen::Vec3*>(&posBuffer.data[posBufferView.byteOffset + *idxC * posStride]);
|
||||
if (Gen::RayTriangleIntersect(rayStart, rayEnd, *triA, *triB, *triC, ptOut))
|
||||
{
|
||||
float len = ptOut.y - mesh.MinPos.y;
|
||||
float len = ptOut.y - rayStart.y;
|
||||
uint8_t val = (uint8_t)(len / mesh.Size.y * UINT8_MAX);
|
||||
int32_t idx = v * HeightMap::Width + u;
|
||||
if (mesh.Height.Values[idx] < val)
|
||||
|
||||
@@ -278,6 +278,8 @@ namespace Tools
|
||||
level.Setup(shared.Game);
|
||||
}
|
||||
|
||||
ImGui::DragFloat3("Player Pos", &player.PlayerCamTransform.Position.x);
|
||||
ImGui::DragFloat3("Puz0 Pos", &level.Puzzles[0].WorldPosition.x);
|
||||
ImGui::SliderFloat("Mouse Sensitivity", &player.MouseSensitivity, 0.1f, 5.0f);
|
||||
ImGui::SliderFloat("Player Speed", &player.MovementSpeed, 1.0f, 30.0f);
|
||||
|
||||
|
||||
BIN
src/game/data/puzzles/0.pzl
LFS
BIN
src/game/data/puzzles/0.pzl
LFS
Binary file not shown.
Binary file not shown.
@@ -1,9 +1,10 @@
|
||||
// raddbg 0.9.19 project file
|
||||
|
||||
recent_file: path: "../src/game/level.cpp"
|
||||
recent_file: path: "../src/game/Log.cpp"
|
||||
recent_file: path: "../src/game/rendering/dither.cpp"
|
||||
recent_file: path: "../src/game/rendering/rendering.cpp"
|
||||
recent_file: path: "../src/game/entity.h"
|
||||
recent_file: path: "../src/game/level.cpp"
|
||||
recent_file: path: "../src/game/ui.cpp"
|
||||
recent_file: path: "../src/gen/generated.cpp"
|
||||
recent_file: path: "../src/engine/main.cpp"
|
||||
@@ -13,7 +14,6 @@ recent_file: path: "../src/game/tools.cpp"
|
||||
recent_file: path: "../src/dependency/bgfx.cmake/bx/src/debug.cpp"
|
||||
recent_file: path: "../src/gen/def.h"
|
||||
recent_file: path: "../src/game/global.cpp"
|
||||
recent_file: path: "../src/game/Log.cpp"
|
||||
target:
|
||||
{
|
||||
executable: "../src/cmake-build/PuzGameEngine.exe"
|
||||
|
||||
Reference in New Issue
Block a user