diff options
| author | Ray <[email protected]> | 2023-07-04 16:58:43 +0200 |
|---|---|---|
| committer | Ray <[email protected]> | 2023-07-04 16:58:43 +0200 |
| commit | 225b4fb3e2503d97a53d3aa746ddac3648cfebd8 (patch) | |
| tree | 571160271eede2367cc55dfb0017d9632314a94e /src/raymath.h | |
| parent | dd2d64e05804e749d470a9d252cea48b8b1d7e17 (diff) | |
| download | raylib-225b4fb3e2503d97a53d3aa746ddac3648cfebd8.tar.gz raylib-225b4fb3e2503d97a53d3aa746ddac3648cfebd8.zip | |
REVIEWED: `Vector2Angle()`
Diffstat (limited to 'src/raymath.h')
| -rw-r--r-- | src/raymath.h | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/src/raymath.h b/src/raymath.h index 087410ef..d7ec1d25 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -316,15 +316,9 @@ RMAPI float Vector2Angle(Vector2 v1, Vector2 v2) { float result = 0.0f; - float dot = v1.x*v2.x + v1.y*v2.y; // Dot product - float dotClamp = (dot < -1.0f)? -1.0f : dot; // Clamp - if (dotClamp > 1.0f) dotClamp = 1.0f; - result = acosf(dotClamp); - - // Alternative implementation, more costly - //float v1Length = sqrtf((v1.x*v1.x) + (v1.y*v1.y)); - //float v2Length = sqrtf((v2.x*v2.x) + (v2.y*v2.y)); - //result = -acosf((v1.x*v2.x + v1.y*v2.y)/(v1Length*v2Length)); + float dot = v1.x*v2.x + v1.y*v2.y; + float det = v1.x*v2.y - v1.y*v2.x; + result = -atan2f(det, dot); return result; } |
