X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fmoof%2Fcml%2Fquaternion%2Fquaternion_functions.h;fp=src%2Fmoof%2Fcml%2Fquaternion%2Fquaternion_functions.h;h=95abcb9bdae5a2edf1d163a7859747e75dc0a32d;hb=831f04d4bc19a390415ac0bbac4331c7a65509bc;hp=0000000000000000000000000000000000000000;hpb=299af4f2047e767e5d79501c26444473bda64c64;p=chaz%2Fyoink diff --git a/src/moof/cml/quaternion/quaternion_functions.h b/src/moof/cml/quaternion/quaternion_functions.h new file mode 100644 index 0000000..95abcb9 --- /dev/null +++ b/src/moof/cml/quaternion/quaternion_functions.h @@ -0,0 +1,172 @@ +/* -*- C++ -*- ------------------------------------------------------------ + +Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/ + +The Configurable Math Library (CML) is distributed under the terms of the +Boost Software License, v1.0 (see cml/LICENSE for details). + + *-----------------------------------------------------------------------*/ +/** @file + * @brief Functions on quaternions. + * + * @todo The functions that return quaternions and vectors should be changed + * to return quaternion expression nodes, as should the corresponding + * class methods. + */ + +#ifndef quaternion_functions_h +#define quaternion_functions_h + +#include // For CheckQuat() +#include +#include // For acos_safe() + +namespace cml { + +/** Returns the real part of the quaternion. */ +template +inline typename quaternion::value_type +real(const quaternion& q) +{ + return q.real(); +} + +/** Returns the real (scalar) part of the QuaternionXpr. */ +template +inline typename et::QuaternionXpr::value_type +real(const et::QuaternionXpr& e) +{ + return e.real(); +} + +/** Returns the imaginary (vector) part of the quaternion. */ +template +inline typename quaternion::imaginary_type +imaginary(const quaternion& q) +{ + return q.imaginary(); +} + +/** Returns the imaginary (vector) part of the QuaternionXpr. */ +template +//inline typename et::QuaternionXpr::temporary_type +inline typename et::QuaternionXpr::imaginary_type +imaginary(const et::QuaternionXpr& e) +{ + return e.imaginary(); +} + +/** Cayley norm of a quaternion. */ +template +inline typename quaternion::value_type +norm(const quaternion& arg) +{ + return arg.length_squared(); +} + +/** Cayley norm of a QuaternionXpr. */ +template +inline typename XprT::value_type +norm(QUATXPR_ARG_TYPE arg) +{ + return arg.length_squared(); +} + +/** Squared length of a quaternion. */ +template +inline typename quaternion::value_type +length_squared(const quaternion& arg) +{ + return arg.length_squared(); +} + +/** Squared length of a quaternion expr. */ +template +inline typename XprT::value_type +length_squared(QUATXPR_ARG_TYPE arg) +{ + return arg.length_squared(); +} + +/** Length of a quaternion. */ +template +inline typename quaternion::value_type +length(const quaternion& arg) +{ + return arg.length(); +} + +/** Length of a quaternion expr. */ +template +inline typename XprT::value_type +length(QUATXPR_ARG_TYPE arg) +{ + return arg.length(); +} + +/** Normalize a quaternion. + * + * The input quaternion is not changed. + */ +template +inline quaternion +normalize(const quaternion& arg) +{ + typename quaternion::temporary_type result(arg); + result.normalize(); + return result; +} + +/** Normalize a quaternion expr. */ +template +inline typename XprT::temporary_type +normalize(QUATXPR_ARG_TYPE arg) +{ + return arg.normalize(); +} + +/** Set a quaternion to the multiplicative identity. + * + * The input quaternion is not changed. + */ +template +inline quaternion +identity(const quaternion& arg) +{ + typename quaternion::temporary_type result(arg); + result.identity(); + return result; +} + +/** Log of a quaternion or quaternion expression. + */ +template < class QuatT > +typename QuatT::temporary_type log( + const QuatT& q, + typename QuatT::value_type tolerance = + epsilon::placeholder()) +{ + detail::CheckQuat(q); + + return q.log(); +} + +/** Exponential function of a quaternion or quaternion expression. + */ +template < class QuatT > +typename QuatT::temporary_type exp( + const QuatT& q, + typename QuatT::value_type tolerance = + epsilon::placeholder()) +{ + detail::CheckQuat(q); + + return q.exp(); +} + +} // namespace cml + +#endif + +// ------------------------------------------------------------------------- +// vim:ft=cpp