Index: ps/trunk/source/maths/FixedVector2D.h =================================================================== --- ps/trunk/source/maths/FixedVector2D.h +++ ps/trunk/source/maths/FixedVector2D.h @@ -204,6 +204,7 @@ /** * Compute the dot product of this vector with another. + * Likely to overflow if both vectors are large-ish (around the 200 range). */ fixed Dot(const CFixedVector2D& v) const { @@ -219,6 +220,16 @@ return ret; } + /** + * @return -1, 0 or 1 if this and @v face respectively opposite directions, perpendicular, or same directions. + */ + int RelativeOrientation(const CFixedVector2D& v) const + { + i64 x = MUL_I64_I32_I32(X.GetInternalValue(), v.X.GetInternalValue()); + i64 y = MUL_I64_I32_I32(Y.GetInternalValue(), v.Y.GetInternalValue()); + return x > -y ? 1 : x < -y ? -1 : 0; + } + CFixedVector2D Perpendicular() const { return CFixedVector2D(Y, -X); Index: ps/trunk/source/simulation2/components/CCmpUnitMotion.cpp =================================================================== --- ps/trunk/source/simulation2/components/CCmpUnitMotion.cpp +++ ps/trunk/source/simulation2/components/CCmpUnitMotion.cpp @@ -1149,7 +1149,7 @@ // Check if we anticipate the target to go through us, in which case we shouldn't anticipate // (or e.g. units fleeing might suddenly turn around towards their attacker). - if ((out - cmpPosition->GetPosition2D()).Dot(tempPos - cmpPosition->GetPosition2D()) >= fixed::Zero()) + if ((out - cmpPosition->GetPosition2D()).RelativeOrientation(tempPos - cmpPosition->GetPosition2D()) >= 0) out = tempPos; } } Index: ps/trunk/source/simulation2/helpers/Geometry.cpp =================================================================== --- ps/trunk/source/simulation2/helpers/Geometry.cpp +++ ps/trunk/source/simulation2/helpers/Geometry.cpp @@ -342,13 +342,13 @@ fixed hh = halfSize.Y; CFixedVector2D p = axis.Perpendicular(); - if (p.Dot((u.Multiply(hw) + v.Multiply(hh)) - a) <= fixed::Zero()) + if (p.RelativeOrientation(u.Multiply(hw) + v.Multiply(hh) - a) <= 0) return true; - if (p.Dot((u.Multiply(hw) - v.Multiply(hh)) - a) <= fixed::Zero()) + if (p.RelativeOrientation(u.Multiply(hw) - v.Multiply(hh) - a) <= 0) return true; - if (p.Dot((-u.Multiply(hw) - v.Multiply(hh)) - a) <= fixed::Zero()) + if (p.RelativeOrientation(-u.Multiply(hw) - v.Multiply(hh) - a) <= 0) return true; - if (p.Dot((-u.Multiply(hw) + v.Multiply(hh)) - a) <= fixed::Zero()) + if (p.RelativeOrientation(-u.Multiply(hw) + v.Multiply(hh) - a) <= 0) return true; return false;