Added GLM_FORCE_RADIANS

This commit is contained in:
Christophe Riccio 2012-01-25 16:37:09 +00:00
parent ebd1ba8bf6
commit 100b2202dd
12 changed files with 236 additions and 91 deletions

View File

@ -590,6 +590,11 @@
# endif//GLM_MESSAGE_COMPONENT_DISPLAYED
#endif//GLM_MESSAGE
///////////////////////////////////////////////////////////////////////////////////////////////////
// Radians
//#define GLM_FORCE_RADIANS
///////////////////////////////////////////////////////////////////////////////////////////////////
// Static assert

View File

@ -83,10 +83,10 @@ namespace glm
detail::tmat4x4<T> const & m,
detail::tvec3<T> 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.

View File

@ -48,7 +48,11 @@ namespace glm
detail::tvec3<T> const & v
)
{
#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<T> 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<T> 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;

View File

@ -195,7 +195,9 @@ namespace detail
detail::tquat<T> inverse(
detail::tquat<T> 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 <typename T>

View File

@ -487,10 +487,14 @@ namespace detail
Tmp.z *= oneOverLen;
}
typename detail::tquat<T>::value_type AngleRad = radians(angle);
typename detail::tquat<T>::value_type fSin = sin(AngleRad * T(0.5));
#ifdef GLM_FORCE_RADIANS
typename detail::tquat<T>::value_type const AngleRad(angle);
#else
typename detail::tquat<T>::value_type const AngleRad = radians(angle);
#endif
typename detail::tquat<T>::value_type const Sin = sin(AngleRad * T(0.5));
return q * detail::tquat<T>(cos(AngleRad * T(0.5)), Tmp.x * fSin, Tmp.y * fSin, Tmp.z * fSin);
return q * detail::tquat<T>(cos(AngleRad * T(0.5)), Tmp.x * Sin, Tmp.y * Sin, Tmp.z * Sin);
//return gtc::quaternion::cross(q, detail::tquat<T>(cos(AngleRad * T(0.5)), Tmp.x * fSin, Tmp.y * fSin, Tmp.z * fSin));
}

View File

@ -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.
///
/// <glm/gtx/reciprocal.hpp> need to be included to use these functionalities.
/// <glm/gtc/reciprocal.hpp> 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

View File

@ -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"

View File

