home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 3 / RISC_DISC_3.iso / resources / etexts / gems / gemsv / ch7_7 / libgm / gmmat4.h < prev    next >
C/C++ Source or Header  |  1995-03-07  |  4KB  |  144 lines

  1. // gmMatrix4.h - 4x4 element matrix class
  2. //
  3. // libgm++: Graphics Math Library
  4. // Ferdi Scheepers and Stephen F May
  5. // 15 June 1994
  6.  
  7. #ifndef GMMATRIX4_H
  8. #define GMMATRIX4_H
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <assert.h>
  13. #include <gmUtils.h>
  14.  
  15. class gmVector3;
  16. class gmVector4;
  17.  
  18. class gmMatrix4 {
  19.  
  20. protected:
  21.   double m_[4][4];
  22.  
  23. public:
  24.   gmMatrix4();
  25.   gmMatrix4(const gmMatrix4&);
  26.   gmMatrix4(double, double, double, double,
  27.           double, double, double, double,
  28.          double, double, double, double,
  29.         double, double, double, double);
  30.  
  31.   // array access
  32.  
  33.   double* operator [](int);
  34.   const double* operator [](int) const;
  35.  
  36.   // assignment
  37.   
  38.   gmMatrix4& assign(double, double, double, double,
  39.             double, double, double, double,
  40.             double, double, double, double,
  41.             double, double, double, double);
  42.   gmMatrix4& operator =(const gmMatrix4&);
  43.  
  44.   // operators
  45.  
  46.   gmMatrix4& operator +=(const gmMatrix4&);
  47.   gmMatrix4& operator -=(const gmMatrix4&);
  48.   gmMatrix4& operator *=(const gmMatrix4&);
  49.   gmMatrix4& operator *=(double);
  50.   gmMatrix4& operator /=(double);
  51.  
  52.   gmMatrix4 operator +(const gmMatrix4&) const;
  53.   gmMatrix4 operator -(const gmMatrix4&) const;
  54.   gmMatrix4 operator -() const;
  55.   gmMatrix4 operator *(const gmMatrix4&) const;
  56.   gmMatrix4 operator *(double) const;
  57.   gmMatrix4 operator /(double) const;
  58.  
  59. friend gmMatrix4 operator *(double, const gmMatrix4&);
  60.  
  61.   bool operator ==(const gmMatrix4&) const;
  62.   bool operator !=(const gmMatrix4&) const;
  63.  
  64.   gmVector4 operator *(const gmVector4&) const;
  65.  
  66. friend gmVector4 operator *(const gmVector4&, const gmMatrix4&);
  67.  
  68.   // operations
  69.  
  70.   gmMatrix4 inverse() const;
  71.   gmMatrix4 transpose() const;
  72.   gmMatrix4 adjoint() const;
  73.   
  74.   double determinant() const;
  75.   bool isSingular() const;
  76.  
  77.   gmVector3 transform(const gmVector3&) const;
  78.   
  79.   void copyTo(float [4][4]) const;
  80.   void copyTo(double [4][4]) const;
  81.  
  82.   // transformation matrices
  83.  
  84.   static gmMatrix4 identity();
  85.   static gmMatrix4 rotate(double, const gmVector3& axis);
  86.   static gmMatrix4 scale(double, double, double);
  87.   static gmMatrix4 translate(double, double, double);
  88.  
  89.   // cubic basis matrices
  90.  
  91.   static gmMatrix4 bezierBasis();
  92.   static gmMatrix4 bsplineBasis();
  93.   static gmMatrix4 catmullromBasis();
  94.   static gmMatrix4 hermiteBasis();
  95.   
  96.   static gmMatrix4 tensedBSplineBasis(double);
  97.   static gmMatrix4 cardinalBasis(double);
  98.   static gmMatrix4 tauBasis(double, double);
  99.   static gmMatrix4 betaSplineBasis(double, double);
  100.  
  101. };
  102.  
  103. // ARRAY ACCESS
  104.  
  105. inline double* gmMatrix4::operator [](int i)
  106. {
  107.   assert(i == 0 || i == 1 || i == 2 || i == 3);
  108.   return &m_[i][0];
  109. }
  110.  
  111. inline const double* gmMatrix4::operator [](int i) const
  112. {
  113.   assert(i == 0 || i == 1 || i == 2 || i == 3);
  114.   return &m_[i][0];
  115. }
  116.  
  117. inline void gmMatrix4::copyTo(float f[4][4]) const
  118. {
  119.   f[0][0] = m_[0][0]; f[0][1] = m_[0][1]; 
  120.   f[0][2] = m_[0][2]; f[0][3] = m_[0][3];
  121.   f[1][0] = m_[1][0]; f[1][1] = m_[1][1]; 
  122.   f[1][2] = m_[1][2]; f[1][3] = m_[1][3];
  123.   f[2][0] = m_[2][0]; f[2][1] = m_[2][1]; 
  124.   f[2][2] = m_[2][2]; f[2][3] = m_[2][3];
  125.   f[3][0] = m_[3][0]; f[3][1] = m_[3][1]; 
  126.   f[3][2] = m_[3][2]; f[3][3] = m_[3][3];
  127. }
  128.  
  129. inline void gmMatrix4::copyTo(double f[4][4]) const
  130. {
  131.   f[0][0] = m_[0][0]; f[0][1] = m_[0][1]; 
  132.   f[0][2] = m_[0][2]; f[0][3] = m_[0][3];
  133.   f[1][0] = m_[1][0]; f[1][1] = m_[1][1]; 
  134.   f[1][2] = m_[1][2]; f[1][3] = m_[1][3];
  135.   f[2][0] = m_[2][0]; f[2][1] = m_[2][1]; 
  136.   f[2][2] = m_[2][2]; f[2][3] = m_[2][3];
  137.   f[3][0] = m_[3][0]; f[3][1] = m_[3][1]; 
  138.   f[3][2] = m_[3][2]; f[3][3] = m_[3][3];
  139. }
  140.  
  141. #endif // GMMATRIX4_H
  142.  
  143.  
  144.