1
0
game/client/utils/Coords.hpp

63 lines
2.4 KiB
C++

#pragma once
#include <raylib.h>
#include <raymath.h>
class Coords {
public:
static constexpr float WORLD_BOUNDS = 50.0f;
static constexpr float WORLD_MIN_HEIGHT = 0.0f;
static constexpr float WORLD_MAX_HEIGHT = 100.0f;
static Vector3 worldToLocal(const Vector3& worldPos, const Vector3& origin) {
return Vector3Subtract(worldPos, origin);
}
static Vector3 localToWorld(const Vector3& localPos, const Vector3& origin) {
return Vector3Add(localPos, origin);
}
static Vector3 clampToWorldBounds(const Vector3& pos) {
return {
Clamp(pos.x, -WORLD_BOUNDS, WORLD_BOUNDS),
Clamp(pos.y, WORLD_MIN_HEIGHT, WORLD_MAX_HEIGHT),
Clamp(pos.z, -WORLD_BOUNDS, WORLD_BOUNDS)
};
}
static bool isInWorldBounds(const Vector3& pos) {
return pos.x >= -WORLD_BOUNDS && pos.x <= WORLD_BOUNDS &&
pos.y >= WORLD_MIN_HEIGHT && pos.y <= WORLD_MAX_HEIGHT &&
pos.z >= -WORLD_BOUNDS && pos.z <= WORLD_BOUNDS;
}
static Matrix buildTransformMatrix(const Vector3& position, const Vector3& rotation, const Vector3& scale) {
Matrix matScale = MatrixScale(scale.x, scale.y, scale.z);
Matrix matRotation = MatrixRotateXYZ(rotation);
Matrix matTranslation = MatrixTranslate(position.x, position.y, position.z);
Matrix result = MatrixMultiply(matScale, matRotation);
result = MatrixMultiply(result, matTranslation);
return result;
}
static Vector3 forward() { return {0.0f, 0.0f, 1.0f}; }
static Vector3 backward() { return {0.0f, 0.0f, -1.0f}; }
static Vector3 right() { return {1.0f, 0.0f, 0.0f}; }
static Vector3 left() { return {-1.0f, 0.0f, 0.0f}; }
static Vector3 up() { return {0.0f, 1.0f, 0.0f}; }
static Vector3 down() { return {0.0f, -1.0f, 0.0f}; }
static void drawDebugAxes(const Vector3& position, float size = 1.0f) {
DrawLine3D(position, Vector3Add(position, Vector3Scale(right(), size)), RED);
DrawLine3D(position, Vector3Add(position, Vector3Scale(up(), size)), GREEN);
DrawLine3D(position, Vector3Add(position, Vector3Scale(forward(), size)), BLUE);
}
static void drawWorldBounds() {
Color boundsColor = {255, 255, 0, 100};
DrawCubeWires({0, WORLD_MAX_HEIGHT/2, 0},
WORLD_BOUNDS * 2, WORLD_MAX_HEIGHT, WORLD_BOUNDS * 2,
boundsColor);
}
};