@ -15,14 +15,21 @@ namespace glm
detail::tvec3<T> const & euclidean
)
{
T length = length(euclidean);
detail::tvec3<T> tmp = euclidean / length;
T xz_dist = sqrt(tmp.x * tmp.x + tmp.z * tmp.z);
T const Length(length(euclidean));
detail::tvec3<T> const tmp(euclidean / Length);
T const xz_dist(sqrt(tmp.x * tmp.x + tmp.z * tmp.z));
#ifdef GLM_FORCE_RADIANS
return detail::tvec3<T>(
atan(xz_dist, tmp.y), // latitude
atan(tmp.x, tmp.z), // longitude
xz_dist); // xz distance
#else
return detail::tvec3<T>(
degrees(atan(xz_dist, tmp.y)), // latitude
degrees(atan(tmp.x, tmp.z)), // longitude
xz_dist); // xz distance
#endif
}
template <typename T>
@ -31,8 +38,14 @@ namespace glm
detail::tvec3<T> 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<T>(
cos(latitude) * sin(longitude),
sin(latitude),

View File

@ -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 <typename valType>
detail::tvec3<valType> cross(
detail::tquat<valType> const & q,
detail::tvec3<valType> const & v);
//! Compute a cross product between a vector and a quaternion.
//! From GLM_GTX_quaternion extension.
///
/// @see gtx_quaternion
template <typename valType>
detail::tvec3<valType> cross(
detail::tvec3<valType> 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 <typename valType>
detail::tquat<valType> squad(
detail::tquat<valType> 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 <typename valType>
detail::tquat<valType> intermediate(
detail::tquat<valType> const & prev,
@ -86,59 +90,70 @@ namespace glm
detail::tquat<valType> const & next);
//! Returns a exp of a quaternion.
//! From GLM_GTX_quaternion extension.
///
/// @see gtx_quaternion
template <typename valType>
detail::tquat<valType> exp(
detail::tquat<valType> const & q,
valType const & exponent);
//! Returns a log of a quaternion.
//! From GLM_GTX_quaternion extension.
///
/// @see gtx_quaternion
template <typename valType>
detail::tquat<valType> log(
detail::tquat<valType> 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 <typename valType>
detail::tquat<valType> pow(
detail::tquat<valType> const & x,
valType const & y);
//! Returns quarternion square root.
//! From GLM_GTX_quaternion extension.
///
/// @see gtx_quaternion
//template <typename valType>
//detail::tquat<valType> sqrt(
// detail::tquat<valType> const & q);
//! Rotates a 3 components vector by a quaternion.
//! From GLM_GTX_transform extension.
///
/// @see gtx_quaternion
template <typename valType>
detail::tvec3<valType> rotate(
detail::tquat<valType> const & q,
detail::tvec3<valType> 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 <typename valType>
detail::tvec4<valType> rotate(
detail::tquat<valType> const & q,
detail::tvec4<valType> const & v);
//! Returns the quaternion rotation angle.
//! From GLM_GTX_quaternion extension.
/// Returns the quaternion rotation angle.
///
/// @see gtx_quaternion
template <typename valType>
valType angle(
detail::tquat<valType> const & x);
//! Returns the q rotation axis.
//! From GLM_GTX_quaternion extension.
/// Returns the q rotation axis.
///
/// @see gtx_quaternion
template <typename valType>
detail::tvec3<valType> axis(
detail::tquat<valType> 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 <typename valType>
detail::tquat<valType> 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 <typename valType>
detail::tquat<valType> angleAxis(
valType const & angle,
detail::tvec3<valType> 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 <typename valType>
valType extractRealComponent(
detail::tquat<valType> 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 <typename valType>
valType roll(
detail::tquat<valType> 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 <typename valType>
valType pitch(
detail::tquat<valType> 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 <typename valType>
valType yaw(
detail::tquat<valType> 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 <typename valType>
detail::tvec3<valType> eulerAngles(
detail::tquat<valType> 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 <typename valType>
detail::tmat3x3<valType> toMat3(
detail::tquat<valType> 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 <typename valType>
detail::tmat4x4<valType> toMat4(
detail::tquat<valType> 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 <typename valType>
detail::tquat<valType> toQuat(
detail::tmat3x3<valType> 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 <typename valType>
detail::tquat<valType> toQuat(
detail::tmat4x4<valType> 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 <typename T>
detail::tquat<T> shortMix(
detail::tquat<T> const & x,
detail::tquat<T> const & y,
T const & a);
//! Quaternion normalized linear interpolation.
//! From GLM_GTX_quaternion extension.
/// Quaternion normalized linear interpolation.
///
/// @see gtx_quaternion
template <typename T>
detail::tquat<T> fastMix(
detail::tquat<T> const & x,

View File

@ -147,7 +147,11 @@ namespace glm
detail::tquat<T> const & x
)
{
#ifdef GLM_FORCE_RADIANS
return acos(x.w) * T(2);
#else
return glm::degrees(acos(x.w) * T(2));
#endif
}
template <typename T>
@ -184,7 +188,11 @@ namespace glm
{
detail::tquat<valType> 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<valType> 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 <typename valType>
@ -222,7 +234,11 @@ namespace glm
detail::tquat<valType> 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 <typename valType>
@ -231,7 +247,11 @@ namespace glm
detail::tquat<valType> 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 <typename valType>

View File

@ -17,8 +17,13 @@ namespace glm
)
{
detail::tvec2<T> 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<T> Result = v;
const T Cos = cos(radians(angle));
const T Sin = sin(radians(angle));
detail::tvec3<T> 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<T> 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<T> 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<T> 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<T> 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<T> 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;

View File

@ -27,8 +27,12 @@ namespace glm
detail::tvec2<valType> const & y
)
{
valType Angle = glm::degrees(acos(dot(x, y)));
detail::tvec2<valType> 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<valType> 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<valType> 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;