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

Ruslan Kabatsayev b7.10110111 at gmail.com
Mon Jul 23 14:51:49 CDT 2018


Hi,

Just curious, which cases does this fix? The ones when fabs(cos)>1 due
to rounding errors? Or is acos broken for arguments near but not
exceeding ±1?

Regards,
Ruslan

On 23/07/2018, Andrew Eikum <aeikum at codeweavers.com> wrote:
> Signed-off-by: Andrew Eikum <aeikum at codeweavers.com>
> ---
>
> v2: Remove old calculation, thanks Nikolay.
>
>  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..6ca79c1bbc 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(fabs(1 - cos) < 0.0001f){
> +		angle = 0;
> +	}else if(fabs(-1 - cos) < 0.0001f){
> +		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