/***********************************************************************
 * FXRuby -- the Ruby language bindings for the FOX GUI toolkit.
 * Copyright (c) 2001-2003 by J. Lyle Johnson. All Rights Reserved.
 *
 * 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
 *
 * For further information please contact the author by e-mail
 * at "lyle@users.sourceforge.net".
 ***********************************************************************/


/// Homogeneous matrix (single-precision version)
class FXHMat {
public:
  // Constructors
  %extend {
    FXHMat(){
      return new FXHMat(0.0f);
      }
  }
  FXHMat(FXfloat w);
  FXHMat(FXfloat a00,FXfloat a01,FXfloat a02,FXfloat a03,
         FXfloat a10,FXfloat a11,FXfloat a12,FXfloat a13,
         FXfloat a20,FXfloat a21,FXfloat a22,FXfloat a23,
         FXfloat a30,FXfloat a31,FXfloat a32,FXfloat a33);
  FXHMat(const FXHVec& a,const FXHVec& b,const FXHVec& c,const FXHVec& d);
  FXHMat(const FXHMat& other);

  %extend {
	// Add matrices
	FXHMat operator+(const FXHMat& other) const { return (*self)+other; }

	// Subtract matrices
	FXHMat operator-(const FXHMat& other) const { return (*self)-other; }

	// Multiply by a matrix
	FXHMat operator*(const FXHMat& other) const { return (*self)*other; }

	// Multiply by a scalar
	FXHMat operator*(FXfloat x) const { return (*self)*x; }

	// Multiply by a homogenous vector
	FXHVec operator*(const FXHVec& other) const { return (*self)*other; }

	// Multiply by a non-homogeneous vector, for non-projective matrix
	FXVec operator*(const FXVec& other) const { return (*self)*other; }

	// Divide by a scalar
	FXHMat operator/(FXfloat x) const {
	  if(x==0.0f) rb_raise(rb_eZeroDivError,"divided by 0");
	  return (*self)/x;
	  }

	// Negation
	FXHMat operator-() const { return -(*self); }

    // Indexing
    FXHVec& __getitem__(FXint i){
      if(i<0 || i>3){
        rb_raise(rb_eIndexError,"index %d out of range",i);
        }
      return (*self)[i];
      }

    // Determinant
    FXfloat det() const {
      return det(*self);
      }

    // Transpose
    FXHMat transpose() const {
      return transpose(*self);
      }

    // Invert
    FXHMat invert() const {
      return invert(*self);
      }

    // Stringify
    FXString to_s() const {
      const FXHMat& m = *self;
      return FXStringFormat("[[%g, %g, %g, %g], [%g, %g, %g, %g], [%g, %g, %g, %g], [%g, %g, %g, %g]]",m[0][0],m[0][1],m[0][2],m[0][3],m[1][0],m[1][1],m[1][2],m[1][3],m[2][0],m[2][1],m[2][2],m[2][3],m[3][0],m[3][1],m[3][2],m[3][3]);
      }
    }

  // Set identity matrix
  FXHMat& eye();

  // Orthographic projection
  FXHMat& ortho(FXfloat left,FXfloat right,FXfloat bottom,FXfloat top,FXfloat hither,FXfloat yon);
  
  // Perspective projection
  FXHMat& frustum(FXfloat left,FXfloat right,FXfloat bottom,FXfloat top,FXfloat hither,FXfloat yon);

  // Multiply by left-hand matrix
  FXHMat& left();

  // Multiply by rotation about unit-quaternion
  FXHMat& rot(const FXQuat& q);

  // Multiply by rotation c,s about axis
  FXHMat& rot(const FXVec& v,FXfloat c,FXfloat s);

  // Multiply by rotation of phi about axis
  FXHMat& rot(const FXVec& v,FXfloat phi);

  // Multiply by x-rotation
  FXHMat& xrot(FXfloat c,FXfloat s);
  FXHMat& xrot(FXfloat phi);

  // Multiply by y-rotation
  FXHMat& yrot(FXfloat c,FXfloat s);
  FXHMat& yrot(FXfloat phi);

  /// Multiply by z-rotation
  FXHMat& zrot(FXfloat c,FXfloat s);
  FXHMat& zrot(FXfloat phi);

  // Look at
  FXHMat& look(const FXVec& eye,const FXVec& cntr,const FXVec& vup);

  // Multiply by translation
  FXHMat& trans(FXfloat tx,FXfloat ty,FXfloat tz);
  FXHMat& trans(const FXVec& v);

  // Multiply by scaling
  FXHMat& scale(FXfloat sx,FXfloat sy,FXfloat sz);
  FXHMat& scale(FXfloat s);
  FXHMat& scale(const FXVec& v);
  };
