Back to index

radiance  4R0+20100331
mat4.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: mat4.c,v 2.4 2003/02/25 02:47:21 greg Exp $";
00003 #endif
00004 /*
00005  *  mat4.c - routines dealing with 4 X 4 homogeneous transformation matrices.
00006  */
00007 
00008 #include "copyright.h"
00009 
00010 #include  "mat4.h"
00011 
00012 MAT4  m4ident = MAT4IDENT;
00013 
00014 static MAT4  m4tmp;         /* for efficiency */
00015 
00016 
00017 void
00018 multmat4(m4a, m4b, m4c)            /* multiply m4b X m4c and put into m4a */
00019 MAT4  m4a;
00020 register MAT4  m4b, m4c;
00021 {
00022        register int  i, j;
00023        
00024        for (i = 4; i--; )
00025               for (j = 4; j--; )
00026                      m4tmp[i][j] = m4b[i][0]*m4c[0][j] +
00027                                   m4b[i][1]*m4c[1][j] +
00028                                   m4b[i][2]*m4c[2][j] +
00029                                   m4b[i][3]*m4c[3][j];
00030        
00031        copymat4(m4a, m4tmp);
00032 }
00033 
00034 
00035 void
00036 multv3(v3a, v3b, m4) /* transform vector v3b by m4 and put into v3a */
00037 FVECT  v3a;
00038 register FVECT  v3b;
00039 register MAT4  m4;
00040 {
00041        m4tmp[0][0] = v3b[0]*m4[0][0] + v3b[1]*m4[1][0] + v3b[2]*m4[2][0];
00042        m4tmp[0][1] = v3b[0]*m4[0][1] + v3b[1]*m4[1][1] + v3b[2]*m4[2][1];
00043        m4tmp[0][2] = v3b[0]*m4[0][2] + v3b[1]*m4[1][2] + v3b[2]*m4[2][2];
00044        
00045        v3a[0] = m4tmp[0][0];
00046        v3a[1] = m4tmp[0][1];
00047        v3a[2] = m4tmp[0][2];
00048 }
00049 
00050 
00051 void
00052 multp3(p3a, p3b, m4)        /* transform p3b by m4 and put into p3a */
00053 register FVECT  p3a;
00054 FVECT  p3b;
00055 register MAT4  m4;
00056 {
00057        multv3(p3a, p3b, m4);       /* transform as vector */
00058        p3a[0] += m4[3][0];  /* translate */
00059        p3a[1] += m4[3][1];
00060        p3a[2] += m4[3][2];
00061 }