Commit 338ae906 authored by Nianchen Deng's avatar Nianchen Deng
Browse files

tog'21 baseline

parent f1dd9e3a
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 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.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// 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_handed_coordinate_space
/// @file glm/gtx/handed_coordinate_space.inl
/// @date 2005-12-21 / 2009-02-19
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace glm
{
template <typename T, precision P>
GLM_FUNC_QUALIFIER bool rightHanded
(
tvec3<T, P> const & tangent,
tvec3<T, P> const & binormal,
tvec3<T, P> const & normal
)
{
return dot(cross(normal, tangent), binormal) > T(0);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER bool leftHanded
(
tvec3<T, P> const & tangent,
tvec3<T, P> const & binormal,
tvec3<T, P> const & normal
)
{
return dot(cross(normal, tangent), binormal) < T(0);
}
}//namespace glm
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 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.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// 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_integer
/// @file glm/gtx/integer.hpp
/// @date 2005-12-24 / 2011-10-13
/// @author Christophe Riccio
///
/// @see core (dependence)
///
/// @defgroup gtx_integer GLM_GTX_integer
/// @ingroup gtx
///
/// @brief Add support for integer for core functions
///
/// <glm/gtx/integer.hpp> need to be included to use these functionalities.
///////////////////////////////////////////////////////////////////////////////////
#pragma once
// Dependency:
#include "../glm.hpp"
#include "../gtc/integer.hpp"
#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
# pragma message("GLM: GLM_GTX_integer extension included")
#endif
namespace glm
{
/// @addtogroup gtx_integer
/// @{
//! Returns x raised to the y power.
//! From GLM_GTX_integer extension.
GLM_FUNC_DECL int pow(int x, int y);
//! Returns the positive square root of x.
//! From GLM_GTX_integer extension.
GLM_FUNC_DECL int sqrt(int x);
//! Returns the floor log2 of x.
//! From GLM_GTX_integer extension.
GLM_FUNC_DECL unsigned int floor_log2(unsigned int x);
//! Modulus. Returns x - y * floor(x / y) for each component in x using the floating point value y.
//! From GLM_GTX_integer extension.
GLM_FUNC_DECL int mod(int x, int y);
//! Return the factorial value of a number (!12 max, integer only)
//! From GLM_GTX_integer extension.
template <typename genType>
GLM_FUNC_DECL genType factorial(genType const & x);
//! 32bit signed integer.
//! From GLM_GTX_integer extension.
typedef signed int sint;
//! Returns x raised to the y power.
//! From GLM_GTX_integer extension.
GLM_FUNC_DECL uint pow(uint x, uint y);
//! Returns the positive square root of x.
//! From GLM_GTX_integer extension.
GLM_FUNC_DECL uint sqrt(uint x);
//! Modulus. Returns x - y * floor(x / y) for each component in x using the floating point value y.
//! From GLM_GTX_integer extension.
GLM_FUNC_DECL uint mod(uint x, uint y);
//! Returns the number of leading zeros.
//! From GLM_GTX_integer extension.
GLM_FUNC_DECL uint nlz(uint x);
/// @}
}//namespace glm
#include "integer.inl"
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 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.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// 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_integer
/// @file glm/gtx/integer.inl
/// @date 2005-12-24 / 2011-10-13
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////////////////////
namespace glm
{
// pow
GLM_FUNC_QUALIFIER int pow(int x, int y)
{
if(y == 0)
return 1;
int result = x;
for(int i = 1; i < y; ++i)
result *= x;
return result;
}
// sqrt: From Christopher J. Musial, An integer square root, Graphics Gems, 1990, page 387
GLM_FUNC_QUALIFIER int sqrt(int x)
{
if(x <= 1) return x;
int NextTrial = x >> 1;
int CurrentAnswer;
do
{
CurrentAnswer = NextTrial;
NextTrial = (NextTrial + x / NextTrial) >> 1;
} while(NextTrial < CurrentAnswer);
return CurrentAnswer;
}
// Henry Gordon Dietz: http://aggregate.org/MAGIC/
namespace detail
{
GLM_FUNC_QUALIFIER unsigned int ones32(unsigned int x)
{
/* 32-bit recursive reduction using SWAR...
but first step is mapping 2-bit values
into sum of 2 1-bit values in sneaky way
*/
x -= ((x >> 1) & 0x55555555);
x = (((x >> 2) & 0x33333333) + (x & 0x33333333));
x = (((x >> 4) + x) & 0x0f0f0f0f);
x += (x >> 8);
x += (x >> 16);
return(x & 0x0000003f);
}
}//namespace detail
// Henry Gordon Dietz: http://aggregate.org/MAGIC/
/*
GLM_FUNC_QUALIFIER unsigned int floor_log2(unsigned int x)
{
x |= (x >> 1);
x |= (x >> 2);
x |= (x >> 4);
x |= (x >> 8);
x |= (x >> 16);
return _detail::ones32(x) >> 1;
}
*/
// mod
GLM_FUNC_QUALIFIER int mod(int x, int y)
{
return x - y * (x / y);
}
// factorial (!12 max, integer only)
template <typename genType>
GLM_FUNC_QUALIFIER genType factorial(genType const & x)
{
genType Temp = x;
genType Result;
for(Result = 1; Temp > 1; --Temp)
Result *= Temp;
return Result;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec2<T, P> factorial(
tvec2<T, P> const & x)
{
return tvec2<T, P>(
factorial(x.x),
factorial(x.y));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> factorial(
tvec3<T, P> const & x)
{
return tvec3<T, P>(
factorial(x.x),
factorial(x.y),
factorial(x.z));
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec4<T, P> factorial(
tvec4<T, P> const & x)
{
return tvec4<T, P>(
factorial(x.x),
factorial(x.y),
factorial(x.z),
factorial(x.w));
}
GLM_FUNC_QUALIFIER uint pow(uint x, uint y)
{
uint result = x;
for(uint i = 1; i < y; ++i)
result *= x;
return result;
}
GLM_FUNC_QUALIFIER uint sqrt(uint x)
{
if(x <= 1) return x;
uint NextTrial = x >> 1;
uint CurrentAnswer;
do
{
CurrentAnswer = NextTrial;
NextTrial = (NextTrial + x / NextTrial) >> 1;
} while(NextTrial < CurrentAnswer);
return CurrentAnswer;
}
GLM_FUNC_QUALIFIER uint mod(uint x, uint y)
{
return x - y * (x / y);
}
#if(GLM_COMPILER & (GLM_COMPILER_VC | GLM_COMPILER_GCC))
GLM_FUNC_QUALIFIER unsigned int nlz(unsigned int x)
{
return 31u - findMSB(x);
}
#else
// Hackers Delight: http://www.hackersdelight.org/HDcode/nlz.c.txt
GLM_FUNC_QUALIFIER unsigned int nlz(unsigned int x)
{
int y, m, n;
y = -int(x >> 16); // If left half of x is 0,
m = (y >> 16) & 16; // set n = 16. If left half
n = 16 - m; // is nonzero, set n = 0 and
x = x >> m; // shift x right 16.
// Now x is of the form 0000xxxx.
y = x - 0x100; // If positions 8-15 are 0,
m = (y >> 16) & 8; // add 8 to n and shift x left 8.
n = n + m;
x = x << m;
y = x - 0x1000; // If positions 12-15 are 0,
m = (y >> 16) & 4; // add 4 to n and shift x left 4.
n = n + m;
x = x << m;
y = x - 0x4000; // If positions 14-15 are 0,
m = (y >> 16) & 2; // add 2 to n and shift x left 2.
n = n + m;
x = x << m;
y = x >> 14; // Set y = 0, 1, 2, or 3.
m = y & ~(y >> 1); // Set m = 0, 1, 2, or 2 resp.
return unsigned(n + 2 - m);
}
#endif//(GLM_COMPILER)
}//namespace glm
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 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.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// 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_intersect
/// @file glm/gtx/intersect.hpp
/// @date 2007-04-03 / 2011-06-07
/// @author Christophe Riccio
///
/// @see core (dependence)
/// @see gtx_closest_point (dependence)
///
/// @defgroup gtx_intersect GLM_GTX_intersect
/// @ingroup gtx
///
/// @brief Add intersection functions
///
/// <glm/gtx/intersect.hpp> need to be included to use these functionalities.
///////////////////////////////////////////////////////////////////////////////////
#pragma once
// Dependency:
#include "../glm.hpp"
#include "../gtx/closest_point.hpp"
#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
# pragma message("GLM: GLM_GTX_closest_point extension included")
#endif
namespace glm
{
/// @addtogroup gtx_intersect
/// @{
//! Compute the intersection of a ray and a triangle.
//! Ray direction and plane normal must be unit length.
//! From GLM_GTX_intersect extension.
template <typename genType>
GLM_FUNC_DECL bool intersectRayPlane(
genType const & orig, genType const & dir,
genType const & planeOrig, genType const & planeNormal,
typename genType::value_type & intersectionDistance);
//! Compute the intersection of a ray and a triangle.
//! From GLM_GTX_intersect extension.
template <typename genType>
GLM_FUNC_DECL bool intersectRayTriangle(
genType const & orig, genType const & dir,
genType const & vert0, genType const & vert1, genType const & vert2,
genType & baryPosition);
//! Compute the intersection of a line and a triangle.
//! From GLM_GTX_intersect extension.
template <typename genType>
GLM_FUNC_DECL bool intersectLineTriangle(
genType const & orig, genType const & dir,
genType const & vert0, genType const & vert1, genType const & vert2,
genType & position);
//! Compute the intersection distance of a ray and a sphere.
//! The ray direction vector is unit length.
//! From GLM_GTX_intersect extension.
template <typename genType>
GLM_FUNC_DECL bool intersectRaySphere(
genType const & rayStarting, genType const & rayNormalizedDirection,
genType const & sphereCenter, typename genType::value_type const sphereRadiusSquered,
typename genType::value_type & intersectionDistance);
//! Compute the intersection of a ray and a sphere.
//! From GLM_GTX_intersect extension.
template <typename genType>
GLM_FUNC_DECL bool intersectRaySphere(
genType const & rayStarting, genType const & rayNormalizedDirection,
genType const & sphereCenter, const typename genType::value_type sphereRadius,
genType & intersectionPosition, genType & intersectionNormal);
//! Compute the intersection of a line and a sphere.
//! From GLM_GTX_intersect extension
template <typename genType>
GLM_FUNC_DECL bool intersectLineSphere(
genType const & point0, genType const & point1,
genType const & sphereCenter, typename genType::value_type sphereRadius,
genType & intersectionPosition1, genType & intersectionNormal1,
genType & intersectionPosition2 = genType(), genType & intersectionNormal2 = genType());
/// @}
}//namespace glm
#include "intersect.inl"
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Mathematics Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2007-04-03
// Updated : 2009-01-20
// Licence : This source is under MIT licence
// File : glm/gtx/intersect.inl
///////////////////////////////////////////////////////////////////////////////////////////////////
#include "../geometric.hpp"
#include <cfloat>
#include <limits>
namespace glm
{
template <typename genType>
GLM_FUNC_QUALIFIER bool intersectRayPlane
(
genType const & orig, genType const & dir,
genType const & planeOrig, genType const & planeNormal,
typename genType::value_type & intersectionDistance
)
{
typename genType::value_type d = glm::dot(dir, planeNormal);
typename genType::value_type Epsilon = std::numeric_limits<typename genType::value_type>::epsilon();
if(d < Epsilon)
{
intersectionDistance = glm::dot(planeOrig - orig, planeNormal) / d;
return true;
}
return false;
}
template <typename genType>
GLM_FUNC_QUALIFIER bool intersectRayTriangle
(
genType const & orig, genType const & dir,
genType const & v0, genType const & v1, genType const & v2,
genType & baryPosition
)
{
genType e1 = v1 - v0;
genType e2 = v2 - v0;
genType p = glm::cross(dir, e2);
typename genType::value_type a = glm::dot(e1, p);
typename genType::value_type Epsilon = std::numeric_limits<typename genType::value_type>::epsilon();
if(a < Epsilon)
return false;
typename genType::value_type f = typename genType::value_type(1.0f) / a;
genType s = orig - v0;
baryPosition.x = f * glm::dot(s, p);
if(baryPosition.x < typename genType::value_type(0.0f))
return false;
if(baryPosition.x > typename genType::value_type(1.0f))
return false;
genType q = glm::cross(s, e1);
baryPosition.y = f * glm::dot(dir, q);
if(baryPosition.y < typename genType::value_type(0.0f))
return false;
if(baryPosition.y + baryPosition.x > typename genType::value_type(1.0f))
return false;
baryPosition.z = f * glm::dot(e2, q);
return baryPosition.z >= typename genType::value_type(0.0f);
}
//template <typename genType>
//GLM_FUNC_QUALIFIER bool intersectRayTriangle
//(
// genType const & orig, genType const & dir,
// genType const & vert0, genType const & vert1, genType const & vert2,
// genType & position
//)
//{
// typename genType::value_type Epsilon = std::numeric_limits<typename genType::value_type>::epsilon();
//
// genType edge1 = vert1 - vert0;
// genType edge2 = vert2 - vert0;
//
// genType pvec = cross(dir, edge2);
//
// float det = dot(edge1, pvec);
// if(det < Epsilon)
// return false;
//
// genType tvec = orig - vert0;
//
// position.y = dot(tvec, pvec);
// if (position.y < typename genType::value_type(0) || position.y > det)
// return typename genType::value_type(0);
//
// genType qvec = cross(tvec, edge1);
//
// position.z = dot(dir, qvec);
// if (position.z < typename genType::value_type(0) || position.y + position.z > det)
// return typename genType::value_type(0);
//
// position.x = dot(edge2, qvec);
// position *= typename genType::value_type(1) / det;
//
// return typename genType::value_type(1);
//}
template <typename genType>
GLM_FUNC_QUALIFIER bool intersectLineTriangle
(
genType const & orig, genType const & dir,
genType const & vert0, genType const & vert1, genType const & vert2,
genType & position
)
{
typename genType::value_type Epsilon = std::numeric_limits<typename genType::value_type>::epsilon();
genType edge1 = vert1 - vert0;
genType edge2 = vert2 - vert0;
genType pvec = cross(dir, edge2);
float det = dot(edge1, pvec);
if (det > -Epsilon && det < Epsilon)
return false;
float inv_det = typename genType::value_type(1) / det;
genType tvec = orig - vert0;
position.y = dot(tvec, pvec) * inv_det;
if (position.y < typename genType::value_type(0) || position.y > typename genType::value_type(1))
return false;
genType qvec = cross(tvec, edge1);
position.z = dot(dir, qvec) * inv_det;
if (position.z < typename genType::value_type(0) || position.y + position.z > typename genType::value_type(1))
return false;
position.x = dot(edge2, qvec) * inv_det;
return true;
}
template <typename genType>
GLM_FUNC_QUALIFIER bool intersectRaySphere
(
genType const & rayStarting, genType const & rayNormalizedDirection,
genType const & sphereCenter, const typename genType::value_type sphereRadiusSquered,
typename genType::value_type & intersectionDistance
)
{
typename genType::value_type Epsilon = std::numeric_limits<typename genType::value_type>::epsilon();
genType diff = sphereCenter - rayStarting;
typename genType::value_type t0 = dot(diff, rayNormalizedDirection);
typename genType::value_type dSquared = dot(diff, diff) - t0 * t0;
if( dSquared > sphereRadiusSquered )
{
return false;
}
typename genType::value_type t1 = sqrt( sphereRadiusSquered - dSquared );
intersectionDistance = t0 > t1 + Epsilon ? t0 - t1 : t0 + t1;
return intersectionDistance > Epsilon;
}
template <typename genType>
GLM_FUNC_QUALIFIER bool intersectRaySphere
(
genType const & rayStarting, genType const & rayNormalizedDirection,
genType const & sphereCenter, const typename genType::value_type sphereRadius,
genType & intersectionPosition, genType & intersectionNormal
)
{
typename genType::value_type distance;
if( intersectRaySphere( rayStarting, rayNormalizedDirection, sphereCenter, sphereRadius * sphereRadius, distance ) )
{
intersectionPosition = rayStarting + rayNormalizedDirection * distance;
intersectionNormal = (intersectionPosition - sphereCenter) / sphereRadius;
return true;
}
return false;
}
template <typename genType>
GLM_FUNC_QUALIFIER bool intersectLineSphere
(
genType const & point0, genType const & point1,
genType const & sphereCenter, typename genType::value_type sphereRadius,
genType & intersectionPoint1, genType & intersectionNormal1,
genType & intersectionPoint2, genType & intersectionNormal2
)
{
typename genType::value_type Epsilon = std::numeric_limits<typename genType::value_type>::epsilon();
genType dir = normalize(point1 - point0);
genType diff = sphereCenter - point0;
typename genType::value_type t0 = dot(diff, dir);
typename genType::value_type dSquared = dot(diff, diff) - t0 * t0;
if( dSquared > sphereRadius * sphereRadius )
{
return false;
}
typename genType::value_type t1 = sqrt( sphereRadius * sphereRadius - dSquared );
if( t0 < t1 + Epsilon )
t1 = -t1;
intersectionPoint1 = point0 + dir * (t0 - t1);
intersectionNormal1 = (intersectionPoint1 - sphereCenter) / sphereRadius;
intersectionPoint2 = point0 + dir * (t0 + t1);
intersectionNormal2 = (intersectionPoint2 - sphereCenter) / sphereRadius;
return true;
}
}//namespace glm
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2013 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.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// 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_io
/// @file glm/gtx/io.hpp
/// @date 2013-11-22 / 2014-11-25
/// @author Jan P Springer (regnirpsj@gmail.com)
///
/// @see core (dependence)
/// @see gtc_quaternion (dependence)
///
/// @defgroup gtx_io GLM_GTX_io
/// @ingroup gtx
///
/// @brief std::[w]ostream support for glm types
///
/// std::[w]ostream support for glm types + precision/width/etc. manipulators
/// based on howard hinnant's std::chrono io proposal
/// [http://home.roadrunner.com/~hinnant/bloomington/chrono_io.html]
///
/// <glm/gtx/io.hpp> needs to be included to use these functionalities.
///////////////////////////////////////////////////////////////////////////////////
#pragma once
// Dependency:
#include "../glm.hpp"
#include "../gtx/quaternion.hpp"
#if(defined(GLM_MESSAGES) && !defined(glm_ext))
# pragma message("GLM: GLM_GTX_io extension included")
#endif
#include <iosfwd> // std::basic_ostream<> (fwd)
#include <locale> // std::locale, std::locale::facet, std::locale::id
#include <utility> // std::pair<>
namespace glm
{
/// @addtogroup gtx_io
/// @{
namespace io
{
enum order_type { column_major, row_major};
template <typename CTy>
class format_punct : public std::locale::facet
{
typedef CTy char_type;
public:
static std::locale::id id;
bool formatted;
unsigned precision;
unsigned width;
char_type separator;
char_type delim_left;
char_type delim_right;
char_type space;
char_type newline;
order_type order;
explicit format_punct(size_t a = 0);
explicit format_punct(format_punct const&);
};
template <typename CTy, typename CTr = std::char_traits<CTy> >
class basic_state_saver {
public:
explicit basic_state_saver(std::basic_ios<CTy,CTr>&);
~basic_state_saver();
private:
typedef ::std::basic_ios<CTy,CTr> state_type;
typedef typename state_type::char_type char_type;
typedef ::std::ios_base::fmtflags flags_type;
typedef ::std::streamsize streamsize_type;
typedef ::std::locale const locale_type;
state_type& state_;
flags_type flags_;
streamsize_type precision_;
streamsize_type width_;
char_type fill_;
locale_type locale_;
basic_state_saver& operator=(basic_state_saver const&);
};
typedef basic_state_saver<char> state_saver;
typedef basic_state_saver<wchar_t> wstate_saver;
template <typename CTy, typename CTr = std::char_traits<CTy> >
class basic_format_saver
{
public:
explicit basic_format_saver(std::basic_ios<CTy,CTr>&);
~basic_format_saver();
private:
basic_state_saver<CTy> const bss_;
basic_format_saver& operator=(basic_format_saver const&);
};
typedef basic_format_saver<char> format_saver;
typedef basic_format_saver<wchar_t> wformat_saver;
struct precision
{
unsigned value;
explicit precision(unsigned);
};
struct width
{
unsigned value;
explicit width(unsigned);
};
template <typename CTy>
struct delimeter
{
CTy value[3];
explicit delimeter(CTy /* left */, CTy /* right */, CTy /* separator */ = ',');
};
struct order
{
order_type value;
explicit order(order_type);
};
// functions, inlined (inline)
template <typename FTy, typename CTy, typename CTr>
FTy const& get_facet(std::basic_ios<CTy,CTr>&);
template <typename FTy, typename CTy, typename CTr>
std::basic_ios<CTy,CTr>& formatted(std::basic_ios<CTy,CTr>&);
template <typename FTy, typename CTy, typename CTr>
std::basic_ios<CTy,CTr>& unformattet(std::basic_ios<CTy,CTr>&);
template <typename CTy, typename CTr>
std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>&, precision const&);
template <typename CTy, typename CTr>
std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>&, width const&);
template <typename CTy, typename CTr>
std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>&, delimeter<CTy> const&);
template <typename CTy, typename CTr>
std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>&, order const&);
}//namespace io
template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, tquat<T,P> const&);
template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, tvec2<T,P> const&);
template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, tvec3<T,P> const&);
template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, tvec4<T,P> const&);
template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, tmat2x2<T,P> const&);
template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, tmat2x3<T,P> const&);
template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, tmat2x4<T,P> const&);
template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, tmat3x2<T,P> const&);
template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, tmat3x3<T,P> const&);
template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, tmat3x4<T,P> const&);
template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, tmat4x2<T,P> const&);
template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, tmat4x3<T,P> const&);
template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_DECL std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>&, tmat4x4<T,P> const&);
template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_DECL std::basic_ostream<CTy,CTr> & operator<<(
std::basic_ostream<CTy,CTr> &,
std::pair<tmat4x4<T,P> const,
tmat4x4<T,P> const> const &);
/// @}
}//namespace glm
#include "io.inl"
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2013 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.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// 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_io
/// @file glm/gtx/io.inl
/// @date 2013-11-22 / 2014-11-25
/// @author Jan P Springer (regnirpsj@gmail.com)
///////////////////////////////////////////////////////////////////////////////////////////////////
#include <iomanip> // std::setfill<>, std::fixed, std::setprecision, std::right, std::setw
#include <ostream> // std::basic_ostream<>
namespace glm{
namespace io
{
template <typename CTy>
/* explicit */ GLM_FUNC_QUALIFIER
format_punct<CTy>::format_punct(size_t a)
: std::locale::facet(a),
formatted (true),
precision (3),
width (1 + 4 + 1 + precision),
separator (','),
delim_left ('['),
delim_right (']'),
space (' '),
newline ('\n'),
order (row_major)
{}
template <typename CTy>
/* explicit */ GLM_FUNC_QUALIFIER
format_punct<CTy>::format_punct(format_punct const& a)
: std::locale::facet(0),
formatted (a.formatted),
precision (a.precision),
width (a.width),
separator (a.separator),
delim_left (a.delim_left),
delim_right (a.delim_right),
space (a.space),
newline (a.newline),
order (a.order)
{}
template <typename CTy> std::locale::id format_punct<CTy>::id;
template <typename CTy, typename CTr>
/* explicit */ GLM_FUNC_QUALIFIER basic_state_saver<CTy,CTr>::basic_state_saver(std::basic_ios<CTy,CTr>& a)
: state_ (a),
flags_ (a.flags()),
precision_(a.precision()),
width_ (a.width()),
fill_ (a.fill()),
locale_ (a.getloc())
{}
template <typename CTy, typename CTr>
GLM_FUNC_QUALIFIER basic_state_saver<CTy,CTr>::~basic_state_saver()
{
state_.imbue(locale_);
state_.fill(fill_);
state_.width(width_);
state_.precision(precision_);
state_.flags(flags_);
}
template <typename CTy, typename CTr>
/* explicit */ GLM_FUNC_QUALIFIER basic_format_saver<CTy,CTr>::basic_format_saver(std::basic_ios<CTy,CTr>& a)
: bss_(a)
{
a.imbue(std::locale(a.getloc(), new format_punct<CTy>(get_facet<format_punct<CTy> >(a))));
}
template <typename CTy, typename CTr>
GLM_FUNC_QUALIFIER
basic_format_saver<CTy,CTr>::~basic_format_saver()
{}
/* explicit */ GLM_FUNC_QUALIFIER precision::precision(unsigned a)
: value(a)
{}
/* explicit */ GLM_FUNC_QUALIFIER width::width(unsigned a)
: value(a)
{}
template <typename CTy>
/* explicit */ GLM_FUNC_QUALIFIER delimeter<CTy>::delimeter(CTy a, CTy b, CTy c)
: value()
{
value[0] = a;
value[1] = b;
value[2] = c;
}
/* explicit */ GLM_FUNC_QUALIFIER
order::order(order_type a)
: value(a)
{}
template <typename FTy, typename CTy, typename CTr>
GLM_FUNC_QUALIFIER FTy const& get_facet(std::basic_ios<CTy,CTr>& ios)
{
if (!std::has_facet<FTy>(ios.getloc())) {
ios.imbue(std::locale(ios.getloc(), new FTy));
}
return std::use_facet<FTy>(ios.getloc());
}
template <typename CTy, typename CTr>
GLM_FUNC_QUALIFIER std::basic_ios<CTy,CTr>& formatted(std::basic_ios<CTy,CTr>& ios)
{
const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(ios)).formatted = true;
return ios;
}
template <typename CTy, typename CTr>
GLM_FUNC_QUALIFIER std::basic_ios<CTy,CTr>& unformatted(std::basic_ios<CTy,CTr>& ios)
{
const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(ios)).formatted = false;
return ios;
}
template <typename CTy, typename CTr>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>& os, precision const& a)
{
const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)).precision = a.value;
return os;
}
template <typename CTy, typename CTr>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>& os, width const& a)
{
const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)).width = a.value;
return os;
}
template <typename CTy, typename CTr>
std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>& os, delimeter<CTy> const& a)
{
format_punct<CTy> & fmt(const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)));
fmt.delim_left = a.value[0];
fmt.delim_right = a.value[1];
fmt.separator = a.value[2];
return os;
}
template <typename CTy, typename CTr>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy, CTr>& operator<<(std::basic_ostream<CTy, CTr>& os, order const& a)
{
const_cast<format_punct<CTy>&>(get_facet<format_punct<CTy> >(os)).order = a.value;
return os;
}
} // namespace io
template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tquat<T,P> const& a)
{
typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
if(cerberus)
{
io::format_punct<CTy> const & fmt(io::get_facet<io::format_punct<CTy> >(os));
if(fmt.formatted)
{
io::basic_state_saver<CTy> const bss(os);
os << std::fixed
<< std::right
<< std::setprecision(fmt.precision)
<< std::setfill(fmt.space)
<< fmt.delim_left
<< std::setw(fmt.width) << a.w << fmt.separator
<< std::setw(fmt.width) << a.x << fmt.separator
<< std::setw(fmt.width) << a.y << fmt.separator
<< std::setw(fmt.width) << a.z
<< fmt.delim_right;
}
else
{
os << a.w << fmt.space << a.x << fmt.space << a.y << fmt.space << a.z;
}
}
return os;
}
template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tvec2<T,P> const& a)
{
typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
if(cerberus)
{
io::format_punct<CTy> const & fmt(io::get_facet<io::format_punct<CTy> >(os));
if(fmt.formatted)
{
io::basic_state_saver<CTy> const bss(os);
os << std::fixed
<< std::right
<< std::setprecision(fmt.precision)
<< std::setfill(fmt.space)
<< fmt.delim_left
<< std::setw(fmt.width) << a.x << fmt.separator
<< std::setw(fmt.width) << a.y
<< fmt.delim_right;
}
else
{
os << a.x << fmt.space << a.y;
}
}
return os;
}
template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tvec3<T,P> const& a)
{
typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
if(cerberus)
{
io::format_punct<CTy> const & fmt(io::get_facet<io::format_punct<CTy> >(os));
if(fmt.formatted)
{
io::basic_state_saver<CTy> const bss(os);
os << std::fixed
<< std::right
<< std::setprecision(fmt.precision)
<< std::setfill(fmt.space)
<< fmt.delim_left
<< std::setw(fmt.width) << a.x << fmt.separator
<< std::setw(fmt.width) << a.y << fmt.separator
<< std::setw(fmt.width) << a.z
<< fmt.delim_right;
}
else
{
os << a.x << fmt.space << a.y << fmt.space << a.z;
}
}
return os;
}
template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tvec4<T,P> const& a)
{
typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
if(cerberus)
{
io::format_punct<CTy> const & fmt(io::get_facet<io::format_punct<CTy> >(os));
if(fmt.formatted)
{
io::basic_state_saver<CTy> const bss(os);
os << std::fixed
<< std::right
<< std::setprecision(fmt.precision)
<< std::setfill(fmt.space)
<< fmt.delim_left
<< std::setw(fmt.width) << a.x << fmt.separator
<< std::setw(fmt.width) << a.y << fmt.separator
<< std::setw(fmt.width) << a.z << fmt.separator
<< std::setw(fmt.width) << a.w
<< fmt.delim_right;
}
else
{
os << a.x << fmt.space << a.y << fmt.space << a.z << fmt.space << a.w;
}
}
return os;
}
template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tmat2x2<T,P> const& a)
{
typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
if(cerberus)
{
io::format_punct<CTy> const & fmt(io::get_facet<io::format_punct<CTy> >(os));
tmat2x2<T,P> m(a);
if(io::row_major == fmt.order)
m = transpose(a);
if(fmt.formatted)
{
os << fmt.newline
<< fmt.delim_left << m[0] << fmt.newline
<< fmt.space << m[1] << fmt.delim_right;
}
else
{
os << m[0] << fmt.space << m[1];
}
}
return os;
}
template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tmat2x3<T,P> const& a)
{
typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
if(cerberus)
{
io::format_punct<CTy> const & fmt(io::get_facet<io::format_punct<CTy> >(os));
tmat3x2<T,P> m(a);
if(io::row_major == fmt.order)
m = transpose(a);
if(fmt.formatted)
{
os << fmt.newline
<< fmt.delim_left << m[0] << fmt.newline
<< fmt.space << m[1] << fmt.newline
<< fmt.space << m[2] << fmt.delim_right;
}
else
{
os << m[0] << fmt.space << m[1] << fmt.space << m[2];
}
}
return os;
}
template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tmat2x4<T,P> const& a)
{
typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
if(cerberus)
{
io::format_punct<CTy> const & fmt(io::get_facet<io::format_punct<CTy> >(os));
tmat4x2<T,P> m(a);
if(io::row_major == fmt.order)
m = transpose(a);
if(fmt.formatted)
{
os << fmt.newline
<< fmt.delim_left << m[0] << fmt.newline
<< fmt.space << m[1] << fmt.newline
<< fmt.space << m[2] << fmt.newline
<< fmt.space << m[3] << fmt.delim_right;
}
else
{
os << m[0] << fmt.space << m[1] << fmt.space << m[2] << fmt.space << m[3];
}
}
return os;
}
template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tmat3x2<T,P> const& a)
{
typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
if(cerberus)
{
io::format_punct<CTy> const & fmt(io::get_facet<io::format_punct<CTy> >(os));
tmat2x3<T,P> m(a);
if(io::row_major == fmt.order)
m = transpose(a);
if(fmt.formatted)
{
os << fmt.newline
<< fmt.delim_left << m[0] << fmt.newline
<< fmt.space << m[1] << fmt.delim_right;
}
else
{
os << m[0] << fmt.space << m[1];
}
}
return os;
}
template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, tmat3x3<T,P> const& a)
{
typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
if(cerberus)
{
io::format_punct<CTy> const & fmt(io::get_facet<io::format_punct<CTy> >(os));
tmat3x3<T,P> m(a);
if(io::row_major == fmt.order)
m = transpose(a);
if(fmt.formatted)
{
os << fmt.newline
<< fmt.delim_left << m[0] << fmt.newline
<< fmt.space << m[1] << fmt.newline
<< fmt.space << m[2] << fmt.delim_right;
}
else
{
os << m[0] << fmt.space << m[1] << fmt.space << m[2];
}
}
return os;
}
template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr> & operator<<(std::basic_ostream<CTy,CTr>& os, tmat3x4<T,P> const& a)
{
typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
if(cerberus)
{
io::format_punct<CTy> const & fmt(io::get_facet<io::format_punct<CTy> >(os));
tmat4x3<T,P> m(a);
if(io::row_major == fmt.order)
m = transpose(a);
if (fmt.formatted)
{
os << fmt.newline
<< fmt.delim_left << m[0] << fmt.newline
<< fmt.space << m[1] << fmt.newline
<< fmt.space << m[2] << fmt.newline
<< fmt.space << m[3] << fmt.delim_right;
}
else
{
os << m[0] << fmt.space << m[1] << fmt.space << m[2] << fmt.space << m[3];
}
}
return os;
}
template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr> & operator<<(std::basic_ostream<CTy,CTr>& os, tmat4x2<T,P> const& a)
{
typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
if(cerberus)
{
io::format_punct<CTy> const & fmt(io::get_facet<io::format_punct<CTy> >(os));
tmat2x4<T,P> m(a);
if(io::row_major == fmt.order)
m = transpose(a);
if (fmt.formatted)
{
os << fmt.newline
<< fmt.delim_left << m[0] << fmt.newline
<< fmt.space << m[1] << fmt.delim_right;
}
else
{
os << m[0] << fmt.space << m[1];
}
}
return os;
}
template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr> & operator<<(std::basic_ostream<CTy,CTr>& os, tmat4x3<T,P> const& a)
{
typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
if(cerberus)
{
io::format_punct<CTy> const & fmt(io::get_facet<io::format_punct<CTy> >(os));
tmat3x4<T,P> m(a);
if(io::row_major == fmt.order)
m = transpose(a);
if(fmt.formatted)
{
os << fmt.newline
<< fmt.delim_left << m[0] << fmt.newline
<< fmt.space << m[1] << fmt.newline
<< fmt.space << m[2] << fmt.delim_right;
}
else
{
os << m[0] << fmt.space << m[1] << fmt.space << m[2];
}
}
return os;
}
template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr> & operator<<(std::basic_ostream<CTy,CTr>& os, tmat4x4<T,P> const& a)
{
typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
if(cerberus)
{
io::format_punct<CTy> const & fmt(io::get_facet<io::format_punct<CTy> >(os));
tmat4x4<T,P> m(a);
if (io::row_major == fmt.order)
m = transpose(a);
if(fmt.formatted)
{
os << fmt.newline
<< fmt.delim_left << m[0] << fmt.newline
<< fmt.space << m[1] << fmt.newline
<< fmt.space << m[2] << fmt.newline
<< fmt.space << m[3] << fmt.delim_right;
}
else
{
os << m[0] << fmt.space << m[1] << fmt.space << m[2] << fmt.space << m[3];
}
}
return os;
}
template <typename CTy, typename CTr, typename T, precision P>
GLM_FUNC_QUALIFIER std::basic_ostream<CTy,CTr>& operator<<(
std::basic_ostream<CTy,CTr> & os,
std::pair<tmat4x4<T,P> const, tmat4x4<T,P> const> const& a)
{
typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
if(cerberus)
{
io::format_punct<CTy> const & fmt(io::get_facet<io::format_punct<CTy> >(os));
tmat4x4<T,P> ml(a.first);
tmat4x4<T,P> mr(a.second);
if(io::row_major == fmt.order)
{
ml = transpose(a.first);
mr = transpose(a.second);
}
if(fmt.formatted)
{
CTy const & l(fmt.delim_left);
CTy const & r(fmt.delim_right);
CTy const & s(fmt.space);
os << fmt.newline
<< l << ml[0] << s << s << l << mr[0] << fmt.newline
<< s << ml[1] << s << s << s << mr[1] << fmt.newline
<< s << ml[2] << s << s << s << mr[2] << fmt.newline
<< s << ml[3] << r << s << s << mr[3] << r;
}
else
{
os << ml << fmt.space << mr;
}
}
return os;
}
}//namespace glm
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 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.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// 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_log_base
/// @file glm/gtx/log_base.hpp
/// @date 2008-10-24 / 2011-06-07
/// @author Christophe Riccio
///
/// @see core (dependence)
///
/// @defgroup gtx_log_base GLM_GTX_log_base
/// @ingroup gtx
///
/// @brief Logarithm for any base. base can be a vector or a scalar.
///
/// <glm/gtx/log_base.hpp> need to be included to use these functionalities.
///////////////////////////////////////////////////////////////////////////////////
#pragma once
// Dependency:
#include "../glm.hpp"
#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
# pragma message("GLM: GLM_GTX_log_base extension included")
#endif
namespace glm
{
/// @addtogroup gtx_log_base
/// @{
//! Logarithm for any base.
//! From GLM_GTX_log_base.
template <typename genType>
GLM_FUNC_DECL genType log(
genType x,
genType base);
//! Logarithm for any base.
//! From GLM_GTX_log_base.
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_DECL vecType<T, P> sign(
vecType<T, P> const & x,
vecType<T, P> const & base);
/// @}
}//namespace glm
#include "log_base.inl"
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 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.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// 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_log_base
/// @file glm/gtx/log_base.inl
/// @date 2008-10-24 / 2014-11-25
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
namespace glm
{
template <typename genType>
GLM_FUNC_QUALIFIER genType log(genType const & x, genType const & base)
{
assert(x != genType(0));
return glm::log(x) / glm::log(base);
}
template <typename T, precision P, template <typename, precision> class vecType>
GLM_FUNC_QUALIFIER vecType<T, P> log(vecType<T, P> const & x, vecType<T, P> const & base)
{
return glm::log(x) / glm::log(base);
}
}//namespace glm
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 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.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// 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_matrix_cross_product
/// @file glm/gtx/matrix_cross_product.hpp
/// @date 2005-12-21 / 2011-06-07
/// @author Christophe Riccio
///
/// @see core (dependence)
/// @see gtx_extented_min_max (dependence)
///
/// @defgroup gtx_matrix_cross_product GLM_GTX_matrix_cross_product
/// @ingroup gtx
///
/// @brief Build cross product matrices
///
/// <glm/gtx/matrix_cross_product.hpp> need to be included to use these functionalities.
///////////////////////////////////////////////////////////////////////////////////
#pragma once
// Dependency:
#include "../glm.hpp"
#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
# pragma message("GLM: GLM_GTX_matrix_cross_product extension included")
#endif
namespace glm
{
/// @addtogroup gtx_matrix_cross_product
/// @{
//! Build a cross product matrix.
//! From GLM_GTX_matrix_cross_product extension.
template <typename T, precision P>
GLM_FUNC_DECL tmat3x3<T, P> matrixCross3(
tvec3<T, P> const & x);
//! Build a cross product matrix.
//! From GLM_GTX_matrix_cross_product extension.
template <typename T, precision P>
GLM_FUNC_DECL tmat4x4<T, P> matrixCross4(
tvec3<T, P> const & x);
/// @}
}//namespace glm
#include "matrix_cross_product.inl"
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 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.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// 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_matrix_cross_product
/// @file glm/gtx/matrix_cross_product.inl
/// @date 2005-12-21 / 2005-12-21
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
namespace glm
{
template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat3x3<T, P> matrixCross3
(
tvec3<T, P> const & x
)
{
tmat3x3<T, P> Result(T(0));
Result[0][1] = x.z;
Result[1][0] = -x.z;
Result[0][2] = -x.y;
Result[2][0] = x.y;
Result[1][2] = x.x;
Result[2][1] = -x.x;
return Result;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x4<T, P> matrixCross4
(
tvec3<T, P> const & x
)
{
tmat4x4<T, P> Result(T(0));
Result[0][1] = x.z;
Result[1][0] = -x.z;
Result[0][2] = -x.y;
Result[2][0] = x.y;
Result[1][2] = x.x;
Result[2][1] = -x.x;
return Result;
}
}//namespace glm
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 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.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// 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_matrix_decompose
/// @file glm/gtx/matrix_decompose.hpp
/// @date 2014-08-29 / 2014-08-29
/// @author Christophe Riccio
///
/// @see core (dependence)
///
/// @defgroup gtx_matrix_decompose GLM_GTX_matrix_decompose
/// @ingroup gtx
///
/// @brief Decomposes a model matrix to translations, rotation and scale components
///
/// <glm/gtx/decomposition.hpp> need to be included to use these functionalities.
///////////////////////////////////////////////////////////////////////////////////
#pragma once
// Dependencies
#include "../mat4x4.hpp"
#include "../vec3.hpp"
#include "../vec4.hpp"
#include "../gtc/quaternion.hpp"
#include "../gtc/matrix_transform.hpp"
#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
# pragma message("GLM: GLM_GTX_matrix_decompose extension included")
#endif
namespace glm
{
/// @addtogroup gtx_matrix_decompose
/// @{
/// Decomposes a model matrix to translations, rotation and scale components
/// @see gtx_matrix_decompose
template <typename T, precision P>
GLM_FUNC_DECL bool decompose(
tmat4x4<T, P> const & modelMatrix,
tvec3<T, P> & scale, tquat<T, P> & orientation, tvec3<T, P> & translation, tvec3<T, P> & skew, tvec4<T, P> & perspective);
/// @}
}//namespace glm
#include "matrix_decompose.inl"
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 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.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// 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_matrix_decompose
/// @file glm/gtx/matrix_decompose.inl
/// @date 2014-08-29 / 2014-08-29
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
namespace glm
{
/// Make a linear combination of two vectors and return the result.
// result = (a * ascl) + (b * bscl)
template <typename T, precision P>
GLM_FUNC_QUALIFIER tvec3<T, P> combine(
tvec3<T, P> const & a,
tvec3<T, P> const & b,
T ascl, T bscl)
{
return (a * ascl) + (b * bscl);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER void v3Scale(tvec3<T, P> & v, T desiredLength)
{
T len = glm::length(v);
if(len != 0)
{
T l = desiredLength / len;
v[0] *= l;
v[1] *= l;
v[2] *= l;
}
}
/**
* Matrix decompose
* http://www.opensource.apple.com/source/WebCore/WebCore-514/platform/graphics/transforms/TransformationMatrix.cpp
* Decomposes the mode matrix to translations,rotation scale components
*
*/
template <typename T, precision P>
GLM_FUNC_QUALIFIER bool decompose(tmat4x4<T, P> const & ModelMatrix, tvec3<T, P> & Scale, tquat<T, P> & Orientation, tvec3<T, P> & Translation, tvec3<T, P> & Skew, tvec4<T, P> & Perspective)
{
tmat4x4<T, P> LocalMatrix(ModelMatrix);
// Normalize the matrix.
if(LocalMatrix[3][3] == static_cast<T>(0))
return false;
for(length_t i = 0; i < 4; ++i)
for(length_t j = 0; j < 4; ++j)
LocalMatrix[i][j] /= LocalMatrix[3][3];
// perspectiveMatrix is used to solve for perspective, but it also provides
// an easy way to test for singularity of the upper 3x3 component.
tmat4x4<T, P> PerspectiveMatrix(LocalMatrix);
for(length_t i = 0; i < 3; i++)
PerspectiveMatrix[i][3] = 0;
PerspectiveMatrix[3][3] = 1;
/// TODO: Fixme!
if(determinant(PerspectiveMatrix) == static_cast<T>(0))
return false;
// First, isolate perspective. This is the messiest.
if(LocalMatrix[0][3] != 0 || LocalMatrix[1][3] != 0 || LocalMatrix[2][3] != 0)
{
// rightHandSide is the right hand side of the equation.
tvec4<T, P> RightHandSide;
RightHandSide[0] = LocalMatrix[0][3];
RightHandSide[1] = LocalMatrix[1][3];
RightHandSide[2] = LocalMatrix[2][3];
RightHandSide[3] = LocalMatrix[3][3];
// Solve the equation by inverting PerspectiveMatrix and multiplying
// rightHandSide by the inverse. (This is the easiest way, not
// necessarily the best.)
tmat4x4<T, P> InversePerspectiveMatrix = glm::inverse(PerspectiveMatrix);// inverse(PerspectiveMatrix, inversePerspectiveMatrix);
tmat4x4<T, P> TransposedInversePerspectiveMatrix = glm::transpose(InversePerspectiveMatrix);// transposeMatrix4(inversePerspectiveMatrix, transposedInversePerspectiveMatrix);
Perspective = TransposedInversePerspectiveMatrix * RightHandSide;
// v4MulPointByMatrix(rightHandSide, transposedInversePerspectiveMatrix, perspectivePoint);
// Clear the perspective partition
LocalMatrix[0][3] = LocalMatrix[1][3] = LocalMatrix[2][3] = 0;
LocalMatrix[3][3] = 1;
}
else
{
// No perspective.
Perspective = tvec4<T, P>(0, 0, 0, 1);
}
// Next take care of translation (easy).
Translation = tvec3<T, P>(LocalMatrix[3]);
LocalMatrix[3] = tvec4<T, P>(0, 0, 0, LocalMatrix[3].w);
tvec3<T, P> Row[3], Pdum3;
// Now get scale and shear.
for(length_t i = 0; i < 3; ++i)
for(int j = 0; j < 3; ++j)
Row[i][j] = LocalMatrix[i][j];
// Compute X scale factor and normalize first row.
Scale.x = length(Row[0]);// v3Length(Row[0]);
v3Scale(Row[0], static_cast<T>(1));
// Compute XY shear factor and make 2nd row orthogonal to 1st.
Skew.z = dot(Row[0], Row[1]);
Row[1] = combine(Row[1], Row[0], static_cast<T>(1), -Skew.z);
// Now, compute Y scale and normalize 2nd row.
Scale.y = length(Row[1]);
v3Scale(Row[1], static_cast<T>(1));
Skew.z /= Scale.y;
// Compute XZ and YZ shears, orthogonalize 3rd row.
Skew.y = glm::dot(Row[0], Row[2]);
Row[2] = combine(Row[2], Row[0], static_cast<T>(1), -Skew.y);
Skew.x = glm::dot(Row[1], Row[2]);
Row[2] = combine(Row[2], Row[1], static_cast<T>(1), -Skew.x);
// Next, get Z scale and normalize 3rd row.
Scale.z = length(Row[2]);
v3Scale(Row[2], static_cast<T>(1));
Skew.y /= Scale.z;
Skew.x /= Scale.z;
// At this point, the matrix (in rows[]) is orthonormal.
// Check for a coordinate system flip. If the determinant
// is -1, then negate the matrix and the scaling factors.
Pdum3 = cross(Row[1], Row[2]); // v3Cross(row[1], row[2], Pdum3);
if(dot(Row[0], Pdum3) < 0)
{
for(length_t i = 0; i < 3; i++)
{
Scale.x *= static_cast<T>(-1);
Row[i] *= static_cast<T>(-1);
}
}
// Now, get the rotations out, as described in the gem.
// FIXME - Add the ability to return either quaternions (which are
// easier to recompose with) or Euler angles (rx, ry, rz), which
// are easier for authors to deal with. The latter will only be useful
// when we fix https://bugs.webkit.org/show_bug.cgi?id=23799, so I
// will leave the Euler angle code here for now.
// ret.rotateY = asin(-Row[0][2]);
// if (cos(ret.rotateY) != 0) {
// ret.rotateX = atan2(Row[1][2], Row[2][2]);
// ret.rotateZ = atan2(Row[0][1], Row[0][0]);
// } else {
// ret.rotateX = atan2(-Row[2][0], Row[1][1]);
// ret.rotateZ = 0;
// }
T s, t, x, y, z, w;
t = Row[0][0] + Row[1][1] + Row[2][2] + 1.0;
if(t > 1e-4)
{
s = 0.5 / sqrt(t);
w = 0.25 / s;
x = (Row[2][1] - Row[1][2]) * s;
y = (Row[0][2] - Row[2][0]) * s;
z = (Row[1][0] - Row[0][1]) * s;
}
else if(Row[0][0] > Row[1][1] && Row[0][0] > Row[2][2])
{
s = sqrt (1.0 + Row[0][0] - Row[1][1] - Row[2][2]) * 2.0; // S=4*qx
x = 0.25 * s;
y = (Row[0][1] + Row[1][0]) / s;
z = (Row[0][2] + Row[2][0]) / s;
w = (Row[2][1] - Row[1][2]) / s;
}
else if(Row[1][1] > Row[2][2])
{
s = sqrt (1.0 + Row[1][1] - Row[0][0] - Row[2][2]) * 2.0; // S=4*qy
x = (Row[0][1] + Row[1][0]) / s;
y = 0.25 * s;
z = (Row[1][2] + Row[2][1]) / s;
w = (Row[0][2] - Row[2][0]) / s;
}
else
{
s = sqrt(1.0 + Row[2][2] - Row[0][0] - Row[1][1]) * 2.0; // S=4*qz
x = (Row[0][2] + Row[2][0]) / s;
y = (Row[1][2] + Row[2][1]) / s;
z = 0.25 * s;
w = (Row[1][0] - Row[0][1]) / s;
}
Orientation.x = x;
Orientation.y = y;
Orientation.z = z;
Orientation.w = w;
return true;
}
}//namespace glm
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 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.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// 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_matrix_interpolation
/// @file glm/gtx/matrix_interpolation.hpp
/// @date 2011-03-05 / 2011-06-07
/// @author Ghenadii Ursachi (the.asteroth@gmail.com)
///
/// @see core (dependence)
///
/// @defgroup gtx_matrix_interpolation GLM_GTX_matrix_interpolation
/// @ingroup gtx
///
/// @brief Allows to directly interpolate two exiciting matrices.
///
/// <glm/gtx/matrix_interpolation.hpp> need to be included to use these functionalities.
///////////////////////////////////////////////////////////////////////////////////
#pragma once
// Dependency:
#include "../glm.hpp"
#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
# pragma message("GLM: GLM_GTX_matrix_interpolation extension included")
#endif
namespace glm
{
/// @addtogroup gtx_matrix_interpolation
/// @{
/// Get the axis and angle of the rotation from a matrix.
/// From GLM_GTX_matrix_interpolation extension.
template <typename T, precision P>
GLM_FUNC_DECL void axisAngle(
tmat4x4<T, P> const & mat,
tvec3<T, P> & axis,
T & angle);
/// Build a matrix from axis and angle.
/// From GLM_GTX_matrix_interpolation extension.
template <typename T, precision P>
GLM_FUNC_DECL tmat4x4<T, P> axisAngleMatrix(
tvec3<T, P> const & axis,
T const angle);
/// Extracts the rotation part of a matrix.
/// From GLM_GTX_matrix_interpolation extension.
template <typename T, precision P>
GLM_FUNC_DECL tmat4x4<T, P> extractMatrixRotation(
tmat4x4<T, P> const & mat);
/// Build a interpolation of 4 * 4 matrixes.
/// From GLM_GTX_matrix_interpolation extension.
/// Warning! works only with rotation and/or translation matrixes, scale will generate unexpected results.
template <typename T, precision P>
GLM_FUNC_DECL tmat4x4<T, P> interpolate(
tmat4x4<T, P> const & m1,
tmat4x4<T, P> const & m2,
T const delta);
/// @}
}//namespace glm
#include "matrix_interpolation.inl"
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 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.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// 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_matrix_interpolation
/// @file glm/gtx/matrix_interpolation.hpp
/// @date 2011-03-05 / 2011-03-05
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
namespace glm
{
template <typename T, precision P>
GLM_FUNC_QUALIFIER void axisAngle
(
tmat4x4<T, P> const & mat,
tvec3<T, P> & axis,
T & angle
)
{
T epsilon = (T)0.01;
T epsilon2 = (T)0.1;
if((abs(mat[1][0] - mat[0][1]) < epsilon) && (abs(mat[2][0] - mat[0][2]) < epsilon) && (abs(mat[2][1] - mat[1][2]) < epsilon))
{
if ((abs(mat[1][0] + mat[0][1]) < epsilon2) && (abs(mat[2][0] + mat[0][2]) < epsilon2) && (abs(mat[2][1] + mat[1][2]) < epsilon2) && (abs(mat[0][0] + mat[1][1] + mat[2][2] - (T)3.0) < epsilon2))
{
angle = (T)0.0;
axis.x = (T)1.0;
axis.y = (T)0.0;
axis.z = (T)0.0;
return;
}
angle = static_cast<T>(3.1415926535897932384626433832795);
T xx = (mat[0][0] + (T)1.0) / (T)2.0;
T yy = (mat[1][1] + (T)1.0) / (T)2.0;
T zz = (mat[2][2] + (T)1.0) / (T)2.0;
T xy = (mat[1][0] + mat[0][1]) / (T)4.0;
T xz = (mat[2][0] + mat[0][2]) / (T)4.0;
T yz = (mat[2][1] + mat[1][2]) / (T)4.0;
if((xx > yy) && (xx > zz))
{
if (xx < epsilon) {
axis.x = (T)0.0;
axis.y = (T)0.7071;
axis.z = (T)0.7071;
} else {
axis.x = sqrt(xx);
axis.y = xy / axis.x;
axis.z = xz / axis.x;
}
}
else if (yy > zz)
{
if (yy < epsilon) {
axis.x = (T)0.7071;
axis.y = (T)0.0;
axis.z = (T)0.7071;
} else {
axis.y = sqrt(yy);
axis.x = xy / axis.y;
axis.z = yz / axis.y;
}
}
else
{
if (zz < epsilon) {
axis.x = (T)0.7071;
axis.y = (T)0.7071;
axis.z = (T)0.0;
} else {
axis.z = sqrt(zz);
axis.x = xz / axis.z;
axis.y = yz / axis.z;
}
}
return;
}
T s = sqrt((mat[2][1] - mat[1][2]) * (mat[2][1] - mat[1][2]) + (mat[2][0] - mat[0][2]) * (mat[2][0] - mat[0][2]) + (mat[1][0] - mat[0][1]) * (mat[1][0] - mat[0][1]));
if (glm::abs(s) < T(0.001))
s = (T)1.0;
angle = acos((mat[0][0] + mat[1][1] + mat[2][2] - (T)1.0) / (T)2.0);
axis.x = (mat[1][2] - mat[2][1]) / s;
axis.y = (mat[2][0] - mat[0][2]) / s;
axis.z = (mat[0][1] - mat[1][0]) / s;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x4<T, P> axisAngleMatrix
(
tvec3<T, P> const & axis,
T const angle
)
{
T c = cos(angle);
T s = sin(angle);
T t = static_cast<T>(1) - c;
tvec3<T, P> n = normalize(axis);
return tmat4x4<T, P>(
t * n.x * n.x + c, t * n.x * n.y + n.z * s, t * n.x * n.z - n.y * s, T(0),
t * n.x * n.y - n.z * s, t * n.y * n.y + c, t * n.y * n.z + n.x * s, T(0),
t * n.x * n.z + n.y * s, t * n.y * n.z - n.x * s, t * n.z * n.z + c, T(0),
T(0), T(0), T(0), T(1)
);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x4<T, P> extractMatrixRotation
(
tmat4x4<T, P> const & mat
)
{
return tmat4x4<T, P>(
mat[0][0], mat[0][1], mat[0][2], 0.0,
mat[1][0], mat[1][1], mat[1][2], 0.0,
mat[2][0], mat[2][1], mat[2][2], 0.0,
0.0, 0.0, 0.0, 1.0
);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x4<T, P> interpolate
(
tmat4x4<T, P> const & m1,
tmat4x4<T, P> const & m2,
T const delta
)
{
tmat4x4<T, P> m1rot = extractMatrixRotation(m1);
tmat4x4<T, P> dltRotation = m2 * transpose(m1rot);
tvec3<T, P> dltAxis;
T dltAngle;
axisAngle(dltRotation, dltAxis, dltAngle);
tmat4x4<T, P> out = axisAngleMatrix(dltAxis, dltAngle * delta) * m1rot;
out[3][0] = m1[3][0] + delta * (m2[3][0] - m1[3][0]);
out[3][1] = m1[3][1] + delta * (m2[3][1] - m1[3][1]);
out[3][2] = m1[3][2] + delta * (m2[3][2] - m1[3][2]);
return out;
}
}//namespace glm
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 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.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// 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_matrix_major_storage
/// @file glm/gtx/matrix_major_storage.hpp
/// @date 2006-04-19 / 2011-06-07
/// @author Christophe Riccio
///
/// @see core (dependence)
/// @see gtx_extented_min_max (dependence)
///
/// @defgroup gtx_matrix_major_storage GLM_GTX_matrix_major_storage
/// @ingroup gtx
///
/// @brief Build matrices with specific matrix order, row or column
///
/// <glm/gtx/matrix_major_storage.hpp> need to be included to use these functionalities.
///////////////////////////////////////////////////////////////////////////////////
#pragma once
// Dependency:
#include "../glm.hpp"
#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
# pragma message("GLM: GLM_GTX_matrix_major_storage extension included")
#endif
namespace glm
{
/// @addtogroup gtx_matrix_major_storage
/// @{
//! Build a row major matrix from row vectors.
//! From GLM_GTX_matrix_major_storage extension.
template <typename T, precision P>
GLM_FUNC_DECL tmat2x2<T, P> rowMajor2(
tvec2<T, P> const & v1,
tvec2<T, P> const & v2);
//! Build a row major matrix from other matrix.
//! From GLM_GTX_matrix_major_storage extension.
template <typename T, precision P>
GLM_FUNC_DECL tmat2x2<T, P> rowMajor2(
tmat2x2<T, P> const & m);
//! Build a row major matrix from row vectors.
//! From GLM_GTX_matrix_major_storage extension.
template <typename T, precision P>
GLM_FUNC_DECL tmat3x3<T, P> rowMajor3(
tvec3<T, P> const & v1,
tvec3<T, P> const & v2,
tvec3<T, P> const & v3);
//! Build a row major matrix from other matrix.
//! From GLM_GTX_matrix_major_storage extension.
template <typename T, precision P>
GLM_FUNC_DECL tmat3x3<T, P> rowMajor3(
tmat3x3<T, P> const & m);
//! Build a row major matrix from row vectors.
//! From GLM_GTX_matrix_major_storage extension.
template <typename T, precision P>
GLM_FUNC_DECL tmat4x4<T, P> rowMajor4(
tvec4<T, P> const & v1,
tvec4<T, P> const & v2,
tvec4<T, P> const & v3,
tvec4<T, P> const & v4);
//! Build a row major matrix from other matrix.
//! From GLM_GTX_matrix_major_storage extension.
template <typename T, precision P>
GLM_FUNC_DECL tmat4x4<T, P> rowMajor4(
tmat4x4<T, P> const & m);
//! Build a column major matrix from column vectors.
//! From GLM_GTX_matrix_major_storage extension.
template <typename T, precision P>
GLM_FUNC_DECL tmat2x2<T, P> colMajor2(
tvec2<T, P> const & v1,
tvec2<T, P> const & v2);
//! Build a column major matrix from other matrix.
//! From GLM_GTX_matrix_major_storage extension.
template <typename T, precision P>
GLM_FUNC_DECL tmat2x2<T, P> colMajor2(
tmat2x2<T, P> const & m);
//! Build a column major matrix from column vectors.
//! From GLM_GTX_matrix_major_storage extension.
template <typename T, precision P>
GLM_FUNC_DECL tmat3x3<T, P> colMajor3(
tvec3<T, P> const & v1,
tvec3<T, P> const & v2,
tvec3<T, P> const & v3);
//! Build a column major matrix from other matrix.
//! From GLM_GTX_matrix_major_storage extension.
template <typename T, precision P>
GLM_FUNC_DECL tmat3x3<T, P> colMajor3(
tmat3x3<T, P> const & m);
//! Build a column major matrix from column vectors.
//! From GLM_GTX_matrix_major_storage extension.
template <typename T, precision P>
GLM_FUNC_DECL tmat4x4<T, P> colMajor4(
tvec4<T, P> const & v1,
tvec4<T, P> const & v2,
tvec4<T, P> const & v3,
tvec4<T, P> const & v4);
//! Build a column major matrix from other matrix.
//! From GLM_GTX_matrix_major_storage extension.
template <typename T, precision P>
GLM_FUNC_DECL tmat4x4<T, P> colMajor4(
tmat4x4<T, P> const & m);
/// @}
}//namespace glm
#include "matrix_major_storage.inl"
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 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.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// 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_matrix_major_storage
/// @file glm/gtx/matrix_major_storage.hpp
/// @date 2006-04-19 / 2014-11-25
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
namespace glm
{
template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat2x2<T, P> rowMajor2
(
tvec2<T, P> const & v1,
tvec2<T, P> const & v2
)
{
tmat2x2<T, P> Result;
Result[0][0] = v1.x;
Result[1][0] = v1.y;
Result[0][1] = v2.x;
Result[1][1] = v2.y;
return Result;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat2x2<T, P> rowMajor2(
const tmat2x2<T, P>& m)
{
tmat2x2<T, P> Result;
Result[0][0] = m[0][0];
Result[0][1] = m[1][0];
Result[1][0] = m[0][1];
Result[1][1] = m[1][1];
return Result;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat3x3<T, P> rowMajor3(
const tvec3<T, P>& v1,
const tvec3<T, P>& v2,
const tvec3<T, P>& v3)
{
tmat3x3<T, P> Result;
Result[0][0] = v1.x;
Result[1][0] = v1.y;
Result[2][0] = v1.z;
Result[0][1] = v2.x;
Result[1][1] = v2.y;
Result[2][1] = v2.z;
Result[0][2] = v3.x;
Result[1][2] = v3.y;
Result[2][2] = v3.z;
return Result;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat3x3<T, P> rowMajor3(
const tmat3x3<T, P>& m)
{
tmat3x3<T, P> Result;
Result[0][0] = m[0][0];
Result[0][1] = m[1][0];
Result[0][2] = m[2][0];
Result[1][0] = m[0][1];
Result[1][1] = m[1][1];
Result[1][2] = m[2][1];
Result[2][0] = m[0][2];
Result[2][1] = m[1][2];
Result[2][2] = m[2][2];
return Result;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x4<T, P> rowMajor4(
const tvec4<T, P>& v1,
const tvec4<T, P>& v2,
const tvec4<T, P>& v3,
const tvec4<T, P>& v4)
{
tmat4x4<T, P> Result;
Result[0][0] = v1.x;
Result[1][0] = v1.y;
Result[2][0] = v1.z;
Result[3][0] = v1.w;
Result[0][1] = v2.x;
Result[1][1] = v2.y;
Result[2][1] = v2.z;
Result[3][1] = v2.w;
Result[0][2] = v3.x;
Result[1][2] = v3.y;
Result[2][2] = v3.z;
Result[3][2] = v3.w;
Result[0][3] = v4.x;
Result[1][3] = v4.y;
Result[2][3] = v4.z;
Result[3][3] = v4.w;
return Result;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x4<T, P> rowMajor4(
const tmat4x4<T, P>& m)
{
tmat4x4<T, P> Result;
Result[0][0] = m[0][0];
Result[0][1] = m[1][0];
Result[0][2] = m[2][0];
Result[0][3] = m[3][0];
Result[1][0] = m[0][1];
Result[1][1] = m[1][1];
Result[1][2] = m[2][1];
Result[1][3] = m[3][1];
Result[2][0] = m[0][2];
Result[2][1] = m[1][2];
Result[2][2] = m[2][2];
Result[2][3] = m[3][2];
Result[3][0] = m[0][3];
Result[3][1] = m[1][3];
Result[3][2] = m[2][3];
Result[3][3] = m[3][3];
return Result;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat2x2<T, P> colMajor2(
const tvec2<T, P>& v1,
const tvec2<T, P>& v2)
{
return tmat2x2<T, P>(v1, v2);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat2x2<T, P> colMajor2(
const tmat2x2<T, P>& m)
{
return tmat2x2<T, P>(m);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat3x3<T, P> colMajor3(
const tvec3<T, P>& v1,
const tvec3<T, P>& v2,
const tvec3<T, P>& v3)
{
return tmat3x3<T, P>(v1, v2, v3);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat3x3<T, P> colMajor3(
const tmat3x3<T, P>& m)
{
return tmat3x3<T, P>(m);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x4<T, P> colMajor4(
const tvec4<T, P>& v1,
const tvec4<T, P>& v2,
const tvec4<T, P>& v3,
const tvec4<T, P>& v4)
{
return tmat4x4<T, P>(v1, v2, v3, v4);
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x4<T, P> colMajor4(
const tmat4x4<T, P>& m)
{
return tmat4x4<T, P>(m);
}
}//namespace glm
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 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.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// 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_matrix_operation
/// @file glm/gtx/matrix_operation.hpp
/// @date 2009-08-29 / 2011-06-07
/// @author Christophe Riccio
///
/// @see core (dependence)
///
/// @defgroup gtx_matrix_operation GLM_GTX_matrix_operation
/// @ingroup gtx
///
/// @brief Build diagonal matrices from vectors.
///
/// <glm/gtx/matrix_operation.hpp> need to be included to use these functionalities.
///////////////////////////////////////////////////////////////////////////////////
#pragma once
// Dependency:
#include "../glm.hpp"
#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
# pragma message("GLM: GLM_GTX_matrix_operation extension included")
#endif
namespace glm
{
/// @addtogroup gtx_matrix_operation
/// @{
//! Build a diagonal matrix.
//! From GLM_GTX_matrix_operation extension.
template <typename T, precision P>
GLM_FUNC_DECL tmat2x2<T, P> diagonal2x2(
tvec2<T, P> const & v);
//! Build a diagonal matrix.
//! From GLM_GTX_matrix_operation extension.
template <typename T, precision P>
GLM_FUNC_DECL tmat2x3<T, P> diagonal2x3(
tvec2<T, P> const & v);
//! Build a diagonal matrix.
//! From GLM_GTX_matrix_operation extension.
template <typename T, precision P>
GLM_FUNC_DECL tmat2x4<T, P> diagonal2x4(
tvec2<T, P> const & v);
//! Build a diagonal matrix.
//! From GLM_GTX_matrix_operation extension.
template <typename T, precision P>
GLM_FUNC_DECL tmat3x2<T, P> diagonal3x2(
tvec2<T, P> const & v);
//! Build a diagonal matrix.
//! From GLM_GTX_matrix_operation extension.
template <typename T, precision P>
GLM_FUNC_DECL tmat3x3<T, P> diagonal3x3(
tvec3<T, P> const & v);
//! Build a diagonal matrix.
//! From GLM_GTX_matrix_operation extension.
template <typename T, precision P>
GLM_FUNC_DECL tmat3x4<T, P> diagonal3x4(
tvec3<T, P> const & v);
//! Build a diagonal matrix.
//! From GLM_GTX_matrix_operation extension.
template <typename T, precision P>
GLM_FUNC_DECL tmat4x2<T, P> diagonal4x2(
tvec2<T, P> const & v);
//! Build a diagonal matrix.
//! From GLM_GTX_matrix_operation extension.
template <typename T, precision P>
GLM_FUNC_DECL tmat4x3<T, P> diagonal4x3(
tvec3<T, P> const & v);
//! Build a diagonal matrix.
//! From GLM_GTX_matrix_operation extension.
template <typename T, precision P>
GLM_FUNC_DECL tmat4x4<T, P> diagonal4x4(
tvec4<T, P> const & v);
/// @}
}//namespace glm
#include "matrix_operation.inl"
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 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.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// 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_matrix_operation
/// @file glm/gtx/matrix_operation.inl
/// @date 2009-08-29 / 2009-08-29
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
namespace glm
{
template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat2x2<T, P> diagonal2x2
(
tvec2<T, P> const & v
)
{
tmat2x2<T, P> Result(static_cast<T>(1));
Result[0][0] = v[0];
Result[1][1] = v[1];
return Result;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat2x3<T, P> diagonal2x3
(
tvec2<T, P> const & v
)
{
tmat2x3<T, P> Result(static_cast<T>(1));
Result[0][0] = v[0];
Result[1][1] = v[1];
return Result;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat2x4<T, P> diagonal2x4
(
tvec2<T, P> const & v
)
{
tmat2x4<T, P> Result(static_cast<T>(1));
Result[0][0] = v[0];
Result[1][1] = v[1];
return Result;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat3x2<T, P> diagonal3x2
(
tvec2<T, P> const & v
)
{
tmat3x2<T, P> Result(static_cast<T>(1));
Result[0][0] = v[0];
Result[1][1] = v[1];
return Result;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat3x3<T, P> diagonal3x3
(
tvec3<T, P> const & v
)
{
tmat3x3<T, P> Result(static_cast<T>(1));
Result[0][0] = v[0];
Result[1][1] = v[1];
Result[2][2] = v[2];
return Result;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat3x4<T, P> diagonal3x4
(
tvec3<T, P> const & v
)
{
tmat3x4<T, P> Result(static_cast<T>(1));
Result[0][0] = v[0];
Result[1][1] = v[1];
Result[2][2] = v[2];
return Result;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x4<T, P> diagonal4x4
(
tvec4<T, P> const & v
)
{
tmat4x4<T, P> Result(static_cast<T>(1));
Result[0][0] = v[0];
Result[1][1] = v[1];
Result[2][2] = v[2];
Result[3][3] = v[3];
return Result;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x3<T, P> diagonal4x3
(
tvec3<T, P> const & v
)
{
tmat4x3<T, P> Result(static_cast<T>(1));
Result[0][0] = v[0];
Result[1][1] = v[1];
Result[2][2] = v[2];
return Result;
}
template <typename T, precision P>
GLM_FUNC_QUALIFIER tmat4x2<T, P> diagonal4x2
(
tvec2<T, P> const & v
)
{
tmat4x2<T, P> Result(static_cast<T>(1));
Result[0][0] = v[0];
Result[1][1] = v[1];
return Result;
}
}//namespace glm
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 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.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// 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_matrix_query
/// @file glm/gtx/matrix_query.hpp
/// @date 2007-03-05 / 2011-08-28
/// @author Christophe Riccio
///
/// @see core (dependence)
/// @see gtx_vector_query (dependence)
///
/// @defgroup gtx_matrix_query GLM_GTX_matrix_query
/// @ingroup gtx
///
/// @brief Query to evaluate matrix properties
///
/// <glm/gtx/matrix_query.hpp> need to be included to use these functionalities.
///////////////////////////////////////////////////////////////////////////////////
#pragma once
// Dependency:
#include "../glm.hpp"
#include "../gtx/vector_query.hpp"
#include <limits>
#if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
# pragma message("GLM: GLM_GTX_matrix_query extension included")
#endif
namespace glm
{
/// @addtogroup gtx_matrix_query
/// @{
/// Return whether a matrix a null matrix.
/// From GLM_GTX_matrix_query extension.
template<typename T, precision P>
GLM_FUNC_DECL bool isNull(tmat2x2<T, P> const & m, T const & epsilon);
/// Return whether a matrix a null matrix.
/// From GLM_GTX_matrix_query extension.
template<typename T, precision P>
GLM_FUNC_DECL bool isNull(tmat3x3<T, P> const & m, T const & epsilon);
/// Return whether a matrix is a null matrix.
/// From GLM_GTX_matrix_query extension.
template<typename T, precision P>
GLM_FUNC_DECL bool isNull(tmat4x4<T, P> const & m, T const & epsilon);
/// Return whether a matrix is an identity matrix.
/// From GLM_GTX_matrix_query extension.
template<typename T, precision P, template <typename, precision> class matType>
GLM_FUNC_DECL bool isIdentity(matType<T, P> const & m, T const & epsilon);
/// Return whether a matrix is a normalized matrix.
/// From GLM_GTX_matrix_query extension.
template<typename T, precision P>
GLM_FUNC_DECL bool isNormalized(tmat2x2<T, P> const & m, T const & epsilon);
/// Return whether a matrix is a normalized matrix.
/// From GLM_GTX_matrix_query extension.
template<typename T, precision P>
GLM_FUNC_DECL bool isNormalized(tmat3x3<T, P> const & m, T const & epsilon);
/// Return whether a matrix is a normalized matrix.
/// From GLM_GTX_matrix_query extension.
template<typename T, precision P>
GLM_FUNC_DECL bool isNormalized(tmat4x4<T, P> const & m, T const & epsilon);
/// Return whether a matrix is an orthonormalized matrix.
/// From GLM_GTX_matrix_query extension.
template<typename T, precision P, template <typename, precision> class matType>
GLM_FUNC_DECL bool isOrthogonal(matType<T, P> const & m, T const & epsilon);
/// @}
}//namespace glm
#include "matrix_query.inl"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment