Browse Source

Integrate previously separate unpublished VMQ math library directly into Antkeeper source

master
C. J. Howard 1 year ago
parent
commit
0a5a7035d8
105 changed files with 4137 additions and 769 deletions
  1. +0
    -3
      CMakeLists.txt
  2. +37
    -57
      src/animation/ease.hpp
  3. +54
    -51
      src/application.cpp
  4. +1
    -0
      src/application.hpp
  5. +3
    -5
      src/camera-rig.cpp
  6. +10
    -7
      src/camera-rig.hpp
  7. +4
    -6
      src/configuration.hpp.in
  8. +1
    -2
      src/entity/components/cavity-component.hpp
  9. +1
    -2
      src/entity/components/locomotion-component.hpp
  10. +1
    -2
      src/entity/components/samara-component.hpp
  11. +2
    -2
      src/entity/components/transform-component.hpp
  12. +1
    -5
      src/entity/entity-commands.hpp
  13. +25
    -27
      src/geometry/aabb.hpp
  14. +2
    -3
      src/geometry/bounding-volume.hpp
  15. +9
    -9
      src/geometry/convex-hull.hpp
  16. +1
    -5
      src/geometry/csg.hpp
  17. +8
    -8
      src/geometry/intersection.cpp
  18. +5
    -9
      src/geometry/intersection.hpp
  19. +4
    -6
      src/geometry/mesh-accelerator.hpp
  20. +2
    -13
      src/geometry/mesh-functions.cpp
  21. +3
    -5
      src/geometry/mesh-functions.hpp
  22. +37
    -33
      src/geometry/plane.hpp
  23. +31
    -0
      src/geometry/projection.hpp
  24. +17
    -9
      src/geometry/ray.hpp
  25. +5
    -6
      src/geometry/sdf.hpp
  26. +18
    -19
      src/geometry/sphere.hpp
  27. +43
    -43
      src/geometry/view-frustum.hpp
  28. +0
    -75
      src/math.hpp
  29. +64
    -0
      src/math/angles.hpp
  30. +104
    -0
      src/math/constants.hpp
  31. +77
    -0
      src/math/interpolation.hpp
  32. +79
    -0
      src/math/math.hpp
  33. +795
    -0
      src/math/matrix-functions.hpp
  34. +100
    -0
      src/math/matrix-operators.hpp
  35. +54
    -0
      src/math/matrix-type.hpp
  36. +29
    -0
      src/math/operators.hpp
  37. +443
    -0
      src/math/quaternion-functions.hpp
  38. +111
    -0
      src/math/quaternion-operators.hpp
  39. +48
    -0
      src/math/quaternion-type.hpp
  40. +55
    -0
      src/math/random.hpp
  41. +114
    -0
      src/math/stream-operators.hpp
  42. +110
    -0
      src/math/transform-functions.hpp
  43. +77
    -0
      src/math/transform-operators.hpp
  44. +54
    -0
      src/math/transform-type.hpp
  45. +627
    -0
      src/math/vector-functions.hpp
  46. +217
    -0
      src/math/vector-operators.hpp
  47. +131
    -0
      src/math/vector-type.hpp
  48. +13
    -14
      src/nest.cpp
  49. +1
    -4
      src/nest.hpp
  50. +17
    -24
      src/orbit-cam.cpp
  51. +7
    -7
      src/orbit-cam.hpp
  52. +4
    -4
      src/pheromone-matrix.cpp
  53. +1
    -2
      src/rasterizer/shader-input.hpp
  54. +6
    -9
      src/renderer/material-property.hpp
  55. +1
    -3
      src/renderer/passes/bloom-pass.cpp
  56. +1
    -3
      src/renderer/passes/bloom-pass.hpp
  57. +1
    -3
      src/renderer/passes/clear-pass.hpp
  58. +1
    -3
      src/renderer/passes/final-pass.cpp
  59. +1
    -3
      src/renderer/passes/final-pass.hpp
  60. +6
    -8
      src/renderer/passes/material-pass.cpp
  61. +1
    -0
      src/renderer/passes/material-pass.hpp
  62. +9
    -12
      src/renderer/passes/shadow-map-pass.cpp
  63. +1
    -5
      src/renderer/passes/shadow-map-pass.hpp
  64. +5
    -7
      src/renderer/passes/sky-pass.cpp
  65. +1
    -3
      src/renderer/passes/ui-pass.cpp
  66. +2
    -5
      src/renderer/render-context.hpp
  67. +1
    -2
      src/renderer/render-operation.hpp
  68. +13
    -14
      src/renderer/renderer.cpp
  69. +1
    -3
      src/renderer/simple-render-pass.cpp
  70. +1
    -3
      src/renderer/simple-render-pass.hpp
  71. +1
    -0
      src/resources/material-loader.cpp
  72. +1
    -0
      src/resources/mesh-loader.cpp
  73. +1
    -3
      src/resources/model-loader.cpp
  74. +1
    -0
      src/scene/billboard.hpp
  75. +23
    -23
      src/scene/camera.cpp
  76. +1
    -0
      src/scene/camera.hpp
  77. +5
    -6
      src/scene/directional-light.cpp
  78. +1
    -3
      src/scene/directional-light.hpp
  79. +4
    -5
      src/scene/light.cpp
  80. +1
    -0
      src/scene/light.hpp
  81. +1
    -1
      src/scene/lod-group.cpp
  82. +2
    -5
      src/scene/point-light.cpp
  83. +1
    -0
      src/scene/point-light.hpp
  84. +9
    -8
      src/scene/scene-object.cpp
  85. +40
    -34
      src/scene/scene-object.hpp
  86. +8
    -10
      src/scene/spotlight.cpp
  87. +1
    -3
      src/scene/spotlight.hpp
  88. +23
    -25
      src/state/play-state.cpp
  89. +3
    -4
      src/systems/camera-system.cpp
  90. +1
    -2
      src/systems/camera-system.hpp
  91. +1
    -1
      src/systems/constraint-system.cpp
  92. +21
    -23
      src/systems/control-system.cpp
  93. +1
    -0
      src/systems/control-system.hpp
  94. +3
    -2
      src/systems/nest-system.cpp
  95. +3
    -2
      src/systems/placement-system.cpp
  96. +10
    -10
      src/systems/samara-system.cpp
  97. +6
    -8
      src/systems/subterrain-system.cpp
  98. +3
    -4
      src/systems/subterrain-system.hpp
  99. +3
    -3
      src/systems/terrain-system.cpp
  100. +10
    -12
      src/systems/tool-system.cpp

