summaryrefslogtreecommitdiffhomepage
path: root/src/math/rodeo_mat4.c
blob: 958e12373dc2fada4f919232f1960d8ac65565b7 (plain)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132

// -- internal --
// public
#include "rodeo/math.h"
// private
#include "math/irodeo_math.h"

static inline
rodeo_math_mat4_t
irodeo_math_cglmMat4_to_rodeoMat4(mat4s in)
{
	return (rodeo_math_mat4_t){
		.val = {
			.m00 = in.raw[0][0], .m01 = in.raw[0][1], .m02 = in.raw[0][2], .m03 = in.raw[0][3],
			.m10 = in.raw[1][0], .m11 = in.raw[1][1], .m12 = in.raw[1][2], .m13 = in.raw[1][3],
			.m20 = in.raw[2][0], .m21 = in.raw[2][1], .m22 = in.raw[2][2], .m23 = in.raw[2][3],
			.m30 = in.raw[3][0], .m31 = in.raw[3][1], .m32 = in.raw[3][2], .m33 = in.raw[3][3]
		}
	};
}

static inline
mat4s
irodeo_math_rodeoMat4_to_cglmMat4(rodeo_math_mat4_t in)
{
	return (mat4s){
		.raw = {
			{
			in.val.m00, in.val.m01, in.val.m02, in.val.m03
			},
			{
			in.val.m10, in.val.m11, in.val.m12, in.val.m13
			},
			{
			in.val.m20, in.val.m21, in.val.m22, in.val.m23
			},
			{
			in.val.m20, in.val.m21, in.val.m22, in.val.m23
			},
		}
	};
}

rodeo_math_mat4_t
rodeo_math_mat4_identity(void)
{
	return irodeo_math_cglmMat4_to_rodeoMat4(glms_mat4_identity());
}

rodeo_math_mat4_t
rodeo_math_mat4_zero(void)
{
	return irodeo_math_cglmMat4_to_rodeoMat4(glms_mat4_zero());
}

rodeo_math_mat4_t
rodeo_math_mat4_transpose(rodeo_math_mat4_t m)
{
	return irodeo_math_cglmMat4_to_rodeoMat4(
		glms_mat4_transpose(
			irodeo_math_rodeoMat4_to_cglmMat4(m)
		)
	);
}

rodeo_math_mat4_t
rodeo_math_mat4_translate(rodeo_math_mat4_t m, rodeo_math_vec3_t v)
{
	return irodeo_math_cglmMat4_to_rodeoMat4(
			glms_translate(
				irodeo_math_rodeoMat4_to_cglmMat4(m),
				irodeo_math_rodeoVec3_to_cglmVec3(v)
			)
	);
}

rodeo_math_mat4_t
rodeo_math_mat4_scale(rodeo_math_mat4_t m, rodeo_math_vec3_t v)
{
	return irodeo_math_cglmMat4_to_rodeoMat4(
			glms_scale(
				irodeo_math_rodeoMat4_to_cglmMat4(m),
				irodeo_math_rodeoVec3_to_cglmVec3(v)
			)
	);
}

rodeo_math_mat4_t
rodeo_math_mat4_rotate(rodeo_math_mat4_t m, float turns, rodeo_math_vec3_t v)
{
	return irodeo_math_cglmMat4_to_rodeoMat4(
			glms_rotate(
				irodeo_math_rodeoMat4_to_cglmMat4(m),
				turns,
				irodeo_math_rodeoVec3_to_cglmVec3(v)
			)
	);
}

rodeo_math_mat4_t
rodeo_math_mat4_multiply(rodeo_math_mat4_t a, rodeo_math_mat4_t b)
{
	return irodeo_math_cglmMat4_to_rodeoMat4(
			glms_mat4_mul(
				irodeo_math_rodeoMat4_to_cglmMat4(a),
				irodeo_math_rodeoMat4_to_cglmMat4(b)
			)
	);
}

rodeo_math_mat4_t
rodeo_math_mat4_orthographic(
	float left,
	float right,
	float bottom,
	float top,
	float near,
	float far
)
{
	return irodeo_math_cglmMat4_to_rodeoMat4(
			glms_ortho_rh_zo(
				left,
				right,
				bottom,
				top,
				near,
				far
			)
	);
}