From fef90baf59efb3678283c0a512204f1d38dac565 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sat, 28 Sep 2019 11:29:26 -0700 Subject: Fixed issue in Quaternion::RotationFromAxisAngle when axis is null --- Common/interface/BasicMath.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'Common/interface') diff --git a/Common/interface/BasicMath.h b/Common/interface/BasicMath.h index 8623bb47..1baedfb9 100644 --- a/Common/interface/BasicMath.h +++ b/Common/interface/BasicMath.h @@ -1640,13 +1640,16 @@ struct Quaternion static Quaternion RotationFromAxisAngle(const float3& axis, float angle) { - Quaternion out; + Quaternion out{0, 0, 0, 1}; float norm = length(axis); - float sina2 = sin(0.5f * angle); - out.q[0] = sina2 * axis[0] / norm; - out.q[1] = sina2 * axis[1] / norm; - out.q[2] = sina2 * axis[2] / norm; - out.q[3] = cos(0.5f * angle); + if (norm != 0) + { + float sina2 = sin(0.5f * angle); + out.q[0] = sina2 * axis[0] / norm; + out.q[1] = sina2 * axis[1] / norm; + out.q[2] = sina2 * axis[2] / norm; + out.q[3] = cos(0.5f * angle); + } return out; } -- cgit v1.2.3