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 # include <memory.h> /* required for memset() and memcpy() */
18 #include <Math/mat3defs.h>
22 /* #include "macros.h" */
24 /* -------------------------- Static Routines ---------------------------- */
26 /* ------------------------- Internal Routines --------------------------- */
28 /* -------------------------- Public Routines ---------------------------- */
31 #if !defined( USE_XTRA_MAT3_INLINES )
34 * Sets a matrix to identity.
38 MAT3identity (register MAT3mat mat)
42 #ifdef USE_MEM /* WIN32 */
43 memset(mat, 0x00, sizeof(MAT3mat));
45 bzero (mat, sizeof(MAT3mat));
48 for (i = 0; i < 4; i++)
53 * Sets a matrix to zero.
57 MAT3zero (MAT3mat mat)
59 #ifdef USE_MEM /* WIN32 */
60 memset(mat,0x00, sizeof(MAT3mat));
62 bzero (mat, sizeof(MAT3mat));
68 * Copies one matrix to another.
72 MAT3copy(MAT3mat to, MAT3mat from)
74 #ifdef USE_MEM /* WIN32 */
75 memcpy(to, from, sizeof(MAT3mat));
77 bcopy(from, to, sizeof(MAT3mat));
82 * This multiplies two matrices, producing a third, which may the same as
83 * either of the first two.
87 MAT3mult (double (*result_mat)[4], register double (*mat1)[4], register double (*mat2)[4])
92 for (i = 0; i < 4; i++)
93 for (j = 0; j < 4; j++)
94 tmp_mat[i][j] = (mat1[i][0] * mat2[0][j] +
95 mat1[i][1] * mat2[1][j] +
96 mat1[i][2] * mat2[2][j] +
97 mat1[i][3] * mat2[3][j]);
98 MAT3copy (result_mat, tmp_mat);
100 #endif // !defined( USE_XTRA_MAT3_INLINES )
103 * This returns the transpose of a matrix. The result matrix may be
104 * the same as the one to transpose.
108 MAT3transpose (double (*result_mat)[4], register double (*mat)[4])
113 for (i = 0; i < 4; i++)
114 for (j = 0; j < 4; j++)
115 tmp_mat[i][j] = mat[j][i];
117 MAT3copy (result_mat, tmp_mat);
122 * This prints the given matrix to the given file pointer.
126 MAT3print(double (*mat)[4], FILE *fp)
128 MAT3print_formatted(mat, fp, CNULL, CNULL, CNULL, CNULL);
132 * This prints the given matrix to the given file pointer.
133 * use the format string to pass to fprintf. head and tail
134 * are printed at the beginning and end of each line.
138 MAT3print_formatted(double (*mat)[4], FILE *fp, char *title, char *head, char *format, char *tail)
142 /* This is to allow this to be called easily from a debugger */
143 if (fp == NULL) fp = stderr;
145 if (title == NULL) title = "MAT3 matrix:\n";
146 if (head == NULL) head = " ";
147 if (format == NULL) format = "%#8.4lf ";
148 if (tail == NULL) tail = "\n";
150 (void) fprintf(fp, title);
152 for (i = 0; i < 4; i++) {
153 (void) fprintf(fp, head);
154 for (j = 0; j < 4; j++) (void) fprintf(fp, format, mat[i][j]);
155 (void) fprintf(fp, tail);