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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
#include "glm_bindings.h"
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* Mat3 Functions
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
int honey_glm_mat3_copy(lua_State* L)
{
honey_glm_array* self, *dest;
honey_lua_parse_arguments
(L, 1, 2,
HONEY_USERDATA, &self,
HONEY_USERDATA, &dest);
if (dest->type != MAT3)
honey_lua_throw_error
(L, "destination must be MAT3 (%d); got %d instead",
MAT3, dest->type);
glm_mat3_copy(self->data, dest->data);
return 0;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
int honey_glm_mat3_eye(lua_State* L)
{
honey_glm_array* self;
honey_lua_parse_arguments
(L, 1, 1, HONEY_USERDATA, &self);
glm_mat3_identity(self->data);
return 0;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
int honey_glm_mat3_zero(lua_State* L)
{
honey_glm_array* self;
honey_lua_parse_arguments
(L, 1, 1, HONEY_USERDATA, &self);
glm_mat3_zero(self->data);
return 0;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
int honey_glm_mat3_mul(lua_State* L)
{
honey_glm_array* self, *mult, *dest;
int choice = honey_lua_parse_arguments
(L, 2,
2, HONEY_USERDATA, &self, HONEY_USERDATA, &mult,
3, HONEY_USERDATA, &self, HONEY_USERDATA, &mult, HONEY_USERDATA, &dest);
if (mult->type != MAT3)
honey_lua_throw_error
(L, "second matrix must be of type MAT3 (%d); got %d instead",
MAT3, mult->type);
if (choice == 1) {
if (dest->type != MAT3)
honey_lua_throw_error
(L, "destination matrix must be of type MAT3 (%d); got %d instead",
MAT3, dest->type);
}
else {
honey_glm_new_mat3(L);
dest = lua_touserdata(L, -1);
}
glm_mat3_mul(self->data, mult->data, dest->data);
if (choice == 0)
return 1;
return 0;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
int honey_glm_mat3_transpose(lua_State* L)
{
honey_glm_array* self, *dest;
int choice = honey_lua_parse_arguments
(L, 2,
1, HONEY_USERDATA, &self,
2, HONEY_USERDATA, &self, HONEY_USERDATA, &dest);
if (choice == 1) {
if (dest->type != MAT3)
honey_lua_throw_error
(L, "destination matrix must be of type MAT3 (%d); got %d instead",
MAT3, dest->type);
}
if (choice == 0)
glm_mat3_transpose(self->data);
else
glm_mat3_transpose_to(self->data, dest->data);
return 0;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
int honey_glm_mat3_mulv(lua_State* L)
{
honey_glm_array* self, *v, *dest;
int choice = honey_lua_parse_arguments
(L, 2,
2, HONEY_USERDATA, &self, HONEY_USERDATA, &v,
3, HONEY_USERDATA, &self, HONEY_USERDATA, &v, HONEY_USERDATA, &dest);
if (v->type != VEC3)
honey_lua_throw_error
(L, "vector must be of type VEC3 (%d); got %d instead",
VEC3, v->type);
if (choice == 0) {
honey_glm_new_vec3(L);
dest = lua_touserdata(L, -1);
}
else {
if (dest->type == MAT3)
honey_lua_throw_error
(L, "destination matrix must be of type MAT3 (%d); got %d instead",
MAT3, dest->type);
}
glm_mat3_mulv(self->data, v->data, dest->data);
if (choice == 0)
return 1;
return 0;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
int honey_glm_mat3_scale(lua_State* L)
{
honey_glm_array* self;
float s;
int choice = honey_lua_parse_arguments
(L, 1,
2, HONEY_USERDATA, &self, HONEY_NUMBER, &s);
glm_mat3_scale(self->data, s);
return 0;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
int honey_glm_mat3_det(lua_State* L)
{
honey_glm_array* self;
honey_lua_parse_arguments(L, 1, 1, HONEY_USERDATA, &self);
float det = glm_mat3_det(self->data);
lua_pushnumber(L, det);
return 1;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
int honey_glm_mat3_inv(lua_State* L)
{
honey_glm_array* self, *dest;
int choice = honey_lua_parse_arguments
(L, 2,
1, HONEY_USERDATA, &self,
2, HONEY_USERDATA, &self, HONEY_USERDATA, &dest);
if (choice == 0) {
honey_glm_new_mat3(L);
dest = lua_touserdata(L, -1);
}
else {
if (dest->type == MAT3)
honey_lua_throw_error
(L, "destination matrix must be of type MAT3 (%d); got %d instead",
MAT3, dest->type);
}
glm_mat3_inv(self->data, dest->data);
if (choice == 0)
return 1;
return 0;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
|