Resolved issue #4, added GLM_GTX_rotate_normalized_axis

This commit is contained in:
Christophe Riccio 2012-12-14 00:14:02 +01:00
parent 8a291a9dc2
commit 739ab3529c
9 changed files with 292 additions and 70 deletions

View File

@ -87,7 +87,7 @@ namespace glm
///
/// @param m Input matrix multiplied by this rotation matrix.
/// @param angle Rotation angle expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise.
/// @param axis Rotation axis, recommanded to be normalized.
/// @param axis Rotation axis.
/// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double.
/// @see gtc_matrix_transform
/// @see gtx_transform

View File

@ -51,7 +51,7 @@ namespace glm
#ifdef GLM_FORCE_RADIANS
T a = angle;
#else
T a = radians(angle);
T a = radians(angle);
#endif
T c = cos(a);
T s = sin(a);

View File

@ -192,11 +192,11 @@ namespace detail
detail::tquat<T> inverse(
detail::tquat<T> const & q);
/// Rotates a quaternion from an vector of 3 components axis and an angle.
/// Rotates a quaternion from a vector of 3 components axis and an angle.
///
/// @param q Source orientation
/// @param angle Angle expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise.
/// @param axis Axis of the rotation, must be normalized.
/// @param axis Axis of the rotation
///
/// @see gtc_quaternion
template <typename T>

View File

@ -0,0 +1,92 @@
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2012 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref gtx_rotate_normalized_axis
/// @file glm/gtx/rotate_normalized_axis.hpp
/// @date 2012-12-13 / 2012-12-13
/// @author Christophe Riccio
///
/// @see core (dependence)
/// @see gtc_matrix_transform
/// @see gtc_quaternion
///
/// @defgroup gtx_rotate_normalized_axis GLM_GTX_rotate_normalized_axis
/// @ingroup gtc
///
/// @brief Quaternions and matrices rotations around normalized axis.
///
/// <glm/gtx/rotate_normalized_axis.hpp> need to be included to use these functionalities.
///////////////////////////////////////////////////////////////////////////////////
#ifndef GLM_GTX_rotate_normalized_axis
#define GLM_GTX_rotate_normalized_axis GLM_VERSION
// Dependency:
#include "../glm.hpp"
#include "../gtc/epsilon.hpp"
#include "../gtc/quaternion.hpp"
#if(defined(GLM_MESSAGES) && !defined(glm_ext))
# pragma message("GLM: GLM_GTX_rotate_normalized_axis extension included")
#endif
namespace glm
{
/// @addtogroup gtx_rotate_normalized_axis
/// @{
/// Builds a rotation 4 * 4 matrix created from a normalized axis and an angle.
///
/// @param m Input matrix multiplied by this rotation matrix.
/// @param angle Rotation angle expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise.
/// @param axis Rotation axis, must be normalized.
/// @tparam T Value type used to build the matrix. Currently supported: half (not recommanded), float or double.
///
/// @see gtx_rotate_normalized_axis
/// @see - rotate(T angle, T x, T y, T z)
/// @see - rotate(detail::tmat4x4<T> const & m, T angle, T x, T y, T z)
/// @see - rotate(T angle, detail::tvec3<T> const & v)
template <typename T>
detail::tmat4x4<T> rotateNormalizedAxis(
detail::tmat4x4<T> const & m,
T const & angle,
detail::tvec3<T> const & axis);
/// Rotates a quaternion from a vector of 3 components normalized axis and an angle.
///
/// @param q Source orientation
/// @param angle Angle expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise.
/// @param axis Normalized axis of the rotation, must be normalized.
///
/// @see gtx_rotate_normalized_axis
template <typename T>
detail::tquat<T> rotateNormalizedAxis(
detail::tquat<T> const & q,
typename detail::tquat<T>::value_type const & angle,
detail::tvec3<T> const & axis);
/// @}
}//namespace glm
#include "rotate_normalized_axis.inl"
#endif//GLM_GTX_rotate_normalized_axis

View File

@ -0,0 +1,92 @@
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2012 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref gtx_rotate_normalized_axis
/// @file glm/gtx/rotate_normalized_axis.inl
/// @date 2012-12-13 / 2012-12-13
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
namespace glm
{
template <typename T>
GLM_FUNC_QUALIFIER detail::tmat4x4<T> rotateNormalizedAxis
(
detail::tmat4x4<T> const & m,
T const & angle,
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);
detail::tvec3<T> axis = v;
detail::tvec3<T> temp = (T(1) - c) * axis;
detail::tmat4x4<T> Rotate(detail::tmat4x4<T>::null);
Rotate[0][0] = c + temp[0] * axis[0];
Rotate[0][1] = 0 + temp[0] * axis[1] + s * axis[2];
Rotate[0][2] = 0 + temp[0] * axis[2] - s * axis[1];
Rotate[1][0] = 0 + temp[1] * axis[0] - s * axis[2];
Rotate[1][1] = c + temp[1] * axis[1];
Rotate[1][2] = 0 + temp[1] * axis[2] + s * axis[0];
Rotate[2][0] = 0 + temp[2] * axis[0] + s * axis[1];
Rotate[2][1] = 0 + temp[2] * axis[1] - s * axis[0];
Rotate[2][2] = c + temp[2] * axis[2];
detail::tmat4x4<T> Result(detail::tmat4x4<T>::null);
Result[0] = m[0] * Rotate[0][0] + m[1] * Rotate[0][1] + m[2] * Rotate[0][2];
Result[1] = m[0] * Rotate[1][0] + m[1] * Rotate[1][1] + m[2] * Rotate[1][2];
Result[2] = m[0] * Rotate[2][0] + m[1] * Rotate[2][1] + m[2] * Rotate[2][2];
Result[3] = m[3];
return Result;
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tquat<T> rotateNormalizedAxis
(
detail::tquat<T> const & q,
typename detail::tquat<T>::value_type const & angle,
detail::tvec3<T> const & v
)
{
detail::tvec3<T> Tmp = v;
#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 * 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));
}
}//namespace glm

