#include #include #include #include constexpr int AMOUNT {2000}; struct Entry { Vector2 pos; Vector2 base; float depth; }; int main(int argc, char* argv[]) { InitWindow(800, 600, "Derelict"); SetWindowState(FLAG_WINDOW_RESIZABLE); SetTargetFPS(60); Camera camera {}; camera.position = Vector3{10.0, 10.0, 10.0}; camera.target = Vector3{0.0, 0.0, 0.0}; camera.up = Vector3{0.0, 1.0, 0.0}; camera.fovy = 45; camera.projection = CAMERA_PERSPECTIVE; SetCameraMode(camera, CAMERA_ORBITAL); std::vector points; points.reserve(AMOUNT); for (int i = 0; i < AMOUNT; ++i) points.push_back({ GetRandomValue(-100, 100) * 0.05f, GetRandomValue(-100, 100) * 0.05f, GetRandomValue(-100, 100) * 0.05f}); std::vector projected; while (!WindowShouldClose()) { UpdateCamera(&camera); projected.clear(); projected.reserve(points.size()); const int height = GetScreenHeight(); const int width = GetScreenWidth(); for (const auto& point : points) { const auto vec2 = GetWorldToScreen(point, camera); const float d = std::sqrt( std::pow(camera.position.x - point.x, 2) + std::pow(camera.position.y - point.y, 2) + std::pow(camera.position.z - point.z, 2)); if (0 > vec2.x || width < vec2.x || 0 > vec2.y || height < vec2.y) continue; projected.push_back(Entry{ vec2, GetWorldToScreen({point.x, 0, point.z}, camera), d }); } std::sort(projected.begin(), projected.end(), [](Entry& a, Entry& b){ return a.depth > b.depth; }); BeginDrawing(); ClearBackground(RAYWHITE); BeginMode3D(camera); DrawGrid(12, 1); EndMode3D(); DrawFPS(5, 5); for (const auto& entry : projected) { DrawLine(entry.base.x, entry.base.y, entry.pos.x, entry.pos.y, LIGHTGRAY); DrawCircle(entry.pos.x, entry.pos.y, 3, RED); } int y = 25; for (const auto& entry : projected) { DrawText(TextFormat("%5.1f x %5.1f x %5.1f", entry.pos.x, entry.pos.y, entry.depth), 5, y, 10, DARKGRAY); y += 10; if (y > height) break; } EndDrawing(); } CloseWindow(); }