diff --git a/CMakeLists.txt b/CMakeLists.txt index bc40e61..d4aa351 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,6 @@ find_package(SDL2 REQUIRED COMPONENTS SDL2::SDL2-static SDL2::SDL2main CONFIG) find_package(OpenAL REQUIRED CONFIG) find_library(physfs REQUIRED NAMES physfs-static PATHS "${CMAKE_PREFIX_PATH}/lib") - # Determine dependencies set(STATIC_LIBS dr_wav diff --git a/src/ecs/components/collision-component.hpp b/src/ecs/components/collision-component.hpp index 6930f2c..ea68575 100644 --- a/src/ecs/components/collision-component.hpp +++ b/src/ecs/components/collision-component.hpp @@ -20,17 +20,17 @@ #ifndef ANTKEEPER_ECS_COLLISION_COMPONENT_HPP #define ANTKEEPER_ECS_COLLISION_COMPONENT_HPP -#include "geometry/aabb.hpp" -#include "geometry/mesh.hpp" -#include "geometry/mesh-accelerator.hpp" +#include "geom/aabb.hpp" +#include "geom/mesh.hpp" +#include "geom/mesh-accelerator.hpp" namespace ecs { struct collision_component { - mesh* mesh; - aabb bounds; - mesh_accelerator mesh_accelerator; + geom::mesh* mesh; + geom::aabb bounds; + geom::mesh_accelerator mesh_accelerator; }; } // namespace ecs diff --git a/src/ecs/components/locomotion-component.hpp b/src/ecs/components/locomotion-component.hpp index 354caee..2a09869 100644 --- a/src/ecs/components/locomotion-component.hpp +++ b/src/ecs/components/locomotion-component.hpp @@ -20,14 +20,14 @@ #ifndef ANTKEEPER_ECS_PLACEMENT_COMPONENT_HPP #define ANTKEEPER_ECS_PLACEMENT_COMPONENT_HPP -#include "geometry/mesh.hpp" +#include "geom/mesh.hpp" #include "utility/fundamental-types.hpp" namespace ecs { struct locomotion_component { - const mesh::face* triangle; + const geom::mesh::face* triangle; float3 barycentric_position; }; diff --git a/src/ecs/components/snap-component.hpp b/src/ecs/components/snap-component.hpp index 0a0ee3d..491c996 100644 --- a/src/ecs/components/snap-component.hpp +++ b/src/ecs/components/snap-component.hpp @@ -20,13 +20,13 @@ #ifndef ANTKEEPER_ECS_SNAP_COMPONENT_HPP #define ANTKEEPER_ECS_SNAP_COMPONENT_HPP -#include "geometry/ray.hpp" +#include "geom/ray.hpp" namespace ecs { struct snap_component { - ::ray ray; + geom::ray ray; bool relative; bool warp; bool autoremove; diff --git a/src/ecs/systems/control-system.cpp b/src/ecs/systems/control-system.cpp index 7782f14..da26a8c 100644 --- a/src/ecs/systems/control-system.cpp +++ b/src/ecs/systems/control-system.cpp @@ -19,7 +19,7 @@ #include "control-system.hpp" #include "input/control.hpp" -#include "geometry/intersection.hpp" +#include "geom/intersection.hpp" #include "animation/ease.hpp" #include "nest.hpp" #include "math/math.hpp" diff --git a/src/ecs/systems/painting-system.cpp b/src/ecs/systems/painting-system.cpp index 144d15d..885ed85 100644 --- a/src/ecs/systems/painting-system.cpp +++ b/src/ecs/systems/painting-system.cpp @@ -33,7 +33,7 @@ #include "rasterizer/vertex-buffer.hpp" #include "rasterizer/vertex-attribute-type.hpp" #include "renderer/vertex-attributes.hpp" -#include "geometry/mesh-functions.hpp" +#include "geom/mesh-functions.hpp" #include namespace ecs { @@ -252,7 +252,7 @@ void painting_system::update(double t, double dt) stroke_bounds_max.x = std::max(stroke_bounds_max.x, std::max(c.x, std::max(d.x, std::max(e.x, f.x)))); stroke_bounds_max.y = std::max(stroke_bounds_max.y, std::max(c.y, std::max(d.y, std::max(e.y, f.y)))); stroke_bounds_max.z = std::max(stroke_bounds_max.z, std::max(c.z, std::max(d.z, std::max(e.z, f.z)))); - stroke_model->set_bounds(aabb{stroke_bounds_min, stroke_bounds_max}); + stroke_model->set_bounds(geom::aabb{stroke_bounds_min, stroke_bounds_max}); stroke_model_instance->update_bounds(); p0 = stroke_start; @@ -313,9 +313,9 @@ std::optional> painting_system::cast_ray(const float3 float3 intersection; float3 surface_normal; - mesh::face* face = nullptr; + geom::mesh::face* face = nullptr; - ray untransformed_ray = {position + float3{0.0f, 10000.0f, 0.0f}, {0, -1, 0}}; + geom::ray untransformed_ray = {position + float3{0.0f, 10000.0f, 0.0f}, {0, -1, 0}}; float min_distance = std::numeric_limits::infinity(); registry.view().each( @@ -325,10 +325,10 @@ std::optional> painting_system::cast_ray(const float3 math::transform inverse_transform = math::inverse(collision_transform.local); float3 origin = inverse_transform * untransformed_ray.origin; float3 direction = math::normalize(math::conjugate(collision_transform.local.rotation) * untransformed_ray.direction); - ray transformed_ray = {origin, direction}; + geom::ray transformed_ray = {origin, direction}; // Broad phase AABB test - auto aabb_result = ray_aabb_intersection(transformed_ray, collision.bounds); + auto aabb_result = geom::ray_aabb_intersection(transformed_ray, collision.bounds); if (!std::get<0>(aabb_result)) { return; diff --git a/src/ecs/systems/snapping-system.cpp b/src/ecs/systems/snapping-system.cpp index 26fa922..e4c0d2a 100644 --- a/src/ecs/systems/snapping-system.cpp +++ b/src/ecs/systems/snapping-system.cpp @@ -39,7 +39,7 @@ void snapping_system::update(double t, double dt) float a = std::numeric_limits::infinity(); float3 pick; - ray snap_ray = snap.ray; + geom::ray snap_ray = snap.ray; if (snap.relative) { snap_ray.origin += snap_transform.local.translation; @@ -53,10 +53,10 @@ void snapping_system::update(double t, double dt) math::transform inverse_transform = math::inverse(collision_transform.local); float3 origin = inverse_transform * snap_ray.origin; float3 direction = math::normalize(math::conjugate(collision_transform.local.rotation) * snap_ray.direction); - ray transformed_ray = {origin, direction}; + geom::ray transformed_ray = {origin, direction}; // Broad phase AABB test - auto aabb_result = ray_aabb_intersection(transformed_ray, collision.bounds); + auto aabb_result = geom::ray_aabb_intersection(transformed_ray, collision.bounds); if (!std::get<0>(aabb_result)) { return; diff --git a/src/ecs/systems/subterrain-system.cpp b/src/ecs/systems/subterrain-system.cpp index b041c96..c67a3a8 100644 --- a/src/ecs/systems/subterrain-system.cpp +++ b/src/ecs/systems/subterrain-system.cpp @@ -23,14 +23,14 @@ #include "ecs/entity.hpp" #include "renderer/model.hpp" #include "renderer/material.hpp" -#include "geometry/mesh-functions.hpp" +#include "geom/mesh-functions.hpp" #include "renderer/vertex-attributes.hpp" #include "rasterizer/vertex-attribute-type.hpp" #include "rasterizer/drawing-mode.hpp" #include "rasterizer/vertex-buffer.hpp" #include "resources/resource-manager.hpp" -#include "geometry/marching-cubes.hpp" -#include "geometry/intersection.hpp" +#include "geom/marching-cubes.hpp" +#include "geom/intersection.hpp" #include "utility/fundamental-types.hpp" #include #include @@ -43,18 +43,18 @@ namespace ecs { struct cube_tree { public: - cube_tree(const aabb& bounds, int max_depth); + cube_tree(const geom::aabb& bounds, int max_depth); ~cube_tree(); const bool is_leaf() const; - const aabb& get_bounds() const; + const geom::aabb& get_bounds() const; /// Subdivides all nodes intersecting with a region to the max depth. - void subdivide_max(const aabb& region); + void subdivide_max(const geom::aabb& region); /// Fills a list with all leaf nodes that intersect with a region. - void query_leaves(std::list& nodes, const aabb& region); - void visit_leaves(const aabb& region, const std::function& f); + void query_leaves(std::list& nodes, const geom::aabb& region); + void visit_leaves(const geom::aabb& region, const std::function& f); /// Counts then number of nodes in the octree. std::size_t size() const; @@ -64,18 +64,18 @@ public: float distances[8]; const int max_depth; const int depth; - const aabb bounds; + const geom::aabb bounds; private: - cube_tree(const aabb& bounds, int max_depth, int depth); + cube_tree(const geom::aabb& bounds, int max_depth, int depth); void subdivide(); }; -cube_tree::cube_tree(const aabb& bounds, int max_depth): +cube_tree::cube_tree(const geom::aabb& bounds, int max_depth): cube_tree(bounds, max_depth, 0) {} -cube_tree::cube_tree(const aabb& bounds, int max_depth, int depth): +cube_tree::cube_tree(const geom::aabb& bounds, int max_depth, int depth): bounds(bounds), max_depth(max_depth), depth(depth) @@ -105,7 +105,7 @@ cube_tree::~cube_tree() delete child; } -void cube_tree::subdivide_max(const aabb& region) +void cube_tree::subdivide_max(const geom::aabb& region) { if (depth != max_depth && aabb_aabb_intersection(bounds, region)) { @@ -117,7 +117,7 @@ void cube_tree::subdivide_max(const aabb& region) } } -void cube_tree::query_leaves(std::list& nodes, const aabb& region) +void cube_tree::query_leaves(std::list& nodes, const geom::aabb& region) { if (aabb_aabb_intersection(bounds, region)) { @@ -133,7 +133,7 @@ void cube_tree::query_leaves(std::list& nodes, const aabb& re } } -void cube_tree::visit_leaves(const aabb& region, const std::function& f) +void cube_tree::visit_leaves(const geom::aabb& region, const std::function& f) { if (aabb_aabb_intersection(bounds, region)) { @@ -166,7 +166,7 @@ inline const bool cube_tree::is_leaf() const return (children[0] == nullptr); } -inline const aabb& cube_tree::get_bounds() const +inline const geom::aabb& cube_tree::get_bounds() const { return bounds; } @@ -177,7 +177,7 @@ void cube_tree::subdivide() for (int i = 0; i < 8; ++i) { - aabb child_bounds; + geom::aabb child_bounds; for (int j = 0; j < 3; ++j) { child_bounds.min_point[j] = std::min(corners[i][j], center[j]); @@ -247,7 +247,7 @@ subterrain_system::subterrain_system(ecs::registry& registry, ::resource_manager cube_tree = new ecs::cube_tree(subterrain_bounds, octree_depth); // Allocate mesh - subterrain_mesh = new mesh(); + subterrain_mesh = new geom::mesh(); first_run = true; } @@ -302,7 +302,7 @@ void subterrain_system::set_scene(scene::collection* collection) void subterrain_system::regenerate_subterrain_mesh() { delete subterrain_mesh; - subterrain_mesh = new mesh(); + subterrain_mesh = new geom::mesh(); subterrain_vertices.clear(); subterrain_triangles.clear(); subterrain_vertex_map.clear(); @@ -335,7 +335,7 @@ void subterrain_system::march(ecs::cube_tree* node) } // Get node bounds - const aabb& bounds = node->get_bounds(); + const geom::aabb& bounds = node->get_bounds(); // Polygonize cube float vertex_buffer[12 * 3]; @@ -344,7 +344,7 @@ void subterrain_system::march(ecs::cube_tree* node) std::uint_fast8_t triangle_count; const float* corners = &node->corners[0][0]; const float* distances = &node->distances[0]; - mc::polygonize(vertex_buffer, &vertex_count, triangle_buffer, &triangle_count, corners, distances); + geom::mc::polygonize(vertex_buffer, &vertex_count, triangle_buffer, &triangle_count, corners, distances); // Remap local vertex buffer indices (0-11) to mesh vertex indices std::uint_fast32_t vertex_remap[12]; @@ -393,22 +393,22 @@ void subterrain_system::regenerate_subterrain_model() float* v = vertex_data; for (std::size_t i = 0; i < subterrain_mesh->get_faces().size(); ++i) { - mesh::face* face = subterrain_mesh->get_faces()[i]; - mesh::edge* ab = face->edge; - mesh::edge* bc = face->edge->next; - mesh::edge* ca = face->edge->previous; - mesh::vertex* a = ab->vertex; - mesh::vertex* b = bc->vertex; - mesh::vertex* c = ca->vertex; - mesh::vertex* vertices[3] = {a, b, c}; + geom::mesh::face* face = subterrain_mesh->get_faces()[i]; + geom::mesh::edge* ab = face->edge; + geom::mesh::edge* bc = face->edge->next; + geom::mesh::edge* ca = face->edge->previous; + geom::mesh::vertex* a = ab->vertex; + geom::mesh::vertex* b = bc->vertex; + geom::mesh::vertex* c = ca->vertex; + geom::mesh::vertex* vertices[3] = {a, b, c}; for (std::size_t j = 0; j < 3; ++j) { - mesh::vertex* vertex = vertices[j]; + geom::mesh::vertex* vertex = vertices[j]; float3 n = {0, 0, 0}; - mesh::edge* start = vertex->edge; - mesh::edge* edge = start; + geom::mesh::edge* start = vertex->edge; + geom::mesh::edge* edge = start; do { if (edge->face) @@ -453,7 +453,7 @@ void subterrain_system::regenerate_subterrain_model() void subterrain_system::dig(const float3& position, float radius) { // Construct region containing the cavity sphere - aabb region = {position, position}; + geom::aabb region = {position, position}; for (int i = 0; i < 3; ++i) { region.min_point[i] -= radius + isosurface_resolution; diff --git a/src/ecs/systems/subterrain-system.hpp b/src/ecs/systems/subterrain-system.hpp index 2cbcde2..644a2c3 100644 --- a/src/ecs/systems/subterrain-system.hpp +++ b/src/ecs/systems/subterrain-system.hpp @@ -21,8 +21,8 @@ #define ANTKEEPER_ECS_SUBTERRAIN_SYSTEM_HPP #include "entity-system.hpp" -#include "geometry/mesh.hpp" -#include "geometry/aabb.hpp" +#include "geom/mesh.hpp" +#include "geom/aabb.hpp" #include "scene/collection.hpp" #include "scene/model-instance.hpp" #include "utility/fundamental-types.hpp" @@ -102,7 +102,7 @@ private: float distance(const ecs::cube_tree& node, const float3& sample) const; resource_manager* resource_manager; - mesh* subterrain_mesh; + geom::mesh* subterrain_mesh; model* subterrain_model; material* subterrain_inside_material; material* subterrain_outside_material; @@ -110,7 +110,7 @@ private: model_group* subterrain_outside_group; int subterrain_model_vertex_size; int subterrain_model_vertex_stride; - aabb subterrain_bounds; + geom::aabb subterrain_bounds; ecs::cube_tree* cube_tree; std::vector subterrain_vertices; std::vector> subterrain_triangles; diff --git a/src/ecs/systems/terrain-system.cpp b/src/ecs/systems/terrain-system.cpp index a6e2679..716834e 100644 --- a/src/ecs/systems/terrain-system.cpp +++ b/src/ecs/systems/terrain-system.cpp @@ -23,8 +23,8 @@ #include "ecs/components/transform-component.hpp" #include "game/cartography/relief-map.hpp" #include "renderer/model.hpp" -#include "geometry/mesh.hpp" -#include "geometry/mesh-functions.hpp" +#include "geom/mesh.hpp" +#include "geom/mesh-functions.hpp" #include "renderer/vertex-attributes.hpp" #include "rasterizer/vertex-attribute-type.hpp" #include "rasterizer/drawing-mode.hpp" @@ -66,7 +66,7 @@ void terrain_system::set_patch_size(float size) patch_size = size; } -mesh* terrain_system::generate_terrain_mesh(float size, int subdivisions) +geom::mesh* terrain_system::generate_terrain_mesh(float size, int subdivisions) { auto elevation = [](float u, float v) -> float { @@ -76,7 +76,7 @@ mesh* terrain_system::generate_terrain_mesh(float size, int subdivisions) return cart::map_elevation(elevation, size, subdivisions); } -model* terrain_system::generate_terrain_model(mesh* terrain_mesh) +model* terrain_system::generate_terrain_model(geom::mesh* terrain_mesh) { // Allocate model model* terrain_model = new model(); @@ -113,13 +113,13 @@ model* terrain_system::generate_terrain_model(mesh* terrain_mesh) return terrain_model; } -void terrain_system::project_terrain_mesh(mesh* terrain_mesh, const terrain_component& component) +void terrain_system::project_terrain_mesh(geom::mesh* terrain_mesh, const terrain_component& component) { float offset_x = (float)component.x * patch_size; float offset_z = (float)component.z * patch_size; - for (mesh::vertex* vertex: terrain_mesh->get_vertices()) + for (geom::mesh::vertex* vertex: terrain_mesh->get_vertices()) { int pixel_x = (vertex->position[0] + offset_x + heightmap_size * 0.5f) / heightmap_size * (float)(heightmap->get_width() - 1); int pixel_y = (vertex->position[2] + offset_z + heightmap_size * 0.5f) / heightmap_size * (float)(heightmap->get_height() - 1); @@ -136,12 +136,12 @@ void terrain_system::project_terrain_mesh(mesh* terrain_mesh, const terrain_comp } -void terrain_system::update_terrain_model(model* terrain_model, mesh* terrain_mesh) +void terrain_system::update_terrain_model(model* terrain_model, geom::mesh* terrain_mesh) { - const std::vector& faces = terrain_mesh->get_faces(); - const std::vector& vertices = terrain_mesh->get_vertices(); + const std::vector& faces = terrain_mesh->get_faces(); + const std::vector& vertices = terrain_mesh->get_vertices(); - aabb bounds = calculate_bounds(*terrain_mesh); + geom::aabb bounds = calculate_bounds(*terrain_mesh); float bounds_width = bounds.max_point.x - bounds.min_point.x; float bounds_height = bounds.max_point.y - bounds.min_point.y; float bounds_depth = bounds.max_point.z - bounds.min_point.z; @@ -168,11 +168,11 @@ void terrain_system::update_terrain_model(model* terrain_model, mesh* terrain_me float3* vertex_normals = new float3[vertices.size()]; for (std::size_t i = 0; i < vertices.size(); ++i) { - const mesh::vertex* vertex = vertices[i]; + const geom::mesh::vertex* vertex = vertices[i]; float3 n = {0, 0, 0}; - mesh::edge* start = vertex->edge; - mesh::edge* edge = start; + geom::mesh::edge* start = vertex->edge; + geom::mesh::edge* edge = start; do { if (edge->face) @@ -192,7 +192,7 @@ void terrain_system::update_terrain_model(model* terrain_model, mesh* terrain_me float2* vertex_texcoords = new float2[vertices.size()]; for (std::size_t i = 0; i < vertices.size(); ++i) { - const mesh::vertex* vertex = vertices[i]; + const geom::mesh::vertex* vertex = vertices[i]; vertex_texcoords[i].x = (vertex->position.x - bounds.min_point.x) / bounds_width; vertex_texcoords[i].y = (vertex->position.z - bounds.min_point.z) / bounds_depth; } @@ -205,15 +205,15 @@ void terrain_system::update_terrain_model(model* terrain_model, mesh* terrain_me float* v = vertex_data; for (int i = 0; i < triangle_count; ++i) { - const mesh::face* triangle = faces[i]; - const mesh::vertex* a = triangle->edge->vertex; - const mesh::vertex* b = triangle->edge->next->vertex; - const mesh::vertex* c = triangle->edge->previous->vertex; - const mesh::vertex* abc[] = {a, b, c}; + const geom::mesh::face* triangle = faces[i]; + const geom::mesh::vertex* a = triangle->edge->vertex; + const geom::mesh::vertex* b = triangle->edge->next->vertex; + const geom::mesh::vertex* c = triangle->edge->previous->vertex; + const geom::mesh::vertex* abc[] = {a, b, c}; for (int j = 0; j < 3; ++j) { - const mesh::vertex* vertex = abc[j]; + const geom::mesh::vertex* vertex = abc[j]; const float3& position = vertex->position; const float2& texcoord = vertex_texcoords[vertex->index]; const float3& normal = vertex_normals[vertex->index]; @@ -258,7 +258,7 @@ void terrain_system::update_terrain_model(model* terrain_model, mesh* terrain_me void terrain_system::on_terrain_construct(ecs::registry& registry, ecs::entity entity, terrain_component& component) { - mesh* terrain_mesh = generate_terrain_mesh(patch_size, component.subdivisions); + geom::mesh* terrain_mesh = generate_terrain_mesh(patch_size, component.subdivisions); model* terrain_model = generate_terrain_model(terrain_mesh); project_terrain_mesh(terrain_mesh, component); update_terrain_model(terrain_model, terrain_mesh); diff --git a/src/ecs/systems/terrain-system.hpp b/src/ecs/systems/terrain-system.hpp index a48d18a..8cfb2cd 100644 --- a/src/ecs/systems/terrain-system.hpp +++ b/src/ecs/systems/terrain-system.hpp @@ -23,10 +23,10 @@ #include "entity-system.hpp" #include "ecs/components/terrain-component.hpp" #include "ecs/entity.hpp" +#include "geom/mesh.hpp" class terrain; class resource_manager; -class mesh; class model; class image; @@ -45,10 +45,10 @@ public: void set_patch_size(float size); private: - mesh* generate_terrain_mesh(float size, int subdivisions); - model* generate_terrain_model(mesh* terrain_mesh); - void project_terrain_mesh(mesh* terrain_mesh, const ecs::terrain_component& component); - void update_terrain_model(model* terrain_model, mesh* terrain_mesh); + geom::mesh* generate_terrain_mesh(float size, int subdivisions); + model* generate_terrain_model(geom::mesh* terrain_mesh); + void project_terrain_mesh(geom::mesh* terrain_mesh, const ecs::terrain_component& component); + void update_terrain_model(model* terrain_model, geom::mesh* terrain_mesh); void on_terrain_construct(ecs::registry& registry, ecs::entity entity, ecs::terrain_component& component); void on_terrain_destroy(ecs::registry& registry, ecs::entity entity); diff --git a/src/ecs/systems/tool-system.cpp b/src/ecs/systems/tool-system.cpp index f9fdd79..bb27807 100644 --- a/src/ecs/systems/tool-system.cpp +++ b/src/ecs/systems/tool-system.cpp @@ -25,8 +25,8 @@ #include "game/events/tool-events.hpp" #include "animation/orbit-cam.hpp" #include "animation/ease.hpp" -#include "geometry/mesh.hpp" -#include "geometry/intersection.hpp" +#include "geom/mesh.hpp" +#include "geom/intersection.hpp" #include "math/math.hpp" #include "ecs/commands.hpp" @@ -108,7 +108,7 @@ void tool_system::update(double t, double dt) float3 pick_far = camera->unproject({mouse_position[0], viewport[3] - mouse_position[1], 1.0f}, viewport); float3 pick_origin = pick_near; float3 pick_direction = math::normalize(pick_far - pick_near); - ray picking_ray = {pick_near, pick_direction}; + geom::ray picking_ray = {pick_near, pick_direction}; float a = std::numeric_limits::infinity(); bool intersection = false; @@ -121,10 +121,10 @@ void tool_system::update(double t, double dt) math::transform inverse_transform = math::inverse(transform.local); float3 origin = inverse_transform * pick_origin; float3 direction = math::normalize(math::conjugate(transform.local.rotation) * pick_direction); - ray transformed_ray = {origin, direction}; + geom::ray transformed_ray = {origin, direction}; // Broad phase AABB test - auto aabb_result = ray_aabb_intersection(transformed_ray, collision.bounds); + auto aabb_result = geom::ray_aabb_intersection(transformed_ray, collision.bounds); if (!std::get<0>(aabb_result)) { return; diff --git a/src/ecs/systems/vegetation-system.cpp b/src/ecs/systems/vegetation-system.cpp index a32b0b6..029f1c4 100644 --- a/src/ecs/systems/vegetation-system.cpp +++ b/src/ecs/systems/vegetation-system.cpp @@ -24,7 +24,7 @@ #include "scene/lod-group.hpp" #include "scene/collection.hpp" #include "renderer/material.hpp" -#include "geometry/aabb.hpp" +#include "geom/aabb.hpp" #include "utility/fundamental-types.hpp" #include @@ -113,7 +113,7 @@ void vegetation_system::on_terrain_construct(ecs::registry& registry, ecs::entit float3 translation = {vegetation_patch_x, 0.0f, vegetation_patch_z}; // Generate culling mask - aabb* culling_mask = new aabb(vegetation_model->get_bounds()); + geom::aabb* culling_mask = new geom::aabb(vegetation_model->get_bounds()); culling_mask->min_point.x = std::min(culling_mask->min_point.x, translation.x - vegetation_patch_size * 0.5f); culling_mask->min_point.z = std::min(culling_mask->min_point.z, translation.z - vegetation_patch_size * 0.5f); culling_mask->max_point.x = std::max(culling_mask->max_point.x, translation.x + vegetation_patch_size * 0.5f); diff --git a/src/game/cartography/relief-map.cpp b/src/game/cartography/relief-map.cpp index 82caa3f..349e1c7 100644 --- a/src/game/cartography/relief-map.cpp +++ b/src/game/cartography/relief-map.cpp @@ -25,10 +25,10 @@ namespace cart { -mesh* map_elevation(const std::function& function, float scale, std::size_t subdivisions) +geom::mesh* map_elevation(const std::function& function, float scale, std::size_t subdivisions) { // Allocate terrain mesh - mesh* mesh = new ::mesh(); + geom::mesh* mesh = new geom::mesh(); // Determine vertex count and placement std::size_t columns = static_cast(std::pow(2, subdivisions)); @@ -56,10 +56,10 @@ mesh* map_elevation(const std::function& function, float sc } // Function to eliminate duplicate edges - std::map, mesh::edge*> edge_map; - auto add_or_find_edge = [&](mesh::vertex* start, mesh::vertex* end) -> mesh::edge* + std::map, geom::mesh::edge*> edge_map; + auto add_or_find_edge = [&](geom::mesh::vertex* start, geom::mesh::vertex* end) -> geom::mesh::edge* { - mesh::edge* edge; + geom::mesh::edge* edge; if (auto it = edge_map.find({start->index, end->index}); it != edge_map.end()) { edge = it->second; @@ -75,15 +75,15 @@ mesh* map_elevation(const std::function& function, float sc }; // Connect vertices with edges and faces - const std::vector& vertices = mesh->get_vertices(); + const std::vector& vertices = mesh->get_vertices(); for (std::size_t i = 0; i < rows; ++i) { for (std::size_t j = 0; j < columns; ++j) { - mesh::vertex* a = vertices[i * (columns + 1) + j]; - mesh::vertex* b = vertices[(i + 1) * (columns + 1) + j]; - mesh::vertex* c = vertices[i * (columns + 1) + j + 1]; - mesh::vertex* d = vertices[(i + 1) * (columns + 1) + j + 1]; + geom::mesh::vertex* a = vertices[i * (columns + 1) + j]; + geom::mesh::vertex* b = vertices[(i + 1) * (columns + 1) + j]; + geom::mesh::vertex* c = vertices[i * (columns + 1) + j + 1]; + geom::mesh::vertex* d = vertices[(i + 1) * (columns + 1) + j + 1]; // +---+---+ // | \ | / | @@ -92,13 +92,13 @@ mesh* map_elevation(const std::function& function, float sc // +---+---+ if ((j % 2) == (i % 2)) { - mesh::edge* ab = add_or_find_edge(a, b); - mesh::edge* bd = add_or_find_edge(b, d); - mesh::edge* da = add_or_find_edge(d, a); + geom::mesh::edge* ab = add_or_find_edge(a, b); + geom::mesh::edge* bd = add_or_find_edge(b, d); + geom::mesh::edge* da = add_or_find_edge(d, a); - mesh::edge* ca = add_or_find_edge(c, a); - mesh::edge* ad = da->symmetric; - mesh::edge* dc = add_or_find_edge(d, c); + geom::mesh::edge* ca = add_or_find_edge(c, a); + geom::mesh::edge* ad = da->symmetric; + geom::mesh::edge* dc = add_or_find_edge(d, c); // a---c // | \ | @@ -108,12 +108,12 @@ mesh* map_elevation(const std::function& function, float sc } else { - mesh::edge* ab = add_or_find_edge(a, b); - mesh::edge* bc = add_or_find_edge(b, c); - mesh::edge* ca = add_or_find_edge(c, a); - mesh::edge* cb = bc->symmetric; - mesh::edge* bd = add_or_find_edge(b, d); - mesh::edge* dc = add_or_find_edge(d, c); + geom::mesh::edge* ab = add_or_find_edge(a, b); + geom::mesh::edge* bc = add_or_find_edge(b, c); + geom::mesh::edge* ca = add_or_find_edge(c, a); + geom::mesh::edge* cb = bc->symmetric; + geom::mesh::edge* bd = add_or_find_edge(b, d); + geom::mesh::edge* dc = add_or_find_edge(d, c); // a---c // | / | diff --git a/src/game/cartography/relief-map.hpp b/src/game/cartography/relief-map.hpp index 1379504..d39ffbf 100644 --- a/src/game/cartography/relief-map.hpp +++ b/src/game/cartography/relief-map.hpp @@ -20,7 +20,7 @@ #ifndef ANTKEEPER_RELIEF_MAP_HPP #define ANTKEEPER_RELIEF_MAP_HPP -#include "geometry/mesh.hpp" +#include "geom/mesh.hpp" #include namespace cart @@ -32,7 +32,7 @@ namespace cart * @param function Function which returns an elevation given UV coordinates on a unit plane. * @param subdivisions Number of lines of longitude. Minimum value is 3. */ -mesh* map_elevation(const std::function& function, float scale, std::size_t subdivisions); +geom::mesh* map_elevation(const std::function& function, float scale, std::size_t subdivisions); } // namespace cart diff --git a/src/game/game-context.hpp b/src/game/game-context.hpp index 9f4d06b..c9733b4 100644 --- a/src/game/game-context.hpp +++ b/src/game/game-context.hpp @@ -24,7 +24,7 @@ #include "resources/string-table.hpp" #include "ecs/entity.hpp" #include "ecs/registry.hpp" -#include "geometry/aabb.hpp" +#include "geom/aabb.hpp" #include #include #include @@ -193,7 +193,7 @@ struct game_context scene::billboard* splash_billboard; scene::spotlight* lens_spotlight; scene::spotlight* flashlight_spotlight; - aabb no_cull; + geom::aabb no_cull; // Animation timeline* timeline; diff --git a/src/geometry/aabb.hpp b/src/geom/aabb.hpp similarity index 95% rename from src/geometry/aabb.hpp rename to src/geom/aabb.hpp index 417dca4..ecdadad 100644 --- a/src/geometry/aabb.hpp +++ b/src/geom/aabb.hpp @@ -17,14 +17,16 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_AABB_HPP -#define ANTKEEPER_AABB_HPP +#ifndef ANTKEEPER_GEOM_AABB_HPP +#define ANTKEEPER_GEOM_AABB_HPP #include "bounding-volume.hpp" #include "sphere.hpp" #include "math/math.hpp" #include +namespace geom { + template struct aabb: public bounding_volume { @@ -101,7 +103,7 @@ aabb aabb::transform(const aabb& a, const matrix_type& m) for (std::size_t i = 0; i < 8; ++i) { vector_type corner = a.corner(i); - vector transformed_corner = math::mul(m, vector{corner.x, corner.y, corner.z, T(1)}); + math::vector transformed_corner = math::mul(m, math::vector{corner.x, corner.y, corner.z, T(1)}); for (std::size_t j = 0; j < 3; ++j) { @@ -195,5 +197,7 @@ typename aabb::vector_type aabb::corner(int index) const noexcept }; } -#endif // ANTKEEPER_AABB_HPP +} // namespace geom + +#endif // ANTKEEPER_GEOM_AABB_HPP diff --git a/src/geometry/bounding-volume.hpp b/src/geom/bounding-volume.hpp similarity index 92% rename from src/geometry/bounding-volume.hpp rename to src/geom/bounding-volume.hpp index 2a02c9c..7fcec5c 100644 --- a/src/geometry/bounding-volume.hpp +++ b/src/geom/bounding-volume.hpp @@ -17,13 +17,13 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_BOUNDING_VOLUME_HPP -#define ANTKEEPER_BOUNDING_VOLUME_HPP +#ifndef ANTKEEPER_GEOM_BOUNDING_VOLUME_HPP +#define ANTKEEPER_GEOM_BOUNDING_VOLUME_HPP #include "math/math.hpp" #include -using math::vector; +namespace geom { template struct sphere; @@ -63,7 +63,7 @@ public: virtual bool contains(const aabb& aabb) const = 0; /// Tests whether this bounding volume contains a point. - virtual bool contains(const vector& point) const = 0; + virtual bool contains(const math::vector& point) const = 0; /// Tests for intersection between this bounding volume and another bounding volume. bool intersects(const bounding_volume& volume) const; @@ -90,4 +90,6 @@ bool bounding_volume::intersects(const bounding_volume& volume) const } } -#endif // ANTKEEPER_BOUNDING_VOLUME_HPP +} // namespace geom + +#endif // ANTKEEPER_GEOM_BOUNDING_VOLUME_HPP diff --git a/src/geometry/convex-hull.hpp b/src/geom/convex-hull.hpp similarity index 88% rename from src/geometry/convex-hull.hpp rename to src/geom/convex-hull.hpp index 756a999..addd7c1 100644 --- a/src/geometry/convex-hull.hpp +++ b/src/geom/convex-hull.hpp @@ -17,16 +17,18 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_CONVEX_HULL_HPP -#define ANTKEEPER_CONVEX_HULL_HPP +#ifndef ANTKEEPER_GEOM_CONVEX_HULL_HPP +#define ANTKEEPER_GEOM_CONVEX_HULL_HPP #include "bounding-volume.hpp" -#include "geometry/plane.hpp" -#include "geometry/sphere.hpp" -#include "geometry/aabb.hpp" +#include "geom/plane.hpp" +#include "geom/sphere.hpp" +#include "geom/aabb.hpp" #include #include +namespace geom { + /** * A plane-bounded convex hull. */ @@ -51,7 +53,7 @@ struct convex_hull: public bounding_volume virtual bool intersects(const aabb& aabb) const; virtual bool contains(const sphere& sphere) const; virtual bool contains(const aabb& aabb) const; - virtual bool contains(const vector& point) const; + virtual bool contains(const math::vector& point) const; }; template @@ -81,7 +83,7 @@ bool convex_hull::intersects(const sphere& sphere) const template bool convex_hull::intersects(const aabb& aabb) const { - vector pv; + math::vector pv; for (const plane& plane: planes) { pv.x = (plane.normal.x > T(0)) ? aabb.max_point.x : aabb.min_point.x; @@ -106,8 +108,8 @@ bool convex_hull::contains(const sphere& sphere) const template bool convex_hull::contains(const aabb& aabb) const { - vector pv; - vector nv; + math::vector pv; + math::vector nv; for (const plane& plane: planes) { @@ -126,7 +128,7 @@ bool convex_hull::contains(const aabb& aabb) const } template -bool convex_hull::contains(const vector& point) const +bool convex_hull::contains(const math::vector& point) const { for (const plane& plane: planes) if (plane.signed_distance(point) < T(0)) @@ -135,5 +137,7 @@ bool convex_hull::contains(const vector& point) const return true; } -#endif // ANTKEEPER_CONVEX_HULL_HPP +} // namespace geom + +#endif // ANTKEEPER_GEOM_CONVEX_HULL_HPP diff --git a/src/geometry/csg.cpp b/src/geom/csg.cpp similarity index 98% rename from src/geometry/csg.cpp rename to src/geom/csg.cpp index f06619a..603ba77 100644 --- a/src/geometry/csg.cpp +++ b/src/geom/csg.cpp @@ -20,6 +20,7 @@ #include "csg.hpp" #include +namespace geom { namespace csg { enum class polygon_classification @@ -112,4 +113,4 @@ bsp_tree::~bsp_tree() } } // namespace csg - +} // namespace geom diff --git a/src/geometry/csg.hpp b/src/geom/csg.hpp similarity index 91% rename from src/geometry/csg.hpp rename to src/geom/csg.hpp index d240eba..060a564 100644 --- a/src/geometry/csg.hpp +++ b/src/geom/csg.hpp @@ -17,12 +17,15 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_CSG_HPP -#define ANTKEEPER_CSG_HPP +#ifndef ANTKEEPER_GEOM_CSG_HPP +#define ANTKEEPER_GEOM_CSG_HPP #include "utility/fundamental-types.hpp" #include +namespace geom { + +/// Constructive solid geometry (CSG) namespace csg { struct plane @@ -79,6 +82,7 @@ solid op_difference(const solid& a, const solid& b); solid op_intersect(const solid& a, const solid& b); } // namespace csg +} // namespace geom -#endif // ANTKEEPER_CSG_HPP +#endif // ANTKEEPER_GEOM_CSG_HPP diff --git a/src/geom/geom.hpp b/src/geom/geom.hpp new file mode 100644 index 0000000..9e2ab23 --- /dev/null +++ b/src/geom/geom.hpp @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2021 Christopher J. Howard + * + * This file is part of Antkeeper source code. + * + * Antkeeper source code is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Antkeeper source code is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Antkeeper source code. If not, see . + */ + +#ifndef ANTKEEPER_GEOM_HPP +#define ANTKEEPER_GEOM_HPP + +/// Geometry +namespace geom {} + +#include "aabb.hpp" +#include "bounding-volume.hpp" +#include "convex-hull.hpp" +#include "csg.hpp" +#include "intersection.hpp" +#include "marching-cubes.hpp" +#include "mesh.hpp" +#include "mesh-accelerator.hpp" +#include "mesh-functions.hpp" +#include "morton.hpp" +#include "octree.hpp" +#include "plane.hpp" +#include "projection.hpp" +#include "ray.hpp" +#include "sdf.hpp" +#include "sphere.hpp" +#include "view-frustum.hpp" + +#endif // ANTKEEPER_GEOM_HPP diff --git a/src/geometry/intersection.cpp b/src/geom/intersection.cpp similarity index 99% rename from src/geometry/intersection.cpp rename to src/geom/intersection.cpp index a0739b0..55a1b43 100644 --- a/src/geometry/intersection.cpp +++ b/src/geom/intersection.cpp @@ -20,6 +20,8 @@ #include "intersection.hpp" #include +namespace geom { + std::tuple ray_plane_intersection(const ray& ray, const plane& plane) { float denom = math::dot(ray.direction, plane.normal); @@ -182,3 +184,4 @@ bool aabb_sphere_intersection(const aabb& aabb, const float3& center, flo return (distance_squared <= (radius * radius)); } +} // namespace geom diff --git a/src/geometry/intersection.hpp b/src/geom/intersection.hpp similarity index 87% rename from src/geometry/intersection.hpp rename to src/geom/intersection.hpp index c6fcd76..08ca36b 100644 --- a/src/geometry/intersection.hpp +++ b/src/geom/intersection.hpp @@ -17,16 +17,18 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_INTERSECTION_HPP -#define ANTKEEPER_INTERSECTION_HPP +#ifndef ANTKEEPER_GEOM_INTERSECTION_HPP +#define ANTKEEPER_GEOM_INTERSECTION_HPP -#include "geometry/aabb.hpp" -#include "geometry/mesh.hpp" -#include "geometry/plane.hpp" -#include "geometry/ray.hpp" +#include "geom/aabb.hpp" +#include "geom/mesh.hpp" +#include "geom/plane.hpp" +#include "geom/ray.hpp" #include "utility/fundamental-types.hpp" #include +namespace geom { + /** * Tests for intersection between a ray and a plane. * @@ -46,5 +48,7 @@ bool aabb_sphere_intersection(const aabb& aabb, const float3& center, flo bool aabb_aabb_intersection(const aabb& a, const aabb& b); -#endif // ANTKEEPER_INTERSECTION_HPP +} // namespace geom + +#endif // ANTKEEPER_GEOM_INTERSECTION_HPP diff --git a/src/geometry/marching-cubes.cpp b/src/geom/marching-cubes.cpp similarity index 99% rename from src/geometry/marching-cubes.cpp rename to src/geom/marching-cubes.cpp index 6f55c76..2d9805d 100644 --- a/src/geometry/marching-cubes.cpp +++ b/src/geom/marching-cubes.cpp @@ -20,6 +20,7 @@ #include "marching-cubes.hpp" #include +namespace geom { namespace mc { static constexpr std::uint_fast8_t vertex_table[12][2] = @@ -414,4 +415,4 @@ void polygonize(float* vertices, std::uint_fast8_t* vertex_count, std::int_fast8 } } // namespace mc - +} // namespace geom diff --git a/src/geometry/marching-cubes.hpp b/src/geom/marching-cubes.hpp similarity index 86% rename from src/geometry/marching-cubes.hpp rename to src/geom/marching-cubes.hpp index ca5f663..8ec2a53 100644 --- a/src/geometry/marching-cubes.hpp +++ b/src/geom/marching-cubes.hpp @@ -17,14 +17,14 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_MARCHING_CUBES_HPP -#define ANTKEEPER_MARCHING_CUBES_HPP +#ifndef ANTKEEPER_GEOM_MARCHING_CUBES_HPP +#define ANTKEEPER_GEOM_MARCHING_CUBES_HPP #include -/** - * Contains functions and constants related to the Marching Cubes (MC) algorithm. - */ +namespace geom { + +/// Functions and constants related to the marching cubes (MC) algorithm. namespace mc { /** @@ -53,6 +53,7 @@ constexpr float unit_cube[8][3] = }; } // namespace mc +} // namespace geom -#endif // ANTKEEPER_MARCHING_CUBES_HPP +#endif // ANTKEEPER_GEOM_MARCHING_CUBES_HPP diff --git a/src/geometry/mesh-accelerator.cpp b/src/geom/mesh-accelerator.cpp similarity index 96% rename from src/geometry/mesh-accelerator.cpp rename to src/geom/mesh-accelerator.cpp index 7dfd384..cd7a295 100644 --- a/src/geometry/mesh-accelerator.cpp +++ b/src/geom/mesh-accelerator.cpp @@ -17,11 +17,13 @@ * along with Antkeeper source code. If not, see . */ -#include "geometry/mesh-accelerator.hpp" -#include "geometry/mesh-functions.hpp" -#include "geometry/morton.hpp" +#include "geom/mesh-accelerator.hpp" +#include "geom/mesh-functions.hpp" +#include "geom/morton.hpp" #include +namespace geom { + mesh_accelerator::mesh_accelerator() {} @@ -90,7 +92,7 @@ std::optional mesh_accelerator::query_neares return std::nullopt; } -void mesh_accelerator::query_nearest_recursive(float& nearest_t, ::mesh::face*& nearest_face, octree32::node_type node, const ray& ray) const +void mesh_accelerator::query_nearest_recursive(float& nearest_t, geom::mesh::face*& nearest_face, octree32::node_type node, const ray& ray) const { // Get node bounds const aabb node_bounds = get_node_bounds(node); @@ -174,3 +176,4 @@ octree32::node_type mesh_accelerator::find_node(const float3& point) const return octree32::node(octree32::max_depth, location); } +} // namespace geom diff --git a/src/geometry/mesh-accelerator.hpp b/src/geom/mesh-accelerator.hpp similarity index 80% rename from src/geometry/mesh-accelerator.hpp rename to src/geom/mesh-accelerator.hpp index 6601399..da7556f 100644 --- a/src/geometry/mesh-accelerator.hpp +++ b/src/geom/mesh-accelerator.hpp @@ -17,18 +17,20 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_MESH_ACCELERATOR_HPP -#define ANTKEEPER_MESH_ACCELERATOR_HPP +#ifndef ANTKEEPER_GEOM_MESH_ACCELERATOR_HPP +#define ANTKEEPER_GEOM_MESH_ACCELERATOR_HPP -#include "geometry/mesh.hpp" -#include "geometry/octree.hpp" -#include "geometry/aabb.hpp" -#include "geometry/intersection.hpp" +#include "geom/mesh.hpp" +#include "geom/octree.hpp" +#include "geom/aabb.hpp" +#include "geom/intersection.hpp" #include "utility/fundamental-types.hpp" #include #include #include +namespace geom { + /** * Acceleration structure for querying mesh geometry. */ @@ -38,7 +40,7 @@ public: struct ray_query_result { float t; - ::mesh::face* face; + geom::mesh::face* face; }; mesh_accelerator(); @@ -59,7 +61,7 @@ public: private: aabb get_node_bounds(octree32::node_type node) const; - void query_nearest_recursive(float& nearest_t, ::mesh::face*& nearest_face, octree32::node_type node, const ray& ray) const; + void query_nearest_recursive(float& nearest_t, geom::mesh::face*& nearest_face, octree32::node_type node, const ray& ray) const; /// Returns the max-depth node in which the point is located octree32::node_type find_node(const float3& point) const; @@ -70,5 +72,7 @@ private: std::unordered_map> face_map; }; -#endif // ANTKEEPER_MESH_ACCELERATOR_HPP +} // namespace geom + +#endif // ANTKEEPER_GEOM_MESH_ACCELERATOR_HPP diff --git a/src/geometry/mesh-functions.cpp b/src/geom/mesh-functions.cpp similarity index 94% rename from src/geometry/mesh-functions.cpp rename to src/geom/mesh-functions.cpp index 2c3a55f..2f5d0a6 100644 --- a/src/geometry/mesh-functions.cpp +++ b/src/geom/mesh-functions.cpp @@ -21,6 +21,8 @@ #include "math/math.hpp" #include +namespace geom { + struct edge_hasher { std::size_t operator()(const std::array& v) const noexcept @@ -35,13 +37,13 @@ void create_triangle_mesh(mesh& mesh, const std::vector& vertices, const for (const auto& vertex: vertices) mesh.add_vertex(vertex); - std::unordered_map, ::mesh::edge*, edge_hasher> edge_map; + std::unordered_map, geom::mesh::edge*, edge_hasher> edge_map; const std::vector& mesh_vertices = mesh.get_vertices(); - std::vector<::mesh::edge*> loop(3); + std::vector loop(3); for (const auto& triangle: triangles) { - ::mesh::vertex* triangle_vertices[3] = + geom::mesh::vertex* triangle_vertices[3] = { mesh_vertices[triangle[0]], mesh_vertices[triangle[1]], @@ -50,8 +52,8 @@ void create_triangle_mesh(mesh& mesh, const std::vector& vertices, const for (int j = 0; j < 3; ++j) { - ::mesh::vertex* start = triangle_vertices[j]; - ::mesh::vertex* end = triangle_vertices[(j + 1) % 3]; + geom::mesh::vertex* start = triangle_vertices[j]; + geom::mesh::vertex* end = triangle_vertices[(j + 1) % 3]; if (auto it = edge_map.find({start->index, end->index}); it != edge_map.end()) { @@ -181,3 +183,5 @@ aabb calculate_bounds(const mesh& mesh) return aabb{bounds_min, bounds_max}; } + +} // namespace geom diff --git a/src/geometry/mesh-functions.hpp b/src/geom/mesh-functions.hpp similarity index 90% rename from src/geometry/mesh-functions.hpp rename to src/geom/mesh-functions.hpp index c92b89d..6587633 100644 --- a/src/geometry/mesh-functions.hpp +++ b/src/geom/mesh-functions.hpp @@ -17,15 +17,17 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_MESH_FUNCTIONS_HPP -#define ANTKEEPER_MESH_FUNCTIONS_HPP +#ifndef ANTKEEPER_GEOM_MESH_FUNCTIONS_HPP +#define ANTKEEPER_GEOM_MESH_FUNCTIONS_HPP -#include "geometry/aabb.hpp" -#include "geometry/mesh.hpp" +#include "geom/aabb.hpp" +#include "geom/mesh.hpp" #include "utility/fundamental-types.hpp" #include #include +namespace geom { + /** * Creates a triangle mesh from a list of vertices and indices. * @@ -54,12 +56,12 @@ float3 calculate_face_normal(const mesh::face& face); */ void calculate_vertex_tangents(float4* tangents, const float2* texcoords, const float3* normals, const mesh& mesh); - /** * Calculates the AABB bounds of a mesh. */ aabb calculate_bounds(const mesh& mesh); +} // namespace geom -#endif // ANTKEEPER_MESH_FUNCTIONS_HPP +#endif // ANTKEEPER_GEOM_MESH_FUNCTIONS_HPP diff --git a/src/geometry/mesh.cpp b/src/geom/mesh.cpp similarity index 99% rename from src/geometry/mesh.cpp rename to src/geom/mesh.cpp index e4841a9..4c4ca14 100644 --- a/src/geometry/mesh.cpp +++ b/src/geom/mesh.cpp @@ -20,6 +20,8 @@ #include "mesh.hpp" #include +namespace geom { + mesh::~mesh() { // Deallocate vertices @@ -330,3 +332,4 @@ bool mesh::make_adjacent(mesh::edge* in, mesh::edge* out) return true; } +} // namespace geom diff --git a/src/geometry/mesh.hpp b/src/geom/mesh.hpp similarity index 96% rename from src/geometry/mesh.hpp rename to src/geom/mesh.hpp index b03cdd3..d59ed4d 100644 --- a/src/geometry/mesh.hpp +++ b/src/geom/mesh.hpp @@ -17,12 +17,14 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_MESH_HPP -#define ANTKEEPER_MESH_HPP +#ifndef ANTKEEPER_GEOM_MESH_HPP +#define ANTKEEPER_GEOM_MESH_HPP #include #include "utility/fundamental-types.hpp" +namespace geom { + /** * Half-edge mesh. * @@ -177,5 +179,7 @@ inline const std::vector& mesh::get_faces() const return faces; } -#endif // ANTKEEPER_MESH_HPP +} // namespace geom + +#endif // ANTKEEPER_GEOM_MESH_HPP diff --git a/src/geometry/morton.cpp b/src/geom/morton.cpp similarity index 98% rename from src/geometry/morton.cpp rename to src/geom/morton.cpp index cf26f84..4273f4b 100644 --- a/src/geometry/morton.cpp +++ b/src/geom/morton.cpp @@ -19,6 +19,7 @@ #include "morton.hpp" +namespace geom { namespace morton { std::uint32_t encode_2d(std::uint32_t x, std::uint32_t y) @@ -82,4 +83,4 @@ std::array decode_3d(std::uint32_t code) } } // namespace morton - +} // namespace geom diff --git a/src/geometry/morton.hpp b/src/geom/morton.hpp similarity index 87% rename from src/geometry/morton.hpp rename to src/geom/morton.hpp index e2df8b1..f76fd29 100644 --- a/src/geometry/morton.hpp +++ b/src/geom/morton.hpp @@ -17,15 +17,15 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_MORTON_HPP -#define ANTKEEPER_MORTON_HPP +#ifndef ANTKEEPER_GEOM_MORTON_HPP +#define ANTKEEPER_GEOM_MORTON_HPP #include #include -/** - * Contains functions for encoding and decoding Morton location codes. - */ +namespace geom { + +/// Functions which encode or decode Morton location codes. namespace morton { /// Encodes 2D coordinates as a 32-bit Morton location code. @@ -41,6 +41,7 @@ std::array decode_2d(std::uint32_t code); std::array decode_3d(std::uint32_t code); } // namespace morton +} // namespace geom -#endif // ANTKEEPER_MORTON_HPP +#endif // ANTKEEPER_GEOM_MORTON_HPP diff --git a/src/geometry/octree.hpp b/src/geom/octree.hpp similarity index 98% rename from src/geometry/octree.hpp rename to src/geom/octree.hpp index 5c0019e..90ffd1e 100644 --- a/src/geometry/octree.hpp +++ b/src/geom/octree.hpp @@ -17,8 +17,8 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_OCTREE_HPP -#define ANTKEEPER_OCTREE_HPP +#ifndef ANTKEEPER_GEOM_OCTREE_HPP +#define ANTKEEPER_GEOM_OCTREE_HPP #include #include @@ -26,6 +26,8 @@ #include #include +namespace geom { + /** * A general purpose (hashed) linear octree. Nodes are integer identifiers and no other data is stored in the octree. * @@ -451,5 +453,7 @@ T octree::clz(T x) #endif } -#endif // ANTKEEPER_OCTREE_HPP +} // namespace geom + +#endif // ANTKEEPER_GEOM_OCTREE_HPP diff --git a/src/geometry/plane.hpp b/src/geom/plane.hpp similarity index 95% rename from src/geometry/plane.hpp rename to src/geom/plane.hpp index a12356d..3bc4d51 100644 --- a/src/geometry/plane.hpp +++ b/src/geom/plane.hpp @@ -17,11 +17,13 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_PLANE_HPP -#define ANTKEEPER_PLANE_HPP +#ifndef ANTKEEPER_GEOM_PLANE_HPP +#define ANTKEEPER_GEOM_PLANE_HPP #include "math/math.hpp" +namespace geom { + template struct plane { @@ -113,4 +115,6 @@ typename plane::vector_type plane::intersection(const plane& p0, const pla return -(p0.distance * math::cross(p1.normal, p2.normal) + p1.distance * math::cross(p2.normal, p0.normal) + p2.distance * math::cross(p0.normal, p1.normal)) / math::dot(p0.normal, math::cross(p1.normal, p2.normal)); } -#endif // ANTKEEPER_PLANE_HPP +} // namespace geom + +#endif // ANTKEEPER_GEOM_PLANE_HPP diff --git a/src/geometry/projection.hpp b/src/geom/projection.hpp similarity index 86% rename from src/geometry/projection.hpp rename to src/geom/projection.hpp index 1af1b22..86bc782 100644 --- a/src/geometry/projection.hpp +++ b/src/geom/projection.hpp @@ -17,15 +17,19 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_PROJECTION_HPP -#define ANTKEEPER_PROJECTION_HPP +#ifndef ANTKEEPER_GEOM_PROJECTION_HPP +#define ANTKEEPER_GEOM_PROJECTION_HPP #include "math/math.hpp" +namespace geom { + template math::vector project_on_plane(const math::vector& v, const math::vector& p, const math::vector& n) { return v - n * math::dot(v - p, n); } -#endif // ANTKEEPER_PROJECTION_HPP +} // namespace geom + +#endif // ANTKEEPER_GEOM_PROJECTION_HPP diff --git a/src/geometry/ray.hpp b/src/geom/ray.hpp similarity index 90% rename from src/geometry/ray.hpp rename to src/geom/ray.hpp index 5780593..cd99c20 100644 --- a/src/geometry/ray.hpp +++ b/src/geom/ray.hpp @@ -17,11 +17,13 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_RAY_HPP -#define ANTKEEPER_RAY_HPP +#ifndef ANTKEEPER_GEOM_RAY_HPP +#define ANTKEEPER_GEOM_RAY_HPP #include "math/math.hpp" +namespace geom { + template struct ray { @@ -48,5 +50,7 @@ inline typename ray::vector_type ray::extrapolate(T distance) const return origin + direction * distance; } -#endif // ANTKEEPER_RAY_HPP +} // namespace geom + +#endif // ANTKEEPER_GEOM_RAY_HPP diff --git a/src/geometry/sdf.hpp b/src/geom/sdf.hpp similarity index 90% rename from src/geometry/sdf.hpp rename to src/geom/sdf.hpp index f9895df..ee0e9ee 100644 --- a/src/geometry/sdf.hpp +++ b/src/geom/sdf.hpp @@ -17,15 +17,15 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_SDF_HPP -#define ANTKEEPER_SDF_HPP +#ifndef ANTKEEPER_GEOM_SDF_HPP +#define ANTKEEPER_GEOM_SDF_HPP #include "utility/fundamental-types.hpp" #include -/** - * Contains signed distance functions. - */ +namespace geom { + +/// Signed distance functions. namespace sdf { inline float3 translate(const float3& sample, const float3& offset) @@ -66,6 +66,7 @@ inline float op_round(float d, float r) } } // namespace sdf +} // namespace geom -#endif // ANTKEEPER_SDF_HPP +#endif // ANTKEEPER_GEOM_SDF_HPP diff --git a/src/geometry/sphere.hpp b/src/geom/sphere.hpp similarity index 93% rename from src/geometry/sphere.hpp rename to src/geom/sphere.hpp index 17efa21..10d0eaf 100644 --- a/src/geometry/sphere.hpp +++ b/src/geom/sphere.hpp @@ -17,14 +17,16 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_SPHERE_HPP -#define ANTKEEPER_SPHERE_HPP +#ifndef ANTKEEPER_GEOM_SPHERE_HPP +#define ANTKEEPER_GEOM_SPHERE_HPP -#include "geometry/bounding-volume.hpp" -#include "geometry/aabb.hpp" +#include "geom/bounding-volume.hpp" +#include "geom/aabb.hpp" #include "math/math.hpp" #include +namespace geom { + template struct sphere: public bounding_volume { @@ -107,5 +109,7 @@ bool sphere::contains(const vector_type& point) const return (math::dot(d, d) <= radius * radius); } -#endif // ANTKEEPER_SPHERE_HPP +} // namespace geom + +#endif // ANTKEEPER_GEOM_SPHERE_HPP diff --git a/src/geometry/view-frustum.hpp b/src/geom/view-frustum.hpp similarity index 96% rename from src/geometry/view-frustum.hpp rename to src/geom/view-frustum.hpp index 0021ea5..20abfcc 100644 --- a/src/geometry/view-frustum.hpp +++ b/src/geom/view-frustum.hpp @@ -17,13 +17,15 @@ * along with Antkeeper source code. If not, see . */ -#ifndef ANTKEEPER_VIEW_FRUSTUM_HPP -#define ANTKEEPER_VIEW_FRUSTUM_HPP +#ifndef ANTKEEPER_GEOM_VIEW_FRUSTUM_HPP +#define ANTKEEPER_GEOM_VIEW_FRUSTUM_HPP -#include "geometry/convex-hull.hpp" +#include "geom/convex-hull.hpp" #include "math/math.hpp" #include +namespace geom { + template class view_frustum { @@ -177,5 +179,7 @@ void view_frustum::recalculate_corners() corners[7] = plane_type::intersection(get_far(), get_bottom(), get_right()); } -#endif // ANTKEEPER_VIEW_FRUSTUM_HPP +} // namespace geom + +#endif // ANTKEEPER_GEOM_VIEW_FRUSTUM_HPP diff --git a/src/nest.hpp b/src/nest.hpp index f4701f4..34487b6 100644 --- a/src/nest.hpp +++ b/src/nest.hpp @@ -20,7 +20,7 @@ #ifndef ANTKEEPER_NEST_HPP #define ANTKEEPER_NEST_HPP -#include "geometry/mesh.hpp" +#include "geom/mesh.hpp" #include "utility/fundamental-types.hpp" #include #include diff --git a/src/renderer/model.hpp b/src/renderer/model.hpp index abf6abd..e77ca7f 100644 --- a/src/renderer/model.hpp +++ b/src/renderer/model.hpp @@ -22,7 +22,7 @@ #include "rasterizer/vertex-array.hpp" #include "rasterizer/vertex-buffer.hpp" -#include "geometry/aabb.hpp" +#include "geom/aabb.hpp" #include #include #include @@ -124,17 +124,19 @@ inline std::size_t model_group::get_index_count() const class model { public: + typedef geom::aabb aabb_type; + model(); ~model(); - void set_bounds(const aabb& bounds); + void set_bounds(const aabb_type& bounds); model_group* add_group(const std::string& name = std::string()); bool remove_group(const std::string& name); bool remove_group(model_group* group); - const aabb& get_bounds() const; + const aabb_type& get_bounds() const; const model_group* get_group(const std::string& name) const; model_group* get_group(const std::string& name); @@ -148,7 +150,7 @@ public: vertex_buffer* get_vertex_buffer(); private: - aabb bounds; + aabb_type bounds; std::vector groups; std::map group_map; vertex_array vao; @@ -156,12 +158,12 @@ private: skeleton* skeleton; }; -inline void model::set_bounds(const aabb& bounds) +inline void model::set_bounds(const aabb_type& bounds) { this->bounds = bounds; } -inline const aabb& model::get_bounds() const +inline const typename model::aabb_type& model::get_bounds() const { return bounds; } diff --git a/src/renderer/passes/shadow-map-pass.cpp b/src/renderer/passes/shadow-map-pass.cpp index 3050d7a..bc03721 100644 --- a/src/renderer/passes/shadow-map-pass.cpp +++ b/src/renderer/passes/shadow-map-pass.cpp @@ -29,8 +29,8 @@ #include "renderer/material-flags.hpp" #include "scene/camera.hpp" #include "scene/light.hpp" -#include "geometry/view-frustum.hpp" -#include "geometry/aabb.hpp" +#include "geom/view-frustum.hpp" +#include "geom/aabb.hpp" #include "configuration.hpp" #include "math/math.hpp" #include @@ -165,11 +165,11 @@ void shadow_map_pass::render(render_context* context) const float4x4 subfrustum_projection = math::perspective_half_z(camera.get_fov(), camera.get_aspect_ratio(), subfrustum_near, subfrustum_far); // Calculate view camera subfrustum - view_frustum subfrustum(subfrustum_projection * camera_view); + geom::view_frustum subfrustum(subfrustum_projection * camera_view); // Create AABB containing the view camera subfrustum corners - const std::array, 8>& subfrustum_corners = subfrustum.get_corners(); - aabb subfrustum_aabb = {subfrustum_corners[0], subfrustum_corners[0]}; + const std::array& subfrustum_corners = subfrustum.get_corners(); + geom::aabb subfrustum_aabb = {subfrustum_corners[0], subfrustum_corners[0]}; for (int j = 1; j < 8; ++j) { for (int k = 0; k < 3; ++k) @@ -180,7 +180,7 @@ void shadow_map_pass::render(render_context* context) const } // Transform subfrustum AABB into the light clip space - aabb cropping_bounds = aabb::transform(subfrustum_aabb, light_view_projection); + geom::aabb cropping_bounds = geom::aabb::transform(subfrustum_aabb, light_view_projection); // Calculate scale float3 scale; diff --git a/src/renderer/render-context.hpp b/src/renderer/render-context.hpp index bdc4f68..3baacba 100644 --- a/src/renderer/render-context.hpp +++ b/src/renderer/render-context.hpp @@ -21,8 +21,8 @@ #define ANTKEEPER_RENDER_CONTEXT_HPP #include "renderer/render-operation.hpp" -#include "geometry/plane.hpp" -#include "geometry/bounding-volume.hpp" +#include "geom/plane.hpp" +#include "geom/bounding-volume.hpp" #include "utility/fundamental-types.hpp" #include "scene/camera.hpp" #include "scene/collection.hpp" @@ -34,8 +34,8 @@ struct render_context math::transform camera_transform; float3 camera_forward; float3 camera_up; - const bounding_volume* camera_culling_volume; - plane clip_near; + const geom::bounding_volume* camera_culling_volume; + geom::plane clip_near; const scene::collection* collection; std::list operations; diff --git a/src/renderer/renderer.cpp b/src/renderer/renderer.cpp index 1d76108..1da1031 100644 --- a/src/renderer/renderer.cpp +++ b/src/renderer/renderer.cpp @@ -28,7 +28,7 @@ #include "renderer/model.hpp" #include "rasterizer/drawing-mode.hpp" #include "math/math.hpp" -#include "geometry/projection.hpp" +#include "geom/projection.hpp" #include "configuration.hpp" #include #include @@ -137,7 +137,7 @@ void renderer::process_model_instance(render_context& context, const scene::mode return; // Get object culling volume - const bounding_volume* object_culling_volume = model_instance->get_culling_mask(); + const geom::bounding_volume* object_culling_volume = model_instance->get_culling_mask(); if (!object_culling_volume) object_culling_volume = &model_instance->get_bounds(); @@ -176,7 +176,7 @@ void renderer::process_model_instance(render_context& context, const scene::mode void renderer::process_billboard(render_context& context, const scene::billboard* billboard) const { // Get object culling volume - const bounding_volume* object_culling_volume = billboard->get_culling_mask(); + const geom::bounding_volume* object_culling_volume = billboard->get_culling_mask(); if (!object_culling_volume) object_culling_volume = &billboard->get_bounds(); @@ -196,7 +196,7 @@ void renderer::process_billboard(render_context& context, const scene::billboard else if (billboard->get_billboard_type() == scene::billboard_type::cylindrical) { const float3& alignment_axis = billboard->get_alignment_axis(); - float3 look = math::normalize(project_on_plane(billboard_transform.translation - context.camera_transform.translation, {0.0f, 0.0f, 0.0f}, alignment_axis)); + float3 look = math::normalize(geom::project_on_plane(billboard_transform.translation - context.camera_transform.translation, {0.0f, 0.0f, 0.0f}, alignment_axis)); float3 right = math::normalize(math::cross(alignment_axis, look)); look = math::cross(right, alignment_axis); float3 up = math::cross(look, right); diff --git a/src/resources/entity-archetype-loader.cpp b/src/resources/entity-archetype-loader.cpp index 4dee43a..8539541 100644 --- a/src/resources/entity-archetype-loader.cpp +++ b/src/resources/entity-archetype-loader.cpp @@ -67,7 +67,7 @@ static bool load_collision_component(archetype& archetype, resource_manager& res std::string filename = parameters[1]; collision_component component; - component.mesh = resource_manager.load(filename); + component.mesh = resource_manager.load(filename); if (!component.mesh) { std::string message = std::string("load_collision_component(): Failed to load model \"") + filename + std::string("\""); diff --git a/src/resources/mesh-loader.cpp b/src/resources/mesh-loader.cpp index 8a7282b..ea80ec6 100644 --- a/src/resources/mesh-loader.cpp +++ b/src/resources/mesh-loader.cpp @@ -18,15 +18,15 @@ */ #include "resources/resource-loader.hpp" -#include "geometry/mesh.hpp" -#include "geometry/mesh-functions.hpp" +#include "geom/mesh.hpp" +#include "geom/mesh-functions.hpp" #include "utility/fundamental-types.hpp" #include #include #include template <> -mesh* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file) +geom::mesh* resource_loader::load(resource_manager* resource_manager, PHYSFS_File* file) { std::string line; std::vector vertices; @@ -83,8 +83,8 @@ mesh* resource_loader::load(resource_manager* resource_manager, PHYSFS_Fil } } - mesh* mesh = new ::mesh(); - create_triangle_mesh(*mesh, vertices, triangles); + geom::mesh* mesh = new geom::mesh(); + geom::create_triangle_mesh(*mesh, vertices, triangles); return mesh; } diff --git a/src/resources/model-loader.cpp b/src/resources/model-loader.cpp index 608767b..097a914 100644 --- a/src/resources/model-loader.cpp +++ b/src/resources/model-loader.cpp @@ -408,7 +408,7 @@ model* resource_loader::load(resource_manager* resource_manager, PHYSFS_F } // Load bounds - aabb bounds = + geom::aabb bounds = { {std::numeric_limits::infinity(), std::numeric_limits::infinity(), std::numeric_limits::infinity()}, {-std::numeric_limits::infinity(), -std::numeric_limits::infinity(), -std::numeric_limits::infinity()} diff --git a/src/scene/billboard.cpp b/src/scene/billboard.cpp index 91d7a77..f030114 100644 --- a/src/scene/billboard.cpp +++ b/src/scene/billboard.cpp @@ -23,7 +23,7 @@ namespace scene { -const aabb billboard::untransformed_bounds = {{-1, -1, -1}, {1, 1, 1}}; +const typename billboard::aabb_type billboard::untransformed_bounds = {{-1, -1, -1}, {1, 1, 1}}; billboard::billboard(): bounds(untransformed_bounds), @@ -63,7 +63,7 @@ void billboard::set_alignment_axis(const float3& axis) void billboard::transformed() { - bounds = aabb::transform(untransformed_bounds, get_transform()); + bounds = aabb_type::transform(untransformed_bounds, get_transform()); } void billboard::update_tweens() diff --git a/src/scene/billboard.hpp b/src/scene/billboard.hpp index d19ca8f..53d7e9c 100644 --- a/src/scene/billboard.hpp +++ b/src/scene/billboard.hpp @@ -21,7 +21,7 @@ #define ANTKEEPER_SCENE_BILLBOARD_HPP #include "scene/object.hpp" -#include "geometry/aabb.hpp" +#include "geom/aabb.hpp" #include "utility/fundamental-types.hpp" class material; @@ -47,6 +47,8 @@ enum class billboard_type class billboard: public object { public: + typedef geom::aabb aabb_type; + billboard(); billboard(const billboard& other); billboard& operator=(const billboard& other); @@ -59,7 +61,7 @@ public: /// Sets the axis around which the billboard will be rotated when the alignment is set to billboard_alignment::cylindrical. void set_alignment_axis(const float3& axis); - virtual const bounding_volume& get_bounds() const; + virtual const bounding_volume_type& get_bounds() const; material* get_material() const; billboard_type get_billboard_type() const; @@ -68,18 +70,18 @@ public: virtual void update_tweens(); private: - static const aabb untransformed_bounds; + static const aabb_type untransformed_bounds; virtual void transformed(); - aabb bounds; + aabb_type bounds; material* material; billboard_type type; float3 alignment_axis; }; -inline const bounding_volume& billboard::get_bounds() const +inline const typename object_base::bounding_volume_type& billboard::get_bounds() const { return bounds; } diff --git a/src/scene/camera.hpp b/src/scene/camera.hpp index abedbca..557ce01 100644 --- a/src/scene/camera.hpp +++ b/src/scene/camera.hpp @@ -21,7 +21,7 @@ #define ANTKEEPER_SCENE_CAMERA_HPP #include "scene/object.hpp" -#include "geometry/view-frustum.hpp" +#include "geom/view-frustum.hpp" #include "utility/fundamental-types.hpp" class compositor; @@ -34,6 +34,8 @@ namespace scene { class camera: public object { public: + typedef geom::view_frustum view_frustum_type; + camera(); /** @@ -79,7 +81,7 @@ public: void set_compositor(compositor* compositor); void set_composite_index(int index); - virtual const bounding_volume& get_bounds() const; + virtual const bounding_volume_type& get_bounds() const; float is_orthographic() const; float get_clip_left() const; @@ -101,7 +103,7 @@ public: const float4x4& get_view_projection() const; /// Returns the camera's view frustum. - const view_frustum& get_view_frustum() const; + const view_frustum_type& get_view_frustum() const; const compositor* get_compositor() const; compositor* get_compositor(); @@ -139,10 +141,10 @@ private: tween view; tween projection; tween view_projection; - view_frustum view_frustum; + view_frustum_type view_frustum; }; -inline const bounding_volume& camera::get_bounds() const +inline const typename object_base::bounding_volume_type& camera::get_bounds() const { return view_frustum.get_bounds(); } @@ -207,7 +209,7 @@ inline const float4x4& camera::get_view_projection() const return view_projection[1]; } -inline const view_frustum& camera::get_view_frustum() const +inline const typename camera::view_frustum_type& camera::get_view_frustum() const { return view_frustum; } diff --git a/src/scene/light.cpp b/src/scene/light.cpp index 248ff3b..2f50fef 100644 --- a/src/scene/light.cpp +++ b/src/scene/light.cpp @@ -52,7 +52,7 @@ void light::update_tweens() void light::transformed() { - bounds = sphere(get_translation(), 0.0f); + bounds = sphere_type(get_translation(), 0.0f); } } // namespace scene diff --git a/src/scene/light.hpp b/src/scene/light.hpp index c860fc4..89af207 100644 --- a/src/scene/light.hpp +++ b/src/scene/light.hpp @@ -21,7 +21,7 @@ #define ANTKEEPER_SCENE_LIGHT_HPP #include "scene/object.hpp" -#include "geometry/sphere.hpp" +#include "geom/sphere.hpp" #include "utility/fundamental-types.hpp" namespace scene { @@ -37,6 +37,8 @@ enum class light_type class light: public object { public: + typedef geom::sphere sphere_type; + light(); virtual light_type get_light_type() const = 0; @@ -44,7 +46,7 @@ public: void set_color(const float3& color); void set_intensity(float intensity); - virtual const bounding_volume& get_bounds() const; + virtual const bounding_volume_type& get_bounds() const; const float3& get_color() const; float get_intensity() const; @@ -63,10 +65,10 @@ private: tween color; tween intensity; tween scaled_color; - sphere bounds; + sphere_type bounds; }; -inline const bounding_volume& light::get_bounds() const +inline const typename object_base::bounding_volume_type& light::get_bounds() const { return bounds; } diff --git a/src/scene/lod-group.hpp b/src/scene/lod-group.hpp index 1f80c09..1d2795f 100644 --- a/src/scene/lod-group.hpp +++ b/src/scene/lod-group.hpp @@ -21,7 +21,7 @@ #define ANTKEEPER_SCENE_LOD_GROUP_HPP #include "scene/object.hpp" -#include "geometry/aabb.hpp" +#include "geom/aabb.hpp" #include #include @@ -32,6 +32,8 @@ class camera; class lod_group: public object { public: + typedef geom::aabb aabb_type; + /** * Creates a LOD group. * @@ -80,7 +82,7 @@ public: */ void remove_objects(std::size_t level); - virtual const bounding_volume& get_bounds() const; + virtual const bounding_volume_type& get_bounds() const; /// Returns the number of detail levels in the group. std::size_t get_level_count() const; @@ -97,11 +99,11 @@ private: void update_bounds(); virtual void transformed(); - aabb bounds; + aabb_type bounds; std::vector> levels; }; -inline const bounding_volume& lod_group::get_bounds() const +inline const typename object_base::bounding_volume_type& lod_group::get_bounds() const { return bounds; } diff --git a/src/scene/model-instance.cpp b/src/scene/model-instance.cpp index 80600e5..5602d94 100644 --- a/src/scene/model-instance.cpp +++ b/src/scene/model-instance.cpp @@ -92,7 +92,7 @@ void model_instance::reset_materials() void model_instance::update_bounds() { if (model) - bounds = aabb::transform(model->get_bounds(), get_transform()); + bounds = aabb_type::transform(model->get_bounds(), get_transform()); else bounds = {get_translation(), get_translation()}; } diff --git a/src/scene/model-instance.hpp b/src/scene/model-instance.hpp index 0e73427..2369f69 100644 --- a/src/scene/model-instance.hpp +++ b/src/scene/model-instance.hpp @@ -21,7 +21,7 @@ #define ANTKEEPER_SCENE_MODEL_INSTANCE_HPP #include "scene/object.hpp" -#include "geometry/aabb.hpp" +#include "geom/aabb.hpp" #include class material; @@ -33,6 +33,8 @@ namespace scene { class model_instance: public object { public: + typedef geom::aabb aabb_type; + explicit model_instance(model* model); model_instance(); model_instance(const model_instance& other); @@ -63,7 +65,7 @@ public: */ void reset_materials(); - virtual const bounding_volume& get_bounds() const; + virtual const bounding_volume_type& get_bounds() const; const model* get_model() const; model* get_model(); @@ -86,12 +88,12 @@ private: model* model; pose* pose; std::vector materials; - aabb bounds; + aabb_type bounds; bool instanced; std::size_t instance_count; }; -inline const bounding_volume& model_instance::get_bounds() const +inline const typename object_base::bounding_volume_type& model_instance::get_bounds() const { return bounds; } diff --git a/src/scene/object.hpp b/src/scene/object.hpp index ff05332..e176919 100644 --- a/src/scene/object.hpp +++ b/src/scene/object.hpp @@ -21,7 +21,7 @@ #define ANTKEEPER_SCENE_OBJECT_HPP #include "animation/tween.hpp" -#include "geometry/bounding-volume.hpp" +#include "geom/bounding-volume.hpp" #include "math/vector-type.hpp" #include "math/quaternion-type.hpp" #include "math/transform-type.hpp" @@ -39,7 +39,7 @@ public: typedef math::vector vector_type; typedef math::quaternion quaternion_type; typedef math::transform transform_type; - typedef bounding_volume bounding_volume_type; + typedef geom::bounding_volume bounding_volume_type; /// Returns the type ID for this scene object type. virtual const std::size_t get_object_type_id() const = 0;