head 1.3; access; symbols; locks; strict; comment @# @; 1.3 date 2002.09.07.01.50.35; author curt; state Exp; branches; next 1.2; 1.2 date 2002.08.31.19.01.50; author curt; state Exp; branches; next 1.1; 1.1 date 2002.08.31.18.53.58; author curt; state Exp; branches; next ; desc @@ 1.3 log @Updated doxygen docs. @ text @
Main Page Class Hierarchy Compound List File List Compound Members File Members

# MAT3mat.c

    00001 /* #include "HEADERS.h" */
    00002 /* Copyright 1988, Brown Computer Graphics Group.  All Rights Reserved. */
    00003
    00004 /* --------------------------------------------------------------------------
    00005  * This file contains routines that operate solely on matrices.
    00006  * -------------------------------------------------------------------------*/
    00007
    00008
    00009 #ifdef HAVE_CONFIG_H
    00010 #  include <config.h>
    00011 #endif
    00012
    00013 #ifdef WIN32
    00014 #  ifndef HAVE_STL_SGI_PORT
    00015 #    ifdef __BORLANDC__
    00016 #      include <mem.h>
    00017 #    else
    00018 #      include <memory.h>      /* required for memset() and memcpy() */
    00019 #    endif
    00020 #  endif
    00021 #endif
    00022
    00023 #include <string.h>
    00024 #include "mat3defs.h"
    00025
    00026 MAT3mat identityMatrix = {
    00027     { 1.0, 0.0, 0.0, 0.0 },
    00028     { 0.0, 1.0, 0.0, 0.0 },
    00029     { 0.0, 0.0, 1.0, 0.0 },
    00030     { 0.0, 0.0, 0.0, 1.0 }
    00031 };
    00032
    00033 /* #include "macros.h" */
    00034
    00035 /* --------------------------  Static Routines  ---------------------------- */
    00036
    00037 /* -------------------------  Internal Routines  --------------------------- */
    00038
    00039 /* --------------------------  Public Routines  ---------------------------- */
    00040
    00041
    00042 #if !defined( USE_XTRA_MAT3_INLINES )
    00043
    00044 /*
    00045  * This multiplies two matrices, producing a third, which may the same as
    00046  * either of the first two.
    00047  */
    00048
    00049 void
    00050 MAT3mult (double (*result_mat)[4], register double (*mat1)[4], register double (*mat2)[4])
    00051 {
    00052    register int i, j;
    00053    MAT3mat      tmp_mat;
    00054
    00055    for (i = 0; i < 4; i++)
    00056       for (j = 0; j < 4; j++)
    00057          tmp_mat[i][j] = (mat1[i][0] * mat2[0][j] +
    00058                        mat1[i][1] * mat2[1][j] +
    00059                        mat1[i][2] * mat2[2][j] +
    00060                        mat1[i][3] * mat2[3][j]);
    00061    MAT3copy (result_mat, tmp_mat);
    00062 }
    00063 #endif // !defined( USE_XTRA_MAT3_INLINES )
    00064
    00065 /*
    00066  * This returns the transpose of a matrix.  The result matrix may be
    00067  * the same as the one to transpose.
    00068  */
    00069
    00070 void
    00071 MAT3transpose (double (*result_mat)[4], register double (*mat)[4])
    00072 {
    00073    register int i, j;
    00074    MAT3mat      tmp_mat;
    00075
    00076    for (i = 0; i < 4; i++)
    00077       for (j = 0; j < 4; j++)
    00078          tmp_mat[i][j] = mat[j][i];
    00079
    00080    MAT3copy (result_mat, tmp_mat);
    00081 }
    00082
    00083
    00084 /*
    00085  * This prints the given matrix to the given file pointer.
    00086  */
    00087
    00088 void
    00089 MAT3print(double (*mat)[4], FILE *fp)
    00090 {
    00091    MAT3print_formatted(mat, fp, CNULL, CNULL, CNULL, CNULL);
    00092 }
    00093
    00094 /*
    00095  * This prints the given matrix to the given file pointer.
    00096  * use the format string to pass to fprintf.  head and tail
    00097  * are printed at the beginning and end of each line.
    00098  */
    00099
    00100 void
    00101 MAT3print_formatted(double (*mat)[4], FILE *fp, char *title, char *head, char *format, char *tail)
    00102 {
    00103    register int i, j;
    00104
    00105    /* This is to allow this to be called easily from a debugger */
    00106    if (fp == NULL) fp = stderr;
    00107
    00108    if (title  == NULL)  title  = "MAT3 matrix:\n";
    00109    if (head   == NULL)  head   = "  ";
    00110    if (format == NULL)  format = "%#8.4lf  ";
    00111    if (tail   == NULL)  tail   = "\n";
    00112
    00113    (void) fprintf(fp, title);
    00114
    00115    for (i = 0; i < 4; i++) {
    00116       (void) fprintf(fp, head);
    00117       for (j = 0; j < 4; j++) (void) fprintf(fp, format, mat[i][j]);
    00118       (void) fprintf(fp, tail);
    00119    }
    00120 }

@ 1.2 log @Oops, try again. @ text @d129 1 a129 1