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() */
15 /* #include "macros.h" */
17 /* -------------------------- Static Routines ---------------------------- */
19 /* ------------------------- Internal Routines --------------------------- */
21 /* -------------------------- Public Routines ---------------------------- */
25 * Sets a matrix to identity.
29 MAT3identity (register MAT3mat mat)
34 memset(mat,0x00, sizeof(MAT3mat));
36 bzero (mat, sizeof(MAT3mat));
39 for (i = 0; i < 4; i++)
44 * Sets a matrix to zero.
48 MAT3zero (MAT3mat mat)
51 memset(mat,0x00, sizeof(MAT3mat));
53 bzero (mat, sizeof(MAT3mat));
59 * Copies one matrix to another.
63 MAT3copy(MAT3mat to, MAT3mat from)
66 memcpy(to, from, sizeof(MAT3mat));
68 bcopy(from, to, sizeof(MAT3mat));
73 * This multiplies two matrices, producing a third, which may the same as
74 * either of the first two.
78 MAT3mult (result_mat, mat1, mat2)
80 register MAT3mat mat1, mat2;
85 for (i = 0; i < 4; i++)
86 for (j = 0; j < 4; j++)
87 tmp_mat[i][j] = (mat1[i][0] * mat2[0][j] +
88 mat1[i][1] * mat2[1][j] +
89 mat1[i][2] * mat2[2][j] +
90 mat1[i][3] * mat2[3][j]);
91 MAT3copy (result_mat, tmp_mat);
95 * This returns the transpose of a matrix. The result matrix may be
96 * the same as the one to transpose.
100 MAT3transpose (result_mat, mat)
102 register MAT3mat mat;
107 for (i = 0; i < 4; i++)
108 for (j = 0; j < 4; j++)
109 tmp_mat[i][j] = mat[j][i];
111 MAT3copy (result_mat, tmp_mat);
116 * This prints the given matrix to the given file pointer.
124 MAT3print_formatted(mat, fp, CNULL, CNULL, CNULL, CNULL);
128 * This prints the given matrix to the given file pointer.
129 * use the format string to pass to fprintf. head and tail
130 * are printed at the beginning and end of each line.
134 MAT3print_formatted(mat, fp, title, head, format, tail)
137 char *title, *head, *format, *tail;
141 /* This is to allow this to be called easily from a debugger */
142 if (fp == NULL) fp = stderr;
144 if (title == NULL) title = "MAT3 matrix:\n";
145 if (head == NULL) head = " ";
146 if (format == NULL) format = "%#8.4lf ";
147 if (tail == NULL) tail = "\n";
149 (void) fprintf(fp, title);
151 for (i = 0; i < 4; i++) {
152 (void) fprintf(fp, head);
153 for (j = 0; j < 4; j++) (void) fprintf(fp, format, mat[i][j]);
154 (void) fprintf(fp, tail);