/*****************************************************************************
 * $LastChangedDate: 2009-12-06 22:22:01 -0500 (Sun, 06 Dec 2009) $
 * @file
 * @author  Jim E. Brooks  http://www.palomino3d.org
 * @brief   Functor attached to a View that computes view matrix for manipulator mode.
 *//*
 * LEGAL:   COPYRIGHT (C) 2009 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2).
 *****************************************************************************/

#define VIEW_VIEWPOINT_MANIPULATOR_CC 1
#include "base/module.hh"
using namespace base;
#include "math/module.hh"
#include "math/matrix.hh"
using namespace math;
#include "view/module.hh"
#include "view/viewpoint.hh"
#include "view/viewpoint_manipulator.hh"
#include "view/manipulator.hh"
#include "view/view.hh"

namespace view {

////////////////////////////////////////////////////////////////////////////////
//////////////////////////  ManipulatorViewpoint  //////////////////////////////
////////////////////////////////////////////////////////////////////////////////

/*****************************************************************************
 * ctor/dtor.
 *****************************************************************************/
ManipulatorViewpoint::ManipulatorViewpoint( RefPtr<Manipulator> manipulator )
:   mManipulator(manipulator)
{
    SET_TYPESIG(this,TYPESIG_MANIPULATOR_VIEWPOINT);
}

ManipulatorViewpoint::~ManipulatorViewpoint()
{
    INVALIDATE_TYPESIG(this,TYPESIG_MANIPULATOR_VIEWPOINT);
}

/*****************************************************************************
 * This is called every frame by Window's graphics loop.
 * Viewpoint must compute the view matrix for the current mode of its View.
 *****************************************************************************/
Matrix
ManipulatorViewpoint::ComputeViewMatrix( shptr<View> view )
{
CHECK_TYPESIG(this,TYPESIG_MANIPULATOR_VIEWPOINT);
CHECK_TYPESIG(view,TYPESIG_VIEW);

    // virtual osg::Matrixd getInverseMatrix () const
    // "Get the position of the manipulator as a inverse matrix of the manipulator,"
    // "typically used as a model view matrix."

    return mManipulator->getInverseMatrix();
}

} // namespace view
