forked from smcameron/space-nerds-in-space
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrix.h
76 lines (60 loc) · 2.88 KB
/
matrix.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef MATRIX_H__
#define MATRIX_H__
/*
Copyright (C) 2010 Stephen M. Cameron
Author: Stephen M. Cameron
This file is part of Spacenerds In Space.
Spacenerds in Space is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Spacenerds in Space is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Spacenerds in Space; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* Matrices need to use row-major memory layout with pre-multiplication OR
* column-major memory layout with post-multiplication.
*/
#ifdef DEFINE_MATRIX_GLOBALS
#define GLOBAL
#else
#define GLOBAL extern
#endif
struct mat44 {
float m[4][4];
};
struct mat41 {
float m[4];
};
GLOBAL void mat44_product(const struct mat44 *lhs, const struct mat44 *rhs,
struct mat44 *output);
GLOBAL void mat44_x_mat41(const struct mat44 *lhs, const struct mat41 *rhs,
struct mat41 *output);
GLOBAL void mat41_x_mat44(const struct mat41 *lhs, const struct mat44 *rhs,
struct mat41 *output);
GLOBAL void mat41_translate(struct mat41 *rhs, float tx, float ty, float tz,
struct mat41 *output);
GLOBAL void mat41_rotate_x(struct mat41 *rhs, float angle, struct mat41 *output);
GLOBAL void mat41_rotate_y(struct mat41 *rhs, float angle, struct mat41 *output);
GLOBAL void mat41_rotate_z(struct mat41 *rhs, float angle, struct mat41 *output);
GLOBAL void mat41_scale(struct mat41 *rhs, float scale, struct mat41 *output);
GLOBAL void mat44_translate(struct mat44 *rhs, float tx, float ty, float tz,
struct mat44 *output);
GLOBAL void mat44_rotate_x(struct mat44 *rhs, float angle, struct mat44 *output);
GLOBAL void mat44_rotate_y(struct mat44 *rhs, float angle, struct mat44 *output);
GLOBAL void mat44_rotate_z(struct mat44 *rhs, float angle, struct mat44 *output);
GLOBAL void mat44_scale(struct mat44 *rhs, float scale, struct mat44 *output);
GLOBAL void normalize_vector(struct mat41 *v, struct mat41 *output);
GLOBAL void mat41_cross_mat41(struct mat41 *v1, struct mat41 *v2, struct mat41 *output);
GLOBAL void print44(struct mat44 *m);
GLOBAL void print41(struct mat41 *m);
GLOBAL float mat41_dot_mat41(struct mat41 *m1, struct mat41 *m2);
GLOBAL float dist3d(float dx, float dy, float dz);
GLOBAL float dist3dsqrd(float dx, float dy, float dz);
GLOBAL void mat41_rotate_mat41(struct mat41 *rhs, struct mat41 *v, struct mat41 *axis, float angle);
#undef GLOBAL
#endif