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

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