Browse Source

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

master
C. J. Howard 3 years 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_package(OpenAL REQUIRED CONFIG)
find_library(physfs REQUIRED NAMES physfs-static PATHS "${CMAKE_PREFIX_PATH}/lib") find_library(physfs REQUIRED NAMES physfs-static PATHS "${CMAKE_PREFIX_PATH}/lib")
# Determine dependencies # Determine dependencies
set(STATIC_LIBS set(STATIC_LIBS
dr_wav dr_wav

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

@ -20,17 +20,17 @@
#ifndef ANTKEEPER_ECS_COLLISION_COMPONENT_HPP #ifndef ANTKEEPER_ECS_COLLISION_COMPONENT_HPP
#define 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 { namespace ecs {
struct collision_component 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 } // namespace ecs

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

@ -20,14 +20,14 @@
#ifndef ANTKEEPER_ECS_PLACEMENT_COMPONENT_HPP #ifndef ANTKEEPER_ECS_PLACEMENT_COMPONENT_HPP
#define ANTKEEPER_ECS_PLACEMENT_COMPONENT_HPP #define ANTKEEPER_ECS_PLACEMENT_COMPONENT_HPP
#include "geometry/mesh.hpp"
#include "geom/mesh.hpp"
#include "utility/fundamental-types.hpp" #include "utility/fundamental-types.hpp"
namespace ecs { namespace ecs {
struct locomotion_component struct locomotion_component
{ {
const mesh::face* triangle;
const geom::mesh::face* triangle;
float3 barycentric_position; float3 barycentric_position;
}; };

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

@ -20,13 +20,13 @@
#ifndef ANTKEEPER_ECS_SNAP_COMPONENT_HPP #ifndef ANTKEEPER_ECS_SNAP_COMPONENT_HPP
#define ANTKEEPER_ECS_SNAP_COMPONENT_HPP #define ANTKEEPER_ECS_SNAP_COMPONENT_HPP
#include "geometry/ray.hpp"
#include "geom/ray.hpp"
namespace ecs { namespace ecs {
struct snap_component struct snap_component
{ {
::ray<float> ray;
geom::ray<float> ray;
bool relative; bool relative;
bool warp; bool warp;
bool autoremove; bool autoremove;

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

@ -19,7 +19,7 @@
#include "control-system.hpp" #include "control-system.hpp"
#include "input/control.hpp" #include "input/control.hpp"
#include "geometry/intersection.hpp"
#include "geom/intersection.hpp"
#include "animation/ease.hpp" #include "animation/ease.hpp"
#include "nest.hpp" #include "nest.hpp"
#include "math/math.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-buffer.hpp"
#include "rasterizer/vertex-attribute-type.hpp" #include "rasterizer/vertex-attribute-type.hpp"
#include "renderer/vertex-attributes.hpp" #include "renderer/vertex-attributes.hpp"
#include "geometry/mesh-functions.hpp"
#include "geom/mesh-functions.hpp"
#include <limits> #include <limits>
namespace ecs { 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.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.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_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(); stroke_model_instance->update_bounds();
p0 = stroke_start; p0 = stroke_start;
@ -313,9 +313,9 @@ std::optional> painting_system::cast_ray(const float3
float3 intersection; float3 intersection;
float3 surface_normal; 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(); float min_distance = std::numeric_limits<float>::infinity();
registry.view<transform_component, collision_component>().each( 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); math::transform<float> inverse_transform = math::inverse(collision_transform.local);
float3 origin = inverse_transform * untransformed_ray.origin; float3 origin = inverse_transform * untransformed_ray.origin;
float3 direction = math::normalize(math::conjugate(collision_transform.local.rotation) * untransformed_ray.direction); 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 // 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)) if (!std::get<0>(aabb_result))
{ {
return; 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(); float a = std::numeric_limits<float>::infinity();
float3 pick; float3 pick;
ray<float> snap_ray = snap.ray;
geom::ray<float> snap_ray = snap.ray;
if (snap.relative) if (snap.relative)
{ {
snap_ray.origin += snap_transform.local.translation; 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); math::transform<float> inverse_transform = math::inverse(collision_transform.local);
float3 origin = inverse_transform * snap_ray.origin; float3 origin = inverse_transform * snap_ray.origin;
float3 direction = math::normalize(math::conjugate(collision_transform.local.rotation) * snap_ray.direction); 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 // 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)) if (!std::get<0>(aabb_result))
{ {
return; return;

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

@ -23,14 +23,14 @@
#include "ecs/entity.hpp" #include "ecs/entity.hpp"
#include "renderer/model.hpp" #include "renderer/model.hpp"
#include "renderer/material.hpp" #include "renderer/material.hpp"
#include "geometry/mesh-functions.hpp"
#include "geom/mesh-functions.hpp"
#include "renderer/vertex-attributes.hpp" #include "renderer/vertex-attributes.hpp"
#include "rasterizer/vertex-attribute-type.hpp" #include "rasterizer/vertex-attribute-type.hpp"
#include "rasterizer/drawing-mode.hpp" #include "rasterizer/drawing-mode.hpp"
#include "rasterizer/vertex-buffer.hpp" #include "rasterizer/vertex-buffer.hpp"
#include "resources/resource-manager.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 "utility/fundamental-types.hpp"
#include <array> #include <array>
#include <limits> #include <limits>
@ -43,18 +43,18 @@ namespace ecs {
struct cube_tree struct cube_tree
{ {
public: public:
cube_tree(const aabb<float>& bounds, int max_depth);
cube_tree(const geom::aabb<float>& bounds, int max_depth);
~cube_tree(); ~cube_tree();
const bool is_leaf() const; 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. /// 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. /// 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. /// Counts then number of nodes in the octree.
std::size_t size() const; std::size_t size() const;
@ -64,18 +64,18 @@ public:
float distances[8]; float distances[8];
const int max_depth; const int max_depth;
const int depth; const int depth;
const aabb<float> bounds;
const geom::aabb<float> bounds;
private: 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(); 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(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), bounds(bounds),
max_depth(max_depth), max_depth(max_depth),
depth(depth) depth(depth)
@ -105,7 +105,7 @@ cube_tree::~cube_tree()
delete child; 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)) 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)) 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)) if (aabb_aabb_intersection(bounds, region))
{ {
@ -166,7 +166,7 @@ inline const bool cube_tree::is_leaf() const
return (children[0] == nullptr); 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; return bounds;
} }
@ -177,7 +177,7 @@ void cube_tree::subdivide()
for (int i = 0; i < 8; ++i) for (int i = 0; i < 8; ++i)
{ {
aabb<float> child_bounds;
geom::aabb<float> child_bounds;
for (int j = 0; j < 3; ++j) for (int j = 0; j < 3; ++j)
{ {
child_bounds.min_point[j] = std::min<float>(corners[i][j], center[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); cube_tree = new ecs::cube_tree(subterrain_bounds, octree_depth);
// Allocate mesh // Allocate mesh
subterrain_mesh = new mesh();
subterrain_mesh = new geom::mesh();
first_run = true; first_run = true;
} }
@ -302,7 +302,7 @@ void subterrain_system::set_scene(scene::collection* collection)
void subterrain_system::regenerate_subterrain_mesh() void subterrain_system::regenerate_subterrain_mesh()
{ {
delete subterrain_mesh; delete subterrain_mesh;
subterrain_mesh = new mesh();
subterrain_mesh = new geom::mesh();
subterrain_vertices.clear(); subterrain_vertices.clear();
subterrain_triangles.clear(); subterrain_triangles.clear();
subterrain_vertex_map.clear(); subterrain_vertex_map.clear();
@ -335,7 +335,7 @@ void subterrain_system::march(ecs::cube_tree* node)
} }
// Get node bounds // Get node bounds
const aabb<float>& bounds = node->get_bounds();
const geom::aabb<float>& bounds = node->get_bounds();
// Polygonize cube // Polygonize cube
float vertex_buffer[12 * 3]; float vertex_buffer[12 * 3];
@ -344,7 +344,7 @@ void subterrain_system::march(ecs::cube_tree* node)
std::uint_fast8_t triangle_count; std::uint_fast8_t triangle_count;
const float* corners = &node->corners[0][0]; const float* corners = &node->corners[0][0];
const float* distances = &node->distances[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 // Remap local vertex buffer indices (0-11) to mesh vertex indices
std::uint_fast32_t vertex_remap[12]; std::uint_fast32_t vertex_remap[12];
@ -393,22 +393,22 @@ void subterrain_system::regenerate_subterrain_model()
float* v = vertex_data; float* v = vertex_data;
for (std::size_t i = 0; i < subterrain_mesh->get_faces().size(); ++i) 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) 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}; 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 do
{ {
if (edge->face) if (edge->face)
@ -453,7 +453,7 @@ void subterrain_system::regenerate_subterrain_model()
void subterrain_system::dig(const float3& position, float radius) void subterrain_system::dig(const float3& position, float radius)
{ {
// Construct region containing the cavity sphere // Construct region containing the cavity sphere
aabb<float> region = {position, position};
geom::aabb<float> region = {position, position};
for (int i = 0; i < 3; ++i) for (int i = 0; i < 3; ++i)
{ {
region.min_point[i] -= radius + isosurface_resolution; 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 #define ANTKEEPER_ECS_SUBTERRAIN_SYSTEM_HPP
#include "entity-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/collection.hpp"
#include "scene/model-instance.hpp" #include "scene/model-instance.hpp"
#include "utility/fundamental-types.hpp" #include "utility/fundamental-types.hpp"
@ -102,7 +102,7 @@ private:
float distance(const ecs::cube_tree& node, const float3& sample) const; float distance(const ecs::cube_tree& node, const float3& sample) const;
resource_manager* resource_manager; resource_manager* resource_manager;
mesh* subterrain_mesh;
geom::mesh* subterrain_mesh;
model* subterrain_model; model* subterrain_model;
material* subterrain_inside_material; material* subterrain_inside_material;
material* subterrain_outside_material; material* subterrain_outside_material;
@ -110,7 +110,7 @@ private:
model_group* subterrain_outside_group; model_group* subterrain_outside_group;
int subterrain_model_vertex_size; int subterrain_model_vertex_size;
int subterrain_model_vertex_stride; int subterrain_model_vertex_stride;
aabb<float> subterrain_bounds;
geom::aabb<float> subterrain_bounds;
ecs::cube_tree* cube_tree; ecs::cube_tree* cube_tree;
std::vector<float3> subterrain_vertices; std::vector<float3> subterrain_vertices;
std::vector<std::array<std::uint_fast32_t, 3>> subterrain_triangles; 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 "ecs/components/transform-component.hpp"
#include "game/cartography/relief-map.hpp" #include "game/cartography/relief-map.hpp"
#include "renderer/model.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 "renderer/vertex-attributes.hpp"
#include "rasterizer/vertex-attribute-type.hpp" #include "rasterizer/vertex-attribute-type.hpp"
#include "rasterizer/drawing-mode.hpp" #include "rasterizer/drawing-mode.hpp"
@ -66,7 +66,7 @@ void terrain_system::set_patch_size(float size)
patch_size = 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 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); 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 // Allocate model
model* terrain_model = new model(); model* terrain_model = new model();
@ -113,13 +113,13 @@ model* terrain_system::generate_terrain_model(mesh* terrain_mesh)
return terrain_model; 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_x = (float)component.x * patch_size;
float offset_z = (float)component.z * 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_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); 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_width = bounds.max_point.x - bounds.min_point.x;
float bounds_height = bounds.max_point.y - bounds.min_point.y; float bounds_height = bounds.max_point.y - bounds.min_point.y;
float bounds_depth = bounds.max_point.z - bounds.min_point.z; 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()]; float3* vertex_normals = new float3[vertices.size()];
for (std::size_t i = 0; i < vertices.size(); ++i) 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}; 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 do
{ {
if (edge->face) 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()]; float2* vertex_texcoords = new float2[vertices.size()];
for (std::size_t i = 0; i < vertices.size(); ++i) 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].x = (vertex->position.x - bounds.min_point.x) / bounds_width;
vertex_texcoords[i].y = (vertex->position.z - bounds.min_point.z) / bounds_depth; 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; float* v = vertex_data;
for (int i = 0; i < triangle_count; ++i) 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) 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 float3& position = vertex->position;
const float2& texcoord = vertex_texcoords[vertex->index]; const float2& texcoord = vertex_texcoords[vertex->index];
const float3& normal = vertex_normals[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) 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); model* terrain_model = generate_terrain_model(terrain_mesh);
project_terrain_mesh(terrain_mesh, component); project_terrain_mesh(terrain_mesh, component);
update_terrain_model(terrain_model, terrain_mesh); 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 "entity-system.hpp"
#include "ecs/components/terrain-component.hpp" #include "ecs/components/terrain-component.hpp"
#include "ecs/entity.hpp" #include "ecs/entity.hpp"
#include "geom/mesh.hpp"
class terrain; class terrain;
class resource_manager; class resource_manager;
class mesh;
class model; class model;
class image; class image;
@ -45,10 +45,10 @@ public:
void set_patch_size(float size); void set_patch_size(float size);
private: 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_construct(ecs::registry& registry, ecs::entity entity, ecs::terrain_component& component);
void on_terrain_destroy(ecs::registry& registry, ecs::entity entity); 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 "game/events/tool-events.hpp"
#include "animation/orbit-cam.hpp" #include "animation/orbit-cam.hpp"
#include "animation/ease.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 "math/math.hpp"
#include "ecs/commands.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_far = camera->unproject({mouse_position[0], viewport[3] - mouse_position[1], 1.0f}, viewport);
float3 pick_origin = pick_near; float3 pick_origin = pick_near;
float3 pick_direction = math::normalize(pick_far - 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(); float a = std::numeric_limits<float>::infinity();
bool intersection = false; bool intersection = false;
@ -121,10 +121,10 @@ void tool_system::update(double t, double dt)
math::transform<float> inverse_transform = math::inverse(transform.local); math::transform<float> inverse_transform = math::inverse(transform.local);
float3 origin = inverse_transform * pick_origin; float3 origin = inverse_transform * pick_origin;
float3 direction = math::normalize(math::conjugate(transform.local.rotation) * pick_direction); 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 // 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)) if (!std::get<0>(aabb_result))
{ {
return; return;

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

@ -24,7 +24,7 @@
#include "scene/lod-group.hpp" #include "scene/lod-group.hpp"
#include "scene/collection.hpp" #include "scene/collection.hpp"
#include "renderer/material.hpp" #include "renderer/material.hpp"
#include "geometry/aabb.hpp"
#include "geom/aabb.hpp"
#include "utility/fundamental-types.hpp" #include "utility/fundamental-types.hpp"
#include <cmath> #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}; float3 translation = {vegetation_patch_x, 0.0f, vegetation_patch_z};
// Generate culling mask // 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.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->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); 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 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 // Allocate terrain mesh
mesh* mesh = new ::mesh();
geom::mesh* mesh = new geom::mesh();
// Determine vertex count and placement // Determine vertex count and placement
std::size_t columns = static_cast<std::size_t>(std::pow(2, subdivisions)); 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 // 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()) if (auto it = edge_map.find({start->index, end->index}); it != edge_map.end())
{ {
edge = it->second; edge = it->second;
@ -75,15 +75,15 @@ mesh* map_elevation(const std::function& function, float sc
}; };
// Connect vertices with edges and faces // 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 i = 0; i < rows; ++i)
{ {
for (std::size_t j = 0; j < columns; ++j) 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)) 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 // a---c
// | \ | // | \ |
@ -108,12 +108,12 @@ mesh* map_elevation(const std::function& function, float sc
} }
else 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 // a---c
// | / | // | / |

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

@ -20,7 +20,7 @@
#ifndef ANTKEEPER_RELIEF_MAP_HPP #ifndef ANTKEEPER_RELIEF_MAP_HPP
#define ANTKEEPER_RELIEF_MAP_HPP #define ANTKEEPER_RELIEF_MAP_HPP
#include "geometry/mesh.hpp"
#include "geom/mesh.hpp"
#include <functional> #include <functional>
namespace cart namespace cart
@ -32,7 +32,7 @@ namespace cart
* @param function Function which returns an elevation given UV coordinates on a unit plane. * @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. * @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 } // namespace cart

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

@ -24,7 +24,7 @@
#include "resources/string-table.hpp" #include "resources/string-table.hpp"
#include "ecs/entity.hpp" #include "ecs/entity.hpp"
#include "ecs/registry.hpp" #include "ecs/registry.hpp"
#include "geometry/aabb.hpp"
#include "geom/aabb.hpp"
#include <optional> #include <optional>
#include <entt/entt.hpp> #include <entt/entt.hpp>
#include <fstream> #include <fstream>
@ -193,7 +193,7 @@ struct game_context
scene::billboard* splash_billboard; scene::billboard* splash_billboard;
scene::spotlight* lens_spotlight; scene::spotlight* lens_spotlight;
scene::spotlight* flashlight_spotlight; scene::spotlight* flashlight_spotlight;
aabb<float> no_cull;
geom::aabb<float> no_cull;
// Animation // Animation
timeline* timeline; 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/>. * 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 "bounding-volume.hpp"
#include "sphere.hpp" #include "sphere.hpp"
#include "math/math.hpp" #include "math/math.hpp"
#include <limits> #include <limits>
namespace geom {
template <class T> template <class T>
struct aabb: public bounding_volume<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) for (std::size_t i = 0; i < 8; ++i)
{ {
vector_type corner = a.corner(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) 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/>. * 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 "math/math.hpp"
#include <stdexcept> #include <stdexcept>
using math::vector;
namespace geom {
template <class T> template <class T>
struct sphere; struct sphere;
@ -63,7 +63,7 @@ public:
virtual bool contains(const aabb<T>& aabb) const = 0; virtual bool contains(const aabb<T>& aabb) const = 0;
/// Tests whether this bounding volume contains a point. /// 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. /// Tests for intersection between this bounding volume and another bounding volume.
bool intersects(const bounding_volume& volume) const; 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/>. * 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 "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 <cstdlib>
#include <vector> #include <vector>
namespace geom {
/** /**
* A plane-bounded convex hull. * 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 intersects(const aabb<T>& aabb) const;
virtual bool contains(const sphere<T>& sphere) const; virtual bool contains(const sphere<T>& sphere) const;
virtual bool contains(const aabb<T>& aabb) 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> template <class T>
@ -81,7 +83,7 @@ bool convex_hull::intersects(const sphere& sphere) const
template <class T> template <class T>
bool convex_hull<T>::intersects(const aabb<T>& aabb) const 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) for (const plane<T>& plane: planes)
{ {
pv.x = (plane.normal.x > T(0)) ? aabb.max_point.x : aabb.min_point.x; 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> template <class T>
bool convex_hull<T>::contains(const aabb<T>& aabb) const 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) for (const plane<T>& plane: planes)
{ {
@ -126,7 +128,7 @@ bool convex_hull::contains(const aabb& aabb) const
} }
template <class T> 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) for (const plane<T>& plane: planes)
if (plane.signed_distance(point) < T(0)) if (plane.signed_distance(point) < T(0))
@ -135,5 +137,7 @@ bool convex_hull::contains(const vector& point) const
return true; 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 "csg.hpp"
#include <tuple> #include <tuple>
namespace geom {
namespace csg { namespace csg {
enum class polygon_classification enum class polygon_classification
@ -112,4 +113,4 @@ bsp_tree::~bsp_tree()
} }
} // namespace csg } // 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/>. * 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 "utility/fundamental-types.hpp"
#include <list> #include <list>
namespace geom {
/// Constructive solid geometry (CSG)
namespace csg { namespace csg {
struct plane struct plane
@ -79,6 +82,7 @@ solid op_difference(const solid& a, const solid& b);
solid op_intersect(const solid& a, const solid& b); solid op_intersect(const solid& a, const solid& b);
} // namespace csg } // 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 "intersection.hpp"
#include <limits> #include <limits>
namespace geom {
std::tuple<bool, float> ray_plane_intersection(const ray<float>& ray, const plane<float>& plane) std::tuple<bool, float> ray_plane_intersection(const ray<float>& ray, const plane<float>& plane)
{ {
float denom = math::dot(ray.direction, plane.normal); 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)); 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/>. * 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 "utility/fundamental-types.hpp"
#include <tuple> #include <tuple>
namespace geom {
/** /**
* Tests for intersection between a ray and a plane. * 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); 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 "marching-cubes.hpp"
#include <cmath> #include <cmath>
namespace geom {
namespace mc { namespace mc {
static constexpr std::uint_fast8_t vertex_table[12][2] = 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 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/>. * 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> #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 { namespace mc {
/** /**
@ -53,6 +53,7 @@ constexpr float unit_cube[8][3] =
}; };
} // namespace mc } // 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/>. * 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> #include <bitset>
namespace geom {
mesh_accelerator::mesh_accelerator() mesh_accelerator::mesh_accelerator()
{} {}
@ -90,7 +92,7 @@ std::optional mesh_accelerator::query_neares
return std::nullopt; 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 // Get node bounds
const aabb<float> node_bounds = get_node_bounds(node); 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); 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/>. * 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 "utility/fundamental-types.hpp"
#include <list> #include <list>
#include <optional> #include <optional>
#include <unordered_map> #include <unordered_map>
namespace geom {
/** /**
* Acceleration structure for querying mesh geometry. * Acceleration structure for querying mesh geometry.
*/ */
@ -38,7 +40,7 @@ public:
struct ray_query_result struct ray_query_result
{ {
float t; float t;
::mesh::face* face;
geom::mesh::face* face;
}; };
mesh_accelerator(); mesh_accelerator();
@ -59,7 +61,7 @@ public:
private: private:
aabb<float> get_node_bounds(octree32::node_type node) const; 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 /// Returns the max-depth node in which the point is located
octree32::node_type find_node(const float3& point) const; 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; 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 "math/math.hpp"
#include <unordered_map> #include <unordered_map>
namespace geom {
struct edge_hasher struct edge_hasher
{ {
std::size_t operator()(const std::array<std::size_t, 2>& v) const noexcept 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) for (const auto& vertex: vertices)
mesh.add_vertex(vertex); 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(); 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) for (const auto& triangle: triangles)
{ {
::mesh::vertex* triangle_vertices[3] =
geom::mesh::vertex* triangle_vertices[3] =
{ {
mesh_vertices[triangle[0]], mesh_vertices[triangle[0]],
mesh_vertices[triangle[1]], 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) 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()) 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}; 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/>. * 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 "utility/fundamental-types.hpp"
#include <array> #include <array>
#include <vector> #include <vector>
namespace geom {
/** /**
* Creates a triangle mesh from a list of vertices and indices. * 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); void calculate_vertex_tangents(float4* tangents, const float2* texcoords, const float3* normals, const mesh& mesh);
/** /**
* Calculates the AABB bounds of a mesh. * Calculates the AABB bounds of a mesh.
*/ */
aabb<float> calculate_bounds(const mesh& 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 "mesh.hpp"
#include <stdexcept> #include <stdexcept>
namespace geom {
mesh::~mesh() mesh::~mesh()
{ {
// Deallocate vertices // Deallocate vertices
@ -330,3 +332,4 @@ bool mesh::make_adjacent(mesh::edge* in, mesh::edge* out)
return true; 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/>. * 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 <vector>
#include "utility/fundamental-types.hpp" #include "utility/fundamental-types.hpp"
namespace geom {
/** /**
* Half-edge mesh. * Half-edge mesh.
* *
@ -177,5 +179,7 @@ inline const std::vector& mesh::get_faces() const
return faces; 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" #include "morton.hpp"
namespace geom {
namespace morton { namespace morton {
std::uint32_t encode_2d(std::uint32_t x, std::uint32_t y) 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 morton
} // namespace geom

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

@ -17,15 +17,15 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef ANTKEEPER_MORTON_HPP
#define ANTKEEPER_MORTON_HPP
#ifndef ANTKEEPER_GEOM_MORTON_HPP
#define ANTKEEPER_GEOM_MORTON_HPP
#include <array> #include <array>
#include <cstdint> #include <cstdint>
/**
* Contains functions for encoding and decoding Morton location codes.
*/
namespace geom {
/// Functions which encode or decode Morton location codes.
namespace morton { namespace morton {
/// Encodes 2D coordinates as a 32-bit Morton location code. /// Encodes 2D coordinates as a 32-bit Morton location code.
@ -41,6 +41,7 @@ std::array decode_2d(std::uint32_t code);
std::array<uint32_t, 3> decode_3d(std::uint32_t code); std::array<uint32_t, 3> decode_3d(std::uint32_t code);
} // namespace morton } // namespace morton
} // namespace geom
#endif // ANTKEEPER_MORTON_HPP
#endif // ANTKEEPER_GEOM_MORTON_HPP

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

@ -17,8 +17,8 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef ANTKEEPER_OCTREE_HPP
#define ANTKEEPER_OCTREE_HPP
#ifndef ANTKEEPER_GEOM_OCTREE_HPP
#define ANTKEEPER_GEOM_OCTREE_HPP
#include <cstdint> #include <cstdint>
#include <limits> #include <limits>
@ -26,6 +26,8 @@
#include <unordered_set> #include <unordered_set>
#include <stack> #include <stack>
namespace geom {
/** /**
* A general purpose (hashed) linear octree. Nodes are integer identifiers and no other data is stored in the octree. * 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
} }
#endif // ANTKEEPER_OCTREE_HPP
} // namespace geom
#endif // ANTKEEPER_GEOM_OCTREE_HPP

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

@ -17,11 +17,13 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef ANTKEEPER_PLANE_HPP
#define ANTKEEPER_PLANE_HPP
#ifndef ANTKEEPER_GEOM_PLANE_HPP
#define ANTKEEPER_GEOM_PLANE_HPP
#include "math/math.hpp" #include "math/math.hpp"
namespace geom {
template <class T> template <class T>
struct plane 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)); 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

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

@ -17,15 +17,19 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef ANTKEEPER_PROJECTION_HPP
#define ANTKEEPER_PROJECTION_HPP
#ifndef ANTKEEPER_GEOM_PROJECTION_HPP
#define ANTKEEPER_GEOM_PROJECTION_HPP
#include "math/math.hpp" #include "math/math.hpp"
namespace geom {
template <class T> template <class T>
math::vector<T, 3> project_on_plane(const math::vector<T, 3>& v, const math::vector<T, 3>& p, const math::vector<T, 3>& n) math::vector<T, 3> project_on_plane(const math::vector<T, 3>& v, const math::vector<T, 3>& p, const math::vector<T, 3>& n)
{ {
return v - n * math::dot(v - p, n); return v - n * math::dot(v - p, n);
} }
#endif // ANTKEEPER_PROJECTION_HPP
} // namespace geom
#endif // ANTKEEPER_GEOM_PROJECTION_HPP

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

@ -17,11 +17,13 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef ANTKEEPER_RAY_HPP
#define ANTKEEPER_RAY_HPP
#ifndef ANTKEEPER_GEOM_RAY_HPP
#define ANTKEEPER_GEOM_RAY_HPP
#include "math/math.hpp" #include "math/math.hpp"
namespace geom {
template <class T> template <class T>
struct ray struct ray
{ {
@ -48,5 +50,7 @@ inline typename ray::vector_type ray::extrapolate(T distance) const
return origin + direction * distance; return origin + direction * distance;
} }
#endif // ANTKEEPER_RAY_HPP
} // namespace geom
#endif // ANTKEEPER_GEOM_RAY_HPP

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

@ -17,15 +17,15 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef ANTKEEPER_SDF_HPP
#define ANTKEEPER_SDF_HPP
#ifndef ANTKEEPER_GEOM_SDF_HPP
#define ANTKEEPER_GEOM_SDF_HPP
#include "utility/fundamental-types.hpp" #include "utility/fundamental-types.hpp"
#include <algorithm> #include <algorithm>
/**
* Contains signed distance functions.
*/
namespace geom {
/// Signed distance functions.
namespace sdf { namespace sdf {
inline float3 translate(const float3& sample, const float3& offset) inline float3 translate(const float3& sample, const float3& offset)
@ -66,6 +66,7 @@ inline float op_round(float d, float r)
} }
} // namespace sdf } // namespace sdf
} // namespace geom
#endif // ANTKEEPER_SDF_HPP
#endif // ANTKEEPER_GEOM_SDF_HPP

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

@ -17,14 +17,16 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/ */
#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 "math/math.hpp"
#include <algorithm> #include <algorithm>
namespace geom {
template <class T> template <class T>
struct sphere: public bounding_volume<T> struct sphere: public bounding_volume<T>
{ {
@ -107,5 +109,7 @@ bool sphere::contains(const vector_type& point) const
return (math::dot(d, d) <= radius * radius); return (math::dot(d, d) <= radius * radius);
} }
#endif // ANTKEEPER_SPHERE_HPP
} // namespace geom
#endif // ANTKEEPER_GEOM_SPHERE_HPP

src/geometry/view-frustum.hpp → src/geom/view-frustum.hpp View File

@ -17,13 +17,15 @@
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/ */
#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 "math/math.hpp"
#include <array> #include <array>
namespace geom {
template <class T> template <class T>
class view_frustum class view_frustum
{ {
@ -177,5 +179,7 @@ void view_frustum::recalculate_corners()
corners[7] = plane_type::intersection(get_far(), get_bottom(), get_right()); corners[7] = plane_type::intersection(get_far(), get_bottom(), get_right());
} }
#endif // ANTKEEPER_VIEW_FRUSTUM_HPP
} // namespace geom
#endif // ANTKEEPER_GEOM_VIEW_FRUSTUM_HPP

+ 1
- 1
src/nest.hpp View File

@ -20,7 +20,7 @@
#ifndef ANTKEEPER_NEST_HPP #ifndef ANTKEEPER_NEST_HPP
#define ANTKEEPER_NEST_HPP #define ANTKEEPER_NEST_HPP
#include "geometry/mesh.hpp"
#include "geom/mesh.hpp"
#include "utility/fundamental-types.hpp" #include "utility/fundamental-types.hpp"
#include <array> #include <array>
#include <vector> #include <vector>

+ 8
- 6
src/renderer/model.hpp View File

@ -22,7 +22,7 @@
#include "rasterizer/vertex-array.hpp" #include "rasterizer/vertex-array.hpp"
#include "rasterizer/vertex-buffer.hpp" #include "rasterizer/vertex-buffer.hpp"
#include "geometry/aabb.hpp"
#include "geom/aabb.hpp"
#include <map> #include <map>
#include <string> #include <string>
#include <vector> #include <vector>
@ -124,17 +124,19 @@ inline std::size_t model_group::get_index_count() const
class model class model
{ {
public: public:
typedef geom::aabb<float> aabb_type;
model(); model();
~model(); ~model();
void set_bounds(const aabb<float>& bounds);
void set_bounds(const aabb_type& bounds);
model_group* add_group(const std::string& name = std::string()); model_group* add_group(const std::string& name = std::string());
bool remove_group(const std::string& name); bool remove_group(const std::string& name);
bool remove_group(model_group* group); bool remove_group(model_group* group);
const aabb<float>& get_bounds() const;
const aabb_type& get_bounds() const;
const model_group* get_group(const std::string& name) const; const model_group* get_group(const std::string& name) const;
model_group* get_group(const std::string& name); model_group* get_group(const std::string& name);
@ -148,7 +150,7 @@ public:
vertex_buffer* get_vertex_buffer(); vertex_buffer* get_vertex_buffer();
private: private:
aabb<float> bounds;
aabb_type bounds;
std::vector<model_group*> groups; std::vector<model_group*> groups;
std::map<std::string, model_group*> group_map; std::map<std::string, model_group*> group_map;
vertex_array vao; vertex_array vao;
@ -156,12 +158,12 @@ private:
skeleton* skeleton; skeleton* skeleton;
}; };
inline void model::set_bounds(const aabb<float>& bounds)
inline void model::set_bounds(const aabb_type& bounds)
{ {
this->bounds = bounds; this->bounds = bounds;
} }
inline const aabb<float>& model::get_bounds() const
inline const typename model::aabb_type& model::get_bounds() const
{ {
return bounds; return bounds;
} }

+ 6
- 6
src/renderer/passes/shadow-map-pass.cpp View File

@ -29,8 +29,8 @@
#include "renderer/material-flags.hpp" #include "renderer/material-flags.hpp"
#include "scene/camera.hpp" #include "scene/camera.hpp"
#include "scene/light.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 "configuration.hpp"
#include "math/math.hpp" #include "math/math.hpp"
#include <cmath> #include <cmath>
@ -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); float4x4 subfrustum_projection = math::perspective_half_z(camera.get_fov(), camera.get_aspect_ratio(), subfrustum_near, subfrustum_far);
// Calculate view camera subfrustum // Calculate view camera subfrustum
view_frustum<float> subfrustum(subfrustum_projection * camera_view);
geom::view_frustum<float> subfrustum(subfrustum_projection * camera_view);
// Create AABB containing the view camera subfrustum corners // Create AABB containing the view camera subfrustum corners
const std::array<vector<float, 3>, 8>& subfrustum_corners = subfrustum.get_corners();
aabb<float> subfrustum_aabb = {subfrustum_corners[0], subfrustum_corners[0]};
const std::array<float3, 8>& subfrustum_corners = subfrustum.get_corners();
geom::aabb<float> subfrustum_aabb = {subfrustum_corners[0], subfrustum_corners[0]};
for (int j = 1; j < 8; ++j) for (int j = 1; j < 8; ++j)
{ {
for (int k = 0; k < 3; ++k) 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 // Transform subfrustum AABB into the light clip space
aabb<float> cropping_bounds = aabb<float>::transform(subfrustum_aabb, light_view_projection);
geom::aabb<float> cropping_bounds = geom::aabb<float>::transform(subfrustum_aabb, light_view_projection);
// Calculate scale // Calculate scale
float3 scale; float3 scale;

+ 4
- 4
src/renderer/render-context.hpp View File

@ -21,8 +21,8 @@
#define ANTKEEPER_RENDER_CONTEXT_HPP #define ANTKEEPER_RENDER_CONTEXT_HPP
#include "renderer/render-operation.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 "utility/fundamental-types.hpp"
#include "scene/camera.hpp" #include "scene/camera.hpp"
#include "scene/collection.hpp" #include "scene/collection.hpp"
@ -34,8 +34,8 @@ struct render_context
math::transform<float> camera_transform; math::transform<float> camera_transform;
float3 camera_forward; float3 camera_forward;
float3 camera_up; float3 camera_up;
const bounding_volume<float>* camera_culling_volume;
plane<float> clip_near;
const geom::bounding_volume<float>* camera_culling_volume;
geom::plane<float> clip_near;
const scene::collection* collection; const scene::collection* collection;
std::list<render_operation> operations; std::list<render_operation> operations;

+ 4
- 4
src/renderer/renderer.cpp View File

@ -28,7 +28,7 @@
#include "renderer/model.hpp" #include "renderer/model.hpp"
#include "rasterizer/drawing-mode.hpp" #include "rasterizer/drawing-mode.hpp"
#include "math/math.hpp" #include "math/math.hpp"
#include "geometry/projection.hpp"
#include "geom/projection.hpp"
#include "configuration.hpp" #include "configuration.hpp"
#include <functional> #include <functional>
#include <set> #include <set>
@ -137,7 +137,7 @@ void renderer::process_model_instance(render_context& context, const scene::mode
return; return;
// Get object culling volume // Get object culling volume
const bounding_volume<float>* object_culling_volume = model_instance->get_culling_mask();
const geom::bounding_volume<float>* object_culling_volume = model_instance->get_culling_mask();
if (!object_culling_volume) if (!object_culling_volume)
object_culling_volume = &model_instance->get_bounds(); 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 void renderer::process_billboard(render_context& context, const scene::billboard* billboard) const
{ {
// Get object culling volume // Get object culling volume
const bounding_volume<float>* object_culling_volume = billboard->get_culling_mask();
const geom::bounding_volume<float>* object_culling_volume = billboard->get_culling_mask();
if (!object_culling_volume) if (!object_culling_volume)
object_culling_volume = &billboard->get_bounds(); 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) else if (billboard->get_billboard_type() == scene::billboard_type::cylindrical)
{ {
const float3& alignment_axis = billboard->get_alignment_axis(); 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)); float3 right = math::normalize(math::cross(alignment_axis, look));
look = math::cross(right, alignment_axis); look = math::cross(right, alignment_axis);
float3 up = math::cross(look, right); float3 up = math::cross(look, right);

+ 1
- 1
src/resources/entity-archetype-loader.cpp View File

@ -67,7 +67,7 @@ static bool load_collision_component(archetype& archetype, resource_manager& res
std::string filename = parameters[1]; std::string filename = parameters[1];
collision_component component; collision_component component;
component.mesh = resource_manager.load<mesh>(filename);
component.mesh = resource_manager.load<geom::mesh>(filename);
if (!component.mesh) if (!component.mesh)
{ {
std::string message = std::string("load_collision_component(): Failed to load model \"") + filename + std::string("\""); std::string message = std::string("load_collision_component(): Failed to load model \"") + filename + std::string("\"");

+ 5
- 5
src/resources/mesh-loader.cpp View File

@ -18,15 +18,15 @@
*/ */
#include "resources/resource-loader.hpp" #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 "utility/fundamental-types.hpp"
#include <sstream> #include <sstream>
#include <stdexcept> #include <stdexcept>
#include <physfs.h> #include <physfs.h>
template <> template <>
mesh* resource_loader<mesh>::load(resource_manager* resource_manager, PHYSFS_File* file)
geom::mesh* resource_loader<geom::mesh>::load(resource_manager* resource_manager, PHYSFS_File* file)
{ {
std::string line; std::string line;
std::vector<float3> vertices; std::vector<float3> 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; return mesh;
} }

+ 1
- 1
src/resources/model-loader.cpp View File

@ -408,7 +408,7 @@ model* resource_loader::load(resource_manager* resource_manager, PHYSFS_F
} }
// Load bounds // Load bounds
aabb<float> bounds =
geom::aabb<float> bounds =
{ {
{std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()}, {std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()},
{-std::numeric_limits<float>::infinity(), -std::numeric_limits<float>::infinity(), -std::numeric_limits<float>::infinity()} {-std::numeric_limits<float>::infinity(), -std::numeric_limits<float>::infinity(), -std::numeric_limits<float>::infinity()}

+ 2
- 2
src/scene/billboard.cpp View File

@ -23,7 +23,7 @@
namespace scene { namespace scene {
const aabb<float> 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(): billboard::billboard():
bounds(untransformed_bounds), bounds(untransformed_bounds),
@ -63,7 +63,7 @@ void billboard::set_alignment_axis(const float3& axis)
void billboard::transformed() void billboard::transformed()
{ {
bounds = aabb<float>::transform(untransformed_bounds, get_transform());
bounds = aabb_type::transform(untransformed_bounds, get_transform());
} }
void billboard::update_tweens() void billboard::update_tweens()

+ 7
- 5
src/scene/billboard.hpp View File

@ -21,7 +21,7 @@
#define ANTKEEPER_SCENE_BILLBOARD_HPP #define ANTKEEPER_SCENE_BILLBOARD_HPP
#include "scene/object.hpp" #include "scene/object.hpp"
#include "geometry/aabb.hpp"
#include "geom/aabb.hpp"
#include "utility/fundamental-types.hpp" #include "utility/fundamental-types.hpp"
class material; class material;
@ -47,6 +47,8 @@ enum class billboard_type
class billboard: public object<billboard> class billboard: public object<billboard>
{ {
public: public:
typedef geom::aabb<float> aabb_type;
billboard(); billboard();
billboard(const billboard& other); billboard(const billboard& other);
billboard& operator=(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. /// 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); void set_alignment_axis(const float3& axis);
virtual const bounding_volume<float>& get_bounds() const;
virtual const bounding_volume_type& get_bounds() const;
material* get_material() const; material* get_material() const;
billboard_type get_billboard_type() const; billboard_type get_billboard_type() const;
@ -68,18 +70,18 @@ public:
virtual void update_tweens(); virtual void update_tweens();
private: private:
static const aabb<float> untransformed_bounds;
static const aabb_type untransformed_bounds;
virtual void transformed(); virtual void transformed();
aabb<float> bounds;
aabb_type bounds;
material* material; material* material;
billboard_type type; billboard_type type;
float3 alignment_axis; float3 alignment_axis;
}; };
inline const bounding_volume<float>& billboard::get_bounds() const
inline const typename object_base::bounding_volume_type& billboard::get_bounds() const
{ {
return bounds; return bounds;
} }

+ 8
- 6
src/scene/camera.hpp View File

@ -21,7 +21,7 @@
#define ANTKEEPER_SCENE_CAMERA_HPP #define ANTKEEPER_SCENE_CAMERA_HPP
#include "scene/object.hpp" #include "scene/object.hpp"
#include "geometry/view-frustum.hpp"
#include "geom/view-frustum.hpp"
#include "utility/fundamental-types.hpp" #include "utility/fundamental-types.hpp"
class compositor; class compositor;
@ -34,6 +34,8 @@ namespace scene {
class camera: public object<camera> class camera: public object<camera>
{ {
public: public:
typedef geom::view_frustum<float> view_frustum_type;
camera(); camera();
/** /**
@ -79,7 +81,7 @@ public:
void set_compositor(compositor* compositor); void set_compositor(compositor* compositor);
void set_composite_index(int index); void set_composite_index(int index);
virtual const bounding_volume<float>& get_bounds() const;
virtual const bounding_volume_type& get_bounds() const;
float is_orthographic() const; float is_orthographic() const;
float get_clip_left() const; float get_clip_left() const;
@ -101,7 +103,7 @@ public:
const float4x4& get_view_projection() const; const float4x4& get_view_projection() const;
/// Returns the camera's view frustum. /// Returns the camera's view frustum.
const view_frustum<float>& get_view_frustum() const;
const view_frustum_type& get_view_frustum() const;
const compositor* get_compositor() const; const compositor* get_compositor() const;
compositor* get_compositor(); compositor* get_compositor();
@ -139,10 +141,10 @@ private:
tween<float4x4> view; tween<float4x4> view;
tween<float4x4> projection; tween<float4x4> projection;
tween<float4x4> view_projection; tween<float4x4> view_projection;
view_frustum<float> view_frustum;
view_frustum_type view_frustum;
}; };
inline const bounding_volume<float>& camera::get_bounds() const
inline const typename object_base::bounding_volume_type& camera::get_bounds() const
{ {
return view_frustum.get_bounds(); return view_frustum.get_bounds();
} }
@ -207,7 +209,7 @@ inline const float4x4& camera::get_view_projection() const
return view_projection[1]; return view_projection[1];
} }
inline const view_frustum<float>& camera::get_view_frustum() const
inline const typename camera::view_frustum_type& camera::get_view_frustum() const
{ {
return view_frustum; return view_frustum;
} }

+ 1
- 1
src/scene/light.cpp View File

@ -52,7 +52,7 @@ void light::update_tweens()
void light::transformed() void light::transformed()
{ {
bounds = sphere<float>(get_translation(), 0.0f);
bounds = sphere_type(get_translation(), 0.0f);
} }
} // namespace scene } // namespace scene

+ 6
- 4
src/scene/light.hpp View File

@ -21,7 +21,7 @@
#define ANTKEEPER_SCENE_LIGHT_HPP #define ANTKEEPER_SCENE_LIGHT_HPP
#include "scene/object.hpp" #include "scene/object.hpp"
#include "geometry/sphere.hpp"
#include "geom/sphere.hpp"
#include "utility/fundamental-types.hpp" #include "utility/fundamental-types.hpp"
namespace scene { namespace scene {
@ -37,6 +37,8 @@ enum class light_type
class light: public object<light> class light: public object<light>
{ {
public: public:
typedef geom::sphere<float> sphere_type;
light(); light();
virtual light_type get_light_type() const = 0; virtual light_type get_light_type() const = 0;
@ -44,7 +46,7 @@ public:
void set_color(const float3& color); void set_color(const float3& color);
void set_intensity(float intensity); void set_intensity(float intensity);
virtual const bounding_volume<float>& get_bounds() const;
virtual const bounding_volume_type& get_bounds() const;
const float3& get_color() const; const float3& get_color() const;
float get_intensity() const; float get_intensity() const;
@ -63,10 +65,10 @@ private:
tween<float3> color; tween<float3> color;
tween<float> intensity; tween<float> intensity;
tween<float3> scaled_color; tween<float3> scaled_color;
sphere<float> bounds;
sphere_type bounds;
}; };
inline const bounding_volume<float>& light::get_bounds() const
inline const typename object_base::bounding_volume_type& light::get_bounds() const
{ {
return bounds; return bounds;
} }

+ 6
- 4
src/scene/lod-group.hpp View File

@ -21,7 +21,7 @@
#define ANTKEEPER_SCENE_LOD_GROUP_HPP #define ANTKEEPER_SCENE_LOD_GROUP_HPP
#include "scene/object.hpp" #include "scene/object.hpp"
#include "geometry/aabb.hpp"
#include "geom/aabb.hpp"
#include <list> #include <list>
#include <vector> #include <vector>
@ -32,6 +32,8 @@ class camera;
class lod_group: public object<lod_group> class lod_group: public object<lod_group>
{ {
public: public:
typedef geom::aabb<float> aabb_type;
/** /**
* Creates a LOD group. * Creates a LOD group.
* *
@ -80,7 +82,7 @@ public:
*/ */
void remove_objects(std::size_t level); void remove_objects(std::size_t level);
virtual const bounding_volume<float>& get_bounds() const;
virtual const bounding_volume_type& get_bounds() const;
/// Returns the number of detail levels in the group. /// Returns the number of detail levels in the group.
std::size_t get_level_count() const; std::size_t get_level_count() const;
@ -97,11 +99,11 @@ private:
void update_bounds(); void update_bounds();
virtual void transformed(); virtual void transformed();
aabb<float> bounds;
aabb_type bounds;
std::vector<std::list<object_base*>> levels; std::vector<std::list<object_base*>> levels;
}; };
inline const bounding_volume<float>& lod_group::get_bounds() const
inline const typename object_base::bounding_volume_type& lod_group::get_bounds() const
{ {
return bounds; return bounds;
} }

+ 1
- 1
src/scene/model-instance.cpp View File

@ -92,7 +92,7 @@ void model_instance::reset_materials()
void model_instance::update_bounds() void model_instance::update_bounds()
{ {
if (model) if (model)
bounds = aabb<float>::transform(model->get_bounds(), get_transform());
bounds = aabb_type::transform(model->get_bounds(), get_transform());
else else
bounds = {get_translation(), get_translation()}; bounds = {get_translation(), get_translation()};
} }

+ 6
- 4
src/scene/model-instance.hpp View File

@ -21,7 +21,7 @@
#define ANTKEEPER_SCENE_MODEL_INSTANCE_HPP #define ANTKEEPER_SCENE_MODEL_INSTANCE_HPP
#include "scene/object.hpp" #include "scene/object.hpp"
#include "geometry/aabb.hpp"
#include "geom/aabb.hpp"
#include <vector> #include <vector>
class material; class material;
@ -33,6 +33,8 @@ namespace scene {
class model_instance: public object<model_instance> class model_instance: public object<model_instance>
{ {
public: public:
typedef geom::aabb<float> aabb_type;
explicit model_instance(model* model); explicit model_instance(model* model);
model_instance(); model_instance();
model_instance(const model_instance& other); model_instance(const model_instance& other);
@ -63,7 +65,7 @@ public:
*/ */
void reset_materials(); void reset_materials();
virtual const bounding_volume<float>& get_bounds() const;
virtual const bounding_volume_type& get_bounds() const;
const model* get_model() const; const model* get_model() const;
model* get_model(); model* get_model();
@ -86,12 +88,12 @@ private:
model* model; model* model;
pose* pose; pose* pose;
std::vector<material*> materials; std::vector<material*> materials;
aabb<float> bounds;
aabb_type bounds;
bool instanced; bool instanced;
std::size_t instance_count; std::size_t instance_count;
}; };
inline const bounding_volume<float>& model_instance::get_bounds() const
inline const typename object_base::bounding_volume_type& model_instance::get_bounds() const
{ {
return bounds; return bounds;
} }

+ 2
- 2
src/scene/object.hpp View File

@ -21,7 +21,7 @@
#define ANTKEEPER_SCENE_OBJECT_HPP #define ANTKEEPER_SCENE_OBJECT_HPP
#include "animation/tween.hpp" #include "animation/tween.hpp"
#include "geometry/bounding-volume.hpp"
#include "geom/bounding-volume.hpp"
#include "math/vector-type.hpp" #include "math/vector-type.hpp"
#include "math/quaternion-type.hpp" #include "math/quaternion-type.hpp"
#include "math/transform-type.hpp" #include "math/transform-type.hpp"
@ -39,7 +39,7 @@ public:
typedef math::vector<float, 3> vector_type; typedef math::vector<float, 3> vector_type;
typedef math::quaternion<float> quaternion_type; typedef math::quaternion<float> quaternion_type;
typedef math::transform<float> transform_type; typedef math::transform<float> transform_type;
typedef bounding_volume<float> bounding_volume_type;
typedef geom::bounding_volume<float> bounding_volume_type;
/// Returns the type ID for this scene object type. /// Returns the type ID for this scene object type.
virtual const std::size_t get_object_type_id() const = 0; virtual const std::size_t get_object_type_id() const = 0;

Loading…
Cancel
Save