/*****************************************************************************
 * $LastChangedDate: 2009-11-22 22:39:11 -0500 (Sun, 22 Nov 2009) $
 * @file
 * @author  Jim E. Brooks  http://www.palomino3d.org
 * @brief   Matrix class.
 *//*
 * LEGAL:   COPYRIGHT (C) 2004 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2).
 *****************************************************************************/

#ifndef MATH_MATRIX_CLASS_HH
#define MATH_MATRIX_CLASS_HH 1

#include <osg/Matrix>
#include "math/vertex.hh"

namespace math {

class Quaternion;

////////////////////////////////////////////////////////////////////////////////
/// @brief math::Matrix is osg::Matrix extended with a flat-index operator[].
///
/// operator[] provides compatibility (esp. with the matrix template functions).
/// Deriving from osg::Matrix may not be what the OSG developers intended,
/// but avoids massive rewriting.
///
class Matrix : public osg::Matrix
{
public:
    Matrix( void ) : osg::Matrix() { }
    Matrix( const Matrix& src ) : osg::Matrix(src) { }
    Matrix( const osg::Matrix& src ) : osg::Matrix(src) { }
    Matrix( const Quaternion& quat, const Vector3& v );  // matrix_funcs.cc

          value_type& operator[]( uint i )       { ASSERT(i<16); return reinterpret_cast<      value_type*>(_mat)[i]; }
    const value_type& operator[]( uint i ) const { ASSERT(i<16); return reinterpret_cast<const value_type*>(_mat)[i]; }

    Vector3 GetPosition( void ) const
    {
        return Vector3( (*this)[Ox],
                        (*this)[Oy],
                        (*this)[Oz] );
    }

    void SetPosition( const Vector3& pos )
    {
        (*this)[Ox] = pos[XX];
        (*this)[Oy] = pos[YY];
        (*this)[Oz] = pos[ZZ];
    }
};

} // namespace math

#endif // MATH_MATRIX_CLASS_HH
