29 #define VMD_PI      3.14159265358979323846    30 #define VMD_TWOPI   (2.0 * VMD_PI)    31 #define DEGTORAD(a)     (a*VMD_PI/180.0)    32 #define RADTODEG(a)     (a*180.0/VMD_PI)    37   memcpy((
void *)
mat, (
const void *)m, 16*
sizeof(
double));
    46     double itmp3 = 1.0 / (opoint[0]*
mat[3] + opoint[1]*
mat[7] + 
    47                           opoint[2]*
mat[11] + 
mat[15]);
    48     npoint[0]=itmp3 * (opoint[0]*
mat[0] + opoint[1]*
mat[4] + opoint[2]*
mat[ 8] + 
mat[12]);
    49     npoint[1]=itmp3 * (opoint[0]*
mat[1] + opoint[1]*
mat[5] + opoint[2]*
mat[ 9] + 
mat[13]);
    50     npoint[2]=itmp3 * (opoint[0]*
mat[2] + opoint[1]*
mat[6] + opoint[2]*
mat[10] + 
mat[14]);
    53     double itmp3 = 1.0 / (opoint[0]*
mat[3] + opoint[1]*
mat[7] +
    54                           opoint[2]*
mat[11] + 
mat[15]);
    55     tmp[0] = itmp3*opoint[0];
    56     tmp[1] = itmp3*opoint[1];
    57     tmp[2] = itmp3*opoint[2];
    58     npoint[0]=tmp[0]*
mat[0] + tmp[1]*
mat[4] + tmp[2]*
mat[ 8] + itmp3*
mat[12];
    59     npoint[1]=tmp[0]*
mat[1] + tmp[1]*
mat[5] + tmp[2]*
mat[ 9] + itmp3*
mat[13];
    60     npoint[2]=tmp[0]*
mat[2] + tmp[1]*
mat[6] + tmp[2]*
mat[10] + itmp3*
mat[14];
    71   tmp[0]=onorm[0]*
mat[0] + onorm[1]*
mat[4] + onorm[2]*
mat[8];
    72   tmp[1]=onorm[0]*
mat[1] + onorm[1]*
mat[5] + onorm[2]*
mat[9];
    73   tmp[2]=onorm[0]*
mat[2] + onorm[1]*
mat[6] + onorm[2]*
mat[10];
    74   tmp[3]=onorm[0]*
mat[3] + onorm[1]*
mat[7] + onorm[2]*
mat[11];
    75   double itmp = 1.0 / sqrtf(tmp[0]*tmp[0] + tmp[1]*tmp[1] + tmp[2]*tmp[2]);
    84   npoint[0]=opoint[0]*
mat[0]+opoint[1]*
mat[4]+opoint[2]*
mat[8]+opoint[3]*
mat[12];
    85   npoint[1]=opoint[0]*
mat[1]+opoint[1]*
mat[5]+opoint[2]*
mat[9]+opoint[3]*
mat[13];
    86   npoint[2]=opoint[0]*
mat[2]+opoint[1]*
mat[6]+opoint[2]*
mat[10]+opoint[3]*
mat[14];
    87   npoint[3]=opoint[0]*