+ 0
- 3
CMakeLists.txt View File

@ -5,7 +5,6 @@ option(VERSION_STRING "Project version string" "0.0.0")
project(antkeeper VERSION ${VERSION_STRING} LANGUAGES CXX)
# Find dependency packages
find_package(vmq REQUIRED CONFIG)
find_package(dr_wav REQUIRED CONFIG)
find_package(stb REQUIRED CONFIG)
find_package(glad REQUIRED CONFIG)
@ -15,10 +14,8 @@ 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
vmq
dr_wav
stb
glad

+ 37
- 57
src/animation/ease.hpp View File

@ -51,9 +51,8 @@
#ifndef ANTKEEPER_EASE_HPP
#define ANTKEEPER_EASE_HPP
#include <vmq/vmq.hpp>
#include "math/math.hpp"
#include <cmath>
#include <type_traits>
/**
* Container for templated easing functions.
@ -62,7 +61,7 @@
*
* value_type operator+(const value_type&, const value_type&);
* value_type operator-(const value_type&, const value_type&);
* value_type operator*(const value_type&, scalar_type) const;
* value_type operator*(const value_type&, scalar_type);
*
* @tparam T Value type.
* @tparam S Scalar type.
@ -72,12 +71,6 @@ struct ease
{
typedef T value_type;
typedef S scalar_type;
/// Linearly interpolates between @p x and @p y.
static T linear(const T& x, const T& y, S a);
/// Logarithmically interpolates between @p x and @p y.
static T log(const T& x, const T& y, S a);
static T in_sine(const T& x, const T& y, S a);
static T out_sine(const T& x, const T& y, S a);
@ -120,101 +113,88 @@ struct ease
static T in_out_bounce(const T& x, const T& y, S a);
};
template <typename T, typename S>
inline T ease<T, S>::linear(const T& x, const T& y, S a)
{
return (y - x) * a + x;
}
template <typename T, typename S>
inline T ease<T, S>::log(const T& x, const T& y, S a)
{
//return std::exp(linear(std::log(x), std::log(y), a));
return x * std::pow(y / x, a);
}
template <typename T, typename S>
T ease<T, S>::in_sine(const T& x, const T& y, S a)
{
return linear(y, x, std::cos(a * vmq::half_pi<S>));
return math::lerp(y, x, std::cos(a * math::half_pi<S>));
}
template <typename T, typename S>
T ease<T, S>::out_sine(const T& x, const T& y, S a)
{
return linear(x, y, std::sin(a * vmq::half_pi<S>));
return math::lerp(x, y, std::sin(a * math::half_pi<S>));
}
template <typename T, typename S>
T ease<T, S>::in_out_sine(const T& x, const T& y, S a)
{
return linear(x, y, -(std::cos(a * vmq::pi<S>) - S(1)) * S(0.5));
return math::lerp(x, y, -(std::cos(a * math::pi<S>) - S(1)) * S(0.5));
}
template <typename T, typename S>
T ease<T, S>::in_quad(const T& x, const T& y, S a)
{
return linear(x, y, a * a);
return math::lerp(x, y, a * a);
}
template <typename T, typename S>
T ease<T, S>::out_quad(const T& x, const T& y, S a)
{
return linear(x, y, (S(2) - a) * a);
return math::lerp(x, y, (S(2) - a) * a);
}
template <typename T, typename S>
T ease<T, S>::in_out_quad(const T& x, const T& y, S a)
{
return linear(x, y, (a < S(0.5)) ? S(2) * a * a : -(S(2) * a * a - S(4) * a + S(1)));
return math::lerp(x, y, (a < S(0.5)) ? S(2) * a * a : -(S(2) * a * a - S(4) * a + S(1)));
}
template <typename T, typename S>
T ease<T, S>::in_cubic(const T& x, const T& y, S a)
{
return linear(x, y, a * a * a);
return math::lerp(x, y, a * a * a);
}
template <typename T, typename S>
T ease<T, S>::out_cubic(const T& x, const T& y, S a)
{
return linear(x, y, a * ((a - S(3)) * a + S(3)));
return math::lerp(x, y, a * ((a - S(3)) * a + S(3)));
}
template <typename T, typename S>
T ease<T, S>::in_out_cubic(const T& x, const T& y, S a)
{
return linear(x, y, (a < S(0.5)) ? S(4) * a * a * a : S(4) * a * a * a - S(12) * a * a + S(12) * a - 3);
return math::lerp(x, y, (a < S(0.5)) ? S(4) * a * a * a : S(4) * a * a * a - S(12) * a * a + S(12) * a - 3);
}
template <typename T, typename S>
T ease<T, S>::in_quart(const T& x, const T& y, S a)
{
return linear(x, y, a * a * a * a);
return math::lerp(x, y, a * a * a * a);
}
template <typename T, typename S>
T ease<T, S>::out_quart(const T& x, const T& y, S a)
{
return linear(x, y, a * (a * ((S(4) - a) * a - S(6)) + S(4)));
return math::lerp(x, y, a * (a * ((S(4) - a) * a - S(6)) + S(4)));
}
template <typename T, typename S>
T ease<T, S>::in_out_quart(const T& x, const T& y, S a)
{
return linear(x, y, (a < S(0.5)) ? S(8) * a * a * a * a : a * (a * ((S(32) - S(8) * a) * a - S(48)) + S(32)) - S(7));
return math::lerp(x, y, (a < S(0.5)) ? S(8) * a * a * a * a : a * (a * ((S(32) - S(8) * a) * a - S(48)) + S(32)) - S(7));
}
template <typename T, typename S>
T ease<T, S>::in_quint(const T& x, const T& y, S a)
{
return linear(x, y, a * a * a * a * a);
return math::lerp(x, y, a * a * a * a * a);
}
template <typename T, typename S>
T ease<T, S>::out_quint(const T& x, const T& y, S a)
{
return linear(x, y, a * (a * (a * ((a - S(5)) * a + S(10)) - S(10)) + S(5)));
return math::lerp(x, y, a * (a * (a * ((a - S(5)) * a + S(10)) - S(10)) + S(5)));
}
template <typename T, typename S>
@ -222,25 +202,25 @@ T ease::in_out_quint(const T& x, const T& y, S a)
{
if (a < S(0.5))
{
return linear(x, y, S(16) * a * a * a * a * a);
return math::lerp(x, y, S(16) * a * a * a * a * a);
}
else
{
a = S(2) * (S(1) - a);
return linear(x, y, S(0.5) * (S(2) - a * a * a * a * a));
return math::lerp(x, y, S(0.5) * (S(2) - a * a * a * a * a));
}
}
template <typename T, typename S>
T ease<T, S>::in_expo(const T& x, const T& y, S a)
{
return (a == S(0)) ? x : linear(x, y, std::pow(S(1024), a - S(1)));
return (a == S(0)) ? x : math::lerp(x, y, std::pow(S(1024), a - S(1)));
}
template <typename T, typename S>
T ease<T, S>::out_expo(const T& x, const T& y, S a)
{
return (a == S(1)) ? y : linear(y, x, std::pow(S(2), S(-10) * a));
return (a == S(1)) ? y : math::lerp(y, x, std::pow(S(2), S(-10) * a));
}
template <typename T, typename S>
@ -255,19 +235,19 @@ T ease::in_out_expo(const T& x, const T& y, S a)
return y;
}
return linear(x, y, (a < S(0.5)) ? std::pow(S(2), S(20) * a - S(11)) : S(1) - std::pow(S(2), S(9) - S(20) * a));
return math::lerp(x, y, (a < S(0.5)) ? std::pow(S(2), S(20) * a - S(11)) : S(1) - std::pow(S(2), S(9) - S(20) * a));
}
template <typename T, typename S>
T ease<T, S>::in_circ(const T& x, const T& y, S a)
{
return linear(y, x, std::sqrt(S(1) - a * a));
return math::lerp(y, x, std::sqrt(S(1) - a * a));
}
template <typename T, typename S>
T ease<T, S>::out_circ(const T& x, const T& y, S a)
{
return linear(x, y, std::sqrt(-(a - S(2)) * a));
return math::lerp(x, y, std::sqrt(-(a - S(2)) * a));
}
template <typename T, typename S>
@ -275,11 +255,11 @@ T ease::in_out_circ(const T& x, const T& y, S a)
{
if (a < S(0.5))
{
return linear(x, y, S(0.5) - S(0.5) * std::sqrt(S(1) - S(4) * a * a));
return math::lerp(x, y, S(0.5) - S(0.5) * std::sqrt(S(1) - S(4) * a * a));
}
else
{
return linear(x, y, S(0.5) * (std::sqrt(S(-4) * (a - S(2)) * a - S(3)) + S(1)));
return math::lerp(x, y, S(0.5) * (std::sqrt(S(-4) * (a - S(2)) * a - S(3)) + S(1)));
}
}
@ -287,7 +267,7 @@ template
T ease<T, S>::in_back(const T& x, const T& y, S a)
{
const S c = S(1.70158);
return linear(x, y, a * a * (a * c + a - c));
return math::lerp(x, y, a * a * (a * c + a - c));
}
template <typename T, typename S>
@ -295,7 +275,7 @@ T ease::out_back(const T& x, const T& y, S a)
{
const S c = S(1.70158);
a -= S(1);
return linear(x, y, a * a * (a * c + a + c) + S(1));
return math::lerp(x, y, a * a * (a * c + a + c) + S(1));
}
template <typename T, typename S>
@ -305,12 +285,12 @@ T ease::in_out_back(const T& x, const T& y, S a)
if (a < S(0.5))
{
return linear(x, y, a * a * (a * (S(4) * c + S(4)) - S(2) * c));
return math::lerp(x, y, a * a * (a * (S(4) * c + S(4)) - S(2) * c));
}
else
{
S b = S(1) - S(2) * a;
return linear(x, y, b * b * (a * c + a - c * S(0.5) - S(1)) + S(1));
return math::lerp(x, y, b * b * (a * c + a - c * S(0.5) - S(1)) + S(1));
}
}
@ -326,7 +306,7 @@ T ease::in_elastic(const T& x, const T& y, S a)
return y;
}
return linear(x, y, -std::pow(S(1024), a - S(1)) * std::sin(S(20.944) * (a - S(1.075))));
return math::lerp(x, y, -std::pow(S(1024), a - S(1)) * std::sin(S(20.944) * (a - S(1.075))));
}
template <typename T, typename S>
@ -341,7 +321,7 @@ T ease::out_elastic(const T& x, const T& y, S a)
return y;
}
return linear(x, y, std::pow(S(2), S(-10) * a) * std::sin(S(20.944) * (a - S(0.075))) + S(1));
return math::lerp(x, y, std::pow(S(2), S(-10) * a) * std::sin(S(20.944) * (a - S(0.075))) + S(1));
}
template <typename T, typename S>
@ -358,19 +338,19 @@ T ease::in_out_elastic(const T& x, const T& y, S a)
if (a < S(0.5))
{
return linear(x, y, std::pow(S(2), S(20) * a - S(11)) * std::sin(S(15.5334) - S(27.5293) * a));
return math::lerp(x, y, std::pow(S(2), S(20) * a - S(11)) * std::sin(S(15.5334) - S(27.5293) * a));
}
else
{
return linear(y, x, std::pow(2, S(9) - S(20) * a) * std::sin(S(15.5334) - S(27.5293) * a));
return math::lerp(y, x, std::pow(2, S(9) - S(20) * a) * std::sin(S(15.5334) - S(27.5293) * a));
}
}
template <typename T, typename S>
T ease<T, S>::in_bounce(const T& x, const T& y, S a)
{
return linear(x, y, S(1) - ease<S, S>::out_bounce(S(0), S(1), S(1) - a));
return math::lerp(x, y, S(1) - ease<S, S>::out_bounce(S(0), S(1), S(1) - a));
}
template <typename T, typename S>
@ -399,7 +379,7 @@ T ease::out_bounce(const T& x, const T& y, S a)
a = n * a * a + S(0.984375);
}
return linear(x, y, a);
return math::lerp(x, y, a);
}
template <typename T, typename S>
@ -407,11 +387,11 @@ T ease::in_out_bounce(const T& x, const T& y, S a)
{
if (a < S(0.5))
{
return linear(x, y, (S(1) - ease<S, S>::out_bounce(S(0), S(1), S(1) - S(2) * a)) * S(0.5));
return math::lerp(x, y, (S(1) - ease<S, S>::out_bounce(S(0), S(1), S(1) - S(2) * a)) * S(0.5));
}
else
{
return linear(x, y, (S(1) + ease<S, S>::out_bounce(S(0), S(1), S(2) * a - S(1))) * S(0.5));
return math::lerp(x, y, (S(1) + ease<S, S>::out_bounce(S(0), S(1), S(2) * a - S(1))) * S(0.5));
}
}

+ 54
- 51
src/application.cpp View File

@ -20,7 +20,6 @@
#include "application.hpp"
#include "configuration.hpp"
#include "state/application-states.hpp"
#include "math.hpp"
// STL
#include <cstdlib>
@ -42,6 +41,9 @@
#include "debug/ansi-codes.hpp"
#include "debug/console-commands.hpp"
// Math
#include "math/math.hpp"
// Resources
#include "resources/resource-manager.hpp"
@ -109,8 +111,7 @@
// Utilities
#include "utility/paths.hpp"
#include "utility/timestamp.hpp"
using namespace vmq::operators;
#include "utility/fundamental-types.hpp"
application::application(int argc, char** argv):
closed(false),
@ -177,7 +178,7 @@ application::application(int argc, char** argv):
// Load configuration
//load_config();
fullscreen = true;
vsync = false;
vsync = true;
// Parse command line options
parse_options(argc, argv);
@ -518,7 +519,7 @@ application::application(int argc, char** argv):
overworld_compositor.add_pass(final_pass);
// Setup overworld camera
overworld_camera.set_perspective(45.0f * vmq::pi<float> / 180.0f, (float)window_width / (float)window_height, 0.1f, 1000.0f);
overworld_camera.set_perspective(math::radians<float>(45.0f), (float)window_width / (float)window_height, 0.1f, 1000.0f);
overworld_camera.set_compositor(&overworld_compositor);
overworld_camera.set_composite_index(0);
overworld_camera.set_active(true);
@ -548,7 +549,7 @@ application::application(int argc, char** argv):
underworld_compositor.add_pass(underworld_final_pass);
// Setup underworld camera
underworld_camera.set_perspective(45.0f * vmq::pi<float> / 180.0f, (float)window_width / (float)window_height, 0.1f, 1000.0f);
underworld_camera.set_perspective(math::radians<float>(45.0f), (float)window_width / (float)window_height, 0.1f, 1000.0f);
underworld_camera.look_at({0, 50, 0}, {0, 0, 0}, {0, 0, -1});
underworld_camera.set_compositor(&underworld_compositor);
underworld_camera.set_composite_index(0);
@ -751,11 +752,11 @@ application::application(int argc, char** argv):
ecs::cavity_component cavity;
cavity.position =
{
frand(-r, r),
frand(-r * 2, r),
frand(-r, r)
math::random(-r, r),
math::random(-r * 2, r),
math::random(-r, r)
};
cavity.radius = frand(0.75f, 1.25f);
cavity.radius = math::random(0.75f, 1.25f);
ecs_registry.assign<ecs::cavity_component>(ecs_registry.create(), cavity);
});
@ -800,7 +801,7 @@ application::application(int argc, char** argv):
spotlight.set_color({1, 1, 1});
spotlight.set_intensity(1.0f);
spotlight.set_attenuation({1.0f, 0.09f, 0.032f});
spotlight.set_cutoff({vmq::radians(15.0f), vmq::radians(30.0f)});
spotlight.set_cutoff({math::radians(15.0f), math::radians(30.0f)});
spotlight.update_tweens();
spotlight.set_active(false);
@ -875,12 +876,9 @@ application::application(int argc, char** argv):
//model_instance* larva = new model_instance(resource_manager->load<model>("larva.obj"));
//underworld_scene.add_object(larva);
quaternion<float> flashlight_rotation = vmq::angle_axis(vmq::half_pi<float>, {0.0f, 1.0f, 0.0f});
model_instance* flashlight = new model_instance(resource_manager->load<model>("flashlight.obj"));
flashlight->set_rotation(flashlight_rotation);
underworld_scene.add_object(flashlight);
model_instance* flashlight_light_cone = new model_instance(resource_manager->load<model>("flashlight-light-cone.obj"));
flashlight_light_cone->set_rotation(flashlight_rotation);
underworld_scene.add_object(flashlight_light_cone);
control_system->set_flashlight(flashlight, flashlight_light_cone);
@ -921,7 +919,7 @@ application::application(int argc, char** argv):
animator->add_animation(radial_transition_outer->get_animation());
// Setup tweens
focal_point_tween.set_interpolator(ease<float3>::linear);
focal_point_tween.set_interpolator(math::lerp<float3, float>);
// Register CLI commands
cli.register_command("echo", cc::echo);
@ -974,7 +972,7 @@ int application::execute()
// Setup time tween
time[0] = time[1] = 0.0;
time.set_interpolator(ease<double>::linear);
time.set_interpolator(math::lerp<double, double>);
// Schedule frames until closed
while (!closed)
@ -1033,19 +1031,24 @@ void application::setup_fsm()
initial_state = &splash_state;
}
void application::load_config()
{
}
void application::parse_options(int argc, char** argv)
{
cxxopts::Options options("Antkeeper", "Ant colony simulation game");
options.add_options()
("q,quick-start", "Skips splash screen")
("c,continue", "Continues from last save")
("c,continue", "Continues from the last save")
("d,data", "Sets the data package path", cxxopts::value<std::string>())
("f,fullscreen", "Starts in fullscreen mode")
("n,new-game", "Starts a new game")
("q,quick-start", "Skips to the main menu")
("r,reset", "Restores all settings to default")
("f,fullscreen", "Starts in fullscreen mode")
("w,windowed", "Starts in windowed mode")
("v,vsync", "Enables or disables v-sync", cxxopts::value<int>())
("d,data", "Specifies the data package path", cxxopts::value<std::string>())
("w,windowed", "Starts in windowed mode")
;
logger.push_task("Parsing command line options");
@ -1054,29 +1057,23 @@ void application::parse_options(int argc, char** argv)
{
auto result = options.parse(argc, argv);
// --quick-start
if (result.count("quick-start"))
{
logger.log("Skipping splash screen");
initial_state = &play_state;
}
// --continue
if (result.count("continue"))
{
logger.log("Continuing from last save");
}
// --new-game
if (result.count("new-game"))
{
logger.log("Starting a new game");
}
// --reset
if (result.count("reset"))
// --data
if (result.count("data"))
{
logger.log("Restoring all settings to default");
data_package_path = result["data"].as<std::string>();
if (std::filesystem::path(data_package_path).is_relative())
{
data_package_path = data_path + data_package_path;
}
logger.log("Set alternative data package path \"" + data_package_path + "\"");
}
// --fullscreen
@ -1086,11 +1083,23 @@ void application::parse_options(int argc, char** argv)
fullscreen = true;
}
// --windowed
if (result.count("windowed"))
// --new-game
if (result.count("new-game"))
{
logger.log("Starting in windowed mode");
fullscreen = false;
logger.log("Starting a new game");
}
// --quick-start
if (result.count("quick-start"))
{
logger.log("Skipping splash screen");
initial_state = &play_state;
}
// --reset
if (result.count("reset"))
{
logger.log("Restoring all settings to default");
}
// --vsync
@ -1108,17 +1117,11 @@ void application::parse_options(int argc, char** argv)
}
}
// --data
if (result.count("data"))
// --windowed
if (result.count("windowed"))
{
data_package_path = result["data"].as<std::string>();
if (std::filesystem::path(data_package_path).is_relative())
{
data_package_path = data_path + data_package_path;
}
logger.log("Set alternative data package path \"" + data_package_path + "\"");
logger.log("Starting in windowed mode");
fullscreen = false;
}
}
catch (const std::exception& e)

+ 1
- 0
src/application.hpp View File

@ -188,6 +188,7 @@ public:
private:
void setup_fsm();
void load_config();
void parse_options(int argc, char** argv);

+ 3
- 5
src/camera-rig.cpp View File

@ -19,16 +19,15 @@
#include "orbit-cam.hpp"
#include "scene/camera.hpp"
#include "math/constants.hpp"
#include "configuration.hpp"
#include <algorithm>
#include <cmath>
using namespace vmq::operators;
camera_rig::camera_rig():
camera(nullptr),
translation{0.0f, 0.0f, 0.0f},
rotation(vmq::identity_quaternion<float>),
rotation(math::identity_quaternion<float>),
forward(global_forward),
right(global_right),
up(global_up)
@ -53,7 +52,7 @@ void camera_rig::set_translation(const float3& translation)
this->translation = translation;
}
void camera_rig::set_rotation(const vmq::quaternion<float>& rotation)
void camera_rig::set_rotation(const quaternion_type& rotation)
{
this->rotation = rotation;
@ -62,4 +61,3 @@ void camera_rig::set_rotation(const vmq::quaternion& rotation)
up = rotation * global_up;
right = rotation * global_right;
}

+ 10
- 7
src/camera-rig.hpp View File

@ -20,9 +20,9 @@
#ifndef ANTKEEPER_CAMERA_RIG_HPP
#define ANTKEEPER_CAMERA_RIG_HPP
#include <vmq/vmq.hpp>
using namespace vmq::types;
#include "math/quaternion-type.hpp"
#include "math/transform-type.hpp"
#include "utility/fundamental-types.hpp"
class camera;
@ -32,6 +32,9 @@ class camera;
class camera_rig
{
public:
typedef math::quaternion<float> quaternion_type;
typedef math::transform<float> transform_type;
camera_rig();
/**
@ -61,7 +64,7 @@ public:
/**
* Sets the rotation of the camera rig.
*/
void set_rotation(const vmq::quaternion<float>& rotation);
void set_rotation(const quaternion_type& rotation);
/**
* Returns the attached camera.
@ -72,7 +75,7 @@ public:
::camera* get_camera();
const float3& get_translation() const;
const vmq::quaternion<float>& get_rotation() const;
const quaternion_type& get_rotation() const;
const float3& get_forward() const;
const float3& get_right() const;
const float3& get_up() const;
@ -80,7 +83,7 @@ public:
private:
camera* camera;
float3 translation;
vmq::quaternion<float> rotation;
quaternion_type rotation;
float3 forward;
float3 right;
float3 up;
@ -101,7 +104,7 @@ inline const float3& camera_rig::get_translation() const
return translation;
}
inline const vmq::quaternion<float>& camera_rig::get_rotation() const
inline const typename camera_rig::quaternion_type& camera_rig::get_rotation() const
{
return rotation;
}

+ 4
- 6
src/configuration.hpp.in View File

@ -20,18 +20,16 @@
#ifndef ANTKEEPER_CONFIGURATION_HPP
#define ANTKEEPER_CONFIGURATION_HPP
#include <vmq/vmq.hpp>
using namespace vmq::types;
#include "math/vector-type.hpp"
#define ANTKEEPER_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
#define ANTKEEPER_VERSION_MINOR @PROJECT_VERSION_MINOR@
#define ANTKEEPER_VERSION_PATCH @PROJECT_VERSION_PATCH@
#define ANTKEEPER_VERSION_STRING "@PROJECT_VERSION@"
constexpr float3 global_forward = {0.0f, 0.0f, -1.0f};
constexpr float3 global_up = {0.0f, 1.0f, 0.0f};
constexpr float3 global_right = {1.0f, 0.0f, 0.0f};
constexpr math::vector<float, 3> global_forward = {0.0f, 0.0f, -1.0f};
constexpr math::vector<float, 3> global_up = {0.0f, 1.0f, 0.0f};
constexpr math::vector<float, 3> global_right = {1.0f, 0.0f, 0.0f};
#define MATERIAL_PASS_MAX_AMBIENT_LIGHT_COUNT 1
#define MATERIAL_PASS_MAX_POINT_LIGHT_COUNT 1

+ 1
- 2
src/entity/components/cavity-component.hpp View File

@ -20,8 +20,7 @@
#ifndef ANTKEEPER_ECS_CAVITY_COMPONENT_HPP
#define ANTKEEPER_ECS_CAVITY_COMPONENT_HPP
#include <vmq/vmq.hpp>
using namespace vmq::types;
#include "math/math.hpp"
namespace ecs {

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

@ -21,8 +21,7 @@
#define ANTKEEPER_ECS_PLACEMENT_COMPONENT_HPP
#include "geometry/mesh.hpp"
#include <vmq/vmq.hpp>
using namespace vmq::types;
#include "utility/fundamental-types.hpp"
namespace ecs {

+ 1
- 2
src/entity/components/samara-component.hpp View File

@ -20,8 +20,7 @@
#ifndef ANTKEEPER_ECS_SAMARA_COMPONENT_HPP
#define ANTKEEPER_ECS_SAMARA_COMPONENT_HPP
#include <vmq/vmq.hpp>
using namespace vmq::types;
#include "utility/fundamental-types.hpp"
namespace ecs {

+ 2
- 2
src/entity/components/transform-component.hpp View File

@ -20,13 +20,13 @@
#ifndef ANTKEEPER_ECS_TRANSFORM_COMPONENT_HPP
#define ANTKEEPER_ECS_TRANSFORM_COMPONENT_HPP
#include <vmq/vmq.hpp>
#include "math/math.hpp"
namespace ecs {
struct transform_component
{
vmq::transform<float> transform;
math::transform<float> transform;
bool warp;
};

+ 1
- 5
src/entity/entity-commands.hpp View File

@ -20,18 +20,14 @@
#ifndef ANTKEEPER_ECS_ENTITY_COMMANDS_HPP
#define ANTKEEPER_ECS_ENTITY_COMMANDS_HPP
#include "utility/fundamental-types.hpp"
#include <entt/entt.hpp>
#include <vmq/vmq.hpp>
using namespace vmq;
namespace ecs {
void move_to(entt::registry& registry, entt::entity entity, const float3& position);
void warp_to(entt::registry& registry, entt::entity entity, const float3& position);
void assign_render_layers(entt::registry& registry, entt::entity entity, unsigned int layers);
void bind_transform(entt::registry& registry, entt::entity entity, entt::entity target);
} // namespace ecs

+ 25
- 27
src/geometry/aabb.hpp View File

@ -22,20 +22,18 @@
#include "bounding-volume.hpp"
#include "sphere.hpp"
#include <vmq/vmq.hpp>
#include <array>
#include "math/math.hpp"
#include <limits>
using vmq::vector;
using vmq::matrix;
using vmq::transform;
using namespace vmq::operators;
template <class T>
struct aabb: public bounding_volume<T>
{
vector<T, 3> min_point;
vector<T, 3> max_point;
typedef math::vector<T, 3> vector_type;
typedef math::matrix<T, 4, 4> matrix_type;
typedef math::transform<T> transform_type;
vector_type min_point;
vector_type max_point;
/**
* Transforms an AABB.
@ -44,7 +42,7 @@ struct aabb: public bounding_volume
* @param t Transform by which the AABB should be transformed.
* @return Transformed AABB.
*/
static aabb transform(const aabb& a, const ::transform<T>& t);
static aabb transform(const aabb& a, const transform_type& t);
/**
* Transforms an AABB.
@ -53,9 +51,9 @@ struct aabb: public bounding_volume
* @param m Matrix by which the AABB should be transformed.
* @return Transformed AABB.
*/
static aabb transform(const aabb& a, const matrix<T, 4, 4>& m);
static aabb transform(const aabb& a, const matrix_type& m);
aabb(const vector<T, 3>& min_point, const vector<T, 3>& max_point);
aabb(const vector_type& min_point, const vector_type& max_point);
aabb();
virtual bounding_volume_type get_bounding_volume_type() const;
@ -63,7 +61,7 @@ struct aabb: 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 vector_type& point) const;
/**
* Returns the position of the specified corner.
@ -71,18 +69,18 @@ struct aabb: public bounding_volume
* @param index Index of a corner.
* @return Position of the specified corner.
*/
vector<T, 3> corner(int index) const noexcept;
vector_type corner(int index) const noexcept;
};
template <class T>
aabb<T> aabb<T>::transform(const aabb& a, const ::transform<T>& t)
aabb<T> aabb<T>::transform(const aabb& a, const transform_type& t)
{
vector<T, 3> min_point = {std::numeric_limits<T>::infinity(), std::numeric_limits<T>::infinity(), std::numeric_limits<T>::infinity()};
vector<T, 3> max_point = {-std::numeric_limits<T>::infinity(), -std::numeric_limits<T>::infinity(), -std::numeric_limits<T>::infinity()};
vector_type min_point = {std::numeric_limits<T>::infinity(), std::numeric_limits<T>::infinity(), std::numeric_limits<T>::infinity()};
vector_type max_point = {-std::numeric_limits<T>::infinity(), -std::numeric_limits<T>::infinity(), -std::numeric_limits<T>::infinity()};
for (std::size_t i = 0; i < 8; ++i)
{
vector<T, 3> transformed_corner = vmq::mul(t, a.corner(i));
vector_type transformed_corner = math::mul(t, a.corner(i));
for (std::size_t j = 0; j < 3; ++j)
{
@ -95,15 +93,15 @@ aabb aabb::transform(const aabb& a, const ::transform& t)
}
template <class T>
aabb<T> aabb<T>::transform(const aabb& a, const matrix<T, 4, 4>& m)
aabb<T> aabb<T>::transform(const aabb& a, const matrix_type& m)
{
vector<T, 3> min_point = {std::numeric_limits<T>::infinity(), std::numeric_limits<T>::infinity(), std::numeric_limits<T>::infinity()};
vector<T, 3> max_point = {-std::numeric_limits<T>::infinity(), -std::numeric_limits<T>::infinity(), -std::numeric_limits<T>::infinity()};
vector_type min_point = {std::numeric_limits<T>::infinity(), std::numeric_limits<T>::infinity(), std::numeric_limits<T>::infinity()};
vector_type max_point = {-std::numeric_limits<T>::infinity(), -std::numeric_limits<T>::infinity(), -std::numeric_limits<T>::infinity()};
for (std::size_t i = 0; i < 8; ++i)
{
vector<T, 3> corner = a.corner(i);
vector<T, 4> transformed_corner = vmq::mul(m, vector<T, 4>{corner.x, corner.y, corner.z, T(1)});
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)});
for (std::size_t j = 0; j < 3; ++j)
{
@ -116,7 +114,7 @@ aabb aabb::transform(const aabb& a, const matrix& m)
}
template <class T>
aabb<T>::aabb(const vector<T, 3>& min_point, const vector<T, 3>& max_point):
aabb<T>::aabb(const vector_type& min_point, const vector_type& max_point):
min_point(min_point),
max_point(max_point)
{}
@ -134,7 +132,7 @@ inline bounding_volume_type aabb::get_bounding_volume_type() const
template <class T>
bool aabb<T>::intersects(const sphere<T>& sphere) const
{
const vector<T, 3> radius_vector = {sphere.radius, sphere.radius, sphere.radius};
const vector_type radius_vector = {sphere.radius, sphere.radius, sphere.radius};
return aabb<T>(min_point - radius_vector, max_point + radius_vector).contains(sphere.center);
}
@ -175,7 +173,7 @@ bool aabb::contains(const aabb& aabb) const
}
template <class T>
bool aabb<T>::contains(const vector<T, 3>& point) const
bool aabb<T>::contains(const vector_type& point) const
{
if (point.x < min_point.x || point.x > max_point.x)
return false;
@ -187,7 +185,7 @@ bool aabb::contains(const vector& point) const
}
template <class T>
vector<T, 3> aabb<T>::corner(int index) const noexcept
typename aabb<T>::vector_type aabb<T>::corner(int index) const noexcept
{
return
{

+ 2
- 3
src/geometry/bounding-volume.hpp View File

@ -20,10 +20,10 @@
#ifndef ANTKEEPER_BOUNDING_VOLUME_HPP
#define ANTKEEPER_BOUNDING_VOLUME_HPP
#include "math/math.hpp"
#include <stdexcept>
#include <vmq/vmq.hpp>
using vmq::vector;
using math::vector;
template <class T>
struct sphere;
@ -91,4 +91,3 @@ bool bounding_volume::intersects(const bounding_volume& volume) const
}
#endif // ANTKEEPER_BOUNDING_VOLUME_HPP

+ 9
- 9
src/geometry/convex-hull.hpp View File

@ -20,12 +20,12 @@
#ifndef ANTKEEPER_CONVEX_HULL_HPP
#define ANTKEEPER_CONVEX_HULL_HPP
#include "bounding-volume.hpp"
#include "geometry/plane.hpp"
#include "geometry/sphere.hpp"
#include "geometry/aabb.hpp"
#include <cstdlib>
#include <vector>
#include "bounding-volume.hpp"
#include "plane.hpp"
#include "sphere.hpp"
#include "aabb.hpp"
/**
* A plane-bounded convex hull.
@ -73,7 +73,7 @@ template
bool convex_hull<T>::intersects(const sphere<T>& sphere) const
{
for (const plane<T>& plane: planes)
if (signed_distance(plane, sphere.center) < -sphere.radius)
if (plane.signed_distance(sphere.center) < -sphere.radius)
return false;
return true;
}
@ -87,7 +87,7 @@ bool convex_hull::intersects(const aabb& aabb) const
pv.x = (plane.normal.x > T(0)) ? aabb.max_point.x : aabb.min_point.x;
pv.y = (plane.normal.y > T(0)) ? aabb.max_point.y : aabb.min_point.y;
pv.z = (plane.normal.z > T(0)) ? aabb.max_point.z : aabb.min_point.z;
if (signed_distance(plane, pv) < T(0))
if (plane.signed_distance(pv) < T(0))
return false;
}
@ -98,7 +98,7 @@ template
bool convex_hull<T>::contains(const sphere<T>& sphere) const
{
for (const plane<T>& plane: planes)
if (signed_distance(plane, sphere.center) < sphere.radius)
if (plane.signed_distance(sphere.center) < sphere.radius)
return false;
return true;
}
@ -118,7 +118,7 @@ bool convex_hull::contains(const aabb& aabb) const
nv.y = (plane.normal.y < T(0)) ? aabb.max_point.y : aabb.min_point.y;
nv.z = (plane.normal.z < T(0)) ? aabb.max_point.z : aabb.min_point.z;
if (signed_distance(plane, pv) < T(0) || signed_distance(plane, nv) < T(0))
if (plane.signed_distance(pv) < T(0) || plane.signed_distance(nv) < T(0))
return false;
}
@ -129,7 +129,7 @@ template
bool convex_hull<T>::contains(const vector<T, 3>& point) const
{
for (const plane<T>& plane: planes)
if (signed_distance(plane, point) < T(0))
if (plane.signed_distance(point) < T(0))
return false;
return true;

+ 1
- 5
src/geometry/csg.hpp View File

@ -20,15 +20,11 @@
#ifndef ANTKEEPER_CSG_HPP
#define ANTKEEPER_CSG_HPP
#include "utility/fundamental-types.hpp"
#include <list>
#include <vmq/vmq.hpp>
namespace csg {
using vmq::float3;
using vmq::float4;
struct plane
{
float3 normal;

+ 8
- 8
src/geometry/intersection.cpp View File

@ -22,10 +22,10 @@
std::tuple<bool, float> ray_plane_intersection(const ray<float>& ray, const plane<float>& plane)
{
float denom = vmq::dot(ray.direction, plane.normal);
float denom = math::dot(ray.direction, plane.normal);
if (denom != 0.0f)
{
float t = -(vmq::dot(ray.origin, plane.normal) + plane.distance) / denom;
float t = -(math::dot(ray.origin, plane.normal) + plane.distance) / denom;
if (t >= 0.0f)
{
@ -43,8 +43,8 @@ std::tuple ray_triangle_intersection(const ray
float3 edge20 = c - a;
// Calculate determinant
float3 pv = vmq::cross(ray.direction, edge20);
float det = vmq::dot(edge10, pv);
float3 pv = math::cross(ray.direction, edge20);
float det = math::dot(edge10, pv);
if (!det)
{
@ -55,7 +55,7 @@ std::tuple ray_triangle_intersection(const ray
// Calculate u
float3 tv = ray.origin - a;
float u = vmq::dot(tv, pv) * inverse_det;
float u = math::dot(tv, pv) * inverse_det;
if (u < 0.0f || u > 1.0f)
{
@ -63,8 +63,8 @@ std::tuple ray_triangle_intersection(const ray
}
// Calculate v
float3 qv = vmq::cross(tv, edge10);
float v = vmq::dot(ray.direction, qv) * inverse_det;
float3 qv = math::cross(tv, edge10);
float v = math::dot(ray.direction, qv) * inverse_det;
if (v < 0.0f || u + v > 1.0f)
{
@ -72,7 +72,7 @@ std::tuple ray_triangle_intersection(const ray
}
// Calculate t
float t = vmq::dot(edge20, qv) * inverse_det;
float t = math::dot(edge20, qv) * inverse_det;
if (t > 0.0f)
{

+ 5
- 9
src/geometry/intersection.hpp View File

@ -20,16 +20,12 @@
#ifndef ANTKEEPER_INTERSECTION_HPP
#define ANTKEEPER_INTERSECTION_HPP
#include "geometry/aabb.hpp"
#include "geometry/mesh.hpp"
#include "geometry/plane.hpp"
#include "geometry/ray.hpp"
#include "utility/fundamental-types.hpp"
#include <tuple>
#include <vmq/vmq.hpp>
#include "aabb.hpp"
#include "mesh.hpp"
#include "plane.hpp"
#include "ray.hpp"
using namespace vmq::types;
using namespace vmq::operators;
/**
* Tests for intersection between a ray and a plane.

+ 4
- 6
src/geometry/mesh-accelerator.hpp View File

@ -20,16 +20,14 @@
#ifndef ANTKEEPER_MESH_ACCELERATOR_HPP
#define ANTKEEPER_MESH_ACCELERATOR_HPP
#include "mesh.hpp"
#include "geometry/mesh.hpp"
#include "geometry/octree.hpp"
#include "geometry/aabb.hpp"
#include "intersection.hpp"
#include "geometry/intersection.hpp"
#include "utility/fundamental-types.hpp"
#include <list>
#include <unordered_map>
#include <optional>
#include <vmq/vmq.hpp>
using namespace vmq::types;
using namespace vmq::operators;
#include <unordered_map>
/**
* Acceleration structure for querying mesh geometry.

+ 2
- 13
src/geometry/mesh-functions.cpp View File

@ -18,13 +18,8 @@
*/
#include "mesh-functions.hpp"
#include <vmq/vmq.hpp>
#include <stdexcept>
#include "math/math.hpp"
#include <unordered_map>
#include <map>
#include <iostream>
using namespace vmq::operators;
struct edge_hasher
{
@ -60,10 +55,6 @@ void create_triangle_mesh(mesh& mesh, const std::vector& vertices, const
if (auto it = edge_map.find({start->index, end->index}); it != edge_map.end())
{
/*
if (it->second->face)
std::cout << "THIS EDGE ALREADY HAS A FACE!\n" << std::endl;
*/
loop[j] = it->second;
}
else
@ -92,7 +83,7 @@ void calculate_face_normals(float* normals, const mesh& mesh)
const float3& b = reinterpret_cast<const float3&>(face.edge->next->vertex->position);
const float3& c = reinterpret_cast<const float3&>(face.edge->previous->vertex->position);
normal = vmq::normalize(vmq::cross(b - a, c - a));
normal = math::normalize(math::cross(b - a, c - a));
}
}
@ -118,5 +109,3 @@ aabb calculate_bounds(const mesh& mesh)
return aabb<float>{bounds_min, bounds_max};
}

