00001
00002
00003
00004
00005
00006 #ifndef MATRIX3_H
00007 #define MATRIX3_H
00008
00009 #include<Vertex3.h>
00010
00011 #include<real.h>
00012 #include<iostream.h>
00013
00014 class Quaternion;
00015 class Matrix4;
00016 class ObjectFile;
00017
00018
00019 #define INDEX3(r, c) (c*3 + r)
00020
00023 class Matrix3
00024 {
00025 friend Matrix4;
00026 friend ostream &operator<<(ostream &stream, Matrix3 &m);
00027 friend ObjectFile &operator>>(ObjectFile &f, Matrix3 &m);
00028 private:
00029 class MatrixRow {
00030 public:
00031 MatrixRow(real *d, unsigned int r) : m(d), row(r) {}
00032 real &operator [](unsigned int col) {
00033 m[INDEX3(row, col)];
00034 }
00035 private:
00036 unsigned int row;
00037 real *m;
00038 };
00039 public:
00040
00041 Matrix3() {};
00042 Matrix3(const Matrix3 &m) {
00043 memcpy(this, &m, sizeof(Matrix3));
00044 }
00045 void identity();
00046 void transpose();
00048 void rotate(Vertex3 &a, real alpha);
00049
00050
00051 void construct(Vertex3 &up, const Vertex3 &dir);
00052
00053
00054 MatrixRow operator [](unsigned int row) {
00055 MatrixRow r(m, row);
00056 return r;
00057 }
00058 const real *data() const { return m; }
00059
00060
00061 Matrix3 &operator =(const Matrix3 &right) {
00062 memcpy(this, &right, sizeof(Matrix3));
00063 return *this;
00064 }
00065 Matrix3 &operator =(const Quaternion &q);
00066 void operator *=(const Matrix3 &right);
00067
00068
00069 Matrix3 operator *(const Matrix3 &right) const;
00070 Vertex3 operator *(const Vertex3 &v) const;
00071 Matrix3 operator ~() const {
00072 Matrix3 m(*this);
00073 m.transpose();
00074 return m;
00075 }
00076
00077 real det() const;
00078 Quaternion quaternion();
00079
00080
00081 Vertex3 apply(const Vertex3 &v) const {
00082 return *this * v;
00083 }
00084 Vertex3 applyInverse(const Vertex3 &v) const;
00085 void scale(Vertex3 &v);
00086
00088 void rotate(Vertex3 &v);
00090 void rotateX(real alpha);
00092 void rotateY(real alpha);
00094 void rotateZ(real alpha);
00095
00096 private:
00097 real m[3*3];
00098 };
00099 #endif