Fixed functions Vector2Angle and Vector3Angle
This commit is contained in:
parent
f09a916587
commit
fcc3f1f2e0
|
|
@ -278,14 +278,10 @@ RMAPI float Vector2Distance(Vector2 v1, Vector2 v2)
|
|||
return result;
|
||||
}
|
||||
|
||||
// Calculate angle from two vectors in X-axis
|
||||
// Calculate angle from two vectors
|
||||
RMAPI float Vector2Angle(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
float result = atan2f(v2.y, v2.x) - atan2f(v1.y, v1.x);
|
||||
|
||||
if (result < 0) result += 2 * PI;
|
||||
|
||||
return result;
|
||||
return atan2f(v2.y, v2.x) - atan2f(v1.y, v1.x);
|
||||
}
|
||||
|
||||
// Scale vector (multiply by value)
|
||||
|
|
@ -532,19 +528,10 @@ RMAPI float Vector3Distance(Vector3 v1, Vector3 v2)
|
|||
return result;
|
||||
}
|
||||
|
||||
// Calculate angle between two vectors in XY and XZ
|
||||
RMAPI Vector2 Vector3Angle(Vector3 v1, Vector3 v2)
|
||||
// Calculate between two vectors
|
||||
RMAPI float 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;
|
||||
return atan2f(Vector3Length(Vector3CrossProduct(v1, v2)), Vector3DotProduct(v1, v2));
|
||||
}
|
||||
|
||||
// Negate provided vector (invert direction)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user