+ 3
- 5
src/geometry/mesh-functions.hpp View File

@ -20,13 +20,11 @@
#ifndef ANTKEEPER_MESH_FUNCTIONS_HPP
#define ANTKEEPER_MESH_FUNCTIONS_HPP
#include "mesh.hpp"
#include <vmq/vmq.hpp>
#include "geometry/aabb.hpp"
#include "geometry/mesh.hpp"
#include "utility/fundamental-types.hpp"
#include <array>
#include <vector>
#include "geometry/aabb.hpp"
using namespace vmq::types;
/**
* Creates a triangle mesh from a list of vertices and indices.

+ 37
- 33
src/geometry/plane.hpp View File

@ -20,93 +20,97 @@
#ifndef ANTKEEPER_PLANE_HPP
#define ANTKEEPER_PLANE_HPP
#include <vmq/vmq.hpp>
using vmq::vector;
using namespace vmq::operators;
#include "math/math.hpp"
template <class T>
struct plane
{
vector<T, 3> normal;
typedef math::vector<T, 3> vector_type;
/// Plane normal vector.
vector_type normal;
/// Plane distance.
T distance;
/**
* Creates a plane given a normal vector and distance.
*/
plane(const vector<T, 3>& normal, T distance);
plane(const vector_type& normal, T distance);
/**
* Creates a plane given a normal vector and offset vector.
*/
plane(const vector<T, 3>& normal, const vector<T, 3>& offset);
plane(const vector_type& normal, const vector_type& offset);
/**
* Creates a plane given three points.
*/
plane(const vector<T, 3>& a, const vector<T, 3>& b, const vector<T, 3>& c);
plane(const vector_type& a, const vector_type& b, const vector_type& c);
/**
* Creates a plane given its coefficients.
*
* @param coefficients Vector containing the plane coefficients, A, B, C and D, as x, y, z, and w, respectively.
*/
plane(const vector<T, 4>& coefficients);
plane(const math::vector<T, 4>& coefficients);
/// Creates an uninitialized plane.
plane() = default;
/**