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 ---------------------------- */
32 * Sets a matrix to identity.
36 MAT3identity (register MAT3mat mat)
40 #ifdef USE_MEM /* WIN32 */
41 memset(mat, 0x00, sizeof(MAT3mat));
43 bzero (mat, sizeof(MAT3mat));
46 for (i = 0; i < 4; i++)
51 * Sets a matrix to zero.
55 MAT3zero (MAT3mat mat)
57 #ifdef USE_MEM /* WIN32 */
58 memset(mat,0x00, sizeof(MAT3mat));
60 bzero (mat, sizeof(MAT3mat));
66 * Copies one matrix to another.
70 MAT3copy(MAT3mat to, MAT3mat from)
72 #ifdef USE_MEM /* WIN32 */
73 memcpy(to, from, sizeof(MAT3mat));
75 bcopy(from, to, sizeof(MAT3mat));
80 * This multiplies two matrices, producing a third, which may the same as
81 * either of the first two.
85 MAT3mult (double (*result_mat)[4], register double (*mat1)[4], register double (*mat2)[4])
90 for (i = 0; i < 4; i++)
91 for (j = 0; j < 4; j++)
92 tmp_mat[i][j] = (mat1[i][0] * mat2[0][j] +
93 mat1[i][1] * mat2[1][j] +
94 mat1[i][2] * mat2[2][j] +
95 mat1[i][3] * mat2[3][j]);
96 MAT3copy (result_mat, tmp_mat);
100 * This returns the transpose of a matrix. The result matrix may be
101 * the same as the one to transpose.
105 MAT3transpose (double (*result_mat)[4], register double (*mat)[4])
110 for (i = 0; i < 4; i++)
111 for (j = 0; j < 4; j++)
112 tmp_mat[i][j] = mat[j][i];
114 MAT3copy (result_mat, tmp_mat);
119 * This prints the given matrix to the given file pointer.
123 MAT3print(double (*mat)[4], FILE *fp)
125 MAT3print_formatted(mat, fp, CNULL, CNULL, CNULL, CNULL);
129 * This prints the given matrix to the given file pointer.
130 * use the format string to pass to fprintf. head and tail
131 * are printed at the beginning and end of each line.
135 MAT3print_formatted(double (*mat)[4], FILE *fp, char *title, char *head, char *format, char *tail)
139 /* This is to allow this to be called easily from a debugger */
140 if (fp == NULL) fp = stderr;
142 if (title == NULL) title = "MAT3 matrix:\n";
143 if (head == NULL) head = " ";
144 if (format == NULL) format = "%#8.4lf ";
145 if (tail == NULL) tail = "\n";
147 (void) fprintf(fp, title);
149 for (i = 0; i < 4; i++) {
150 (void) fprintf(fp, head);
151 for (j = 0; j < 4; j++) (void) fprintf(fp, format, mat[i][j]);
152 (void) fprintf(fp, tail);