Browse Source

Rename geometry folder to geom and move all code in the geom folder into the geom namespace

master
C. J. Howard 1 year ago
parent
commit
d16167586c
58 changed files with 399 additions and 273 deletions
  1. +0
    -1
      CMakeLists.txt
  2. +6
    -6
      src/ecs/components/collision-component.hpp
  3. +2
    -2
      src/ecs/components/locomotion-component.hpp
  4. +2
    -2
      src/ecs/components/snap-component.hpp
  5. +1
    -1
      src/ecs/systems/control-system.cpp
  6. +6
    -6
      src/ecs/systems/painting-system.cpp
  7. +3
    -3
      src/ecs/systems/snapping-system.cpp
  8. +33
    -33
      src/ecs/systems/subterrain-system.cpp
  9. +4
    -4
      src/ecs/systems/subterrain-system.hpp
  10. +21
    -21
      src/ecs/systems/terrain-system.cpp
  11. +5
    -5
      src/ecs/systems/terrain-system.hpp
  12. +5
    -5
      src/ecs/systems/tool-system.cpp
  13. +2
    -2
      src/ecs/systems/vegetation-system.cpp
  14. +22
    -22
      src/game/cartography/relief-map.cpp
  15. +2
    -2
      src/game/cartography/relief-map.hpp
  16. +2
    -2
      src/game/game-context.hpp
  17. +8
    -4
      src/geom/aabb.hpp
  18. +7
    -5
      src/geom/bounding-volume.hpp
  19. +15
    -11
      src/geom/convex-hull.hpp
  20. +2
    -1
      src/geom/csg.cpp
  21. +7
    -3
      src/geom/csg.hpp
  22. +44
    -0
      src/geom/geom.hpp
  23. +3
    -0
      src/geom/intersection.cpp
  24. +11
    -7
      src/geom/intersection.hpp
  25. +2
    -1
      src/geom/marching-cubes.cpp
  26. +7
    -6
      src/geom/marching-cubes.hpp
  27. +7
    -4
      src/geom/mesh-accelerator.cpp
  28. +13
    -9
      src/geom/mesh-accelerator.hpp
  29. +9
    -5
      src/geom/mesh-functions.cpp
  30. +8
    -6
      src/geom/mesh-functions.hpp
  31. +3
    -0
      src/geom/mesh.cpp
  32. +7
    -3
      src/geom/mesh.hpp
  33. +2
    -1
      src/geom/morton.cpp
  34. +7
    -6
      src/geom/morton.hpp
  35. +7
    -3
      src/geom/octree.hpp
  36. +7
    -3
      src/geom/plane.hpp
  37. +7
    -3
      src/geom/projection.hpp
  38. +7
    -3
      src/geom/ray.hpp
  39. +7
    -6
      src/geom/sdf.hpp
  40. +9
    -5
      src/geom/sphere.hpp
  41. +8
    -4
      src/geom/view-frustum.hpp
  42. +1
    -1
      src/nest.hpp
  43. +8
    -6
      src/renderer/model.hpp
  44. +6
    -6
      src/renderer/passes/shadow-map-pass.cpp
  45. +4
    -4
      src/renderer/render-context.hpp
  46. +4
    -4
      src/renderer/renderer.cpp
  47. +1
    -1
      src/resources/entity-archetype-loader.cpp
  48. +5
    -5
      src/resources/mesh-loader.cpp
  49. +1
    -1
      src/resources/model-loader.cpp
  50. +2
    -2
      src/scene/billboard.cpp
  51. +7
    -5
      src/scene/billboard.hpp
  52. +8
    -6
      src/scene/camera.hpp
  53. +1
    -1
      src/scene/light.cpp
  54. +6
    -4
      src/scene/light.hpp
  55. +6
    -4
      src/scene/lod-group.hpp
  56. +1
    -1
      src/scene/model-instance.cpp
  57. +6
    -4
      src/scene/model-instance.hpp
  58. +2
    -2
      src/scene/object.hpp

+ 0
- 1
CMakeLists.txt View File

@ -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

+ 6
- 6
src/ecs/components/collision-component.hpp View File

