diff options
author | sanine <sanine.not@pm.me> | 2022-08-23 13:28:01 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2022-08-23 13:28:01 -0500 |
commit | ae4e17fc743ca0344af818ab767db7311ea7829c (patch) | |
tree | 0dfad8ace50a0eaeb43f398a95f36dfd30822502 /src/glm | |
parent | 711f530f7afe3358c674cf418ee067e7a4501699 (diff) |
add basic transforms
Diffstat (limited to 'src/glm')
-rw-r--r-- | src/glm/CMakeLists.txt | 7 | ||||
-rw-r--r-- | src/glm/glm.c | 13 | ||||
-rw-r--r-- | src/glm/glm.h | 10 | ||||
-rw-r--r-- | src/glm/mat4.c | 36 | ||||
-rw-r--r-- | src/glm/transform.c | 31 |
5 files changed, 97 insertions, 0 deletions
diff --git a/src/glm/CMakeLists.txt b/src/glm/CMakeLists.txt new file mode 100644 index 0000000..962dbbd --- /dev/null +++ b/src/glm/CMakeLists.txt @@ -0,0 +1,7 @@ +project(honey_engine) + +target_sources(honey PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/glm.c + ${CMAKE_CURRENT_LIST_DIR}/mat4.c + ${CMAKE_CURRENT_LIST_DIR}/transform.c +) diff --git a/src/glm/glm.c b/src/glm/glm.c new file mode 100644 index 0000000..786fcf0 --- /dev/null +++ b/src/glm/glm.c @@ -0,0 +1,13 @@ +#include <lua.h> +#include <honeysuckle.h> + + +void setup_glm(lua_State *L, int honey_index) +{ + lua_createtable(L, 0, 1); + int glm_index = lua_gettop(L); + + setup_mat4(L, glm_index); + setup_transform(L, glm_index); + lua_setfield(L, honey_index, "glm"); +} diff --git a/src/glm/glm.h b/src/glm/glm.h new file mode 100644 index 0000000..2bf803b --- /dev/null +++ b/src/glm/glm.h @@ -0,0 +1,10 @@ +#ifndef HONEY_GLM_H +#define HONEY_GLM_H + +#include <lua.h> + +void setup_glm(lua_State *L, int honey_index); +void setup_mat4(lua_State *L, int glm_index); +void setup_transform(lua_State *L, int glm_index); + +#endif diff --git a/src/glm/mat4.c b/src/glm/mat4.c new file mode 100644 index 0000000..f98cdfb --- /dev/null +++ b/src/glm/mat4.c @@ -0,0 +1,36 @@ +#include <lua.h> +#include <honeysuckle.h> +#include <cglm/cglm.h> +#include "util/util.h" + +int mat4_create(lua_State *L); +int mat4_identity(lua_State *L); + +void setup_mat4(lua_State *L, int glm_tbl) +{ + int tbl = hs_create_table(L, + hs_str_cfunc("mat4", mat4_create), + hs_str_cfunc("mat4_identity", mat4_identity), + ); + + append_table(L, glm_tbl, tbl); + lua_pop(L, 1); +} + + +int mat4_create(lua_State *L) +{ + lua_newuserdata(L, 16*sizeof(float)); + return 1; +} + + +int mat4_identity(lua_State *L) +{ + void *ptr; + hs_parse_args(L, hs_user(ptr)); + mat4 *m = ptr; + + glm_mat4_identity(*m); + return 0; +} diff --git a/src/glm/transform.c b/src/glm/transform.c new file mode 100644 index 0000000..4dce595 --- /dev/null +++ b/src/glm/transform.c @@ -0,0 +1,31 @@ +#include <lua.h> +#include <honeysuckle.h> +#include <cglm/cglm.h> +#include "util/util.h" + + +int rotate_z(lua_State *L); + + +void setup_transform(lua_State *L, int glm_tbl) +{ + int tbl = hs_create_table(L, + hs_str_cfunc("rotate_z", rotate_z), + ); + + append_table(L, glm_tbl, tbl); + lua_pop(L, 1); +} + + +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; +} |