]> git.mxchange.org Git - flightgear.git/blob - Math/MAT3mat.c
Eliminated some harmless compiler warnings.
[flightgear.git] / Math / MAT3mat.c
1 /* #include "HEADERS.h" */
2 /* Copyright 1988, Brown Computer Graphics Group.  All Rights Reserved. */
3
4 /* --------------------------------------------------------------------------
5  * This file contains routines that operate solely on matrices.
6  * -------------------------------------------------------------------------*/
7
8 #include <string.h>
9 #include "mat3defs.h"
10
11 /* #include "macros.h" */
12
13 /* --------------------------  Static Routines  ---------------------------- */
14
15 /* -------------------------  Internal Routines  --------------------------- */
16
17 /* --------------------------  Public Routines  ---------------------------- */
18
19
20 /*
21  * Sets a matrix to identity.
22  */
23
24 void
25 MAT3identity (register MAT3mat mat)
26 {
27    register int i;
28
29    bzero (mat, sizeof(MAT3mat));
30    for (i = 0; i < 4; i++)
31       mat[i][i] = 1.0;
32 }
33
34 /*
35  * Sets a matrix to zero.
36  */
37
38 void
39 MAT3zero (MAT3mat mat)
40 {
41    bzero (mat, sizeof(MAT3mat));
42 }
43
44
45 /*
46  * Copies one matrix to another.
47  */
48
49 void
50 MAT3copy(MAT3mat to, MAT3mat from)
51 {
52    bcopy (from, to, sizeof(MAT3mat));
53 }
54
55 /*
56  * This multiplies two matrices, producing a third, which may the same as
57  * either of the first two.
58  */
59
60 void
61 MAT3mult (result_mat, mat1, mat2)
62 MAT3mat result_mat;
63 register MAT3mat mat1, mat2;
64 {
65    register int i, j;
66    MAT3mat      tmp_mat;
67
68    for (i = 0; i < 4; i++)
69       for (j = 0; j < 4; j++)
70          tmp_mat[i][j] = (mat1[i][0] * mat2[0][j] +
71                        mat1[i][1] * mat2[1][j] +
72                        mat1[i][2] * mat2[2][j] +
73                        mat1[i][3] * mat2[3][j]);
74    MAT3copy (result_mat, tmp_mat);
75 }
76
77 /*
78  * This returns the transpose of a matrix.  The result matrix may be
79  * the same as the one to transpose.
80  */
81
82 void
83 MAT3transpose (result_mat, mat)
84 MAT3mat result_mat;
85 register MAT3mat mat;
86 {
87    register int i, j;
88    MAT3mat      tmp_mat;
89
90    for (i = 0; i < 4; i++) 
91       for (j = 0; j < 4; j++) 
92          tmp_mat[i][j] = mat[j][i];
93
94    MAT3copy (result_mat, tmp_mat);
95 }
96
97
98 /*
99  * This prints the given matrix to the given file pointer.
100  */
101
102 void
103 MAT3print(mat, fp)
104 MAT3mat mat;
105 FILE    *fp;
106 {
107    MAT3print_formatted(mat, fp, CNULL, CNULL, CNULL, CNULL);
108 }
109
110 /*
111  * This prints the given matrix to the given file pointer.
112  * use the format string to pass to fprintf.  head and tail
113  * are printed at the beginning and end of each line.
114  */
115
116 void
117 MAT3print_formatted(mat, fp, title, head, format, tail)
118 MAT3mat mat;
119 FILE    *fp;
120 char    *title, *head, *format, *tail;
121 {
122    register int i, j;
123
124    /* This is to allow this to be called easily from a debugger */
125    if (fp == NULL) fp = stderr;
126
127    if (title  == NULL)  title  = "MAT3 matrix:\n";
128    if (head   == NULL)  head   = "  ";
129    if (format == NULL)  format = "%#8.4lf  ";
130    if (tail   == NULL)  tail   = "\n";
131
132    (void) fprintf(fp, title);
133
134    for (i = 0; i < 4; i++) {
135       (void) fprintf(fp, head);
136       for (j = 0; j < 4; j++) (void) fprintf(fp, format, mat[i][j]);
137       (void) fprintf(fp, tail);
138    }
139 }