1 /* #include "HEADERS.h" */
2 /* Copyright 1988, Brown Computer Graphics Group. All Rights Reserved. */
4 /* --------------------------------------------------------------------------
5 * This file contains routines that operate solely on matrices.
6 * -------------------------------------------------------------------------*/
14 # ifndef HAVE_STL_SGI_PORT
15 # include <memory.h> /* required for memset() and memcpy() */
20 #include <Math/mat3defs.h>
22 MAT3mat identityMatrix = {
23 { 1.0, 0.0, 0.0, 0.0 },
24 { 0.0, 1.0, 0.0, 0.0 },
25 { 0.0, 0.0, 1.0, 0.0 },
26 { 0.0, 0.0, 0.0, 1.0 }
29 /* #include "macros.h" */
31 /* -------------------------- Static Routines ---------------------------- */
33 /* ------------------------- Internal Routines --------------------------- */
35 /* -------------------------- Public Routines ---------------------------- */
38 #if !defined( USE_XTRA_MAT3_INLINES )
41 * This multiplies two matrices, producing a third, which may the same as
42 * either of the first two.
46 MAT3mult (double (*result_mat)[4], register double (*mat1)[4], register double (*mat2)[4])
51 for (i = 0; i < 4; i++)
52 for (j = 0; j < 4; j++)
53 tmp_mat[i][j] = (mat1[i][0] * mat2[0][j] +
54 mat1[i][1] * mat2[1][j] +
55 mat1[i][2] * mat2[2][j] +
56 mat1[i][3] * mat2[3][j]);
57 MAT3copy (result_mat, tmp_mat);
59 #endif // !defined( USE_XTRA_MAT3_INLINES )
62 * This returns the transpose of a matrix. The result matrix may be
63 * the same as the one to transpose.
67 MAT3transpose (double (*result_mat)[4], register double (*mat)[4])
72 for (i = 0; i < 4; i++)
73 for (j = 0; j < 4; j++)
74 tmp_mat[i][j] = mat[j][i];
76 MAT3copy (result_mat, tmp_mat);
81 * This prints the given matrix to the given file pointer.
85 MAT3print(double (*mat)[4], FILE *fp)
87 MAT3print_formatted(mat, fp, CNULL, CNULL, CNULL, CNULL);
91 * This prints the given matrix to the given file pointer.
92 * use the format string to pass to fprintf. head and tail
93 * are printed at the beginning and end of each line.
97 MAT3print_formatted(double (*mat)[4], FILE *fp, char *title, char *head, char *format, char *tail)
101 /* This is to allow this to be called easily from a debugger */
102 if (fp == NULL) fp = stderr;
104 if (title == NULL) title = "MAT3 matrix:\n";
105 if (head == NULL) head = " ";
106 if (format == NULL) format = "%#8.4lf ";
107 if (tail == NULL) tail = "\n";
109 (void) fprintf(fp, title);
111 for (i = 0; i < 4; i++) {
112 (void) fprintf(fp, head);
113 for (j = 0; j < 4; j++) (void) fprintf(fp, format, mat[i][j]);
114 (void) fprintf(fp, tail);