View File

@ -54,71 +54,71 @@ namespace glm
/// @addtogroup gtx_transform
/// @{
//! Builds a translation 4 * 4 matrix created from 3 scalars.
//! - From \link gtx_transform GLM_GTX_transform \endlink extension
// - See also: \link glm::translate GLM_GTC_matrix_transform \endlink
/// Builds a translation 4 * 4 matrix created from 3 scalars.
/// - From \link gtx_transform GLM_GTX_transform \endlink extension
/// - See also: \link glm::translate GLM_GTC_matrix_transform \endlink
template <typename T>
detail::tmat4x4<T> translate(
T x, T y, T z);
//! Transforms a matrix with a translation 4 * 4 matrix created from 3 scalars.
//! - From \link gtx_transform GLM_GTX_transform \endlink extension
// - See also: \link glm::translate GLM_GTC_matrix_transform \endlink
/// Transforms a matrix with a translation 4 * 4 matrix created from 3 scalars.
/// - From \link gtx_transform GLM_GTX_transform \endlink extension
/// - See also: \link glm::translate GLM_GTC_matrix_transform \endlink
template <typename T>
detail::tmat4x4<T> translate(
detail::tmat4x4<T> const & m,
T x, T y, T z);
//! Transforms a matrix with a translation 4 * 4 matrix created from 3 scalars.
//! - From \link gtx_transform GLM_GTX_transform \endlink extension
// - See also: \link glm::translate GLM_GTC_matrix_transform \endlink
/// Transforms a matrix with a translation 4 * 4 matrix created from 3 scalars.
/// - From \link gtx_transform GLM_GTX_transform \endlink extension
/// - See also: \link glm::translate GLM_GTC_matrix_transform \endlink
template <typename T>
detail::tmat4x4<T> translate(
detail::tvec3<T> const & v);
//! Builds a rotation 4 * 4 matrix created from an axis of 3 scalars and an angle expressed in degrees.
//! - From \link gtx_transform GLM_GTX_transform \endlink extension
// - See also: \link glm::rotate GLM_GTC_matrix_transform \endlink
/// Builds a rotation 4 * 4 matrix created from an axis of 3 scalars and an angle expressed in degrees.
/// - From \link gtx_transform GLM_GTX_transform \endlink extension
/// - See also: \link glm::rotate GLM_GTC_matrix_transform \endlink
template <typename T>
detail::tmat4x4<T> rotate(
T angle,
T x, T y, T z);
//! Builds a rotation 4 * 4 matrix created from an axis of 3 scalars and an angle expressed in degrees.
//! - From \link gtx_transform GLM_GTX_transform \endlink extension
// - See also: \link glm::rotate GLM_GTC_matrix_transform \endlink
/// Builds a rotation 4 * 4 matrix created from an axis of 3 scalars and an angle expressed in degrees.
/// - From \link gtx_transform GLM_GTX_transform \endlink extension
/// - See also: \link glm::rotate GLM_GTC_matrix_transform \endlink
template <typename T>
detail::tmat4x4<T> rotate(
T angle,
detail::tvec3<T> const & v);
//! Transforms a matrix with a rotation 4 * 4 matrix created from an axis of 3 scalars and an angle expressed in degrees.
//! - From \link gtx_transform GLM_GTX_transform \endlink extension
// - See also: \link glm::rotate GLM_GTC_matrix_transform \endlink
/// Transforms a matrix with a rotation 4 * 4 matrix created from an axis of 3 scalars and an angle expressed in degrees.
/// - From \link gtx_transform GLM_GTX_transform \endlink extension
/// - See also: \link glm::rotate GLM_GTC_matrix_transform \endlink
template <typename T>
detail::tmat4x4<T> rotate(
detail::tmat4x4<T> const & m,
T angle,
T x, T y, T z);
//! Builds a scale 4 * 4 matrix created from 3 scalars.
//! - From \link gtx_transform GLM_GTX_transform \endlink extension
// - See also: \link glm::scale GLM_GTC_matrix_transform \endlink
/// Builds a scale 4 * 4 matrix created from 3 scalars.
/// - From \link gtx_transform GLM_GTX_transform \endlink extension
/// - See also: \link glm::scale GLM_GTC_matrix_transform \endlink
template <typename T>
detail::tmat4x4<T> scale(
T x, T y, T z);
//! Transforms a matrix with a scale 4 * 4 matrix created from 3 scalars.
//! - From \link gtx_transform GLM_GTX_transform \endlink extension
// - See also: \link glm::scale GLM_GTC_matrix_transform \endlink
/// Transforms a matrix with a scale 4 * 4 matrix created from 3 scalars.
/// - From \link gtx_transform GLM_GTX_transform \endlink extension
/// - See also: \link glm::scale GLM_GTC_matrix_transform \endlink
template <typename T>
detail::tmat4x4<T> scale(
detail::tmat4x4<T> const & m,
T x, T y, T z);
//! Transforms a matrix with a scale 4 * 4 matrix created from a vector of 3 components.
//! - From \link gtx_transform GLM_GTX_transform \endlink extension
// - See also: \link glm::scale GLM_GTC_matrix_transform \endlink
/// Transforms a matrix with a scale 4 * 4 matrix created from a vector of 3 components.
/// - From \link gtx_transform GLM_GTX_transform \endlink extension
/// - See also: \link glm::scale GLM_GTC_matrix_transform \endlink
template <typename T>
detail::tmat4x4<T> scale(
detail::tvec3<T> const & v);

