Ticket #37: Added pickMatrix function

This commit is contained in:
Christophe Riccio 2011-02-07 14:37:53 +00:00
parent 7a3aa677be
commit 9fbfb8c208
2 changed files with 27 additions and 0 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,