Skip to content

Commit

Permalink
UPBGE: Fix FuzzyZero for very small vectors. (#664)
Browse files Browse the repository at this point in the history
Previously FuzzyZero for vectors was comparing the squared length
of the vector, but as it is a squared length the value are even
more low for small values. To solve this issue the function should
compare the length directly but this is too expensive.
Instead the sum of all the absolute vector components and comparing
the sum to float epsilon.
  • Loading branch information
panzergame committed Jul 4, 2018
1 parent ba30dbb commit aac6b53
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion intern/mathfu/mathfu/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,12 @@ static inline T DotProductHelper(const Vector<T, 4>& v1,

template <class T, int d>
static inline bool FuzzyZeroHelper(const Vector<T, d>& v) {
return FuzzyZero(v.LengthSquared());
T abs = 0;
for (int i = 0; i < d; ++i) {
abs += std::abs(v[i]);
}

return FuzzyZero(abs);
}

/// @cond MATHFU_INTERNAL
Expand Down

0 comments on commit aac6b53

Please sign in to comment.