more math & testing
This commit is contained in:
@@ -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<void*>(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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -145,7 +145,6 @@ namespace Game
|
||||
EntityManager<PuzzleTileEntity, PuzzleTileEntityHandle, 1024> PuzzleTiles;
|
||||
EntityManager<UIQuadEntity, UIQuadEntityHandle, 1024> UIQuads;
|
||||
|
||||
|
||||
public:
|
||||
Puzzle::StaticPuzzleData PuzzleData;
|
||||
WorldPuzzle Puzzles[1];
|
||||
|
||||
@@ -5,18 +5,30 @@
|
||||
|
||||
#include <debugapi.h>
|
||||
|
||||
#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);
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace Game
|
||||
GameInstance& instance = *reinterpret_cast<GameInstance*>(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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user