summaryrefslogtreecommitdiffstats
path: root/Common/interface
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2019-09-28 18:29:26 +0000
committerEgor Yusov <egor.yusov@gmail.com>2019-09-28 18:29:26 +0000
commitfef90baf59efb3678283c0a512204f1d38dac565 (patch)
tree468773037fa4f77fc90bb9b6116e4bd7af2a796b /Common/interface
parentGL backend: reworked VAO cache key to use object unique IDs instead of pointers (diff)
downloadDiligentCore-fef90baf59efb3678283c0a512204f1d38dac565.tar.gz
DiligentCore-fef90baf59efb3678283c0a512204f1d38dac565.zip
Fixed issue in Quaternion::RotationFromAxisAngle when axis is null
Diffstat (limited to 'Common/interface')
-rw-r--r--Common/interface/BasicMath.h15
1 files changed, 9 insertions, 6 deletions
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;
}