Back to index

radiance  4R0+20100331
Defines | Typedefs | Functions | Variables
mat4.h File Reference
#include <string.h>
#include "fvect.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define copymat4(m4a, m4b)   (void)memcpy((void *)m4a,(void *)m4b,sizeof(MAT4))
#define MAT4IDENT
#define setident4(m4)   copymat4(m4, m4ident)

Typedefs

typedef RREAL MAT4 [4][4]

Functions

void multmat4 (MAT4 m4a, MAT4 m4b, MAT4 m4c)
void multv3 (FVECT v3a, FVECT v3b, MAT4 m4)
void multp3 (FVECT p3a, FVECT p3b, MAT4 m4)
int invmat4 (MAT4 inverse, MAT4 mat)

Variables

MAT4 m4ident

Define Documentation

#define copymat4 (   m4a,
  m4b 
)    (void)memcpy((void *)m4a,(void *)m4b,sizeof(MAT4))

Definition at line 18 of file mat4.h.

#define MAT4IDENT
Value:
{ {1.,0.,0.,0.}, {0.,1.,0.,0.}, \
                            {0.,0.,1.,0.}, {0.,0.,0.,1.} }

Definition at line 20 of file mat4.h.

#define setident4 (   m4)    copymat4(m4, m4ident)

Definition at line 25 of file mat4.h.


Typedef Documentation

typedef RREAL MAT4[4][4]

Definition at line 16 of file mat4.h.


Function Documentation

int invmat4 ( MAT4  inverse,
MAT4  mat 
)

Definition at line 21 of file invmat4.c.

{
       MAT4  m4tmp;
       register int i,j,k;
       register double temp;

       copymat4(m4tmp, mat);
                                   /* set inverse to identity */
       setident4(inverse);

       for(i = 0; i < 4; i++) {
              /* Look for row with largest pivot and swap rows */
              temp = FTINY; j = -1;
              for(k = i; k < 4; k++)
                     if(ABS(m4tmp[k][i]) > temp) {
                            temp = ABS(m4tmp[k][i]);
                            j = k;
                            }
              if(j == -1)   /* No replacing row -> no inverse */
                     return(0);
              if (j != i)
                     for(k = 0; k < 4; k++) {
                            SWAP(m4tmp[i][k],m4tmp[j][k],temp);
                            SWAP(inverse[i][k],inverse[j][k],temp);
                            }

              temp = m4tmp[i][i];
              for(k = 0; k < 4; k++) {
                     m4tmp[i][k] /= temp;
                     inverse[i][k] /= temp;
                     }
              for(j = 0; j < 4; j++) {
                     if(j != i) {
                            temp = m4tmp[j][i];
                            for(k = 0; k < 4; k++) {
                                   m4tmp[j][k] -= m4tmp[i][k]*temp;
                                   inverse[j][k] -= inverse[i][k]*temp;
                                   }
                            }
                     }
              }
       return(1);
}

Here is the caller graph for this function:

void multmat4 ( MAT4  m4a,
MAT4  m4b,
MAT4  m4c 
)

Definition at line 18 of file mat4.c.

{
       register int  i, j;
       
       for (i = 4; i--; )
              for (j = 4; j--; )
                     m4tmp[i][j] = m4b[i][0]*m4c[0][j] +
                                  m4b[i][1]*m4c[1][j] +
                                  m4b[i][2]*m4c[2][j] +
                                  m4b[i][3]*m4c[3][j];
       
       copymat4(m4a, m4tmp);
}
void multp3 ( FVECT  p3a,
FVECT  p3b,
MAT4  m4 
)

Definition at line 52 of file mat4.c.

{
       multv3(p3a, p3b, m4);       /* transform as vector */
       p3a[0] += m4[3][0];  /* translate */
       p3a[1] += m4[3][1];
       p3a[2] += m4[3][2];
}
void multv3 ( FVECT  v3a,
FVECT  v3b,
MAT4  m4 
)

Definition at line 36 of file mat4.c.

{
       m4tmp[0][0] = v3b[0]*m4[0][0] + v3b[1]*m4[1][0] + v3b[2]*m4[2][0];
       m4tmp[0][1] = v3b[0]*m4[0][1] + v3b[1]*m4[1][1] + v3b[2]*m4[2][1];
       m4tmp[0][2] = v3b[0]*m4[0][2] + v3b[1]*m4[1][2] + v3b[2]*m4[2][2];
       
       v3a[0] = m4tmp[0][0];
       v3a[1] = m4tmp[0][1];
       v3a[2] = m4tmp[0][2];
}

Variable Documentation

Definition at line 12 of file mat4.c.