[PATCH v3] dsound: Correctly calculate angle between vectors with equal and opposite directions

Andrew Eikum aeikum at codeweavers.com
Tue Jul 24 11:05:06 CDT 2018


Signed-off-by: Andrew Eikum <aeikum at codeweavers.com>
---

v3: With suggestion from Ruslan.

 dlls/dsound/sound3d.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/dlls/dsound/sound3d.c b/dlls/dsound/sound3d.c
index 03fd3d4678..118bb60456 100644
--- a/dlls/dsound/sound3d.c
+++ b/dlls/dsound/sound3d.c
@@ -111,7 +111,13 @@ static inline D3DVALUE AngleBetweenVectorsRad (const D3DVECTOR *a, const D3DVECT
 		return 0;
 
 	cos = product/(la*lb);
-	angle = acos(cos);
+	if(cos > 1.f){
+		angle = 0;
+	}else if(cos < -1.f){
+		angle = M_PI;
+	}else{
+		angle = acos(cos);
+	}
 	TRACE("angle between (%f,%f,%f) and (%f,%f,%f) = %f radians (%f degrees)\n",  a->x, a->y, a->z, b->x,
 	      b->y, b->z, angle, RadToDeg(angle));
 	return angle;	
-- 
2.18.0




More information about the wine-devel mailing list