View File

@ -9,82 +9,82 @@
namespace glm
{
template <typename T>
GLM_FUNC_QUALIFIER detail::tmat4x4<T> translate(
template <typename T>
GLM_FUNC_QUALIFIER detail::tmat4x4<T> translate(
T x, T y, T z)
{
{
return translate(
detail::tmat4x4<T>(1.0f),
detail::tvec3<T>(x, y , z));
}
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tmat4x4<T> translate(
template <typename T>
GLM_FUNC_QUALIFIER detail::tmat4x4<T> translate(
detail::tmat4x4<T> const & m,
T x, T y, T z)
{
return translate(
{
return translate(
m, detail::tvec3<T>(x, y , z));
}
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tmat4x4<T> translate(
template <typename T>
GLM_FUNC_QUALIFIER detail::tmat4x4<T> translate(
detail::tvec3<T> const & v)
{
{
return translate(
detail::tmat4x4<T>(1.0f), v);
}
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tmat4x4<T> rotate(
template <typename T>
GLM_FUNC_QUALIFIER detail::tmat4x4<T> rotate(
T angle,
T x, T y, T z)
{
{
return rotate(
detail::tmat4x4<T>(1), angle, detail::tvec3<T>(x, y, z));
}
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tmat4x4<T> rotate(
template <typename T>
GLM_FUNC_QUALIFIER detail::tmat4x4<T> rotate(
T angle,
detail::tvec3<T> const & v)
{
{
return rotate(
detail::tmat4x4<T>(1), angle, v);
}
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tmat4x4<T> rotate(
template <typename T>
GLM_FUNC_QUALIFIER detail::tmat4x4<T> rotate(
detail::tmat4x4<T> const & m,
T angle,
T x, T y, T z)
{
{
return rotate(
m, angle, detail::tvec3<T>(x, y, z));
}
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tmat4x4<T> scale(T x, T y, T z)
{
template <typename T>
GLM_FUNC_QUALIFIER detail::tmat4x4<T> scale(T x, T y, T z)
{
return scale(
detail::tmat4x4<T>(1), detail::tvec3<T>(x, y, z));
}
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tmat4x4<T> scale(
template <typename T>
GLM_FUNC_QUALIFIER detail::tmat4x4<T> scale(
detail::tmat4x4<T> const & m,
T x, T y, T z)
{
return scale(
{
return scale(
m, detail::tvec3<T>(x, y, z));
}
}
template <typename T>
GLM_FUNC_QUALIFIER detail::tmat4x4<T> scale(
template <typename T>
GLM_FUNC_QUALIFIER detail::tmat4x4<T> scale(
detail::tvec3<T> const & v)
{
return scale(
{
return scale(
detail::tmat4x4<T>(1.0f), v);
}
}
}//namespace glm

View File

@ -5,6 +5,7 @@ glmCreateTestGTC(gtx_matrix_interpolation)
glmCreateTestGTC(gtx_matrix_query)
glmCreateTestGTC(gtx_multiple)
glmCreateTestGTC(gtx_quaternion)
glmCreateTestGTC(gtx_rotate_normalized_axis)
glmCreateTestGTC(gtx_rotate_vector)
glmCreateTestGTC(gtx_simd_vec4)
glmCreateTestGTC(gtx_simd_mat4)

View File

@ -0,0 +1,37 @@
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2012 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @ref gtx_rotate_normalized_axis
/// @file test/gtx/rotate_normalized_axis.cpp
/// @date 2012-12-13 / 2012-12-13
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////////////////////
#include <glm/glm.hpp>
#include <glm/gtx/rotate_normalized_axis.hpp>
int main()
{
int Error(0);
return Error;
}