// // matrix.h // // Handle matrices // // Copyright (C) J. Belson 1998.01.21 // // Matrix arranged as follows: // 0 1 2 3 // 4 5 6 7 // 8 9 10 11 // 12 13 14 15 #ifndef _MATRIX_H_ #define _MATRIX_H_ #include #include #include "point3d.h" #include "vector3d.h" enum { MATRIX_WIDTH = 4, NUM_ELEMENTS = MATRIX_WIDTH*MATRIX_WIDTH, }; /** * Implement 4x4 homogeneous matrix. Provides operators * for working on points and vectors. */ class matrix { private: // 4x4 matrix float elem[NUM_ELEMENTS]; public: enum matrix_type { IDENTITY, ROTATION, TRANSLATION, PROJECTION, SCALING }; matrix(float *m); matrix(matrix_type m, float a=0.0, float b=0.0, float c=0.0); matrix(const vector3d& v1, const vector3d& v2, const vector3d& v3); matrix(); matrix operator=(const matrix &m); void dump(void); void make_identity(); // Make a rotation/translation matrix void make_rotation(float a, float b, float c); void make_translation(float x, float y, float z); void make_projection(float depth); void make_scaling(float a, float b, float c); matrix transpose(void); // matrix operator*(const matrix &m); // matrix operator*(matrix &m); // Perform transformations on primitives point3d operator*(const point3d& p); vector3d operator*(const vector3d& v); matrix operator*(float scale); friend matrix operator*(matrix &m, matrix &n); friend matrix operator+(matrix &m, const matrix &n); friend matrix operator-(matrix &m, const matrix &n); float& operator[](int index); const float& operator[](int index) const; }; #endif // _MATRIX_H_