diff -r f7dd937667a5 -r f99d52b1646b src/geometry.cpp --- a/src/geometry.cpp Fri Feb 28 19:24:33 2020 +0200 +++ b/src/geometry.cpp Sat Feb 29 23:43:38 2020 +0200 @@ -1,3 +1,4 @@ +#include #include "geometry.h" /** @@ -38,7 +39,7 @@ */ geom::Plane geom::planeFromTriangle(const geom::Triangle& triangle) { - return geom::Plane{triangle.points[0], normalVector(triangle)}; + return geom::Plane{normalVector(triangle), triangle.points[0]}; } /** @@ -53,3 +54,31 @@ triangle.points[1] - triangle.points[0], triangle.points[2] - triangle.points[0])); } + +/** + * @brief Extracts the scaling component of the specified matrix into a vector and returns both the scaling + * components as well as the unscaled matrix. + * @param matrix Matrix to compute + * @return scaling vector and unscaled matrix + */ +geom::ScalingExtract geom::extractScaling(const glm::mat4& matrix) +{ + geom::ScalingExtract result; + result.scaling = geom::scalingVector(matrix); + result.unscaled = glm::scale(matrix, 1.0f / result.scaling); + return result; +} + +/** + * @brief Computes the scaling vector, which contains the scaling of the specified matrix + * @param matrix + * @return scaling vector + */ +glm::vec3 geom::scalingVector(const glm::mat4 matrix) +{ + auto component = [](const glm::mat4& matrix, const int i) -> float + { + return std::hypot(std::hypot(matrix[i][0], matrix[i][1]), matrix[i][2]); + }; + return glm::vec3{component(matrix, 0), component(matrix, 1), component(matrix, 2)}; +}