51 return glm::normalize( |
52 return glm::normalize( |
52 glm::cross( |
53 glm::cross( |
53 triangle.points[1] - triangle.points[0], |
54 triangle.points[1] - triangle.points[0], |
54 triangle.points[2] - triangle.points[0])); |
55 triangle.points[2] - triangle.points[0])); |
55 } |
56 } |
|
57 |
|
58 /** |
|
59 * @brief Extracts the scaling component of the specified matrix into a vector and returns both the scaling |
|
60 * components as well as the unscaled matrix. |
|
61 * @param matrix Matrix to compute |
|
62 * @return scaling vector and unscaled matrix |
|
63 */ |
|
64 geom::ScalingExtract geom::extractScaling(const glm::mat4& matrix) |
|
65 { |
|
66 geom::ScalingExtract result; |
|
67 result.scaling = geom::scalingVector(matrix); |
|
68 result.unscaled = glm::scale(matrix, 1.0f / result.scaling); |
|
69 return result; |
|
70 } |
|
71 |
|
72 /** |
|
73 * @brief Computes the scaling vector, which contains the scaling of the specified matrix |
|
74 * @param matrix |
|
75 * @return scaling vector |
|
76 */ |
|
77 glm::vec3 geom::scalingVector(const glm::mat4 matrix) |
|
78 { |
|
79 auto component = [](const glm::mat4& matrix, const int i) -> float |
|
80 { |
|
81 return std::hypot(std::hypot(matrix[i][0], matrix[i][1]), matrix[i][2]); |
|
82 }; |
|
83 return glm::vec3{component(matrix, 0), component(matrix, 1), component(matrix, 2)}; |
|
84 } |