Skip to content

Commit 3e03467

Browse files
committed
_static_create quaternion to matrix, create quaternion from axis-angle
1 parent 9be65a0 commit 3e03467

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

include/nbl/builtin/hlsl/math/quaternions.hlsl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ struct quaternion
5959
return other;
6060
}
6161

62+
// angle: Rotation angle expressed in radians.
63+
// axis: Rotation axis, must be normalized.
64+
static this_t create(scalar_type angle, const vector3_type axis)
65+
{
66+
this_t q;
67+
const scalar_type sinTheta = hlsl::sin(angle * 0.5);
68+
const scalar_type cosTheta = hlsl::cos(angle * 0.5);
69+
q.data = data_type(axis.x * sinTheta, axis.y * sinTheta, axis.z * sinTheta, cosTheta);
70+
return q;
71+
}
72+
73+
6274
static this_t create(scalar_type pitch, scalar_type yaw, scalar_type roll)
6375
{
6476
const scalar_type rollDiv2 = roll * scalar_type(0.5);
@@ -227,6 +239,19 @@ struct quaternion
227239
};
228240

229241
}
242+
243+
namespace impl
244+
{
245+
template<typename T>
246+
struct static_cast_helper<matrix<T,3,3>, math::quaternion<T> >
247+
{
248+
static inline matrix<T,3,3> cast(math::quaternion<T> q)
249+
{
250+
return q.constructMatrix();
251+
}
252+
};
253+
}
254+
230255
}
231256
}
232257

0 commit comments

Comments
 (0)