home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / oct93 / graphics / graphtal.lha / Graphtal / TransMatrix.h < prev    next >
C/C++ Source or Header  |  1992-11-20  |  3KB  |  99 lines

  1. /*
  2.  * TransMatrix.h - class definition for general 4x3 transformation matrices.
  3.  *
  4.  * Copyright (C) 1992, Christoph Streit (streit@iam.unibe.ch)
  5.  *                     University of Berne, Switzerland
  6.  * Portions Copyright (C) 1990, Jonathan P. Leech
  7.  * All rights reserved.
  8.  *
  9.  * This software may be freely copied, modified, and redistributed
  10.  * provided that this copyright notice is preserved on all copies.
  11.  *
  12.  * You may not distribute this software, in whole or in part, as part of
  13.  * any commercial product without the express consent of the authors.
  14.  *
  15.  * There is no warranty or other guarantee of fitness of this software
  16.  * for any purpose.  It is provided solely "as is".
  17.  *
  18.  */
  19.  
  20. #ifndef TransMatrix_H
  21. # define TransMatrix_H
  22.  
  23. #include <iostream.h>
  24. #include "mathutilities.h"
  25. #include "Vector.h"
  26.  
  27. void SinCos(real alpha, real&, real&);
  28.  
  29. //___________________________________________________________ TransMatrix
  30. /*
  31.  *  [ m11 m12 m13 0 ]   
  32.  *  [ m21 m22 m23 0 ]   representation of a 
  33.  *  [ m31 m32 m33 0 ]   transformation matrix
  34.  *  [ m41 m42 m43 1 ]
  35.  */
  36.  
  37. class TransMatrix
  38. {
  39. public:
  40.   enum Axis {X, Y, Z};
  41.  
  42. public:
  43.   TransMatrix();
  44.   TransMatrix(const Vector&, const Vector&, const Vector&);
  45.   TransMatrix(const Vector&, const Vector&, const Vector&, const Vector&);
  46.   TransMatrix(const TransMatrix&);
  47.  
  48.   const TransMatrix& operator=(const TransMatrix&);
  49.   
  50.   real& operator()(int i, int j);
  51.   real  operator()(int i, int j) const;
  52.  
  53.   TransMatrix& operator+=(const TransMatrix&);
  54.   TransMatrix& operator-=(const TransMatrix&);
  55.   TransMatrix& operator*=(const TransMatrix&);
  56.  
  57.   TransMatrix operator-();   
  58.   TransMatrix operator+(const TransMatrix&);
  59.   TransMatrix operator-(const TransMatrix&);
  60.   TransMatrix operator*(const TransMatrix&);
  61.  
  62.   int invert();
  63.   void setRotate(const Vector&, real);
  64.   TransMatrix& rotate(const Vector&, real);
  65.   TransMatrix& rotate(Axis, const real, const real);
  66.   TransMatrix& rotate(Axis, const real);
  67.   TransMatrix& scale(const real, const real, const real);
  68.   TransMatrix& translate(const Vector&);
  69.  
  70.   friend ostream& operator<<(ostream&, const TransMatrix&);
  71.   friend Vector operator*(const Vector&, const TransMatrix&);
  72.    
  73. private:
  74.   real m[4][3];
  75. };
  76.  
  77. inline real& TransMatrix::operator()(int i, int j)
  78. {
  79. #ifndef __OPTIMIZE__
  80.   if (i<0 || i>3 || j<0 || j>2)
  81.     Error(ERR_PANIC, "TransMatrix::operator(i,j) index out of range");
  82. #endif
  83.  
  84.   return m[i][j];
  85. }
  86.  
  87. inline real TransMatrix::operator()(int i, int j) const
  88. {
  89. #ifndef __OPTIMIZE__
  90.   if (i<0 || i>3 || j<0 || j>2)
  91.     Error(ERR_PANIC, "TransMatrix::operator(i,j) index out of range");
  92. #endif
  93.  
  94.   return m[i][j];
  95. }
  96.  
  97.  
  98. #endif // TransMatrix_H
  99.