mirror of
https://github.com/godotengine/godot.git
synced 2026-02-07 19:32:36 +00:00
Make acos and asin safe
A common bug with using acos and asin is that input outside -1 to 1 range will result in Nan output. This can occur due to floating point error in the input. The standard solution is to provide safe_acos function with clamped input. For Godot it may make more sense to make the standard functions safe.
This commit is contained in:
@@ -807,8 +807,8 @@ void Basis::get_axis_angle(Vector3 &r_axis, real_t &r_angle) const {
|
||||
z = (rows[1][0] - rows[0][1]) / s;
|
||||
|
||||
r_axis = Vector3(x, y, z);
|
||||
// CLAMP to avoid NaN if the value passed to acos is not in [0,1].
|
||||
r_angle = Math::acos(CLAMP((rows[0][0] + rows[1][1] + rows[2][2] - 1) / 2, (real_t)0.0, (real_t)1.0));
|
||||
// acos does clamping.
|
||||
r_angle = Math::acos((rows[0][0] + rows[1][1] + rows[2][2] - 1) / 2);
|
||||
}
|
||||
|
||||
void Basis::set_quaternion(const Quaternion &p_quaternion) {
|
||||
|
||||
Reference in New Issue
Block a user