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 * -------------------------------------------------------------------------*/
12 # include <memory.h> /* required for memset() and memcpy() */
16 #include <Math/mat3defs.h>
20 /* #include "macros.h" */
22 /* -------------------------- Static Routines ---------------------------- */
24 /* ------------------------- Internal Routines --------------------------- */
26 /* -------------------------- Public Routines ---------------------------- */
30 * Sets a matrix to identity.
34 MAT3identity (register MAT3mat mat)
38 #ifdef USE_MEM /* WIN32 */
39 memset(mat, 0x00, sizeof(MAT3mat));
41 bzero (mat, sizeof(MAT3mat));
44 for (i = 0; i < 4; i++)
49 * Sets a matrix to zero.
53 MAT3zero (MAT3mat mat)
55 #ifdef USE_MEM /* WIN32 */
56 memset(mat,0x00, sizeof(MAT3mat));
58 bzero (mat, sizeof(MAT3mat));
64 * Copies one matrix to another.
68 MAT3copy(MAT3mat to, MAT3mat from)
70 #ifdef USE_MEM /* WIN32 */
71 memcpy(to, from, sizeof(MAT3mat));
73 bcopy(from, to, sizeof(MAT3mat));
78 * This multiplies two matrices, producing a third, which may the same as
79 * either of the first two.
83 MAT3mult (double (*result_mat)[4], register double (*mat1)[4], register double (*mat2)[4])
88 for (i = 0; i < 4; i++)
89 for (j = 0; j < 4; j++)
90 tmp_mat[i][j] = (mat1[i][0] * mat2[0][j] +
91 mat1[i][1] * mat2[1][j] +
92 mat1[i][2] * mat2[2][j] +
93 mat1[i][3] * mat2[3][j]);
94 MAT3copy (result_mat, tmp_mat);
98 * This returns the transpose of a matrix. The result matrix may be
99 * the same as the one to transpose.
103 MAT3transpose (double (*result_mat)[4], register double (*mat)[4])
108 for (i = 0; i < 4; i++)
109 for (j = 0; j < 4; j++)
110 tmp_mat[i][j] = mat[j][i];
112 MAT3copy (result_mat, tmp_mat);
117 * This prints the given matrix to the given file pointer.
121 MAT3print(double (*mat)[4], FILE *fp)
123 MAT3print_formatted(mat, fp, CNULL, CNULL, CNULL, CNULL);
127 * This prints the given matrix to the given file pointer.
128 * use the format string to pass to fprintf. head and tail
129 * are printed at the beginning and end of each line.
133 MAT3print_formatted(double (*mat)[4], FILE *fp, char *title, char *head, char *format, char *tail)
137 /* This is to allow this to be called easily from a debugger */
138 if (fp == NULL) fp = stderr;
140 if (title == NULL) title = "MAT3 matrix:\n";
141 if (head == NULL) head = " ";
142 if (format == NULL) format = "%#8.4lf ";
143 if (tail == NULL) tail = "\n";
145 (void) fprintf(fp, title);
147 for (i = 0; i < 4; i++) {
148 (void) fprintf(fp, head);
149 for (j = 0; j < 4; j++) (void) fprintf(fp, format, mat[i][j]);
150 (void) fprintf(fp, tail);