mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-05 08:05:28 +02:00
Warn against zero-length vectors
This commit is contained in:
parent
3a140145ae
commit
2dd70f1fcd
1 changed files with 7 additions and 1 deletions
|
@ -294,7 +294,13 @@ glm::vec3 safeEulerAngles(const glm::quat& q) {
|
|||
|
||||
// Helper function returns the positive angle (in radians) between two 3D vectors
|
||||
float angleBetween(const glm::vec3& v1, const glm::vec3& v2) {
|
||||
float cosAngle = glm::dot(v1, v2) / (glm::length(v1) * glm::length(v2));
|
||||
float lengthFactor = glm::length(v1) * glm::length(v2);
|
||||
|
||||
if (lengthFactor < EPSILON) {
|
||||
qWarning() << "DANGER: don't supply zero-length vec3's as arguments";
|
||||
}
|
||||
|
||||
float cosAngle = glm::dot(v1, v2) / lengthFactor;
|
||||
// If v1 and v2 are colinear, then floating point rounding errors might cause
|
||||
// cosAngle to be slightly higher than 1 or slightly lower than -1
|
||||
// which is are values for which acos is not defined and result in a NaN
|
||||
|
|
Loading…
Reference in a new issue