CMU462 Library  1.0
15-462/15-662: Computer Graphics (Fall 2015)
matrix4x4.h
1 #ifndef CMU462_MATRIX4X4_H
2 #define CMU462_MATRIX4X4_H
3 
4 #include "CMU462.h"
5 #include "vector4D.h"
6 
7 #include <iosfwd>
8 
9 namespace CMU462 {
10 
22 class Matrix4x4 {
23 
24  public:
25 
26 
27  // The default constructor.
28  Matrix4x4(void) { }
29 
30  // Constructor for row major form data.
31  // Transposes to the internal column major form.
32  // REQUIRES: data should be of size 16.
33  Matrix4x4(double * data)
34  {
35  for( int i = 0; i < 4; i++ )
36  for( int j = 0; j < 4; j++ )
37  {
38  // Transpostion happens within the () query.
39  (*this)(i,j) = data[i*4 + j];
40  }
41 
42  }
43 
44 
48  void zero(double val = 0.0);
49 
53  double det( void ) const;
54 
58  double norm( void ) const;
59 
63  static Matrix4x4 identity( void );
64 
65  // No Cross products for 4 by 4 matrix.
66 
70  Vector4D& column( int i );
71  const Vector4D& column( int i ) const;
72 
76  Matrix4x4 T( void ) const;
77 
81  Matrix4x4 inv( void ) const;
82 
83  // accesses element (i,j) of A using 0-based indexing
84  // where (i, j) is (row, column).
85  double& operator()( int i, int j );
86  const double& operator()( int i, int j ) const;
87 
88  // accesses the ith column of A
89  Vector4D& operator[]( int i );
90  const Vector4D& operator[]( int i ) const;
91 
92  // increments by B
93  void operator+=( const Matrix4x4& B );
94 
95  // returns -A
96  Matrix4x4 operator-( void ) const;
97 
98  // returns A-B
99  Matrix4x4 operator-( const Matrix4x4& B ) const;
100 
101  // returns c*A
102  Matrix4x4 operator*( double c ) const;
103 
104  // returns A*B
105  Matrix4x4 operator*( const Matrix4x4& B ) const;
106 
107  // returns A*x
108  Vector4D operator*( const Vector4D& x ) const;
109 
110  // divides each element by x
111  void operator/=( double x );
112 
113  protected:
114 
115  // 4 by 4 matrices are represented by an array of 4 column vectors.
116  Vector4D entries[4];
117 
118 }; // class Matrix3x3
119 
120 // returns the outer product of u and v.
121 Matrix4x4 outer( const Vector4D& u, const Vector4D& v );
122 
123 // returns c*A
124 Matrix4x4 operator*( double c, const Matrix4x4& A );
125 
126 // prints entries
127 std::ostream& operator<<( std::ostream& os, const Matrix4x4& A );
128 
129 } // namespace CMU462
130 
131 #endif // CMU462_MATRIX4X4_H
Definition: CMU462.h:8
Matrix4x4 inv(void) const
Returns the inverse of A.
Definition: matrix4x4.cpp:195
Defines 4D standard vectors.
Definition: vector4D.h:15
void zero(double val=0.0)
Sets all elements to val.
Definition: matrix4x4.cpp:26
static Matrix4x4 identity(void)
Returns a fresh 4x4 identity matrix.
Definition: matrix4x4.cpp:235
Vector4D & column(int i)
Returns the ith column.
Definition: matrix4x4.cpp:275
Defines a 4x4 matrix.
Definition: matrix4x4.h:22
double norm(void) const
Returns the Frobenius norm of A.
Definition: matrix4x4.cpp:53
double det(void) const
Returns the determinant of A.
Definition: matrix4x4.cpp:34
Matrix4x4 T(void) const
Returns the transpose of A.
Definition: matrix4x4.cpp:182