Merge branch '0.9.1' of ssh://ogl-math.git.sourceforge.net/gitroot/ogl-math/ogl-math into 0.9.1

This commit is contained in:
Christophe Riccio
2011-02-08 23:55:15 +00:00
14 changed files with 399 additions and 165 deletions

View File

@@ -133,6 +133,14 @@ namespace glm
detail::tmat4x4<T> const & proj,
detail::tvec4<U> const & viewport);
//! Define a picking region
//! From GLM_GTC_matrix_transform extension.
template <typename T, typename U>
detail::tmat4x4<T> pickMatrix(
detail::tvec2<T> const & center,
detail::tvec2<T> const & delta,
detail::tvec4<U> const & viewport);
//! Build a look at view matrix.
//! From GLM_GTC_matrix_transform extension.
template <typename T>

View File

@@ -324,6 +324,25 @@ namespace matrix_transform
return detail::tvec3<T>(obj);
}
template <typename T, typename U>
detail::tmat4x4<T> pickMatrix
(
detail::tvec2<T> const & center,
detail::tvec2<T> const & delta,
detail::tvec4<U> const & viewport
)
{
assert(delta.x > 0.0f && delta.y > 0.0f)
detail::tmat4x4<T> Result(1.0f);
if(!(delta.x > 0.0f && delta.y > 0.0f))
return Result; // Error
// Translate and scale the picked region to the entire window
Result = translate(Result, (T(viewport[2]) - T(2) * (x - T(viewport[0]))) / delta.x, (T(viewport[3]) - T(2) * (y - T(viewport[1]))) / delta.y, T(0));
return scale(Result, T(viewport[2]) / delta.x, T(viewport[3]) / delta.y, T(1));
}
template <typename T>
inline detail::tmat4x4<T> lookAt(
const detail::tvec3<T>& eye,

View File

@@ -150,7 +150,7 @@ namespace glm
detail::tquat<T> const & q1,
detail::tquat<T> const & q2);
//! Returns a LERP interpolated quaternion of x and y according a.
//! Returns a SLERP interpolated quaternion of x and y according a.
//! From GLM_GTC_quaternion extension.
template <typename T>
detail::tquat<T> mix(

View File

@@ -370,6 +370,43 @@ namespace quaternion{
k0 * x.z + k1 * y2.z);
}
template <typename T>
inline detail::tquat<T> mix2
(
detail::tquat<T> const & x,
detail::tquat<T> const & y,
T const & a
)
{
bool flip = false;
if(a <= T(0)) return x;
if(a >= T(1)) return y;
T cos_t = dot(x, y);
if(cos_t < T(0))
{
cos_t = -cos_t;
flip = true;
}
T alpha(0), beta(0);
if(T(1) - cos_t < 1e-7)
beta = T(1) - alpha;
else
{
T theta = acos(cos_t);
T sin_t = sin(theta);
beta = sin(theta * (T(1) - alpha)) / sin_t;
alpha = sin(alpha * theta) / sin_t;
}
if(flip)
alpha = -alpha;
return normalize(beta * x + alpha * y2);
}
template <typename T>
inline detail::tquat<T> conjugate
(