/// This file is part of the X3DToolKit library
/// Copyright (C) 2002-2004  Yannick Le Goc (legoc@imag.fr)

/// http://artis.imag.fr/Members/Yannick.Legoc/X3D/

/// This library is free software; you can redistribute it and/or
/// modify it under the terms of the GNU Lesser General Public
/// License as published by the Free Software Foundation; either
/// version 2.1 of the License, or (at your option) any later version.

/// This library is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
/// Lesser General Public License for more details.

/// You should have received a copy of the GNU Lesser General Public
/// License along with this library; if not, write to the Free Software
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#ifndef X3DTK_SFMATRIX34F_H
#define X3DTK_SFMATRIX34F_H

#include "SFVec3f.h"
#include "SFPoint3f.h"

#include <iostream>
#include <vector>

namespace X3DTK {

class SFRotation;

/*! \brief Class declared in <b><X3DTK/kernel.h></b> providing a 4*4 matrix in homogeneous 
 *  coordinates.
 * 
 *  The matrices are represented by 3*4 elements to economize memory and unnecessary
 *  calculus. The fourth coordinates is not represented because the first three 
 *  columns represent the vectors and the fourth the point.
 *
 *  \ingroup base
 */

class SFMatrix34f
{
public:
  /// 1, 1 coordinate.
  float _11;
  /// 2, 1 coordinate.
  float _21;
  /// 3, 1 coordinate.
  float _31;

  /// 1, 2 coordinate.	
  float _12;
  /// 2, 2 coordinate.
  float _22;
  /// 3, 2 coordinate.
  float _32;

  /// 1, 3 coordinate.
  float _13;
  /// 2, 3 coordinate.
  float _23;
  /// 3, 3 coordinate.
  float _33;

  /// 1, 4 coordinate.
  float _14;
  /// 2, 4 coordinate.
  float _24;
  /// 3, 4 coordinate.
  float _34;

  /// Constructor.
  SFMatrix34f();
  /// Constructor with the coordinates in parameters.
  SFMatrix34f(float _11, float _21, float _31, float _12, float _22, float _32, float _13, float _23, float _33, float _14, float _24, float _34);
  /// Constructor from a GL matrix.
  explicit SFMatrix34f(const float GLMatrix[16]);
  /// Constructor from the three vectors and the point.
  SFMatrix34f(const SFVec3f &vx, const SFVec3f &vy, const SFVec3f &vz, const SFPoint3f &p);
  /// Constructor from an X3D::Transform attributes.
  SFMatrix34f(const SFVec3f &translation, const SFVec3f &center, const SFRotation &rotation, const SFRotation &scaleOrientation, const SFVec3f &scale);
  /// Copy constructor.
  SFMatrix34f(const SFMatrix34f &m);

  /// Overloaded operator+.
  friend SFMatrix34f operator+ (const SFMatrix34f &m1, const SFMatrix34f &m2);
  /// Overloaded operator-.
  friend SFMatrix34f operator- (const SFMatrix34f &m1, const SFMatrix34f &m2);
  /// Overloaded operator*.
  friend SFMatrix34f operator* (const SFMatrix34f &m1, const SFMatrix34f &m2);
  /// Overloaded operator*.
  friend SFMatrix34f operator* (const float a, const SFMatrix34f &m);
  /// Overloaded operator*.
  friend SFVec3f operator* (const SFMatrix34f &m, const SFVec3f &v);
  /// Overloaded operator*.
  friend SFPoint3f operator* (const SFMatrix34f &m, const SFPoint3f &v);
  /// Overloaded operator*.
  friend bool operator== (const SFMatrix34f &A, const SFMatrix34f &B);
  /// Overloaded operator*.
  friend bool operator!= (const SFMatrix34f &A, const SFMatrix34f &B);
  /// General inverse of the matrix.
  SFMatrix34f i();
  /// Inverse of the matrix taking in account that the matrix is unit and performing
  /// the operation faster than i().
  SFMatrix34f iu();
  /// Conversion to float[16].
  float *toFloat16() const;
  
  /// null matrix
  static const SFMatrix34f null;
  /// Identity matrix
  static const SFMatrix34f identity;

  /// Returns a scale matrix.
  static SFMatrix34f scale34(float sx, float sy, float sz);
  /// Returns a rotation matrix around the x axis.
  static SFMatrix34f rotationX(float angle);
  /// Returns a rotation matrix around the y axis.
  static SFMatrix34f rotationY(float angle);
  /// Returns a rotation matrix around the z axis.
  static SFMatrix34f rotationZ(float angle);
  /// Returns a translation matrix.
  static SFMatrix34f translation(const SFVec3f &t);
  /// Returns a general rotation matrix.
  static SFMatrix34f rotation(float angle, const SFVec3f &u); 
};


}

#endif

