Open Broadcaster Software
Free, open source software for live streaming and recording
matrix3.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 "axisang.h"
22 
23 /* 3x4 Matrix */
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 struct matrix4;
30 
31 struct matrix3 {
32  struct vec3 x;
33  struct vec3 y;
34  struct vec3 z;
35  struct vec3 t;
36 };
37 
38 static inline void matrix3_copy(struct matrix3 *dst, const struct matrix3 *m)
39 {
40  vec3_copy(&dst->x, &m->x);
41  vec3_copy(&dst->y, &m->y);
42  vec3_copy(&dst->z, &m->z);
43  vec3_copy(&dst->t, &m->t);
44 }
45 
46 static inline void matrix3_identity(struct matrix3 *dst)
47 {
48  vec3_zero(&dst->x);
49  vec3_zero(&dst->y);
50  vec3_zero(&dst->z);
51  vec3_zero(&dst->t);
52  dst->x.x = dst->y.y = dst->z.z = 1.0f;
53 }
54 
55 EXPORT void matrix3_from_quat(struct matrix3 *dst, const struct quat *q);
56 EXPORT void matrix3_from_axisang(struct matrix3 *dst,
57  const struct axisang *aa);
58 EXPORT void matrix3_from_matrix4(struct matrix3 *dst, const struct matrix4 *m);
59 
60 EXPORT void matrix3_mul(struct matrix3 *dst, const struct matrix3 *m1,
61  const struct matrix3 *m2);
62 static inline void matrix3_translate(struct matrix3 *dst,
63  const struct matrix3 *m, const struct vec3 *v)
64 {
65  vec3_sub(&dst->t, &m->t, v);
66 }
67 
68 EXPORT void matrix3_rotate(struct matrix3 *dst, const struct matrix3 *m,
69  const struct quat *q);
70 EXPORT void matrix3_rotate_aa(struct matrix3 *dst, const struct matrix3 *m,
71  const struct axisang *aa);
72 EXPORT void matrix3_scale(struct matrix3 *dst, const struct matrix3 *m,
73  const struct vec3 *v);
74 EXPORT void matrix3_transpose(struct matrix3 *dst, const struct matrix3 *m);
75 EXPORT void matrix3_inv(struct matrix3 *dst, const struct matrix3 *m);
76 
77 EXPORT void matrix3_mirror(struct matrix3 *dst, const struct matrix3 *m,
78  const struct plane *p);
79 EXPORT void matrix3_mirrorv(struct matrix3 *dst, const struct matrix3 *m,
80  const struct vec3 *v);
81 
82 static inline void matrix3_translate3f(struct matrix3 *dst,
83  const struct matrix3 *m, float x, float y, float z)
84 {
85  struct vec3 v;
86  vec3_set(&v, x, y, z);
87  matrix3_translate(dst, m, &v);
88 }
89 
90 static inline void matrix3_rotate_aa4f(struct matrix3 *dst,
91  const struct matrix3 *m, float x, float y, float z, float rot)
92 {
93  struct axisang aa;
94  axisang_set(&aa, x, y, z, rot);
95  matrix3_rotate_aa(dst, m, &aa);
96 }
97 
98 static inline void matrix3_scale3f(struct matrix3 *dst,
99  const struct matrix3 *m, float x, float y, float z)
100 {
101  struct vec3 v;
102  vec3_set(&v, x, y, z);
103  matrix3_scale(dst, m, &v);
104 }
105 
106 #ifdef __cplusplus
107 }
108 #endif
Definition: axisang.h:28
struct vec3 z
Definition: matrix3.h:34
EXPORT void matrix3_mirrorv(struct matrix3 *dst, const struct matrix3 *m, const struct vec3 *v)
struct vec3 t
Definition: matrix3.h:35
Definition: vec3.h:33
struct vec3 y
Definition: matrix3.h:33
EXPORT void matrix3_from_axisang(struct matrix3 *dst, const struct axisang *aa)
Definition: matrix3.h:31
float z
Definition: vec3.h:36
struct vec3 x
Definition: matrix3.h:32
#define EXPORT
Definition: c99defs.h:49
EXPORT void matrix3_transpose(struct matrix3 *dst, const struct matrix3 *m)
__m128 m
Definition: vec3.h:39
Definition: matrix4.h:32
EXPORT void matrix3_scale(struct matrix3 *dst, const struct matrix3 *m, const struct vec3 *v)
EXPORT void matrix3_mirror(struct matrix3 *dst, const struct matrix3 *m, const struct plane *p)
Definition: quat.h:41
float x
Definition: vec3.h:36
EXPORT void matrix3_from_quat(struct matrix3 *dst, const struct quat *q)
float y
Definition: vec3.h:36
EXPORT void matrix3_rotate(struct matrix3 *dst, const struct matrix3 *m, const struct quat *q)
EXPORT void matrix3_rotate_aa(struct matrix3 *dst, const struct matrix3 *m, const struct axisang *aa)
EXPORT void matrix3_mul(struct matrix3 *dst, const struct matrix3 *m1, const struct matrix3 *m2)
EXPORT void matrix3_inv(struct matrix3 *dst, const struct matrix3 *m)
Definition: plane.h:30
EXPORT void matrix3_from_matrix4(struct matrix3 *dst, const struct matrix4 *m)