GLManager.cpp
// Generates a look-at matrix
Generates a look-at matrix
Generates a look - at matrix
gmtl::Matrix44f GLManager::Lookat(gmtl::Vec3f target, gmtl::Vec3f camera, gmtl::Vec3f up)
{
    gmtl::Vec3f zAxis = camera - target;
    gmtl::normalize(zAxis);
    gmtl::Vec3f xAxis = gmtl::makeCross(up, zAxis);
    gmtl::normalize(xAxis);
    gmtl::Vec3f yAxis = gmtl::makeCross(zAxis, xAxis);
    gmtl::Matrix44f result;
    result.set(
        xAxis[0], yAxis[0], zAxis[0], 0,
        xAxis[1], yAxis[1], zAxis[1], 0,
        xAxis[2], yAxis[2], zAxis[2], 0,
        -gmtl::dot(xAxis, camera), -gmtl::dot(yAxis, camera), -gmtl::dot(zAxis, camera), 1);
    result = gmtl::transpose(result);
    return result;
}
gmtl :: Matrix44f GLManager :: Lookat ( gmtl :: Vec3f target , gmtl :: Vec3f camera , gmtl :: Vec3f up ) { gmtl :: Vec3f zAxis = camera - target ; gmtl :: normalize ( zAxis ) ; gmtl :: Vec3f xAxis = gmtl :: makeCross ( up , zAxis ) ; gmtl :: normalize ( xAxis ) ; gmtl :: Vec3f yAxis = gmtl :: makeCross ( zAxis , xAxis ) ; gmtl :: Matrix44f result ; result . set ( xAxis [ 0 ] , yAxis [ 0 ] , zAxis [ 0 ] , 0 , xAxis [ 1 ] , yAxis [ 1 ] , zAxis [ 1 ] , 0 , xAxis [ 2 ] , yAxis [ 2 ] , zAxis [ 2 ] , 0 , - gmtl :: dot ( xAxis , camera ) , - gmtl :: dot ( yAxis , camera ) , - gmtl :: dot ( zAxis , camera ) , 1 ) ; result = gmtl :: transpose ( result ) ; return result ; }
Generates a look-at matrix
Generates a look - at matrix
// Rewritten to use the standardized public-domain code for a RH matrix here: http://msdn.microsoft.com/en-us/library/windows/desktop/bb281711(v=vs.85).aspx