1
#ifndef MATRIX_H
2
#define MATRIX_H
3
4
#include <math.h>
5
#include <stdio.h>
6
7
typedef struct Matrix4Struct {
8
	double element[4][4];
9
} Matrix4;
10
11
typedef struct Matrix3Struct {
12
	double element[3][3];
13
} Matrix3;
14
15
typedef struct Vector4Struct {
16
	double element[4];
17
} Vector4;
18
19
typedef struct Vector3Struct {
20
	double element[3];
21
} Vector3;
22
23
24
/* initialize a translation matrix */
25
void matrix4_translate(Matrix4* matrix, double dx, double dy, double dz);
26
27
/* initialize a rotation matrix */
28
void matrix4_rotateXYZ(Matrix4* matrix, double rx, double ry, double rz);
29
void matrix4_rotateX(Matrix4* matrix, double ry);
30
void matrix4_rotateY(Matrix4* matrix, double rx);
31
void matrix4_rotateZ(Matrix4* matrix, double rz);
32
33
/* initialize an identity matrix */
34
void matrix4_identity(Matrix4* matrix);
35
36
/* initialize an identity matrix */
37
void matrix4_identity(Matrix4* matrix);
38
39
/* multiply matrix a by matrix b, result in matrix result */
40
void matrix4_multiply(Matrix4 *a, Matrix4 *b, Matrix4 *result);
41
42
void vector_multiply(Matrix4 *a, Vector4 *b, Vector4 *result);
43
44
/* add matrix b to matrix a, result in matrix result */
45
void matrix4_add(Matrix4 *a, Matrix4 *b, Matrix4 *result);
46
47
void vector3_subtract(Vector3 *A, Vector3 *B, Vector3 *result);
48
void vector4_subtract(Vector4 *A, Vector4 *B, Vector4 *result);
49
50
void vector3_cross(Vector3 *A, Vector3 *B, Vector3 *result);
51
52
double vector3_magnitude(Vector3 *A);
53
double vector4_magnitude(Vector4 *A);
54
55
/* print */
56
void matrix4_print(Matrix4 *matrix);
57
void matrix4_fprint(FILE* fp, Matrix4 *matrix);
58
59
void matrix3_print(Matrix3 *matrix);
60
void matrix3_fprint(FILE* fp, Matrix3 *matrix);
61
62
void vector3_print(Vector3 *vector);
63
void vector3_fprint(FILE *fp, Vector3 *vector);
64
65
void vector4_print(Vector4 *vector);
66
void vector4_fprint(FILE *fp, Vector4 *vector);
67
68
69
70
#endif /*defined MATRIX_H */