matrix: fix transposed matrix in look_at
This commit is contained in:
parent
9cff1e9c85
commit
607aaceb29
30
matrix.cpp
30
matrix.cpp
@ -282,26 +282,32 @@ matrix<S,T>::perspective (T fov, T aspect, range<T> Z)
|
|||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Emulates gluLookAt
|
// Emulates gluLookAt
|
||||||
|
//
|
||||||
|
// Translates the viewpoint to the origin, then rotates the world to point
|
||||||
|
// along eye to centre (negative-Z).
|
||||||
|
// Implemented for right handed world coordinates.
|
||||||
|
//
|
||||||
|
// Assumes 'up' is normalised.
|
||||||
template <size_t S, typename T>
|
template <size_t S, typename T>
|
||||||
matrix4<T>
|
matrix4<T>
|
||||||
matrix<S,T>::look_at (util::point<3,T> eye,
|
matrix<S,T>::look_at (const util::point<3,T> eye,
|
||||||
util::point<3,T> target,
|
const util::point<3,T> centre,
|
||||||
util::vector<3,T> up)
|
const util::vector<3,T> up)
|
||||||
{
|
{
|
||||||
CHECK (is_normalised (up));
|
CHECK (is_normalised (up));
|
||||||
|
|
||||||
auto forward = normalised (eye.to (target));
|
const auto f = normalised (centre - eye);
|
||||||
auto side = normalised (cross (forward, up));
|
const auto s = normalised (cross (f, up));
|
||||||
up = cross (side, forward);
|
const auto u = cross (s, f);
|
||||||
|
|
||||||
auto rot = util::matrix4<T> {{
|
const util::matrix4<T> rot {{
|
||||||
{ side[0], up[0], -forward[0], 0 },
|
{ s.x, s.y, s.z, 0 },
|
||||||
{ side[1], up[1], -forward[1], 0 },
|
{ u.x, u.y, u.z, 0 },
|
||||||
{ side[2], up[2], -forward[2], 0 },
|
{-f.x,-f.y,-f.z, 0 },
|
||||||
{ 0, 0, 0, 1 }
|
{ 0, 0, 0, 1 },
|
||||||
}};
|
}};
|
||||||
|
|
||||||
return rot * util::matrix4<T>::translation (-eye.template as<vector> ());
|
return rot * util::matrix4<T>::translation (0-eye);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user