Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Matrix4.h

00001 /*
00002   File: Matrix4.h
00003 
00004   Copyright(C) C. Kotterink, Computed Graphics
00005 */
00006 #ifndef MATRIX4_H
00007 #define MATRIX4_H
00008 
00009 #include<Vertex3.h>
00010 #include<Vertex4.h>
00011 
00012 #include<real.h>
00013 #include<iostream.h>
00014 
00015 class Matrix3;
00016 class ObjectFile;
00017 
00018 // Matrix representation is transposed
00019 #define INDEX4(r, c) (c*4 + r)
00020 
00023 class Matrix4
00024 {
00025     friend ostream &operator<<(ostream &stream, Matrix4 &m);
00026     friend ObjectFile &operator>>(ObjectFile &f, Matrix4 &m);
00027 private:
00028     class MatrixRow {
00029     public:
00030         MatrixRow(real *d, unsigned int r) : m(d), row(r) {}
00031         real &operator [](unsigned int col) {
00032             m[INDEX4(row, col)];
00033         }
00034     private:
00035         unsigned int row;
00036         real *m;
00037     };
00038 public:
00039     // Constructors
00040     Matrix4() {};
00041     Matrix4(const Matrix4 &m) {
00042         memcpy(this, &m, sizeof(Matrix4));
00043     }
00044     void identity();
00045     void transpose();
00046     bool inverse();
00047     void perspective(float fovy, float aspect, float zNear, float zFar);
00048     Matrix4 &setXAxis(Vertex3 &x);
00049     Matrix4 &setYAxis(Vertex3 &y);
00050     Matrix4 &setZAxis(Vertex3 &z);
00051     Matrix4 &setOrigin(Vertex3 &o);
00052 
00053     // Get
00054     MatrixRow operator [](unsigned int row) {
00055         MatrixRow r(m, row);
00056         return r;
00057     }
00058     const real *data() const { return m; }
00059 
00060     // Assignment operators
00061     Matrix4 &operator =(const Matrix4 &right) {
00062         memcpy(this, &right, sizeof(Matrix4));
00063         return *this;
00064     }
00065     Matrix4 &operator =(const Matrix3 &right);
00066     void operator *=(const Matrix4 &right);
00067 
00068     // Operators
00069     Matrix4 operator *(const Matrix4 &right) const;
00070     Matrix3 operator *(const Matrix3 &right) const;
00071     Vertex3 operator *(const Vertex3 &v) const;
00072     Vertex4 operator *(const Vertex4 &v) const;
00073     Matrix4 operator ~() const {
00074         Matrix4 m(*this);
00075         m.transpose();
00076         return m;
00077     }
00078 
00079     real det() const;
00080     real lipschitz() const;
00081 
00082     // 3D Transfomations, righthanded
00083     Vertex3 apply(const Vertex3 &v) const {
00084         return *this * v;
00085     }
00086     Vertex4 apply(const Vertex4 &v) const {
00087         return *this * v;
00088     }
00089     Vertex3 applyHomogenous(const Vertex3 &v) const;
00090     Vertex3 applyM3(const Vertex3 &v) const;
00091     void scale(real x, real y, real z);
00092     void scale(Vertex3 v) { scale(v.x, v.y, v.z); }
00093     void translate(real x, real y, real z);
00094     void translateSimple(real x, real y, real z);
00095     void translate(Vertex3 v) { translate(v.x, v.y, v.z); }
00096 
00097     // calculates: this = rotate(alpha) * this;
00098     void rotate(Vertex3 &v);
00099     void rotateX(real alpha);
00100     void rotateY(real alpha);
00101     void rotateZ(real alpha);
00102 
00103 private:
00104     real m[4*4];
00105 };
00106 #endif

This documentation was generated using doxygen. If you have any comments or additions please mail me.