Skip to content

Commit

Permalink
LookRotationSafe now handles NaN input
Browse files Browse the repository at this point in the history
  • Loading branch information
runestubbe committed Oct 1, 2018
1 parent 5ba2595 commit 4408031
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Unity.Mathematics/matrix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ public static float3x3 LookRotationSafe(float3 forward, float3 up)
float mn = min(min(forwardLengthSq, upLengthSq), tLengthSq);
float mx = max(max(forwardLengthSq, upLengthSq), tLengthSq);

bool accept = mn > 1e-35f && mx < 1e35f;
bool accept = mn > 1e-35f && mx < 1e35f && isfinite(forwardLengthSq) && isfinite(upLengthSq) && isfinite(tLengthSq);
return float3x3(
select(float3(1,0,0), t, accept),
select(float3(0,1,0), cross(forward, t), accept),
Expand Down
2 changes: 1 addition & 1 deletion src/Unity.Mathematics/quaternion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ public static quaternion LookRotationSafe(float3 forward, float3 up)
float mn = min(min(forwardLengthSq, upLengthSq), tLengthSq);
float mx = max(max(forwardLengthSq, upLengthSq), tLengthSq);

bool accept = mn > 1e-35f && mx < 1e35f;
bool accept = mn > 1e-35f && mx < 1e35f && isfinite(forwardLengthSq) && isfinite(upLengthSq) && isfinite(tLengthSq);
return quaternion(select(float4(0.0f, 0.0f, 0.0f, 1.0f), quaternion(float3x3(t, cross(forward, t),forward)).value, accept));
}

Expand Down

0 comments on commit 4408031

Please sign in to comment.