Open Broadcaster Software
Free, open source software for live streaming and recording
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
matrix4.h
Go to the documentation of this file.
1 /******************************************************************************
2  Copyright (C) 2013 by Hugh Bailey <obs.jim@gmail.com>
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 ******************************************************************************/
17 
18 #pragma once
19 
20 #include "vec3.h"
21 #include "vec4.h"
22 #include "axisang.h"
23 
24 /* 4x4 Matrix */
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 struct matrix3;
31 
32 struct matrix4 {
33  struct vec4 x, y, z, t;
34 };
35 
36 static inline void matrix4_copy(struct matrix4 *dst, const struct matrix4 *m)
37 {
38  dst->x.m = m->x.m;
39  dst->y.m = m->y.m;
40  dst->z.m = m->z.m;
41  dst->t.m = m->t.m;
42 }
43 
44 static inline void matrix4_identity(struct matrix4 *dst)
45 {
46  vec4_zero(&dst->x);
47  vec4_zero(&dst->y);
48  vec4_zero(&dst->z);
49  vec4_zero(&dst->t);
50  dst->x.x = 1.0f;
51  dst->y.y = 1.0f;
52  dst->z.z = 1.0f;
53  dst->t.w = 1.0f;
54 }
55 
56 EXPORT void matrix4_from_matrix3(struct matrix4 *dst, const struct matrix3 *m);
57 EXPORT void matrix4_from_quat(struct matrix4 *dst, const struct quat *q);
58 EXPORT void matrix4_from_axisang(struct matrix4 *dst,
59  const struct axisang *aa);
60 
61 EXPORT void matrix4_mul(struct matrix4 *dst, const struct matrix4 *m1,
62  const struct matrix4 *m2);
63 
64 EXPORT float matrix4_determinant(const struct matrix4 *m);
65 
66 EXPORT void matrix4_translate3v(struct matrix4 *dst, const struct matrix4 *m,
67  const struct vec3 *v);
68 EXPORT void matrix4_translate4v(struct matrix4 *dst, const struct matrix4 *m,
69  const struct vec4 *v);
70 EXPORT void matrix4_rotate(struct matrix4 *dst, const struct matrix4 *m,
71  const struct quat *q);
72 EXPORT void matrix4_rotate_aa(struct matrix4 *dst, const struct matrix4 *m,
73  const struct axisang *aa);
74 EXPORT void matrix4_scale(struct matrix4 *dst, const struct matrix4 *m,
75  const struct vec3 *v);
76 EXPORT bool matrix4_inv(struct matrix4 *dst, const struct matrix4 *m);
77 EXPORT void matrix4_transpose(struct matrix4 *dst, const struct matrix4 *m);
78 
79 EXPORT void matrix4_translate3v_i(struct matrix4 *dst, const struct vec3 *v,
80  const struct matrix4 *m);
81 EXPORT void matrix4_translate4v_i(struct matrix4 *dst, const struct vec4 *v,
82  const struct matrix4 *m);
83 EXPORT void matrix4_rotate_i(struct matrix4 *dst, const struct quat *q,
84  const struct matrix4 *m);
85 EXPORT void matrix4_rotate_aa_i(struct matrix4 *dst, const struct axisang *aa,
86  const struct matrix4 *m);
87 EXPORT void matrix4_scale_i(struct matrix4 *dst, const struct vec3 *v,
88  const struct matrix4 *m);
89 
90 static inline void matrix4_translate3f(struct matrix4 *dst,
91  const struct matrix4 *m, float x, float y, float z)
92 {
93  struct vec3 v;
94  vec3_set(&v, x, y, z);
95  matrix4_translate3v(dst, m, &v);
96 }
97 
98 static inline void matrix4_rotate_aa4f(struct matrix4 *dst,
99  const struct matrix4 *m, float x, float y, float z, float rot)
100 {
101  struct axisang aa;
102  axisang_set(&aa, x, y, z, rot);
103  matrix4_rotate_aa(dst, m, &aa);
104 }
105 
106 static inline void matrix4_scale3f(struct matrix4 *dst,
107  const struct matrix4 *m, float x, float y, float z)
108 {
109  struct vec3 v;
110  vec3_set(&v, x, y, z);
111  matrix4_scale(dst, m, &v);
112 }
113 
114 #ifdef __cplusplus
115 }
116 #endif
EXPORT void matrix4_from_matrix3(struct matrix4 *dst, const struct matrix3 *m)
struct vec4 x y z t
Definition: matrix4.h:33
EXPORT void matrix4_rotate_aa(struct matrix4 *dst, const struct matrix4 *m, const struct axisang *aa)
Definition: axisang.h:28
EXPORT float matrix4_determinant(const struct matrix4 *m)
EXPORT void matrix4_transpose(struct matrix4 *dst, const struct matrix4 *m)
EXPORT void matrix4_scale(struct matrix4 *dst, const struct matrix4 *m, const struct vec3 *v)
Definition: vec3.h:33
EXPORT void matrix4_mul(struct matrix4 *dst, const struct matrix4 *m1, const struct matrix4 *m2)
EXPORT void matrix4_translate4v_i(struct matrix4 *dst, const struct vec4 *v, const struct matrix4 *m)
EXPORT void matrix4_from_axisang(struct matrix4 *dst, const struct axisang *aa)
float z
Definition: axisang.h:30
Definition: matrix3.h:31
EXPORT void matrix4_translate3v_i(struct matrix4 *dst, const struct vec3 *v, const struct matrix4 *m)
EXPORT void matrix4_translate3v(struct matrix4 *dst, const struct matrix4 *m, const struct vec3 *v)
float z
Definition: vec3.h:36
float y
Definition: axisang.h:30
Definition: vec4.h:30
__m128 m
Definition: vec4.h:36
#define EXPORT
Definition: c99defs.h:49
__m128 m
Definition: vec3.h:39
Definition: matrix4.h:32
Definition: quat.h:41
float w
Definition: vec4.h:33
float x
Definition: vec3.h:36
EXPORT bool matrix4_inv(struct matrix4 *dst, const struct matrix4 *m)
float y
Definition: vec3.h:36
EXPORT void matrix4_translate4v(struct matrix4 *dst, const struct matrix4 *m, const struct vec4 *v)
EXPORT void matrix4_rotate_aa_i(struct matrix4 *dst, const struct axisang *aa, const struct matrix4 *m)
float z
Definition: vec4.h:33
EXPORT void matrix4_rotate(struct matrix4 *dst, const struct matrix4 *m, const struct quat *q)
EXPORT void matrix4_from_quat(struct matrix4 *dst, const struct quat *q)
float x
Definition: vec4.h:33
EXPORT void matrix4_rotate_i(struct matrix4 *dst, const struct quat *q, const struct matrix4 *m)
float y
Definition: vec4.h:33
float x
Definition: axisang.h:30
EXPORT void matrix4_scale_i(struct matrix4 *dst, const struct vec3 *v, const struct matrix4 *m)