summaryrefslogtreecommitdiff
path: root/src/glm/transform.c
blob: daf75a5041d6d4b33cb7cdb64645b6b13cb0ed9d (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
#include <lua.h>
#include <honeysuckle.h>
#include <cglm/cglm.h>
#include "util/util.h"


int translate(lua_State *L);
int rotate(lua_State *L);
int rotate_z(lua_State *L);


void setup_transform(lua_State *L, int glm_tbl)
{
	int tbl = hs_create_table(L,
		hs_str_cfunc("translate", translate),
		hs_str_cfunc("rotate", rotate),
		hs_str_cfunc("rotate_z", rotate_z),
	);

	append_table(L, glm_tbl, tbl);
	lua_pop(L, 1);
}


int translate(lua_State *L)
{
	void *m_ptr, *v_ptr;
	hs_parse_args(L, hs_user(m_ptr), hs_user(v_ptr));
	mat4 *m = m_ptr;
	vec3 *v = v_ptr;

	glm_translate(*m, *v);
	return 0;
}


int rotate(lua_State *L)
{
	void *m_ptr, *axis_ptr;
	lua_Number angle;
	hs_parse_args(L, hs_user(m_ptr), hs_num(angle), hs_user(axis_ptr));
	mat4 *m = m_ptr;
	vec3 *axis = axis_ptr;

	glm_rotate(*m, angle, *axis);
	return 0;
}


int rotate_z(lua_State *L)
{
	void *src_ptr, *dest_ptr;
	lua_Number angle;
	hs_parse_args(L, hs_user(src_ptr), hs_num(angle), hs_user(dest_ptr));
	mat4 *source = src_ptr;
	mat4 *dest = dest_ptr;

	glm_rotate_z(*source, angle, *dest);
	return 0;
}