mat[3]+opoint[1]*
mat[7]+opoint[2]*
mat[11]+opoint[3]*
mat[15];
    93   memset((
void *)
mat, 0, 16*
sizeof(
double));
   103   for (
int i=0; i<16; 
mat[i++] = f); 
   109 #define MATSWAP(a,b) {temp=(a);(a)=(b);(b)=temp;}   112   double matr[4][4], ident[4][4];
   115   int indxc[4], indxr[4], ipiv[4];
   116   double big, dum, pivinv, temp;
   118   for (i=0; i<4; i++) {
   119     for (j=0; j<4; j++) {
   120       matr[i][j] = 
mat[4*i+j];
   131   for(j=0;j<=3;j++) ipiv[j] = 0;
   138             if(fabs(matr[j][k]) >= big) {
   139               big = (double) fabs(matr[j][k]);
   143           } 
else if (ipiv[k] > 1) 
return 1;
   149       for (l=0;l<=3;l++) 
MATSWAP(matr[irow][l],matr[icol][l]);
   150       for (l=0;l<=3;l++) 
MATSWAP(ident[irow][l],ident[icol][l]);
   154     if(matr[icol][icol] == 0.0) 
return 1; 
   155     pivinv = 1.0 / matr[icol][icol];
   156     matr[icol][icol]=1.0;
   157     for (l=0;l<=3;l++) matr[icol][l] *= pivinv;
   158     for (l=0;l<=3;l++) ident[icol][l] *= pivinv;
   159     for (ll=0;ll<=3;ll++) {
   163         for (l=0;l<=3;l++) matr[ll][l] -= matr[icol][l]*dum;
   164         for (l=0;l<=3;l++) ident[ll][l] -= ident[icol][l]*dum;
   169     if (indxr[l] != indxc[l]) {
   171         MATSWAP(matr[k][indxr[l]],matr[k][indxc[l]]);
   177       mat[4*i+j] = matr[i][j];
   186       tmp[4*i+j] = 
mat[i+4*j];
   195   memcpy((
void *)
mat, (
const void *)m.
mat, 16*
sizeof(
double));
   201   for (
int j=0; j<4; j++) {
   206     for (
int i=0; i<4; i++) {
   207       mat[4*i+j] = m.
mat[4*i]*tmp[0] + m.
mat[4*i+1]*tmp[1] +
   208         m.
mat[4*i+2]*tmp[2] + m.
mat[4*i+3]*tmp[3]; 
   227   } 
else if (axis == 
'y') {
   233   } 
else if (axis == 
'z') {
   246   transvec(axis[0], axis[1], axis[2]);
   253   double theta = atan2(y,x);
   254   double length = sqrt(y*y + x*x);
   255   double phi = atan2((
double) z, length);
   262   double theta = atan2(y,x);
   263   double length = sqrt(y*y + x*x);
   264   double phi = atan2((
double) z, length);
   289                          double top, 
double nearval, 
double farval) {
   292   mat[0] = (2.0*nearval) / (right-left);
   293   mat[5] = (2.0*nearval) / (top-bottom);
   294   mat[8] = (right+left) / (right-left);
   295   mat[9] = (top+bottom) / (top-bottom);
   296   mat[10] = -(farval+nearval) / (farval-nearval);
   298   mat[14] = -(2.0*farval*nearval) / (farval-nearval);
   304                         double top, 
double nearval, 
double farval) {
   307   mat[0] =  2.0 / (right-left);
   308   mat[5] =  2.0 / (top-bottom);
   309   mat[10] = -2.0 / (farval-nearval);
   310   mat[12] = -(right+left) / (right-left);
   311   mat[13] = -(top+bottom) / (top-bottom);
   312   mat[14] = -(farval+nearval) / (farval-nearval);
   321   mat[0] =  2.0 / (right-left);
   322   mat[5] =  2.0 / (top-bottom);
   324   mat[12] = -(right+left) / (right-left);
   325   mat[13] = -(top+bottom) / (top-bottom);
   337                          double pz, 
short twist) {
   342   rot(-twist / 10.0,
'z');
   344   tmp = sqrtf((px-vx)*(px-vx) + (py-vy)*(py-vy) + (pz-vz)*(pz-vz));
   346   m.
mat[5] = sqrtf((px-vx)*(px-vx) + (pz-vz)*(pz-vz)) / tmp;
   347   m.
mat[6] = (vy-py) / tmp;
   355   tmp = sqrtf((px-vx)*(px-vx) + (pz-vz)*(pz-vz));
   356   m.
mat[0] = (vz-pz) / tmp;
   360   m.
mat[2] = -(px-vx) / tmp;
   371   for (i=0; i<3; i++) {
   372     mat4->
mat[0+i] = mat3[3*i];
   373     mat4->
mat[4+i] = mat3[3*i+1];
   374     mat4->
mat[8+i] = mat3[3*i+2];
   381   for (i=0; i<4; i++) {
   382     for (j=0; j<4; j++) {
   383       printf(
"%f ", mat4->
mat[4*j+i]);
 void identity(void)
clears the matrix (resets it to identity) 
 
void transvecinv(double x, double y, double z)
apply a rotation such that the given vector is brought along 'x'. 
 
Matrix4(void)
identity constructor 
 
void multnorm3d(const double[3], double[3]) const
multiplies a 3D norm (first arg) by the Matrix, returns in second arg 
 
void lookat(double, double, double, double, double, double, short)
 
void window(double, double, double, double, double, double)
sets this matrix to represent a window perspective 
 
void scale(double, double, double)
performs scaling 
 
void print_Matrix4(const Matrix4 *mat4)
Print formatted matrix. 
 
4x4 matrix class with numerous operators, conversions, etc. 
 
void loadmatrix(const Matrix4 &m)
replaces this matrix with the given one 
 
void multpoint3d(const double[3], double[3]) const
multiplies a 3D point (first arg) by the Matrix, returns in second arg 
 
void trans_from_rotate(const double mat3[9], Matrix4 *mat4)
Transform 3x3 into 4x4 matrix: 
 
void multpoint4d(const double[4], double[4]) const
multiplies a 4D point (first arg) by the Matrix, returns in second arg 
 
void rotate_axis(const double axis[3], double angle)
apply a rotation around the given vector; angle in radians. 
 
void ortho2(double, double, double, double)
sets this matrix to a 2D orthographic matrix 
 
double mat[16]
the matrix itself 
 
void transvec(double x, double y, double z)
apply a rotation such that 'x' is brought along the given vector. 
 
void transpose(void)
transposes the matrix 
 
void translate(double, double, double)
performs a translation 
 
void rot(double, char)
performs a left-handed rotation around an axis (char == 'x', 'y', or 'z') 
 
void multmatrix(const Matrix4 &)
premultiply the matrix by the given matrix, this->other * this 
 
void constant(double)
sets the matrix so all items are the given constant value 
 
void ortho(double, double, double, double, double, double)
sets this matrix to a 3D orthographic matrix