mirror of
https://github.com/g-truc/glm.git
synced 2024-11-10 04:31:47 +00:00
updated GL and GLU replacement extensions
This commit is contained in:
parent
25248b822b
commit
8f2cae1e1f
@ -1,5 +1,6 @@
|
||||
#include "../glm.hpp"
|
||||
#include "../ext.hpp"
|
||||
#include <map>
|
||||
|
||||
int main()
|
||||
{
|
||||
@ -85,6 +86,22 @@ int main()
|
||||
glm::mat4x3 q = m * x;
|
||||
}
|
||||
|
||||
class test
|
||||
{
|
||||
private:
|
||||
glm::vec3 Data;
|
||||
};
|
||||
|
||||
std::map<int, test*> TestMap;
|
||||
TestMap.insert(std::make_pair(0, new test));
|
||||
TestMap.insert(std::make_pair(1, new test));
|
||||
TestMap.insert(std::make_pair(2, new test));
|
||||
std::map<int, test*>::iterator It = TestMap.find(1);
|
||||
if(It != TestMap.end())
|
||||
{
|
||||
TestMap.insert(std::make_pair(3, new test));
|
||||
}
|
||||
|
||||
//{
|
||||
// glm::mat3x4 m(1.0f);
|
||||
// glm::vec3 v(1.0f);
|
||||
|
@ -11,6 +11,8 @@
|
||||
#define glm_ext
|
||||
|
||||
#include "./gtc/double_float.hpp"
|
||||
#include "./gtc/gl_replacement.hpp"
|
||||
#include "./gtc/glu_replacement.hpp"
|
||||
#include "./gtc/half_float.hpp"
|
||||
#include "./gtc/matrix_access.hpp"
|
||||
#include "./gtc/matrix_operation.hpp"
|
||||
|
@ -0,0 +1,82 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// OpenGL Mathematics Copyright (c) 2005 - 2010 G-Truc Creation (www.g-truc.net)
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Created : 2010-11-12
|
||||
// Updated : 2010-11-12
|
||||
// Licence : This source is under MIT License
|
||||
// File : glm/gtc/gl_replacement.hpp
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Dependency:
|
||||
// - GLM core
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef glm_gl_replacement
|
||||
#define glm_gl_replacement
|
||||
|
||||
// Dependency:
|
||||
#include "../glm.hpp"
|
||||
#include "../gtc/gl_replacement.hpp"
|
||||
|
||||
namespace glm
|
||||
{
|
||||
namespace test{
|
||||
bool main_gtc_gl_replacement();
|
||||
}//namespace test
|
||||
|
||||
namespace gtc{
|
||||
//! GLM_GTC_gl_replacement extension: GLM replacement functions for OpenGL compatibility function
|
||||
namespace gl_replacement
|
||||
{
|
||||
//! Builds a translation 4 * 4 matrix created from a vector of 3 components.
|
||||
//! From GLM_GTC_gl_replacement extension.
|
||||
template <typename T>
|
||||
detail::tmat4x4<T> translate(
|
||||
detail::tmat4x4<T> const & m,
|
||||
detail::tvec3<T> const & v);
|
||||
|
||||
//! Builds a rotation 4 * 4 matrix created from an axis vector and an angle expressed in degrees.
|
||||
//! From GLM_GTC_gl_replacement extension.
|
||||
template <typename T>
|
||||
detail::tmat4x4<T> rotate(
|
||||
detail::tmat4x4<T> const & m,
|
||||
T const & angle,
|
||||
detail::tvec3<T> const & v);
|
||||
|
||||
//! Builds a scale 4 * 4 matrix created from 3 scalars.
|
||||
//! From GLM_GTC_gl_replacement extension.
|
||||
template <typename T>
|
||||
detail::tmat4x4<T> scale(
|
||||
detail::tmat4x4<T> const & m,
|
||||
detail::tvec3<T> const & v);
|
||||
|
||||
//! Creates a matrix for an orthographic parallel viewing volume.
|
||||
//! From GLM_GTC_matrix_projection extension.
|
||||
template <typename T>
|
||||
detail::tmat4x4<T> ortho(
|
||||
T const & left,
|
||||
T const & right,
|
||||
T const & bottom,
|
||||
T const & top,
|
||||
T const & zNear,
|
||||
T const & zFar);
|
||||
|
||||
//! Creates a frustum matrix.
|
||||
//! From GLM_GTC_matrix_projection extension.
|
||||
template <typename T>
|
||||
detail::tmat4x4<T> frustum(
|
||||
T const & left,
|
||||
T const & right,
|
||||
T const & bottom,
|
||||
T const & top,
|
||||
T const & nearVal,
|
||||
T const & farVal);
|
||||
|
||||
}//namespace gl_replacement
|
||||
}//namespace gtc
|
||||
}//namespace glm
|
||||
|
||||
#include "gl_replacement.inl"
|
||||
|
||||
namespace glm{using namespace gtc::gl_replacement;}
|
||||
|
||||
#endif//glm_gl_replacement
|
@ -0,0 +1,187 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// OpenGL Mathematics Copyright (c) 2005 - 2010 G-Truc Creation (www.g-truc.net)
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Created : 2010-11-12
|
||||
// Updated : 2010-11-12
|
||||
// Licence : This source is under MIT License
|
||||
// File : glm/gtc/gl_replacement.inl
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace glm{
|
||||
namespace gtc{
|
||||
namespace gl_replacement
|
||||
{
|
||||
template <typename T>
|
||||
inline detail::tmat4x4<T> translate
|
||||
(
|
||||
detail::tmat4x4<T> const & m,
|
||||
detail::tvec3<T> const & v
|
||||
)
|
||||
{
|
||||
detail::tmat4x4<T> Result(m);
|
||||
Result[3] = m[0] * v[0] + m[1] * v[1] + m[2] * v[2] + m[3];
|
||||
return Result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline detail::tmat4x4<T> rotate
|
||||
(
|
||||
detail::tmat4x4<T> const & m,
|
||||
T const & angle,
|
||||
detail::tvec3<T> const & v
|
||||
)
|
||||
{
|
||||
T a = radians(angle);
|
||||
T c = cos(a);
|
||||
T s = sin(a);
|
||||
|
||||
detail::tvec3<T> axis = normalize(v);
|
||||
|
||||
detail::tvec3<T> temp = (T(1) - c) * axis;
|
||||
|
||||
detail::tmat4x4<T> Rotate(detail::tmat4x4<T>::null);
|
||||
Rotate[0][0] = c + temp[0] * axis[0];
|
||||
Rotate[0][1] = 0 + temp[0] * axis[1] + s * axis[2];
|
||||
Rotate[0][2] = 0 + temp[0] * axis[2] - s * axis[1];
|
||||
|
||||
Rotate[1][0] = 0 + temp[1] * axis[0] - s * axis[2];
|
||||
Rotate[1][1] = c + temp[1] * axis[1];
|
||||
Rotate[1][2] = 0 + temp[1] * axis[2] + s * axis[0];
|
||||
|
||||
Rotate[2][0] = 0 + temp[2] * axis[0] + s * axis[1];
|
||||
Rotate[2][1] = 0 + temp[2] * axis[1] - s * axis[0];
|
||||
Rotate[2][2] = c + temp[2] * axis[2];
|
||||
|
||||
detail::tmat4x4<T> Result(detail::tmat4x4<T>::null);
|
||||
Result[0] = m[0] * Rotate[0][0] + m[1] * Rotate[0][1] + m[2] * Rotate[0][2];
|
||||
Result[1] = m[0] * Rotate[1][0] + m[1] * Rotate[1][1] + m[2] * Rotate[1][2];
|
||||
Result[2] = m[0] * Rotate[2][0] + m[1] * Rotate[2][1] + m[2] * Rotate[2][2];
|
||||
Result[3] = m[3];
|
||||
return Result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline detail::tmat4x4<T> scale
|
||||
(
|
||||
detail::tmat4x4<T> const & m,
|
||||
detail::tvec3<T> const & v
|
||||
)
|
||||
{
|
||||
detail::tmat4x4<T> Result(detail::tmat4x4<T>::null);
|
||||
Result[0] = m[0] * v[0];
|
||||
Result[1] = m[1] * v[1];
|
||||
Result[2] = m[2] * v[2];
|
||||
Result[3] = m[3];
|
||||
return Result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline detail::tmat4x4<T> translate_slow
|
||||
(
|
||||
detail::tmat4x4<T> const & m,
|
||||
detail::tvec3<T> const & v
|
||||
)
|
||||
{
|
||||
detail::tmat4x4<T> Result(T(1));
|
||||
Result[3] = detail::tvec4<T>(v, T(1));
|
||||
return m * Result;
|
||||
|
||||
//detail::tmat4x4<valType> Result(m);
|
||||
Result[3] = m[0] * v[0] + m[1] * v[1] + m[2] * v[2] + m[3];
|
||||
//Result[3][0] = m[0][0] * v[0] + m[1][0] * v[1] + m[2][0] * v[2] + m[3][0];
|
||||
//Result[3][1] = m[0][1] * v[0] + m[1][1] * v[1] + m[2][1] * v[2] + m[3][1];
|
||||
//Result[3][2] = m[0][2] * v[0] + m[1][2] * v[1] + m[2][2] * v[2] + m[3][2];
|
||||
//Result[3][3] = m[0][3] * v[0] + m[1][3] * v[1] + m[2][3] * v[2] + m[3][3];
|
||||
//return Result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline detail::tmat4x4<T> rotate_slow
|
||||
(
|
||||
detail::tmat4x4<T> const & m,
|
||||
T const & angle,
|
||||
detail::tvec3<T> const & v
|
||||
)
|
||||
{
|
||||
T a = radians(angle);
|
||||
T c = cos(a);
|
||||
T s = sin(a);
|
||||
detail::tmat4x4<T> Result;
|
||||
|
||||
detail::tvec3<T> axis = normalize(v);
|
||||
|
||||
Result[0][0] = c + (1 - c) * axis.x * axis.x;
|
||||
Result[0][1] = (1 - c) * axis.x * axis.y + s * axis.z;
|
||||
Result[0][2] = (1 - c) * axis.x * axis.z - s * axis.y;
|
||||
Result[0][3] = 0;
|
||||
|
||||
Result[1][0] = (1 - c) * axis.y * axis.x - s * axis.z;
|
||||
Result[1][1] = c + (1 - c) * axis.y * axis.y;
|
||||
Result[1][2] = (1 - c) * axis.y * axis.z + s * axis.x;
|
||||
Result[1][3] = 0;
|
||||
|
||||
Result[2][0] = (1 - c) * axis.z * axis.x + s * axis.y;
|
||||
Result[2][1] = (1 - c) * axis.z * axis.y - s * axis.x;
|
||||
Result[2][2] = c + (1 - c) * axis.z * axis.z;
|
||||
Result[2][3] = 0;
|
||||
|
||||
Result[3] = detail::tvec4<T>(0, 0, 0, 1);
|
||||
return m * Result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline detail::tmat4x4<T> scale_slow
|
||||
(
|
||||
detail::tmat4x4<T> const & m,
|
||||
detail::tvec3<T> const & v
|
||||
)
|
||||
{
|
||||
detail::tmat4x4<T> Result(T(1));
|
||||
Result[0][0] = v.x;
|
||||
Result[1][1] = v.y;
|
||||
Result[2][2] = v.z;
|
||||
return m * Result;
|
||||
}
|
||||
|
||||
template <typename valType>
|
||||
inline detail::tmat4x4<valType> ortho(
|
||||
valType const & left,
|
||||
valType const & right,
|
||||
valType const & bottom,
|
||||
valType const & top,
|
||||
valType const & zNear,
|
||||
valType const & zFar)
|
||||
{
|
||||
detail::tmat4x4<valType> Result(1);
|
||||
Result[0][0] = valType(2) / (right - left);
|
||||
Result[1][1] = valType(2) / (top - bottom);
|
||||
Result[2][2] = - valType(2) / (zFar - zNear);
|
||||
Result[3][0] = - (right + left) / (right - left);
|
||||
Result[3][1] = - (top + bottom) / (top - bottom);
|
||||
Result[3][2] = - (zFar + zNear) / (zFar - zNear);
|
||||
return Result;
|
||||
}
|
||||
|
||||
template <typename valType>
|
||||
inline detail::tmat4x4<valType> frustum(
|
||||
valType const & left,
|
||||
valType const & right,
|
||||
valType const & bottom,
|
||||
valType const & top,
|
||||
valType const & nearVal,
|
||||
valType const & farVal)
|
||||
{
|
||||
detail::tmat4x4<valType> Result(0);
|
||||
Result[0][0] = (valType(2) * nearVal) / (right - left);
|
||||
Result[1][1] = (valType(2) * nearVal) / (top - bottom);
|
||||
Result[2][0] = (right + left) / (right - left);
|
||||
Result[2][1] = (top + bottom) / (top - bottom);
|
||||
Result[2][2] = -(farVal + nearVal) / (farVal - nearVal);
|
||||
Result[2][3] = valType(-1);
|
||||
Result[3][2] = -(valType(2) * farVal * nearVal) / (farVal - nearVal);
|
||||
return Result;
|
||||
}
|
||||
|
||||
}//namespace gl_replacement
|
||||
}//namespace gtc
|
||||
}//namespace glm
|
@ -0,0 +1,84 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// OpenGL Mathematics Copyright (c) 2005 - 2010 G-Truc Creation (www.g-truc.net)
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Created : 2010-11-12
|
||||
// Updated : 2010-11-12
|
||||
// Licence : This source is under MIT License
|
||||
// File : glm/gtc/gl_replacement.hpp
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Dependency:
|
||||
// - GLM core
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef glm_glu_replacement
|
||||
#define glm_glu_replacement
|
||||
|
||||
// Dependency:
|
||||
#include "../glm.hpp"
|
||||
#include "../gtc/gl_replacement.hpp"
|
||||
|
||||
namespace glm
|
||||
{
|
||||
namespace test{
|
||||
bool main_gtc_gl_replacement();
|
||||
}//namespace test
|
||||
|
||||
namespace gtc{
|
||||
//! GLM_GTC_glu_replacement extension: GLM replacement functions for GLU
|
||||
namespace glu_replacement
|
||||
{
|
||||
using namespace gtc::gl_replacement;
|
||||
|
||||
//! Creates a matrix for projecting two-dimensional coordinates onto the screen.
|
||||
//! From GLM_GTC_glu_replacement extension.
|
||||
template <typename T>
|
||||
detail::tmat4x4<T> ortho(
|
||||
T const & left,
|
||||
T const & right,
|
||||
T const & bottom,
|
||||
T const & top);
|
||||
|
||||
//! Creates a matrix for a symetric perspective-view frustum.
|
||||
//! From GLM_GTC_glu_replacement extension.
|
||||
template <typename T>
|
||||
detail::tmat4x4<T> perspective(
|
||||
T const & fovy,
|
||||
T const & aspect,
|
||||
T const & zNear,
|
||||
T const & zFar);
|
||||
|
||||
//! Map the specified object coordinates (obj.x, obj.y, obj.z) into window coordinates.
|
||||
//! From GLM_GTC_glu_replacement extension.
|
||||
template <typename T, typename U>
|
||||
detail::tvec3<T> project(
|
||||
detail::tvec3<T> const & obj,
|
||||
detail::tmat4x4<T> const & model,
|
||||
detail::tmat4x4<T> const & proj,
|
||||
detail::tvec4<U> const & viewport);
|
||||
|
||||
//! Map the specified window coordinates (win.x, win.y, win.z) into object coordinates.
|
||||
//! From GLM_GTC_glu_replacement extension.
|
||||
template <typename T, typename U>
|
||||
detail::tvec3<T> unProject(
|
||||
detail::tvec3<T> const & win,
|
||||
detail::tmat4x4<T> const & model,
|
||||
detail::tmat4x4<T> const & proj,
|
||||
detail::tvec4<U> const & viewport);
|
||||
|
||||
//! Build a look at view matrix.
|
||||
//! From GLM_GTC_glu_replacement extension.
|
||||
template <typename T>
|
||||
detail::tmat4x4<T> lookAt(
|
||||
detail::tvec3<T> const & eye,
|
||||
detail::tvec3<T> const & center,
|
||||
detail::tvec3<T> const & up);
|
||||
|
||||
}//namespace glu_replacement
|
||||
}//namespace gtc
|
||||
}//namespace glm
|
||||
|
||||
#include "glu_replacement.inl"
|
||||
|
||||
namespace glm{using namespace gtc::glu_replacement;}
|
||||
|
||||
#endif//glm_glu_replacement
|
@ -0,0 +1,122 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// OpenGL Mathematics Copyright (c) 2005 - 2010 G-Truc Creation (www.g-truc.net)
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Created : 2010-11-12
|
||||
// Updated : 2010-11-12
|
||||
// Licence : This source is under MIT License
|
||||
// File : glm/gtc/glu_replacement.inl
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace glm{
|
||||
namespace gtc{
|
||||
namespace glu_replacement
|
||||
{
|
||||
template <typename valType>
|
||||
inline detail::tmat4x4<valType> ortho(
|
||||
valType const & left,
|
||||
valType const & right,
|
||||
valType const & bottom,
|
||||
valType const & top)
|
||||
{
|
||||
detail::tmat4x4<valType> Result(1);
|
||||
Result[0][0] = valType(2) / (right - left);
|
||||
Result[1][1] = valType(2) / (top - bottom);
|
||||
Result[2][2] = - valType(1);
|
||||
Result[3][0] = - (right + left) / (right - left);
|
||||
Result[3][1] = - (top + bottom) / (top - bottom);
|
||||
return Result;
|
||||
}
|
||||
|
||||
template <typename valType>
|
||||
inline detail::tmat4x4<valType> perspective(
|
||||
valType const & fovy,
|
||||
valType const & aspect,
|
||||
valType const & zNear,
|
||||
valType const & zFar)
|
||||
{
|
||||
valType range = tan(radians(fovy / valType(2))) * zNear;
|
||||
valType left = -range * aspect;
|
||||
valType right = range * aspect;
|
||||
valType bottom = -range;
|
||||
valType top = range;
|
||||
|
||||
detail::tmat4x4<valType> Result(valType(0));
|
||||
Result[0][0] = (valType(2) * zNear) / (right - left);
|
||||
Result[1][1] = (valType(2) * zNear) / (top - bottom);
|
||||
Result[2][2] = - (zFar + zNear) / (zFar - zNear);
|
||||
Result[2][3] = - valType(1);
|
||||
Result[3][2] = - (valType(2) * zFar * zNear) / (zFar - zNear);
|
||||
return Result;
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
inline detail::tvec3<T> project(
|
||||
detail::tvec3<T> const & obj,
|
||||
detail::tmat4x4<T> const & model,
|
||||
detail::tmat4x4<T> const & proj,
|
||||
detail::tvec4<U> const & viewport)
|
||||
{
|
||||
detail::tvec4<T> tmp = detail::tvec4<T>(obj, T(1));
|
||||
tmp = model * tmp;
|
||||
tmp = proj * tmp;
|
||||
|
||||
tmp /= tmp.w;
|
||||
tmp = tmp * T(0.5) + T(0.5);
|
||||
tmp[0] = tmp[0] * T(viewport[2]) + T(viewport[0]);
|
||||
tmp[1] = tmp[1] * T(viewport[3]) + T(viewport[1]);
|
||||
|
||||
return detail::tvec3<T>(tmp);
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
inline detail::tvec3<T> unProject(
|
||||
detail::tvec3<T> const & win,
|
||||
detail::tmat4x4<T> const & model,
|
||||
detail::tmat4x4<T> const & proj,
|
||||
detail::tvec4<U> const & viewport)
|
||||
{
|
||||
detail::tmat4x4<T> inverse = glm::inverse(proj * model);
|
||||
|
||||
detail::tvec4<T> tmp = detail::tvec4<T>(win, T(1));
|
||||
tmp.x = (tmp.x - T(viewport[0])) / T(viewport[2]);
|
||||
tmp.y = (tmp.y - T(viewport[1])) / T(viewport[3]);
|
||||
tmp = tmp * T(2) - T(1);
|
||||
|
||||
detail::tvec4<T> obj = inverse * tmp;
|
||||
obj /= obj.w;
|
||||
|
||||
return detail::tvec3<T>(obj);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline detail::tmat4x4<T> lookAt(
|
||||
const detail::tvec3<T>& eye,
|
||||
const detail::tvec3<T>& center,
|
||||
const detail::tvec3<T>& up)
|
||||
{
|
||||
detail::tvec3<T> f = normalize(center - eye);
|
||||
detail::tvec3<T> u = normalize(up);
|
||||
detail::tvec3<T> s = normalize(cross(f, u));
|
||||
u = cross(s, f);
|
||||
|
||||
detail::tmat4x4<T> Result(1);
|
||||
Result[0][0] = s.x;
|
||||
Result[1][0] = s.y;
|
||||
Result[2][0] = s.z;
|
||||
Result[0][1] = u.x;
|
||||
Result[1][1] = u.y;
|
||||
Result[2][1] = u.z;
|
||||
Result[0][2] =-f.x;
|
||||
Result[1][2] =-f.y;
|
||||
Result[2][2] =-f.z;
|
||||
/* Test this instead of translate3D
|
||||
Result[3][0] =-dot(s, eye);
|
||||
Result[3][1] =-dot(y, eye);
|
||||
Result[3][2] = dot(f, eye);
|
||||
*/
|
||||
return gtc::matrix_transform::translate(Result, -eye);
|
||||
}
|
||||
|
||||
}//namespace glu_replacement
|
||||
}//namespace gtc
|
||||
}//namespace glm
|
@ -16,7 +16,7 @@
|
||||
|
||||
// Dependency:
|
||||
#include "../glm.hpp"
|
||||
#include "../gtc/matrix_operation.hpp"
|
||||
#include "../gtc/glu_replacement.hpp"
|
||||
|
||||
namespace glm
|
||||
{
|
||||
@ -28,65 +28,7 @@ namespace glm
|
||||
//! GLM_GTC_matrix_projection: Varius ways to build and operate on projection matrices
|
||||
namespace matrix_projection
|
||||
{
|
||||
using namespace gtc::matrix_operation;
|
||||
|
||||
//! Creates a matrix for projecting two-dimensional coordinates onto the screen.
|
||||
//! From GLM_GTC_matrix_projection extension.
|
||||
template <typename T>
|
||||
detail::tmat4x4<T> ortho(
|
||||
T const & left,
|
||||
T const & right,
|
||||
T const & bottom,
|
||||
T const & top);
|
||||
|
||||
//! Creates a matrix for an orthographic parallel viewing volume.
|
||||
//! From GLM_GTC_matrix_projection extension.
|
||||
template <typename T>
|
||||
detail::tmat4x4<T> ortho(
|
||||
T const & left,
|
||||
T const & right,
|
||||
T const & bottom,
|
||||
T const & top,
|
||||
T const & zNear,
|
||||
T const & zFar);
|
||||
|
||||
//! Creates a frustum matrix.
|
||||
//! From GLM_GTC_matrix_projection extension.
|
||||
template <typename T>
|
||||
detail::tmat4x4<T> frustum(
|
||||
T const & left,
|
||||
T const & right,
|
||||
T const & bottom,
|
||||
T const & top,
|
||||
T const & nearVal,
|
||||
T const & farVal);
|
||||
|
||||
//! Creates a matrix for a symetric perspective-view frustum.
|
||||
//! From GLM_GTC_matrix_projection extension.
|
||||
template <typename T>
|
||||
detail::tmat4x4<T> perspective(
|
||||
T const & fovy,
|
||||
T const & aspect,
|
||||
T const & zNear,
|
||||
T const & zFar);
|
||||
|
||||
//! Map the specified object coordinates (obj.x, obj.y, obj.z) into window coordinates.
|
||||
//! From GLM_GTC_matrix_projection extension.
|
||||
template <typename T, typename U>
|
||||
detail::tvec3<T> project(
|
||||
detail::tvec3<T> const & obj,
|
||||
detail::tmat4x4<T> const & model,
|
||||
detail::tmat4x4<T> const & proj,
|
||||
detail::tvec4<U> const & viewport);
|
||||
|
||||
//! Map the specified window coordinates (win.x, win.y, win.z) into object coordinates.
|
||||
//! From GLM_GTC_matrix_projection extension.
|
||||
template <typename T, typename U>
|
||||
detail::tvec3<T> unProject(
|
||||
detail::tvec3<T> const & win,
|
||||
detail::tmat4x4<T> const & model,
|
||||
detail::tmat4x4<T> const & proj,
|
||||
detail::tvec4<U> const & viewport);
|
||||
using namespace gtc::glu_replacement;
|
||||
|
||||
}//namespace matrix_projection
|
||||
}//namespace gtc
|
||||
|
@ -11,121 +11,7 @@ namespace glm{
|
||||
namespace gtc{
|
||||
namespace matrix_projection
|
||||
{
|
||||
template <typename valType>
|
||||
inline detail::tmat4x4<valType> ortho(
|
||||
valType const & left,
|
||||
valType const & right,
|
||||
valType const & bottom,
|
||||
valType const & top)
|
||||
{
|
||||
detail::tmat4x4<valType> Result(1);
|
||||
Result[0][0] = valType(2) / (right - left);
|
||||
Result[1][1] = valType(2) / (top - bottom);
|
||||
Result[2][2] = - valType(1);
|
||||
Result[3][0] = - (right + left) / (right - left);
|
||||
Result[3][1] = - (top + bottom) / (top - bottom);
|
||||
return Result;
|
||||
}
|
||||
|
||||
template <typename valType>
|
||||
inline detail::tmat4x4<valType> ortho(
|
||||
valType const & left,
|
||||
valType const & right,
|
||||
valType const & bottom,
|
||||
valType const & top,
|
||||
valType const & zNear,
|
||||
valType const & zFar)
|
||||
{
|
||||
detail::tmat4x4<valType> Result(1);
|
||||
Result[0][0] = valType(2) / (right - left);
|
||||
Result[1][1] = valType(2) / (top - bottom);
|
||||
Result[2][2] = - valType(2) / (zFar - zNear);
|
||||
Result[3][0] = - (right + left) / (right - left);
|
||||
Result[3][1] = - (top + bottom) / (top - bottom);
|
||||
Result[3][2] = - (zFar + zNear) / (zFar - zNear);
|
||||
return Result;
|
||||
}
|
||||
|
||||
template <typename valType>
|
||||
inline detail::tmat4x4<valType> frustum(
|
||||
valType const & left,
|
||||
valType const & right,
|
||||
valType const & bottom,
|
||||
valType const & top,
|
||||
valType const & nearVal,
|
||||
valType const & farVal)
|
||||
{
|
||||
detail::tmat4x4<valType> Result(0);
|
||||
Result[0][0] = (valType(2) * nearVal) / (right - left);
|
||||
Result[1][1] = (valType(2) * nearVal) / (top - bottom);
|
||||
Result[2][0] = (right + left) / (right - left);
|
||||
Result[2][1] = (top + bottom) / (top - bottom);
|
||||
Result[2][2] = -(farVal + nearVal) / (farVal - nearVal);
|
||||
Result[2][3] = valType(-1);
|
||||
Result[3][2] = -(valType(2) * farVal * nearVal) / (farVal - nearVal);
|
||||
return Result;
|
||||
}
|
||||
|
||||
template <typename valType>
|
||||
inline detail::tmat4x4<valType> perspective(
|
||||
valType const & fovy,
|
||||
valType const & aspect,
|
||||
valType const & zNear,
|
||||
valType const & zFar)
|
||||
{
|
||||
valType range = tan(radians(fovy / valType(2))) * zNear;
|
||||
valType left = -range * aspect;
|
||||
valType right = range * aspect;
|
||||
valType bottom = -range;
|
||||
valType top = range;
|
||||
|
||||
detail::tmat4x4<valType> Result(valType(0));
|
||||
Result[0][0] = (valType(2) * zNear) / (right - left);
|
||||
Result[1][1] = (valType(2) * zNear) / (top - bottom);
|
||||
Result[2][2] = - (zFar + zNear) / (zFar - zNear);
|
||||
Result[2][3] = - valType(1);
|
||||
Result[3][2] = - (valType(2) * zFar * zNear) / (zFar - zNear);
|
||||
return Result;
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
inline detail::tvec3<T> project(
|
||||
detail::tvec3<T> const & obj,
|
||||
detail::tmat4x4<T> const & model,
|
||||
detail::tmat4x4<T> const & proj,
|
||||
detail::tvec4<U> const & viewport)
|
||||
{
|
||||
detail::tvec4<T> tmp = detail::tvec4<T>(obj, T(1));
|
||||
tmp = model * tmp;
|
||||
tmp = proj * tmp;
|
||||
|
||||
tmp /= tmp.w;
|
||||
tmp = tmp * T(0.5) + T(0.5);
|
||||
tmp[0] = tmp[0] * T(viewport[2]) + T(viewport[0]);
|
||||
tmp[1] = tmp[1] * T(viewport[3]) + T(viewport[1]);
|
||||
|
||||
return detail::tvec3<T>(tmp);
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
inline detail::tvec3<T> unProject(
|
||||
detail::tvec3<T> const & win,
|
||||
detail::tmat4x4<T> const & model,
|
||||
detail::tmat4x4<T> const & proj,
|
||||
detail::tvec4<U> const & viewport)
|
||||
{
|
||||
detail::tmat4x4<T> inverse = glm::inverse(proj * model);
|
||||
|
||||
detail::tvec4<T> tmp = detail::tvec4<T>(win, T(1));
|
||||
tmp.x = (tmp.x - T(viewport[0])) / T(viewport[2]);
|
||||
tmp.y = (tmp.y - T(viewport[1])) / T(viewport[3]);
|
||||
tmp = tmp * T(2) - T(1);
|
||||
|
||||
detail::tvec4<T> obj = inverse * tmp;
|
||||
obj /= obj.w;
|
||||
|
||||
return detail::tvec3<T>(obj);
|
||||
}
|
||||
|
||||
}//namespace matrix_projection
|
||||
}//namespace gtc
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
// Dependency:
|
||||
#include "../glm.hpp"
|
||||
#include "../gtc/matrix_operation.hpp"
|
||||
#include "../gtc/gl_replacement.hpp"
|
||||
|
||||
namespace glm
|
||||
{
|
||||
@ -28,29 +28,7 @@ namespace glm
|
||||
//! GLM_GTC_matrix_transform extension: Add transformation matrices
|
||||
namespace matrix_transform
|
||||
{
|
||||
using namespace gtc::matrix_operation;
|
||||
|
||||
//! Builds a translation 4 * 4 matrix created from a vector of 3 components.
|
||||
//! From GLM_GTC_matrix_transform extension.
|
||||
template <typename T>
|
||||
detail::tmat4x4<T> translate(
|
||||
detail::tmat4x4<T> const & m,
|
||||
detail::tvec3<T> const & v);
|
||||
|
||||
//! Builds a rotation 4 * 4 matrix created from an axis vector and an angle expressed in degrees.
|
||||
//! From GLM_GTC_matrix_transform extension.
|
||||
template <typename T>
|
||||
detail::tmat4x4<T> rotate(
|
||||
detail::tmat4x4<T> const & m,
|
||||
T const & angle,
|
||||
detail::tvec3<T> const & v);
|
||||
|
||||
//! Builds a scale 4 * 4 matrix created from 3 scalars.
|
||||
//! From GLM_GTC_matrix_transform extension.
|
||||
template <typename T>
|
||||
detail::tmat4x4<T> scale(
|
||||
detail::tmat4x4<T> const & m,
|
||||
detail::tvec3<T> const & v);
|
||||
using namespace gtc::gl_replacement;
|
||||
|
||||
}//namespace matrix_transform
|
||||
}//namespace gtc
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
// Dependency:
|
||||
#include "../glm.hpp"
|
||||
#include "../gtc/glu_replacement.hpp"
|
||||
#include "../gtx/transform.hpp"
|
||||
|
||||
namespace glm
|
||||
@ -29,6 +30,7 @@ namespace glm
|
||||
namespace transform2
|
||||
{
|
||||
using namespace gtx::transform;
|
||||
using namespace gtc::glu_replacement;
|
||||
|
||||
//! Transforms a matrix with a shearing on X axis.
|
||||
//! From GLM_GTX_transform2 extension.
|
||||
@ -90,14 +92,6 @@ namespace glm
|
||||
const detail::tmat4x4<T> & m,
|
||||
const detail::tvec3<T>& normal);
|
||||
|
||||
//! Build a look at view matrix.
|
||||
//! From GLM_GTX_transform2 extension.
|
||||
template <typename T>
|
||||
detail::tmat4x4<T> lookAt(
|
||||
detail::tvec3<T> const & eye,
|
||||
detail::tvec3<T> const & center,
|
||||
detail::tvec3<T> const & up);
|
||||
|
||||
//! Build a scale bias matrix.
|
||||
//! From GLM_GTX_transform2 extension.
|
||||
template <typename valType>
|
||||
|
@ -131,35 +131,6 @@ namespace transform2
|
||||
return m * r;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline detail::tmat4x4<T> lookAt(
|
||||
const detail::tvec3<T>& eye,
|
||||
const detail::tvec3<T>& center,
|
||||
const detail::tvec3<T>& up)
|
||||
{
|
||||
detail::tvec3<T> f = normalize(center - eye);
|
||||
detail::tvec3<T> u = normalize(up);
|
||||
detail::tvec3<T> s = normalize(cross(f, u));
|
||||
u = cross(s, f);
|
||||
|
||||
detail::tmat4x4<T> Result(1);
|
||||
Result[0][0] = s.x;
|
||||
Result[1][0] = s.y;
|
||||
Result[2][0] = s.z;
|
||||
Result[0][1] = u.x;
|
||||
Result[1][1] = u.y;
|
||||
Result[2][1] = u.z;
|
||||
Result[0][2] =-f.x;
|
||||
Result[1][2] =-f.y;
|
||||
Result[2][2] =-f.z;
|
||||
/* Test this instead of translate3D
|
||||
Result[3][0] =-dot(s, eye);
|
||||
Result[3][1] =-dot(y, eye);
|
||||
Result[3][2] = dot(f, eye);
|
||||
*/
|
||||
return gtc::matrix_transform::translate(Result, -eye);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline detail::tmat4x4<T> scaleBias(
|
||||
T scale,
|
||||
|
Loading…
Reference in New Issue
Block a user