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, const struct axisang *aa);
57 EXPORT void matrix3_from_matrix4(struct matrix3 *dst, const struct matrix4 *m);
58 
59 EXPORT void matrix3_mul(struct matrix3 *dst, const struct matrix3 *m1,
60  const struct matrix3 *m2);
61 static inline void matrix3_translate(struct matrix3 *dst,
62  const struct matrix3 *m,
63  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,
84  float y, float z)
85 {
86  struct vec3 v;
87  vec3_set(&v, x, y, z);
88  matrix3_translate(dst, m, &v);
89 }
90 
91 static inline void matrix3_rotate_aa4f(struct matrix3 *dst,
92  const struct matrix3 *m, float x,
93  float y, float z, float rot)
94 {
95  struct axisang aa;
96  axisang_set(&aa, x, y, z, rot);
97  matrix3_rotate_aa(dst, m, &aa);
98 }
99 
100 static inline void matrix3_scale3f(struct matrix3 *dst, const struct matrix3 *m,
101  float x, float y, float z)
102 {
103  struct vec3 v;
104  vec3_set(&v, x, y, z);
105  matrix3_scale(dst, m, &v);
106 }
107 
108 #ifdef __cplusplus
109 }
110 #endif
matrix3_from_matrix4
EXPORT void matrix3_from_matrix4(struct matrix3 *dst, const struct matrix4 *m)
matrix3_from_axisang
EXPORT void matrix3_from_axisang(struct matrix3 *dst, const struct axisang *aa)
matrix4
Definition: matrix4.h:32
matrix3_mirrorv
EXPORT void matrix3_mirrorv(struct matrix3 *dst, const struct matrix3 *m, const struct vec3 *v)
EXPORT
#define EXPORT
Definition: c99defs.h:37
vec3.h
axisang::x
float x
Definition: axisang.h:31
matrix3_transpose
EXPORT void matrix3_transpose(struct matrix3 *dst, const struct matrix3 *m)
vec3::z
float z
Definition: vec3.h:37
axisang::z
float z
Definition: axisang.h:31
axisang
Definition: axisang.h:28
matrix3::y
struct vec3 y
Definition: matrix3.h:33
matrix3::x
struct vec3 x
Definition: matrix3.h:32
matrix3::z
struct vec3 z
Definition: matrix3.h:34
vec3::y
float y
Definition: vec3.h:37
matrix3::t
struct vec3 t
Definition: matrix3.h:35
matrix3_mirror
EXPORT void matrix3_mirror(struct matrix3 *dst, const struct matrix3 *m, const struct plane *p)
vec3
Definition: vec3.h:34
matrix3_from_quat
EXPORT void matrix3_from_quat(struct matrix3 *dst, const struct quat *q)
vec3::m
__m128 m
Definition: vec3.h:40
matrix3_scale
EXPORT void matrix3_scale(struct matrix3 *dst, const struct matrix3 *m, const struct vec3 *v)
vec3::x
float x
Definition: vec3.h:37
axisang.h
axisang::y
float y
Definition: axisang.h:31
matrix3_rotate
EXPORT void matrix3_rotate(struct matrix3 *dst, const struct matrix3 *m, const struct quat *q)
matrix3_inv
EXPORT void matrix3_inv(struct matrix3 *dst, const struct matrix3 *m)
plane
Definition: plane.h:30
matrix3_rotate_aa
EXPORT void matrix3_rotate_aa(struct matrix3 *dst, const struct matrix3 *m, const struct axisang *aa)
matrix3
Definition: matrix3.h:31
matrix3_mul
EXPORT void matrix3_mul(struct matrix3 *dst, const struct matrix3 *m1, const struct matrix3 *m2)
quat
Definition: quat.h:42