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