Skip to content

Commit

Permalink
slightly optimize Vector3Normalize (#2982)
Browse files Browse the repository at this point in the history
  • Loading branch information
RicoP authored Mar 22, 2023
1 parent e55bdd5 commit 8b8eddc
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/raymath.h
Original file line number Diff line number Diff line change
Expand Up @@ -703,12 +703,14 @@ RMAPI Vector3 Vector3Normalize(Vector3 v)
Vector3 result = v;

float length = sqrtf(v.x*v.x + v.y*v.y + v.z*v.z);
if (length == 0.0f) length = 1.0f;
float ilength = 1.0f/length;
if (length != 0.0f)
{
float ilength = 1.0f/length;

result.x *= ilength;
result.y *= ilength;
result.z *= ilength;
result.x *= ilength;
result.y *= ilength;
result.z *= ilength;
}

return result;
}
Expand Down

0 comments on commit 8b8eddc

Please sign in to comment.