X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmodel%2Fgeometry.hpp;fp=src%2Fmodel%2Fgeometry.hpp;h=0000000000000000000000000000000000000000;hb=4fbf5a3c1b0e530706023f5fc4be2f68d30ea645;hp=5065124dad69a9974738a12035b8d4e1c18f4182;hpb=0d580658b896dfec07466c31ae4847455724ee95;p=blank.git diff --git a/src/model/geometry.hpp b/src/model/geometry.hpp deleted file mode 100644 index 5065124..0000000 --- a/src/model/geometry.hpp +++ /dev/null @@ -1,102 +0,0 @@ -#ifndef BLANK_MODEL_GEOMETRY_H_ -#define BLANK_MODEL_GEOMETRY_H_ - -#include -#include -#include - - -namespace blank { - -constexpr float PI = 3.141592653589793238462643383279502884; -constexpr float PI_0p25 = PI * 0.25f; -constexpr float PI_0p5 = PI * 0.5f; -constexpr float PI_1p5 = PI * 1.5f; -constexpr float PI_2p0 = PI * 2.0f; - -constexpr float PI_inv = 1.0f / PI; -constexpr float PI_0p5_inv = 1.0f / PI_0p5; - -constexpr float DEG_RAD_FACTOR = PI / 180.0f; -constexpr float RAD_DEG_FACTOR = 180.0f / PI; - -constexpr float deg2rad(float d) noexcept { - return d * DEG_RAD_FACTOR; -} - -constexpr float rad2deg(float r) noexcept { - return r * RAD_DEG_FACTOR; -} - - -inline float length_squared(const glm::vec3 &v) noexcept { - return dot(v, v); -} - -inline float distance_squared(const glm::vec3 &a, const glm::vec3 &b) noexcept { - return length_squared(a - b); -} - - -template -inline bool iszero(const T &v) noexcept { - return length_squared(v) < std::numeric_limits::epsilon(); -} - - -template -T manhattan_distance(const glm::tvec3 &a, const glm::tvec3 &b) noexcept { - glm::tvec3 diff(abs(a - b)); - return diff.x + diff.y + diff.z; -} - -template -T manhattan_radius(const glm::tvec3 &v) noexcept { - glm::tvec3 a(abs(v)); - return std::max(a.x, std::max(a.y, a.z)); -} - - -glm::mat3 find_rotation(const glm::vec3 &a, const glm::vec3 &b) noexcept; - - -struct AABB { - glm::vec3 min; - glm::vec3 max; - - void Adjust() noexcept { - if (max.x < min.x) std::swap(max.x, min.x); - if (max.y < min.y) std::swap(max.y, min.y); - if (max.z < min.z) std::swap(max.z, min.z); - } - - glm::vec3 Center() const noexcept { - return min + (max - min) * 0.5f; - } -}; - -struct Ray { - glm::vec3 orig; - glm::vec3 dir; -}; - -bool Intersection( - const Ray &, - const AABB &, - const glm::mat4 &M, - float *dist = nullptr, - glm::vec3 *normal = nullptr) noexcept; - -bool Intersection( - const AABB &a_box, - const glm::mat4 &a_m, - const AABB &b_box, - const glm::mat4 &b_m, - float &depth, - glm::vec3 &normal) noexcept; - -bool CullTest(const AABB &box, const glm::mat4 &MVP) noexcept; - -} - -#endif