@ -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<float> bounds;
mesh_accelerator mesh_accelerator;
geom::mesh* mesh;
geom::aabb<float> bounds;
geom::mesh_accelerator mesh_accelerator;
};
} // namespace ecs

+ 2
- 2
src/ecs/components/locomotion-component.hpp View File

@ -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;
};

+ 2
- 2
src/ecs/components/snap-component.hpp View File

@ -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<float> ray;
geom::ray<float> ray;
bool relative;
bool warp;
bool autoremove;

+ 1
- 1
src/ecs/systems/control-system.cpp View File

@ -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"

+ 6
- 6
src/ecs/systems/painting-system.cpp View File

@ -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 <limits>
namespace ecs {
@ -252,7 +252,7 @@ void painting_system::update(double t, double dt)
stroke_bounds_max.x = std::max<float>(stroke_bounds_max.x, std::max<float>(c.x, std::max<float>(d.x, std::max<float>(e.x, f.x))));
stroke_bounds_max.y = std::max<float>(stroke_bounds_max.y, std::max<float>(c.y, std::max<float>(d.y, std::max<float>(e.y, f.y))));
stroke_bounds_max.z = std::max<float>(stroke_bounds_max.z, std::max<float>(c.z, std::max<float>(d.z, std::max<float>(e.z, f.z))));
stroke_model->set_bounds(aabb<float>{stroke_bounds_min, stroke_bounds_max});
stroke_model->set_bounds(geom::aabb<float>{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<float> untransformed_ray = {position + float3{0.0f, 10000.0f, 0.0f}, {0, -1, 0}};
geom::ray<float> untransformed_ray = {position + float3{0.0f, 10000.0f, 0.0f}, {0, -1, 0}};
float min_distance = std::numeric_limits<float>::infinity();
registry.view<transform_component, collision_component>().each(
@ -325,10 +325,10 @@ std::optional> painting_system::cast_ray(const float3
math::transform<float> 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<float> transformed_ray = {origin, direction};
geom::ray<float> 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;

+ 3
- 3
src/ecs/systems/snapping-system.cpp View File

@ -39,7 +39,7 @@ void snapping_system::update(double t, double dt)
float a = std::numeric_limits<float>::infinity();
float3 pick;
ray<float> snap_ray = snap.ray;
geom::ray<float> 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<float> 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<float> transformed_ray = {origin, direction};
geom::ray<float> 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;

+ 33
- 33
src/ecs/systems/subterrain-system.cpp View File

@ -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 <array>
#include <limits>
@ -43,18 +43,18 @@ namespace ecs {
struct cube_tree
{
public:
cube_tree(const aabb<float>& bounds, int max_depth);
cube_tree(const geom::aabb<float>& bounds, int max_depth);
~cube_tree();
const bool is_leaf() const;
const aabb<float>& get_bounds() const;
const geom::aabb<float>& get_bounds() const;
/// Subdivides all nodes intersecting with a region to the max depth.
void subdivide_max(const aabb<float>& region);
void subdivide_max(const geom::aabb<float>& region);
/// Fills a list with all leaf nodes that intersect with a region.
void query_leaves(std::list<cube_tree*>& nodes, const aabb<float>& region);
void visit_leaves(const aabb<float>& region, const std::function<void(cube_tree&)>& f);
void query_leaves(std::list<cube_tree*>& nodes, const geom::aabb<float>& region);
void visit_leaves(const geom::aabb<float>& region, const std::function<void(cube_tree&)>& 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<float> bounds;
const geom::aabb<float> bounds;
private:
cube_tree(const aabb<float>& bounds, int max_depth, int depth);
cube_tree(const geom::aabb<float>& bounds, int max_depth, int depth);
void subdivide();
};
cube_tree::cube_tree(const aabb<float>& bounds, int max_depth):
cube_tree::cube_tree(const geom::aabb<float>& bounds, int max_depth):
cube_tree(bounds, max_depth, 0)
{}
cube_tree::cube_tree(const aabb<float>& bounds, int max_depth, int depth):
cube_tree::cube_tree(const geom::aabb<float>& 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<float>& region)
void cube_tree::subdivide_max(const geom::aabb<float>& 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<cube_tree*>& nodes, const aabb<float>& region)
void cube_tree::query_leaves(std::list<cube_tree*>& nodes, const geom::aabb<float>& 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<float>& region, const std::function<void(cube_tree&)>& f)
void cube_tree::visit_leaves(const geom::aabb<float>& region, const std::function<void(cube_tree&)>& 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<float>& cube_tree::get_bounds() const
inline const geom::aabb<float>& cube_tree::get_bounds() const
{
return bounds;
}
@ -177,7 +177,7 @@ void cube_tree::subdivide()
for (int i = 0; i < 8; ++i)
{
aabb<float> child_bounds;
geom::aabb<float> child_bounds;
for (int j = 0; j < 3; ++j)
{
child_bounds.min_point[j] = std::min<float>(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<float>& bounds = node->get_bounds();
const geom::aabb<float>& 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<float> region = {position, position};
geom::aabb<float> region = {position, position};
for (int i = 0; i < 3; ++i)
{
region.min_point[i] -= radius + isosurface_resolution;

+ 4
- 4
src/ecs/systems/subterrain-system.hpp View File

@ -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<float> subterrain_bounds;
geom::aabb<float> subterrain_bounds;
ecs::cube_tree* cube_tree;
std::vector<float3> subterrain_vertices;
std::vector<std::array<std::uint_fast32_t, 3>> subterrain_triangles;

+ 21
- 21
src/ecs/systems/terrain-system.cpp View File

@ -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<mesh::face*>& faces = terrain_mesh->get_faces();
const std::vector<mesh::vertex*>& vertices = terrain_mesh->get_vertices();
const std::vector<geom::mesh::face*>& faces = terrain_mesh->get_faces();
const std::vector<geom::mesh::vertex*>& vertices = terrain_mesh->get_vertices();
aabb<float> bounds = calculate_bounds(*terrain_mesh);
geom::aabb<float> 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);

+ 5
- 5
src/ecs/systems/terrain-system.hpp View File

@ -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);

+ 5
- 5
src/ecs/systems/tool-system.cpp View File

@ -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<float> picking_ray = {pick_near, pick_direction};
geom::ray<float> picking_ray = {pick_near, pick_direction};
float a = std::numeric_limits<float>::infinity();
bool intersection = false;
@ -121,10 +121,10 @@ void tool_system::update(double t, double dt)
math::transform<float> inverse_transform = math::inverse(transform.local);
float3 origin = inverse_transform * pick_origin;
float3 direction = math::normalize(math::conjugate(transform.local.rotation) * pick_direction);
ray<float> transformed_ray = {origin, direction};
geom::ray<float> 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;

+ 2
- 2
src/ecs/systems/vegetation-system.cpp View File

@ -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 <cmath>
@ -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<float>* culling_mask = new aabb<float>(vegetation_model->get_bounds());
geom::aabb<float>* culling_mask = new geom::aabb<float>(vegetation_model->get_bounds());
culling_mask->min_point.x = std::min<float>(culling_mask->min_point.x, translation.x - vegetation_patch_size * 0.5f);
culling_mask->min_point.z = std::min<float>(culling_mask->min_point.z, translation.z - vegetation_patch_size * 0.5f);
culling_mask->max_point.x = std::max<float>(culling_mask->max_point.x, translation.x + vegetation_patch_size * 0.5f);

+ 22
- 22
src/game/cartography/relief-map.cpp View File

@ -25,10 +25,10 @@
namespace cart
{
mesh* map_elevation(const std::function<float(float, float)>& function, float scale, std::size_t subdivisions)
geom::mesh* map_elevation(const std::function<float(float, float)>& 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::size_t>(std::pow(2, subdivisions));
@ -56,10 +56,10 @@ mesh* map_elevation(const std::function& function, float sc
}
// Function to eliminate duplicate edges
std::map<std::array<std::size_t, 2>, mesh::edge*> edge_map;
auto add_or_find_edge = [&](mesh::vertex* start, mesh::vertex* end) -> mesh::edge*
std::map<std::array<std::size_t, 2>, 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<mesh::vertex*>& vertices = mesh->get_vertices();
const std::vector<geom::mesh::vertex*>& 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
// | / |

+ 2
- 2
src/game/cartography/relief-map.hpp View File

@ -20,7 +20,7 @@
#ifndef ANTKEEPER_RELIEF_MAP_HPP
#define ANTKEEPER_RELIEF_MAP_HPP
#include "geometry/mesh.hpp"
#include "geom/mesh.hpp"
#include <functional>
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<float(float, float)>& function, float scale, std::size_t subdivisions);
geom::mesh* map_elevation(const std::function<float(float, float)>& function, float scale, std::size_t subdivisions);
} // namespace cart

+ 2
- 2
src/game/game-context.hpp View File

@ -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 <optional>
#include <entt/entt.hpp>
#include <fstream>
@ -193,7 +193,7 @@ struct game_context
scene::billboard* splash_billboard;
scene::spotlight* lens_spotlight;
scene::spotlight* flashlight_spotlight;
aabb<float> no_cull;
geom::aabb<float> no_cull;
// Animation
timeline* timeline;

src/geometry/aabb.hpp → src/geom/aabb.hpp View File

@ -17,14 +17,16 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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 <limits>
namespace geom {
template <class T>
struct aabb: public bounding_volume<T>
{
@ -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<T, 4> transformed_corner = math::mul(m, vector<T, 4>{corner.x, corner.y, corner.z, T(1)});
math::vector<T, 4> transformed_corner = math::mul(m, math::vector<T, 4>{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

src/geometry/bounding-volume.hpp → src/geom/bounding-volume.hpp View File

@ -17,13 +17,13 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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 <stdexcept>
using math::vector;
namespace geom {
template <class T>
struct sphere;
@ -63,7 +63,7 @@ public:
virtual bool contains(const aabb<T>& aabb) const = 0;
/// Tests whether this bounding volume contains a point.
virtual bool contains(const vector<T, 3>& point) const = 0;
virtual bool contains(const math::vector<T, 3>& 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

src/geometry/convex-hull.hpp → src/geom/convex-hull.hpp View File

@ -17,16 +17,18 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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 <cstdlib>
#include <vector>
namespace geom {
/**
* A plane-bounded convex hull.
*/
@ -51,7 +53,7 @@ struct convex_hull: public bounding_volume
virtual bool intersects(const aabb<T>& aabb) const;
virtual bool contains(const sphere<T>& sphere) const;
virtual bool contains(const aabb<T>& aabb) const;
virtual bool contains(const vector<T, 3>& point) const;
virtual bool contains(const math::vector<T, 3>& point) const;
};
template <class T>
@ -81,7 +83,7 @@ bool convex_hull::intersects(const sphere& sphere) const
template <class T>
bool convex_hull<T>::intersects(const aabb<T>& aabb) const
{
vector<T, 3> pv;
math::vector<T, 3> pv;
for (const plane<T>& 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 <class T>
bool convex_hull<T>::contains(const aabb<T>& aabb) const
{
vector<T, 3> pv;
vector<T, 3> nv;
math::vector<T, 3> pv;
math::vector<T, 3> nv;
for (const plane<T>& plane: planes)
{
@ -126,7 +128,7 @@ bool convex_hull::contains(const aabb& aabb) const
}
template <class T>
bool convex_hull<T>::contains(const vector<T, 3>& point) const
bool convex_hull<T>::contains(const math::vector<T, 3>& point) const
{
for (const plane<T>& 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

src/geometry/csg.cpp → src/geom/csg.cpp View File

@ -20,6 +20,7 @@
#include "csg.hpp"
#include <tuple>
namespace geom {
namespace csg {
enum class polygon_classification
@ -112,4 +113,4 @@ bsp_tree::~bsp_tree()
}
} // namespace csg
} // namespace geom

src/geometry/csg.hpp → src/geom/csg.hpp View File

@ -17,12 +17,15 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_CSG_HPP
#define ANTKEEPER_CSG_HPP
#ifndef ANTKEEPER_GEOM_CSG_HPP
#define ANTKEEPER_GEOM_CSG_HPP
#include "utility/fundamental-types.hpp"
#include <list>
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

+ 44
- 0
src/geom/geom.hpp View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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

src/geometry/intersection.cpp → src/geom/intersection.cpp View File

@ -20,6 +20,8 @@
#include "intersection.hpp"
#include <limits>
namespace geom {
std::tuple<bool, float> ray_plane_intersection(const ray<float>& ray, const plane<float>& 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

src/geometry/intersection.hpp → src/geom/intersection.hpp View File

@ -17,16 +17,18 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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 <tuple>
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<float>& a, const aabb<float>& b);
#endif // ANTKEEPER_INTERSECTION_HPP
} // namespace geom
#endif // ANTKEEPER_GEOM_INTERSECTION_HPP

src/geometry/marching-cubes.cpp → src/geom/marching-cubes.cpp View File

@ -20,6 +20,7 @@
#include "marching-cubes.hpp"
#include <cmath>
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

src/geometry/marching-cubes.hpp → src/geom/marching-cubes.hpp View File

@ -17,14 +17,14 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_MARCHING_CUBES_HPP
#define ANTKEEPER_MARCHING_CUBES_HPP
#ifndef ANTKEEPER_GEOM_MARCHING_CUBES_HPP
#define ANTKEEPER_GEOM_MARCHING_CUBES_HPP
#include <cstdint>
/**
* 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

src/geometry/mesh-accelerator.cpp → src/geom/mesh-accelerator.cpp View File

@ -17,11 +17,13 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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 <bitset>
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<float>& ray) const
void mesh_accelerator::query_nearest_recursive(float& nearest_t, geom::mesh::face*& nearest_face, octree32::node_type node, const ray<float>& ray) const
{
// Get node bounds
const aabb<float> 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

src/geometry/mesh-accelerator.hpp → src/geom/mesh-accelerator.hpp View File

@ -17,18 +17,20 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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 <list>
#include <optional>
#include <unordered_map>
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<float> 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<float>& ray) const;
void query_nearest_recursive(float& nearest_t, geom::mesh::face*& nearest_face, octree32::node_type node, const ray<float>& 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<octree32::node_type, std::list<mesh::face*>> face_map;
};
#endif // ANTKEEPER_MESH_ACCELERATOR_HPP
} // namespace geom
#endif // ANTKEEPER_GEOM_MESH_ACCELERATOR_HPP

src/geometry/mesh-functions.cpp → src/geom/mesh-functions.cpp View File

@ -21,6 +21,8 @@
#include "math/math.hpp"
#include <unordered_map>
namespace geom {
struct edge_hasher
{
std::size_t operator()(const std::array<std::size_t, 2>& 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<std::array<std::size_t, 2>, ::mesh::edge*, edge_hasher> edge_map;
std::unordered_map<std::array<std::size_t, 2>, geom::mesh::edge*, edge_hasher> edge_map;
const std::vector<mesh::vertex*>& mesh_vertices = mesh.get_vertices();
std::vector<::mesh::edge*> loop(3);
std::vector<geom::mesh::edge*> 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<float>{bounds_min, bounds_max};
}
} // namespace geom

src/geometry/mesh-functions.hpp → src/geom/mesh-functions.hpp View File

@ -17,15 +17,17 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#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 <array>
#include <vector>
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<float> calculate_bounds(const mesh& mesh);
} // namespace geom
#endif // ANTKEEPER_MESH_FUNCTIONS_HPP
#endif // ANTKEEPER_GEOM_MESH_FUNCTIONS_HPP

src/geometry/mesh.cpp → src/geom/mesh.cpp View File

@ -20,6 +20,8 @@
#include "mesh.hpp"
#include <stdexcept>
namespace geom {
mesh::~mesh()
{
// Deallocate vertices
@ -330,3 +332,4 @@ bool mesh::make_adjacent(mesh::edge* in, mesh::edge* out)
return true;
}
} // namespace geom

src/geometry/mesh.hpp → src/geom/mesh.hpp View File

@ -17,12 +17,14 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_MESH_HPP
#define ANTKEEPER_MESH_HPP
#ifndef ANTKEEPER_GEOM_MESH_HPP
#define ANTKEEPER_GEOM_MESH_HPP
#include <vector>
#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

src/geometry/morton.cpp → src/geom/morton.cpp View File

@ -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

src/geometry/morton.hpp → src/geom/morton.hpp View File