feat: 'lines' (cave-like structures/tunnels) (WIP)

This commit is contained in:
MihailRis
2024-10-08 02:32:45 +03:00
parent 8813d280dc
commit 116cbd61db
7 changed files with 176 additions and 33 deletions
+23
View File
@@ -4,7 +4,13 @@
#include <ctime>
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/glm.hpp>
#include <glm/gtx/norm.hpp>
namespace util {
constexpr inline float EPSILON = 1e-6f;
class PseudoRandom {
unsigned short seed;
public:
@@ -63,4 +69,21 @@ namespace util {
rand();
}
};
/// @brief Find nearest point on segment to given
/// @param a segment point A
/// @param b segment point B
/// @param point given point (may be anywhere)
/// @return nearest point on the segment to given point
inline glm::vec3 closest_point_on_segment(
glm::vec3 a, glm::vec3 b, const glm::vec3& point
) {
auto vec = b - a;
float da = glm::distance2(point, a);
float db = glm::distance2(point, b);
float len = glm::length2(vec);
float t = (((da - db) / len) * 0.5f + 0.5f);
t = std::min(1.0f, std::max(0.0f, t));
return a + vec * t;
}
}