#include "entities/world.hpp" #include "utils/frame_profiler.hpp" namespace Nimbin { World::World() { _wall_surfaces.generate(get_BoxScale()); _floor_surface = cpputils::make_unique(); _floor_surface->generate(World::get_BoxScale(), World::get_FloorY()); } static double sweepAxis(double end, double min, double max, bool& hit) { hit = false; if (end < min) { hit = true; return min; } if (end > max) { hit = true; return max; } return end; } PlayerCollision World::resolve_Player(const Player& player) const { PlayerCollision out; out.vel = player.vel; const double min = -get_BoxScale() + player.radius; const double max = get_BoxScale() - player.radius; const double minY = player.height - get_BoxScale(); const double maxY = get_BoxScale(); out.pos.x = sweepAxis(player.pos.x, min, max, out.hit_x); out.pos.y = sweepAxis(player.pos.y, minY, maxY, out.hit_y); out.pos.z = sweepAxis(player.pos.z, min, max, out.hit_z); if (out.hit_x) out.vel.x = 0; if (out.hit_y) out.vel.y = 0; if (out.hit_z) out.vel.z = 0; return out; } void World::draw(GlRenderer& gl, const Camera& camera, const Light& light) const { { FP_ZONE("world.draw.wall"); _wall_surfaces.draw(gl, camera, light); } { FP_ZONE("world.draw.floor"); _floor_surface->draw(gl, camera, light); } } Vec3 World::get_SpawnPoint() const { return {0.0, 2.0, 0.0}; } } // namespace Nimbin