diff options
| author | raysan5 <[email protected]> | 2021-09-27 13:57:06 +0200 |
|---|---|---|
| committer | raysan5 <[email protected]> | 2021-09-27 13:57:06 +0200 |
| commit | 18c92b3104db7bb9899cb1d541109dbe4dec5ee8 (patch) | |
| tree | 55d32489c61285143a3cd45c6801d0ebc69f1dae /src/raymath.h | |
| parent | dd7d65a6b42665049dd817d1ea59258dc8a618a0 (diff) | |
| download | raylib-18c92b3104db7bb9899cb1d541109dbe4dec5ee8.tar.gz raylib-18c92b3104db7bb9899cb1d541109dbe4dec5ee8.zip | |
ADDED: Vector3Angle()
Diffstat (limited to 'src/raymath.h')
| -rw-r--r-- | src/raymath.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/raymath.h b/src/raymath.h index 43e81135..79fd5480 100644 --- a/src/raymath.h +++ b/src/raymath.h @@ -470,6 +470,21 @@ RMDEF float Vector3Distance(Vector3 v1, Vector3 v2) return result; } +// Calculate angle between two vectors in XY and XZ +RMDEF Vector2 Vector3Angle(Vector3 v1, Vector3 v2) +{ + Vector2 result = { 0 }; + + float dx = v2.x - v1.x; + float dy = v2.y - v1.y; + float dz = v2.z - v1.z; + + result.x = atan2f(dx, dz); // Angle in XZ + result.y = atan2f(dy, sqrtf(dx*dx + dz*dz)); // Angle in XY + + return result; +} + // Negate provided vector (invert direction) RMDEF Vector3 Vector3Negate(Vector3 v) { |
