Added a quation constructor taking two axis

This commit is contained in:
Christophe Riccio 2013-09-22 23:37:55 +02:00
parent a15201dc59
commit 1e69dfe30e
5 changed files with 49 additions and 27 deletions

View File

@ -70,7 +70,7 @@ namespace detail
tquat<U, Q> const & q); tquat<U, Q> const & q);
GLM_FUNC_DECL explicit tquat( GLM_FUNC_DECL explicit tquat(
T const & s, T const & s,
glm::detail::tvec3<T, P> const & v); tvec3<T, P> const & v);
GLM_FUNC_DECL explicit tquat( GLM_FUNC_DECL explicit tquat(
T const & w, T const & w,
T const & x, T const & x,
@ -79,6 +79,15 @@ namespace detail
// Convertions // Convertions
/// Create a quaternion from two normalized axis
///
/// @param u A first normalized axis
/// @param v A second normalized axis
/// @see gtc_quaternion
/// @see http://lolengine.net/blog/2013/09/18/beautiful-maths-quaternion-from-vectors
GLM_FUNC_DECL explicit tquat(
detail::tvec3<T, P> const & u,
detail::tvec3<T, P> const & v);
/// Build a quaternion from euler angles (pitch, yaw, roll), in radians. /// Build a quaternion from euler angles (pitch, yaw, roll), in radians.
GLM_FUNC_DECL explicit tquat( GLM_FUNC_DECL explicit tquat(
tvec3<T, P> const & eulerAngles); tvec3<T, P> const & eulerAngles);

View File

@ -104,6 +104,18 @@ namespace detail
// this->z = c.x * c.y * s.z - s.x * s.y * c.z; // this->z = c.x * c.y * s.z - s.x * s.y * c.z;
//} //}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tquat<T, P>::tquat
(
detail::tvec3<T, P> const & u,
detail::tvec3<T, P> const & v
)
{
detail::tvec3<T, P> w = cross(u, v);
detail::tquat<T, P> q(T(1) + dot(u, v), w.x, w.y, w.z);
*this = normalize(q);
}
template <typename T, precision P> template <typename T, precision P>
GLM_FUNC_QUALIFIER tquat<T, P>::tquat GLM_FUNC_QUALIFIER tquat<T, P>::tquat
( (

View File

@ -65,6 +65,7 @@ GLM 0.9.5.0: 2013-XX-XX
- Replaced GLM traits by STL traits when possible - Replaced GLM traits by STL traits when possible
- Allowed including individual core feature - Allowed including individual core feature
- Increased unit tests completness - Increased unit tests completness
- Added creating of a quaternion from two vectors
================================================================================ ================================================================================
GLM 0.9.4.6: 2013-09-20 GLM 0.9.4.6: 2013-09-20

View File

@ -11,9 +11,9 @@ using namespace glm;
int main() int main()
{ {
f32 first = 1.046 ; f32 first = 1.046f;
f32 second = 0.52 ; f32 second = 0.52f;
f32 third = -0.785; f32 third = -0.785f;
fmat4 rotationEuler = eulerAngleYXZ(first, second, third); fmat4 rotationEuler = eulerAngleYXZ(first, second, third);