00001 /*************************************************************************** 00002 matrix3d.h 00003 ------------------- 00004 copyright : (C) 2004 by Jos van den Oever 00005 email : jos@vandenoever.info 00006 ***************************************************************************/ 00007 00008 /*************************************************************************** 00009 * * 00010 * This program is free software; you can redistribute it and/or modify * 00011 * it under the terms of the GNU General Public License as published by * 00012 * the Free Software Foundation; either version 2 of the License, or * 00013 * (at your option) any later version. * 00014 * * 00015 ***************************************************************************/ 00016 #ifndef MATRIX3D_H 00017 #define MATRIX3D_H 00018 00019 /* A matrix class that allows the mapping of a set of coordinates in 3D to 00020 coordinates in a rotated and scaled 3D space. 00021 The rotation is determined by four parameters. The first two (t and p) 00022 parameters define a point on a circle in spherical coordinates. 00023 x = sin(t)*cos(p) 00024 y = sin(t)*sin(p) 00025 z = cos(t) 00026 The range for t is 0 <= t <= pi. The range for p is 0 <= p <= 2*pi. 00027 The parameter r gives the rotation around the vector given by t and p. 00028 00029 The real matrix is calculated from t, p and r by calculating the elemenary 00030 vectors (1,0,0), (0,1,0), (0,0,1) for the rotated space. These three 00031 vectors next to each other form the matrix. 00032 00033 The matrix can be rotated from the point of view of the rotated space with 00034 the functions rotX, rotY and rotZ. These funtions update the matrix directly. 00035 The parameters t, p and r are inferred from the matrix by calling the 00036 function updateTPR(). 00037 00038 The parameter s can be used for applying a uniformly scaled transformation. 00039 00040 An additional feature of the matrix is the interpolation between matrices. 00041 The function savePosition() stores the current possition. With each call to 00042 the function stepBack(), the current matrix is rotated to look more like 00043 the stored matrix. When the current and the stored matrix are the same, 00044 false is returned by stepBack(). 00045 00046 */ 00047 class Matrix3D { 00048 private: 00049 bool lastanim; 00050 double t, p, r, s; 00051 double oldt, oldp, oldr; 00052 double xx, xy, xz; 00053 double yx, yy, yz; 00054 double zx, zy, zz; 00055 double angstep; 00056 static double pi, twopi; 00057 void updateMatrix(); 00058 void updateTPR(); 00059 public: 00060 Matrix3D(); 00061 void rotX(double); 00062 void rotY(double); 00063 void rotZ(double); 00064 void scale(double f); 00065 void transform(const double v[], double tv[], int nvert) const; 00066 void unit(); 00067 void savePosition(); 00068 bool stepBack(); 00069 void setOrient(double t, double p, double r); 00070 }; 00071 00072 #endif