diff --git a/glm/core/setup.hpp b/glm/core/setup.hpp index f50fb38c..9d554738 100644 --- a/glm/core/setup.hpp +++ b/glm/core/setup.hpp @@ -590,6 +590,11 @@ # endif//GLM_MESSAGE_COMPONENT_DISPLAYED #endif//GLM_MESSAGE +/////////////////////////////////////////////////////////////////////////////////////////////////// +// Radians + +//#define GLM_FORCE_RADIANS + /////////////////////////////////////////////////////////////////////////////////////////////////// // Static assert diff --git a/glm/gtc/matrix_transform.hpp b/glm/gtc/matrix_transform.hpp index b4ec5e22..87ff2bf5 100644 --- a/glm/gtc/matrix_transform.hpp +++ b/glm/gtc/matrix_transform.hpp @@ -83,10 +83,10 @@ namespace glm detail::tmat4x4 const & m, detail::tvec3 const & v); - /// Builds a rotation 4 * 4 matrix created from an axis vector and an angle expressed in degrees. + /// Builds a rotation 4 * 4 matrix created from an axis vector and an angle. /// /// @param m Input matrix multiplied by this rotation matrix. - /// @param angle Rotation angle expressed in degrees. + /// @param angle Rotation angle expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise. /// @param axis Rotation axis, recommanded to be normalized. /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double. /// @see gtc_matrix_transform @@ -172,7 +172,7 @@ namespace glm /// Creates a matrix for a symetric perspective-view frustum. /// - /// @param fovy + /// @param fovy Expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise. /// @param aspect /// @param near /// @param far @@ -187,7 +187,7 @@ namespace glm /// Builds a perspective projection matrix based on a field of view. /// - /// @param fov + /// @param fov Expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise. /// @param width /// @param height /// @param near @@ -204,7 +204,7 @@ namespace glm /// Creates a matrix for a symmetric perspective-view frustum with far plane at infinite. /// - /// @param fovy + /// @param fovy Expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise. /// @param aspect /// @param near /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double. @@ -215,7 +215,7 @@ namespace glm /// Creates a matrix for a symmetric perspective-view frustum with far plane at infinite for graphics hardware that doesn't support depth clamping. /// - /// @param fovy + /// @param fovy Expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise. /// @param aspect /// @param near /// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double. diff --git a/glm/gtc/matrix_transform.inl b/glm/gtc/matrix_transform.inl index f5dbe78b..3ceaa3dd 100644 --- a/glm/gtc/matrix_transform.inl +++ b/glm/gtc/matrix_transform.inl @@ -48,7 +48,11 @@ namespace glm detail::tvec3 const & v ) { - T a = radians(angle); +#ifdef GLM_FORCE_RADIANS + T a = angle; +#else + T a = radians(angle); +#endif T c = cos(a); T s = sin(a); @@ -120,7 +124,11 @@ namespace glm detail::tvec3 const & v ) { - T a = radians(angle); +#ifdef GLM_FORCE_RADIANS + T const a = angle; +#else + T const a = radians(angle); +#endif T c = cos(a); T s = sin(a); detail::tmat4x4 Result; @@ -253,7 +261,11 @@ namespace glm valType const & zFar ) { +#ifdef GLM_FORCE_RADIANS + valType rad = fov; +#else valType rad = glm::radians(fov); +#endif valType h = glm::cos(valType(0.5) * rad) / glm::sin(valType(0.5) * rad); valType w = h * height / width; @@ -274,7 +286,11 @@ namespace glm T zNear ) { - T range = tan(radians(fovy / T(2))) * zNear; +#ifdef GLM_FORCE_RADIANS + T const range = tan(fovy / T(2)) * zNear; +#else + T const range = tan(radians(fovy / T(2))) * zNear; +#endif T left = -range * aspect; T right = range * aspect; T bottom = -range; @@ -297,7 +313,11 @@ namespace glm T zNear ) { +#ifdef GLM_FORCE_RADIANS + T range = tan(fovy / T(2)) * zNear; +#else T range = tan(radians(fovy / T(2))) * zNear; +#endif T left = -range * aspect; T right = range * aspect; T bottom = -range; diff --git a/glm/gtc/quaternion.hpp b/glm/gtc/quaternion.hpp index 5b669c8b..68bc0743 100644 --- a/glm/gtc/quaternion.hpp +++ b/glm/gtc/quaternion.hpp @@ -195,7 +195,9 @@ namespace detail detail::tquat inverse( detail::tquat const & q); - /// Rotates a quaternion from an vector of 3 components axis and an angle expressed in degrees. + /// Rotates a quaternion from an vector of 3 components axis and an angle. + /// + /// @param angle Angle expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise. /// /// @see gtc_quaternion template diff --git a/glm/gtc/quaternion.inl b/glm/gtc/quaternion.inl index 3cb4a604..b4a6c64e 100644 --- a/glm/gtc/quaternion.inl +++ b/glm/gtc/quaternion.inl @@ -487,10 +487,14 @@ namespace detail Tmp.z *= oneOverLen; } - typename detail::tquat::value_type AngleRad = radians(angle); - typename detail::tquat::value_type fSin = sin(AngleRad * T(0.5)); +#ifdef GLM_FORCE_RADIANS + typename detail::tquat::value_type const AngleRad(angle); +#else + typename detail::tquat::value_type const AngleRad = radians(angle); +#endif + typename detail::tquat::value_type const Sin = sin(AngleRad * T(0.5)); - return q * detail::tquat(cos(AngleRad * T(0.5)), Tmp.x * fSin, Tmp.y * fSin, Tmp.z * fSin); + return q * detail::tquat(cos(AngleRad * T(0.5)), Tmp.x * Sin, Tmp.y * Sin, Tmp.z * Sin); //return gtc::quaternion::cross(q, detail::tquat(cos(AngleRad * T(0.5)), Tmp.x * fSin, Tmp.y * fSin, Tmp.z * fSin)); } diff --git a/glm/gtc/reciprocal.hpp b/glm/gtc/reciprocal.hpp index 8c328aed..8d890796 100644 --- a/glm/gtc/reciprocal.hpp +++ b/glm/gtc/reciprocal.hpp @@ -20,29 +20,29 @@ /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN /// THE SOFTWARE. /// -/// @ref gtx_reciprocal -/// @file glm/gtx/reciprocal.hpp -/// @date 2008-10-09 / 2011-06-07 +/// @ref gtc_reciprocal +/// @file glm/gtc/reciprocal.hpp +/// @date 2008-10-09 / 2012-01-25 /// @author Christophe Riccio /// /// @see core (dependence) /// -/// @defgroup gtx_reciprocal GLM_GTX_reciprocal: Reciprocal -/// @ingroup gtx +/// @defgroup gtc_reciprocal GLM_GTC_reciprocal: Reciprocal +/// @ingroup gtc /// /// @brief Define secant, cosecant and cotangent functions. /// -/// need to be included to use these functionalities. +/// need to be included to use these functionalities. /////////////////////////////////////////////////////////////////////////////////// -#ifndef GLM_GTX_reciprocal -#define GLM_GTX_reciprocal GLM_VERSION +#ifndef GLM_GTC_reciprocal +#define GLM_GTC_reciprocal GLM_VERSION // Dependency: #include "../glm.hpp" #if(defined(GLM_MESSAGES) && !defined(glm_ext)) -# pragma message("GLM: GLM_GTX_reciprocal extension included") +# pragma message("GLM: GLM_GTC_reciprocal extension included") #endif namespace glm @@ -118,4 +118,4 @@ namespace glm #include "reciprocal.inl" -#endif//GLM_GTX_reciprocal +#endif//GLM_GTC_reciprocal diff --git a/glm/gtc/reciprocal.inl b/glm/gtc/reciprocal.inl index d3ae48ac..1a23a56a 100644 --- a/glm/gtc/reciprocal.inl +++ b/glm/gtc/reciprocal.inl @@ -2,9 +2,9 @@ // OpenGL Mathematics Copyright (c) 2005 - 2012 G-Truc Creation (www.g-truc.net) /////////////////////////////////////////////////////////////////////////////////////////////////// // Created : 2008-10-09 -// Updated : 2011-10-14 +// Updated : 2012-01-25 // Licence : This source is under MIT License -// File : glm/gtx/reciprocal.inl +// File : glm/gtc/reciprocal.inl /////////////////////////////////////////////////////////////////////////////////////////////////// #include "../core/_vectorize.hpp" diff --git a/glm/gtx/polar_coordinates.inl b/glm/gtx/polar_coordinates.inl index 173fbaea..4cfdf708 100644 --- a/glm/gtx/polar_coordinates.inl +++ b/glm/gtx/polar_coordinates.inl @@ -15,14 +15,21 @@ namespace glm detail::tvec3 const & euclidean ) { - T length = length(euclidean); - detail::tvec3 tmp = euclidean / length; - T xz_dist = sqrt(tmp.x * tmp.x + tmp.z * tmp.z); + T const Length(length(euclidean)); + detail::tvec3 const tmp(euclidean / Length); + T const xz_dist(sqrt(tmp.x * tmp.x + tmp.z * tmp.z)); +#ifdef GLM_FORCE_RADIANS + return detail::tvec3( + atan(xz_dist, tmp.y), // latitude + atan(tmp.x, tmp.z), // longitude + xz_dist); // xz distance +#else return detail::tvec3( degrees(atan(xz_dist, tmp.y)), // latitude - degrees(atan(tmp.x, tmp.z)), // longitude - xz_dist); // xz distance + degrees(atan(tmp.x, tmp.z)), // longitude + xz_dist); // xz distance +#endif } template @@ -31,8 +38,14 @@ namespace glm detail::tvec3 const & polar ) { - T latitude = radians(polar.x); - T longitude = radians(polar.y); +#ifdef GLM_FORCE_RADIANS + T const latitude(polar.x); + T const longitude(polar.y); +#else + T const latitude(radians(polar.x)); + T const longitude(radians(polar.y)); +#endif + return detail::tvec3( cos(latitude) * sin(longitude), sin(latitude), diff --git a/glm/gtx/quaternion.hpp b/glm/gtx/quaternion.hpp index e5e3e404..60ed46f8 100644 --- a/glm/gtx/quaternion.hpp +++ b/glm/gtx/quaternion.hpp @@ -53,14 +53,16 @@ namespace glm /// @{ //! Compute a cross product between a quaternion and a vector. - //! From GLM_GTX_quaternion extension. + /// + /// @see gtx_quaternion template detail::tvec3 cross( detail::tquat const & q, detail::tvec3 const & v); //! Compute a cross product between a vector and a quaternion. - //! From GLM_GTX_quaternion extension. + /// + /// @see gtx_quaternion template detail::tvec3 cross( detail::tvec3 const & v, @@ -68,7 +70,8 @@ namespace glm //! Compute a point on a path according squad equation. //! q1 and q2 are control points; s1 and s2 are intermediate control points. - //! From GLM_GTX_quaternion extension. + /// + /// @see gtx_quaternion template detail::tquat squad( detail::tquat const & q1, @@ -78,7 +81,8 @@ namespace glm valType const & h); //! Returns an intermediate control point for squad interpolation. - //! From GLM_GTX_quaternion extension. + /// + /// @see gtx_quaternion template detail::tquat intermediate( detail::tquat const & prev, @@ -86,59 +90,70 @@ namespace glm detail::tquat const & next); //! Returns a exp of a quaternion. - //! From GLM_GTX_quaternion extension. + /// + /// @see gtx_quaternion template detail::tquat exp( detail::tquat const & q, valType const & exponent); //! Returns a log of a quaternion. - //! From GLM_GTX_quaternion extension. + /// + /// @see gtx_quaternion template detail::tquat log( detail::tquat const & q); - //! Returns x raised to the y power. - //! From GLM_GTX_quaternion extension. + /// Returns x raised to the y power. + /// + /// @see gtx_quaternion template detail::tquat pow( detail::tquat const & x, valType const & y); //! Returns quarternion square root. - //! From GLM_GTX_quaternion extension. + /// + /// @see gtx_quaternion //template //detail::tquat sqrt( // detail::tquat const & q); //! Rotates a 3 components vector by a quaternion. - //! From GLM_GTX_transform extension. + /// + /// @see gtx_quaternion template detail::tvec3 rotate( detail::tquat const & q, detail::tvec3 const & v); - //! Rotates a 4 components vector by a quaternion. - //! From GLM_GTX_transform extension. + /// Rotates a 4 components vector by a quaternion. + /// + /// @see gtx_quaternion template detail::tvec4 rotate( detail::tquat const & q, detail::tvec4 const & v); - //! Returns the quaternion rotation angle. - //! From GLM_GTX_quaternion extension. + /// Returns the quaternion rotation angle. + /// + /// @see gtx_quaternion template valType angle( detail::tquat const & x); - //! Returns the q rotation axis. - //! From GLM_GTX_quaternion extension. + /// Returns the q rotation axis. + /// + /// @see gtx_quaternion template detail::tvec3 axis( detail::tquat const & x); - //! Build a quaternion from an angle and a normalized axis. - //! From GLM_GTX_quaternion extension. + /// Build a quaternion from an angle and a normalized axis. + /// + /// @param angle Angle expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise. + /// + /// @see gtx_quaternion template detail::tquat angleAxis( valType const & angle, @@ -146,77 +161,92 @@ namespace glm valType const & y, valType const & z); - //! Build a quaternion from an angle and a normalized axis. - //! From GLM_GTX_quaternion extension. + /// Build a quaternion from an angle and a normalized axis. + /// + /// @param angle Angle expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise. + /// @param axis Axis of the quaternion, must be normalized. + /// + /// @see gtx_quaternion template detail::tquat angleAxis( valType const & angle, detail::tvec3 const & axis); - //! Extract the real component of a quaternion. - //! From GLM_GTX_quaternion extension. + /// Extract the real component of a quaternion. + /// + /// @see gtx_quaternion template valType extractRealComponent( detail::tquat const & q); - //! Returns roll value of euler angles in degrees. - //! From GLM_GTX_quaternion extension. + /// Returns roll value of euler angles expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise. + /// + /// @see gtx_quaternion template valType roll( detail::tquat const & x); - //! Returns pitch value of euler angles in degrees. - //! From GLM_GTX_quaternion extension. + /// Returns pitch value of euler angles expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise. + /// + /// @see gtx_quaternion template valType pitch( detail::tquat const & x); - //! Returns yaw value of euler angles in degrees. - //! From GLM_GTX_quaternion extension. + /// Returns yaw value of euler angles expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise. + /// + /// @see gtx_quaternion template valType yaw( detail::tquat const & x); - //! Returns euler angles, yitch as x, yaw as y, roll as z. - //! From GLM_GTX_quaternion extension. + /// Returns euler angles, yitch as x, yaw as y, roll as z. + /// + /// @see gtx_quaternion template detail::tvec3 eulerAngles( detail::tquat const & x); - //! Converts a quaternion to a 3 * 3 matrix. - //! From GLM_GTX_quaternion extension. + /// Converts a quaternion to a 3 * 3 matrix. + /// + /// @see gtx_quaternion template detail::tmat3x3 toMat3( detail::tquat const & x){return mat3_cast(x);} - //! Converts a quaternion to a 4 * 4 matrix. - //! From GLM_GTX_quaternion extension. + /// Converts a quaternion to a 4 * 4 matrix. + /// + /// @see gtx_quaternion template detail::tmat4x4 toMat4( detail::tquat const & x){return mat4_cast(x);} - //! Converts a 3 * 3 matrix to a quaternion. - //! From GLM_GTX_quaternion extension. + /// Converts a 3 * 3 matrix to a quaternion. + /// + /// @see gtx_quaternion template detail::tquat toQuat( detail::tmat3x3 const & x){return quat_cast(x);} - //! Converts a 4 * 4 matrix to a quaternion. - //! From GLM_GTX_quaternion extension. + /// Converts a 4 * 4 matrix to a quaternion. + /// + /// @see gtx_quaternion template detail::tquat toQuat( detail::tmat4x4 const & x){return quat_cast(x);} - //! Quaternion interpolation using the rotation short path. - //! From GLM_GTX_quaternion extension. + /// Quaternion interpolation using the rotation short path. + /// + /// @see gtx_quaternion template detail::tquat shortMix( detail::tquat const & x, detail::tquat const & y, T const & a); - //! Quaternion normalized linear interpolation. - //! From GLM_GTX_quaternion extension. + /// Quaternion normalized linear interpolation. + /// + /// @see gtx_quaternion template detail::tquat fastMix( detail::tquat const & x, diff --git a/glm/gtx/quaternion.inl b/glm/gtx/quaternion.inl index b8805a14..42e08a3a 100644 --- a/glm/gtx/quaternion.inl +++ b/glm/gtx/quaternion.inl @@ -147,7 +147,11 @@ namespace glm detail::tquat const & x ) { +#ifdef GLM_FORCE_RADIANS + return acos(x.w) * T(2); +#else return glm::degrees(acos(x.w) * T(2)); +#endif } template @@ -184,7 +188,11 @@ namespace glm { detail::tquat result; - valType a = glm::radians(angle); +#ifdef GLM_FORCE_RADIANS + valType a(angle); +#else + valType a(glm::radians(angle)); +#endif valType s = glm::sin(a * valType(0.5)); result.w = glm::cos(a * valType(0.5)); @@ -213,7 +221,11 @@ namespace glm detail::tquat const & q ) { +#ifdef GLM_FORCE_RADIANS + return atan2(valType(2) * (q.x * q.y + q.w * q.z), q.w * q.w + q.x * q.x - q.y * q.y - q.z * q.z); +#else return glm::degrees(atan2(valType(2) * (q.x * q.y + q.w * q.z), q.w * q.w + q.x * q.x - q.y * q.y - q.z * q.z)); +#endif } template @@ -222,7 +234,11 @@ namespace glm detail::tquat const & q ) { +#ifdef GLM_FORCE_RADIANS + return atan2(valType(2) * (q.y * q.z + q.w * q.x), q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z); +#else return glm::degrees(atan2(valType(2) * (q.y * q.z + q.w * q.x), q.w * q.w - q.x * q.x - q.y * q.y + q.z * q.z)); +#endif } template @@ -231,7 +247,11 @@ namespace glm detail::tquat const & q ) { +#ifdef GLM_FORCE_RADIANS + return asin(valType(-2) * (q.x * q.z - q.w * q.y)); +#else return glm::degrees(asin(valType(-2) * (q.x * q.z - q.w * q.y))); +#endif } template diff --git a/glm/gtx/rotate_vector.inl b/glm/gtx/rotate_vector.inl index 4a934ac5..2866200e 100644 --- a/glm/gtx/rotate_vector.inl +++ b/glm/gtx/rotate_vector.inl @@ -17,8 +17,13 @@ namespace glm ) { detail::tvec2 Result; +#ifdef GLM_FORCE_RADIANS + T const Cos(cos(angle)); + T const Sin(sin(angle)); +#else T const Cos = cos(radians(angle)); T const Sin = sin(radians(angle)); +#endif Result.x = v.x * Cos - v.y * Sin; Result.y = v.x * Sin + v.y * Cos; return Result; @@ -64,9 +69,16 @@ namespace glm T const & angle ) { - detail::tvec3 Result = v; - const T Cos = cos(radians(angle)); - const T Sin = sin(radians(angle)); + detail::tvec3 Result(v); + +#ifdef GLM_FORCE_RADIANS + T const Cos(cos(angle)); + T const Sin(sin(angle)); +#else + T const Cos = cos(radians(angle)); + T const Sin = sin(radians(angle)); +#endif + Result.y = v.y * Cos - v.z * Sin; Result.z = v.y * Sin + v.z * Cos; return Result; @@ -80,8 +92,15 @@ namespace glm ) { detail::tvec3 Result = v; - const T Cos = cos(radians(angle)); - const T Sin = sin(radians(angle)); + +#ifdef GLM_FORCE_RADIANS + T const Cos(cos(angle)); + T const Sin(sin(angle)); +#else + T const Cos(cos(radians(angle))); + T const Sin(sin(radians(angle))); +#endif + Result.x = v.x * Cos + v.z * Sin; Result.z = -v.x * Sin + v.z * Cos; return Result; @@ -95,8 +114,15 @@ namespace glm ) { detail::tvec3 Result = v; - const T Cos = cos(radians(angle)); - const T Sin = sin(radians(angle)); + +#ifdef GLM_FORCE_RADIANS + T const Cos(cos(angle)); + T const Sin(sin(angle)); +#else + T const Cos(cos(radians(angle))); + T const Sin(sin(radians(angle))); +#endif + Result.x = v.x * Cos - v.y * Sin; Result.y = v.x * Sin + v.y * Cos; return Result; @@ -110,8 +136,15 @@ namespace glm ) { detail::tvec4 Result = v; - const T Cos = cos(radians(angle)); - const T Sin = sin(radians(angle)); + +#ifdef GLM_FORCE_RADIANS + T const Cos(cos(angle)); + T const Sin(sin(angle)); +#else + T const Cos(cos(radians(angle))); + T const Sin(sin(radians(angle))); +#endif + Result.y = v.y * Cos - v.z * Sin; Result.z = v.y * Sin + v.z * Cos; return Result; @@ -125,8 +158,15 @@ namespace glm ) { detail::tvec4 Result = v; - const T Cos = cos(radians(angle)); - const T Sin = sin(radians(angle)); + +#ifdef GLM_FORCE_RADIANS + T const Cos(cos(angle)); + T const Sin(sin(angle)); +#else + T const Cos(cos(radians(angle))); + T const Sin(sin(radians(angle))); +#endif + Result.x = v.x * Cos + v.z * Sin; Result.z = -v.x * Sin + v.z * Cos; return Result; @@ -140,8 +180,15 @@ namespace glm ) { detail::tvec4 Result = v; - const T Cos = cos(radians(angle)); - const T Sin = sin(radians(angle)); + +#ifdef GLM_FORCE_RADIANS + T const Cos(cos(angle)); + T const Sin(sin(angle)); +#else + T const Cos(cos(radians(angle))); + T const Sin(sin(radians(angle))); +#endif + Result.x = v.x * Cos - v.y * Sin; Result.y = v.x * Sin + v.y * Cos; return Result; diff --git a/glm/gtx/vector_angle.inl b/glm/gtx/vector_angle.inl index f15206be..9e12bd4c 100644 --- a/glm/gtx/vector_angle.inl +++ b/glm/gtx/vector_angle.inl @@ -27,8 +27,12 @@ namespace glm detail::tvec2 const & y ) { - valType Angle = glm::degrees(acos(dot(x, y))); - detail::tvec2 TransformedVector = glm::rotate(x, Angle); +#ifdef GLM_FORCE_RADIANS + valType const Angle(acos(dot(x, y))); +#else + valType const Angle(glm::degrees(acos(dot(x, y)))); +#endif + detail::tvec2 const TransformedVector(glm::rotate(x, Angle)); if(all(equalEpsilon(y, TransformedVector, valType(0.01)))) return Angle; else @@ -43,7 +47,7 @@ namespace glm detail::tvec3 const & ref ) { - valType Angle = glm::degrees(glm::acos(glm::dot(x, y))); + valType const Angle(glm::degrees(glm::acos(glm::dot(x, y)))); if(glm::dot(ref, glm::cross(x, y)) < valType(0)) return -Angle;