summaryrefslogtreecommitdiff
path: root/src/glm/mat3.c
blob: be5abdd1deeefa5cfd17aceb33a39183b20f2ee2 (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
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
#include <lua.h>
#include <lauxlib.h>
#include <cglm/cglm.h>
#include "glm.h"


int glm_mat3_create(lua_State *L)
{
	lua_newuserdata(L, sizeof(mat3));
	luaL_getmetatable(L, glm_mat3_tname);
	lua_setmetatable(L, -2);
	return 1;
}


int glm_mat3_set(lua_State *L)
{
	mat3 *m = luaL_checkudata(L, 1, glm_mat3_tname);
	int col = luaL_checkinteger(L, 2);
	int row = luaL_checkinteger(L, 3);
	float value = luaL_checknumber(L, 4);
	(*m)[col][row] = value;
	return 0;
}


int glm_mat3_get(lua_State *L)
{
	mat3 *m = luaL_checkudata(L, 1, glm_mat3_tname);
	int col = luaL_checkinteger(L, 2);
	int row = luaL_checkinteger(L, 3);
	lua_pushnumber(L, (*m)[col][row]);
	return 1;
}


int glm_mat3_copy_bind(lua_State *L)
{
	mat3 *mat = luaL_checkudata(L, 1, glm_mat3_tname);
	mat3 *dest = luaL_checkudata(L, 2, glm_mat3_tname);
	glm_mat3_copy(*mat, *dest);
	return 0;
}


int glm_mat3_identity_bind(lua_State *L)
{
	mat3 *mat = luaL_checkudata(L, 1, glm_mat3_tname);
	glm_mat3_identity(*mat);
	return 0;
}


int glm_mat3_zero_bind(lua_State *L)
{
	mat3 *mat = luaL_checkudata(L, 1, glm_mat3_tname);
	glm_mat3_zero(*mat);
	return 0;
}


int glm_mat3_mul_bind(lua_State *L)
{
	mat3 *m1 = luaL_checkudata(L, 1, glm_mat3_tname);
	mat3 *m2 = luaL_checkudata(L, 2, glm_mat3_tname);
	mat3 *dest = luaL_checkudata(L, 3, glm_mat3_tname);
	glm_mat3_mul(*m1, *m2, *dest);
	return 0;
}


int glm_mat3_transpose_to_bind(lua_State *L)
{
	mat3 *m = luaL_checkudata(L, 1, glm_mat3_tname);
	mat3 *dest = luaL_checkudata(L, 2, glm_mat3_tname);
	glm_mat3_transpose_to(*m, *dest);
	return 0;
}


int glm_mat3_transpose_bind(lua_State *L)
{
	mat3 *m = luaL_checkudata(L, 1, glm_mat3_tname);
	glm_mat3_transpose(*m);
	return 0;
}


int glm_mat3_mulv_bind(lua_State *L)
{
	mat3 *m = luaL_checkudata(L, 1, glm_mat3_tname);
	vec3 *v = luaL_checkudata(L, 2, glm_vec3_tname);
	vec3 *dest = luaL_checkudata(L, 3, glm_vec3_tname);
	glm_mat3_mulv(*m, *v, *dest);
	return 0;
}


int glm_mat3_quat_bind(lua_State *L)
{
	mat3 *m = luaL_checkudata(L, 1, glm_mat3_tname);
	versor *dest = luaL_checkudata(L, 2, glm_versor_tname);
	glm_mat3_quat(*m, *dest);
	return 0;
}


int glm_mat3_scale_bind(lua_State *L)
{
	mat3 *m = luaL_checkudata(L, 1, glm_mat3_tname);
	float s = luaL_checknumber(L, 2);
	glm_mat3_scale(*m, s);
	return 0;
}


int glm_mat3_det_bind(lua_State *L)
{
	mat3 *mat = luaL_checkudata(L, 1, glm_mat3_tname);
	float bind_result = glm_mat3_det(*mat);
	lua_pushnumber(L, bind_result);
	return 1;
}


int glm_mat3_inv_bind(lua_State *L)
{
	mat3 *mat = luaL_checkudata(L, 1, glm_mat3_tname);
	mat3 *dest = luaL_checkudata(L, 2, glm_mat3_tname);
	glm_mat3_inv(*mat, *dest);
	return 0;
}


int glm_mat3_trace_bind(lua_State *L)
{
	mat3 *m = luaL_checkudata(L, 1, glm_mat3_tname);
	glm_mat3_trace(*m);
	return 0;
}


int glm_mat3_swap_col_bind(lua_State *L)
{
	mat3 *mat = luaL_checkudata(L, 1, glm_mat3_tname);
	int col1 = luaL_checkinteger(L, 2);
	int col2 = luaL_checkinteger(L, 3);
	glm_mat3_swap_col(*mat, col1, col2);
	return 0;
}


int glm_mat3_swap_row_bind(lua_State *L)
{
	mat3 *mat = luaL_checkudata(L, 1, glm_mat3_tname);
	int row1 = luaL_checkinteger(L, 2);
	int row2 = luaL_checkinteger(L, 3);
	glm_mat3_swap_row(*mat, row1, row2);
	return 0;
}


int glm_mat3_rmc_bind(lua_State *L)
{
	vec3 *r = luaL_checkudata(L, 1, glm_vec3_tname);
	mat3 *m = luaL_checkudata(L, 2, glm_mat3_tname);
	vec3 *c = luaL_checkudata(L, 3, glm_vec3_tname);
	float bind_result = glm_mat3_rmc(*r, *m, *c);
	lua_pushnumber(L, bind_result);
	return 1;
}