From b5f0a45d9b10ebab8610ba235bc46f69fd58e2a2 Mon Sep 17 00:00:00 2001 From: sanine Date: Wed, 22 Feb 2023 17:35:17 -0600 Subject: begin cglm bind refactor --- src/glm/CMakeLists.txt | 6 +- src/glm/affine3d.c | 207 ++++++++++++++++++++++ src/glm/camera.c | 45 ----- src/glm/glm.c | 34 ---- src/glm/glm.h | 92 +++++++++- src/glm/mat4.c | 64 ------- src/glm/setup.c | 41 +++++ src/glm/transform.c | 60 ------- src/glm/vec3.c | 464 ++++++++++++++++++++++++++++++++++++++++++------- src/import/notes.md | 14 ++ 10 files changed, 744 insertions(+), 283 deletions(-) create mode 100644 src/glm/affine3d.c delete mode 100644 src/glm/camera.c delete mode 100644 src/glm/glm.c delete mode 100644 src/glm/mat4.c create mode 100644 src/glm/setup.c delete mode 100644 src/glm/transform.c create mode 100644 src/import/notes.md (limited to 'src') diff --git a/src/glm/CMakeLists.txt b/src/glm/CMakeLists.txt index 3f0dada..3c5fb32 100644 --- a/src/glm/CMakeLists.txt +++ b/src/glm/CMakeLists.txt @@ -1,9 +1,7 @@ project(honey_engine) target_sources(honey PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/glm.c + ${CMAKE_CURRENT_LIST_DIR}/setup.c ${CMAKE_CURRENT_LIST_DIR}/vec3.c - ${CMAKE_CURRENT_LIST_DIR}/mat4.c - ${CMAKE_CURRENT_LIST_DIR}/transform.c - ${CMAKE_CURRENT_LIST_DIR}/camera.c + ${CMAKE_CURRENT_LIST_DIR}/affine3d.c ) diff --git a/src/glm/affine3d.c b/src/glm/affine3d.c new file mode 100644 index 0000000..c392d03 --- /dev/null +++ b/src/glm/affine3d.c @@ -0,0 +1,207 @@ +#include +#include +#include +#include "glm.h" + + +int glm_uniscaled_bind(lua_State *L) +{ + mat4 *m = luaL_checkudata(L, 1, glm_mat4_tname); + bool bind_result = glm_uniscaled(*m); + lua_pushboolean(L, bind_result); + return 1; +} + + +int glm_decompose_bind(lua_State *L) +{ + mat4 *m = luaL_checkudata(L, 1, glm_mat4_tname); + vec4 *t = luaL_checkudata(L, 2, glm_vec4_tname); + mat4 *r = luaL_checkudata(L, 3, glm_mat4_tname); + vec3 *s = luaL_checkudata(L, 4, glm_vec3_tname); + glm_decompose(*m, *t, *r, *s); + return 0; +} + + +int glm_decompose_rs_bind(lua_State *L) +{ + mat4 *m = luaL_checkudata(L, 1, glm_mat4_tname); + mat4 *r = luaL_checkudata(L, 2, glm_mat4_tname); + vec3 *s = luaL_checkudata(L, 3, glm_vec3_tname); + glm_decompose_rs(*m, *r, *s); + return 0; +} + + +int glm_decompose_scalev_bind(lua_State *L) +{ + mat4 *m = luaL_checkudata(L, 1, glm_mat4_tname); + vec3 *s = luaL_checkudata(L, 2, glm_vec3_tname); + glm_decompose_scalev(*m, *s); + return 0; +} + + +int glm_rotate_bind(lua_State *L) +{ + mat4 *m = luaL_checkudata(L, 1, glm_mat4_tname); + float angle = luaL_checknumber(L, 2); + vec3 *axis = luaL_checkudata(L, 3, glm_vec3_tname); + glm_rotate(*m, angle, *axis); + return 0; +} + + +int glm_rotate_at_bind(lua_State *L) +{ + mat4 *m = luaL_checkudata(L, 1, glm_mat4_tname); + vec3 *pivot = luaL_checkudata(L, 2, glm_vec3_tname); + float angle = luaL_checknumber(L, 3); + vec3 *axis = luaL_checkudata(L, 4, glm_vec3_tname); + glm_rotate_at(*m, *pivot, angle, *axis); + return 0; +} + + +int glm_rotate_atm_bind(lua_State *L) +{ + mat4 *m = luaL_checkudata(L, 1, glm_mat4_tname); + vec3 *pivot = luaL_checkudata(L, 2, glm_vec3_tname); + float angle = luaL_checknumber(L, 3); + vec3 *axis = luaL_checkudata(L, 4, glm_vec3_tname); + glm_rotate_atm(*m, *pivot, angle, *axis); + return 0; +} + + +int glm_rotate_make_bind(lua_State *L) +{ + mat4 *m = luaL_checkudata(L, 1, glm_mat4_tname); + float angle = luaL_checknumber(L, 2); + vec3 *axis = luaL_checkudata(L, 3, glm_vec3_tname); + glm_rotate_make(*m, angle, *axis); + return 0; +} + + +int glm_rotate_x_bind(lua_State *L) +{ + mat4 *m = luaL_checkudata(L, 1, glm_mat4_tname); + float angle = luaL_checknumber(L, 2); + mat4 *dest = luaL_checkudata(L, 3, glm_mat4_tname); + glm_rotate_x(*m, angle, *dest); + return 0; +} + + +int glm_rotate_y_bind(lua_State *L) +{ + mat4 *m = luaL_checkudata(L, 1, glm_mat4_tname); + float angle = luaL_checknumber(L, 2); + mat4 *dest = luaL_checkudata(L, 3, glm_mat4_tname); + glm_rotate_y(*m, angle, *dest); + return 0; +} + + +int glm_rotate_z_bind(lua_State *L) +{ + mat4 *m = luaL_checkudata(L, 1, glm_mat4_tname); + float angle = luaL_checknumber(L, 2); + mat4 *dest = luaL_checkudata(L, 3, glm_mat4_tname); + glm_rotate_z(*m, angle, *dest); + return 0; +} + + +int glm_scale_bind(lua_State *L) +{ + mat4 *m = luaL_checkudata(L, 1, glm_mat4_tname); + vec3 *v = luaL_checkudata(L, 2, glm_vec3_tname); + glm_scale(*m, *v); + return 0; +} + + +int glm_scale_make_bind(lua_State *L) +{ + mat4 *m = luaL_checkudata(L, 1, glm_mat4_tname); + vec3 *v = luaL_checkudata(L, 2, glm_vec3_tname); + glm_scale_make(*m, *v); + return 0; +} + + +int glm_scale_to_bind(lua_State *L) +{ + mat4 *m = luaL_checkudata(L, 1, glm_mat4_tname); + vec3 *v = luaL_checkudata(L, 2, glm_vec3_tname); + mat4 *dest = luaL_checkudata(L, 3, glm_mat4_tname); + glm_scale_to(*m, *v, *dest); + return 0; +} + + +int glm_scale_uni_bind(lua_State *L) +{ + mat4 *m = luaL_checkudata(L, 1, glm_mat4_tname); + float s = luaL_checknumber(L, 2); + glm_scale_uni(*m, s); + return 0; +} + + +int glm_translate_bind(lua_State *L) +{ + mat4 *m = luaL_checkudata(L, 1, glm_mat4_tname); + vec3 *v = luaL_checkudata(L, 2, glm_vec3_tname); + glm_translate(*m, *v); + return 0; +} + + +int glm_translate_make_bind(lua_State *L) +{ + mat4 *m = luaL_checkudata(L, 1, glm_mat4_tname); + vec3 *v = luaL_checkudata(L, 2, glm_vec3_tname); + glm_translate_make(*m, *v); + return 0; +} + + +int glm_translate_to_bind(lua_State *L) +{ + mat4 *m = luaL_checkudata(L, 1, glm_mat4_tname); + vec3 *v = luaL_checkudata(L, 2, glm_vec3_tname); + mat4 *dest = luaL_checkudata(L, 3, glm_mat4_tname); + glm_translate_to(*m, *v, *dest); + return 0; +} + + +int glm_translate_x_bind(lua_State *L) +{ + mat4 *m = luaL_checkudata(L, 1, glm_mat4_tname); + float x = luaL_checknumber(L, 2); + glm_translate_x(*m, x); + return 0; +} + + +int glm_translate_y_bind(lua_State *L) +{ + mat4 *m = luaL_checkudata(L, 1, glm_mat4_tname); + float y = luaL_checknumber(L, 2); + glm_translate_y(*m, y); + return 0; +} + + +int glm_translate_z_bind(lua_State *L) +{ + mat4 *m = luaL_checkudata(L, 1, glm_mat4_tname); + float z = luaL_checknumber(L, 2); + glm_translate_z(*m, z); + return 0; +} diff --git a/src/glm/camera.c b/src/glm/camera.c deleted file mode 100644 index 11d309d..0000000 --- a/src/glm/camera.c +++ /dev/null @@ -1,45 +0,0 @@ -#include -#include -#include -#include "util/util.h" -#include "glm.h" - - -int perspective(lua_State *L); -int look(lua_State *L); - - -void setup_camera(lua_State *L, int glm_tbl) -{ - int tbl = hs_create_table(L, - hs_str_cfunc("perspective", perspective), - hs_str_cfunc("look", look), - ); - - append_table(L, glm_tbl, tbl); - lua_pop(L, 1); -} - - -int perspective(lua_State *L) -{ - lua_Number fov, aspect, near, far; - void *dest_ptr; - hs_parse_args(L, hs_num(fov), hs_num(aspect), hs_num(near), hs_num(far), hs_user(dest_ptr)); - mat4 *dest = dest_ptr; - - glm_perspective(fov, aspect, near, far, *dest); - return 0; -} - - -int look(lua_State *L) -{ - float *eye = luaL_checkudata(L, 1, vec3_tname); - float *dir = luaL_checkudata(L, 2, vec3_tname); - float *up = luaL_checkudata(L, 3, vec3_tname); - void *dest = luaL_checkudata(L, 4, mat4_tname); - - glm_look(eye, dir, up, dest); - return 0; -} diff --git a/src/glm/glm.c b/src/glm/glm.c deleted file mode 100644 index ca6238a..0000000 --- a/src/glm/glm.c +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include -#include "glm.h" - - -void setup_glm(lua_State *L, int honey_index) -{ - lua_createtable(L, 0, 1); - int glm_tbl = lua_gettop(L); - - setup_vec3(L, glm_tbl); - setup_mat4(L, glm_tbl); - - setup_transform(L, glm_tbl); - setup_camera(L, glm_tbl); - - lua_setfield(L, honey_index, "glm"); -} - - -void array_get(lua_State *L, int max, float *array, int index) -{ - if (index < 0 || index >= max) - hs_throw_error(L, "index %d is out of range [0-%d]", index, max-1); - lua_pushnumber(L, array[index]); -} - - -void array_set(lua_State *L, int max, float *array, int index, float value) -{ - if (index < 0 || index >= max) - hs_throw_error(L, "index %d is out of range [0-%d]", index, max-1); - array[index] = value; -} diff --git a/src/glm/glm.h b/src/glm/glm.h index 8bcf7cc..b331d37 100644 --- a/src/glm/glm.h +++ b/src/glm/glm.h @@ -4,17 +4,91 @@ #include -extern const char *vec3_tname; -extern const char *mat4_tname; +extern const char *glm_mat2_tname; +extern const char *glm_mat3_tname; +extern const char *glm_mat4_tname; +extern const char *glm_vec2_tname; +extern const char *glm_vec3_tname; +extern const char *glm_vec4_tname; -void setup_glm(lua_State *L, int honey_index); -void setup_vec3(lua_State *L, int glm_tbl); -void setup_mat4(lua_State *L, int glm_tbl); -void setup_transform(lua_State *L, int glm_tbl); -void setup_camera(lua_State *L, int glm_tbl); +#define GLM_FUNCTIONS \ + /* 3d affine transforms */ \ + X("decompose", glm_decompose_bind) \ + X("decompose_rs", glm_decompose_rs_bind) \ + X("decompose_scalev", glm_decompose_scalev_bind) \ + X("rotate", glm_rotate_bind) \ + X("rotate_at", glm_rotate_at_bind) \ + X("rotate_atm", glm_rotate_atm_bind) \ + X("rotate_make", glm_rotate_make_bind) \ + X("rotate_x", glm_rotate_x_bind) \ + X("rotate_y", glm_rotate_y_bind) \ + X("rotate_z", glm_rotate_z_bind) \ + X("scale", glm_scale_bind) \ + X("scale_make", glm_scale_make_bind) \ + X("scale_to", glm_scale_to_bind) \ + X("scale_uni", glm_scale_uni_bind) \ + X("translate", glm_translate_bind) \ + X("translate_make", glm_translate_make_bind) \ + X("translate_to", glm_translate_to_bind) \ + X("translate_x", glm_translate_x_bind) \ + X("translate_y", glm_translate_y_bind) \ + X("translate_z", glm_translate_z_bind) \ + X("uniscaled", glm_uniscaled_bind) \ +\ + /* vec3 */ \ + X("vec3_create", glm_vec3_create) \ + X("vec3_set", glm_vec3_set) \ + X("vec3_get", glm_vec3_get) \ + X("vec3", glm_vec3_bind) \ + X("vec3_copy", glm_vec3_copy_bind) \ + X("vec3_zero", glm_vec3_zero_bind) \ + X("vec3_one", glm_vec3_one_bind) \ + X("vec3_dot", glm_vec3_dot_bind) \ + X("vec3_norm2", glm_vec3_norm2_bind) \ + X("vec3_norm", glm_vec3_norm_bind) \ + X("vec3_add", glm_vec3_add_bind) \ + X("vec3_adds", glm_vec3_adds_bind) \ + X("vec3_sub", glm_vec3_sub_bind) \ + X("vec3_subs", glm_vec3_subs_bind) \ + X("vec3_mul", glm_vec3_mul_bind) \ + X("vec3_scale", glm_vec3_scale_bind) \ + X("vec3_scale_as", glm_vec3_scale_as_bind) \ + X("vec3_div", glm_vec3_div_bind) \ + X("vec3_divs", glm_vec3_divs_bind) \ + X("vec3_addadd", glm_vec3_addadd_bind) \ + X("vec3_subadd", glm_vec3_subadd_bind) \ + X("vec3_muladd", glm_vec3_muladd_bind) \ + X("vec3_muladds", glm_vec3_muladds_bind) \ + X("vec3_maxadd", glm_vec3_maxadd_bind) \ + X("vec3_minadd", glm_vec3_minadd_bind) \ + X("vec3_flipsign", glm_vec3_flipsign_bind) \ + X("vec3_flipsign_to", glm_vec3_flipsign_to_bind) \ + X("vec3_inv", glm_vec3_inv_bind) \ + X("vec3_inv_to", glm_vec3_inv_to_bind) \ + X("vec3_negate", glm_vec3_negate_bind) \ + X("vec3_negate_to", glm_vec3_negate_to_bind) \ + X("vec3_normalize", glm_vec3_normalize_bind) \ + X("vec3_normalize_to", glm_vec3_normalize_to_bind) \ + X("vec3_cross", glm_vec3_cross_bind) \ + X("vec3_crossn", glm_vec3_crossn_bind) \ + X("vec3_distance2", glm_vec3_distance2_bind) \ + X("vec3_distance", glm_vec3_distance_bind) \ + X("vec3_angle", glm_vec3_angle_bind) \ + X("vec3_rotate", glm_vec3_rotate_bind) \ + X("vec3_rotate_m4", glm_vec3_rotate_m4_bind) \ + X("vec3_rotate_m3", glm_vec3_rotate_m3_bind) \ + X("vec3_proj", glm_vec3_proj_bind) \ + X("vec3_center", glm_vec3_center_bind) \ + X("vec3_maxv", glm_vec3_maxv_bind) \ + X("vec3_minv", glm_vec3_minv_bind) \ + X("vec3_ortho", glm_vec3_ortho_bind) \ + X("vec3_clamp", glm_vec3_clamp_bind) \ + X("vec3_lerp", glm_vec3_lerp_bind) \ -void array_get(lua_State *L, int max, float *array, int index); -void array_set(lua_State *L, int max, float *array, int index, float value); + +#define X(name, func) int func(lua_State *L); +GLM_FUNCTIONS +#undef X #endif diff --git a/src/glm/mat4.c b/src/glm/mat4.c deleted file mode 100644 index 5197891..0000000 --- a/src/glm/mat4.c +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include -#include -#include "util/util.h" -#include "glm.h" - -int mat4_create(lua_State *L); -int mat4_set(lua_State *L); -int mat4_get(lua_State *L); -int mat4_identity(lua_State *L); - -const char *mat4_tname = "glm.mat4"; - -void setup_mat4(lua_State *L, int glm_tbl) -{ - luaL_newmetatable(L, mat4_tname); - lua_pop(L, 1); - - int tbl = hs_create_table(L, - hs_str_cfunc("mat4", mat4_create), - hs_str_cfunc("mat4_set", mat4_set), - hs_str_cfunc("mat4_get", mat4_get), - 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)); - luaL_getmetatable(L, mat4_tname); - lua_setmetatable(L, -2); - return 1; -} - - -int mat4_set(lua_State *L) -{ - float *matrix = luaL_checkudata(L, 1, mat4_tname); - int index = luaL_checkinteger(L, 2); - float value = luaL_checknumber(L, 3); - array_set(L, 16, matrix, index, value); - return 0; -} - - -int mat4_get(lua_State *L) -{ - float *matrix = luaL_checkudata(L, 1, mat4_tname); - int index = luaL_checkinteger(L, 2); - array_get(L, 16, matrix, index); - return 1; -} - - -int mat4_identity(lua_State *L) -{ - void *m = luaL_checkudata(L, 1, mat4_tname); - glm_mat4_identity(m); - return 0; -} diff --git a/src/glm/setup.c b/src/glm/setup.c new file mode 100644 index 0000000..a36eeb1 --- /dev/null +++ b/src/glm/setup.c @@ -0,0 +1,41 @@ +#include +#include +#include "util/util.h" +#include "glm.h" + + +const char *glm_mat2_tname = "glm.mat2"; +const char *glm_mat3_tname = "glm.mat3"; +const char *glm_mat4_tname = "glm.mat4"; +const char *glm_vec2_tname = "glm.vec2"; +const char *glm_vec3_tname = "glm.vec3"; +const char *glm_vec4_tname = "glm.vec4"; + + +void setup_glm(lua_State *L, int honey_index) +{ + struct honey_tbl_t glm[] = { + #define X(name, func) H_FUNC(name, func), + GLM_FUNCTIONS + #undef X + H_END, + }; + create_table(L, glm); + lua_setfield(L, honey_index, "glm"); +} + + +void array_get(lua_State *L, int max, float *array, int index) +{ + if (index < 0 || index >= max) + luaL_error(L, "index %d is out of range [0-%d]", index, max-1); + lua_pushnumber(L, array[index]); +} + + +void array_set(lua_State *L, int max, float *array, int index, float value) +{ + if (index < 0 || index >= max) + luaL_error(L, "index %d is out of range [0-%d]", index, max-1); + array[index] = value; +} diff --git a/src/glm/transform.c b/src/glm/transform.c deleted file mode 100644 index daf75a5..0000000 --- a/src/glm/transform.c +++ /dev/null @@ -1,60 +0,0 @@ -#include -#include -#include -#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; -} diff --git a/src/glm/vec3.c b/src/glm/vec3.c index f278471..b85cf63 100644 --- a/src/glm/vec3.c +++ b/src/glm/vec3.c @@ -1,133 +1,463 @@ #include -#include +#include #include #include "util/util.h" #include "glm.h" -int vec3_create(lua_State *L); -int vec3_set(lua_State *L); -int vec3_get(lua_State *L); -int vec3_normalize(lua_State *L); +int glm_vec3_create(lua_State *L) +{ + lua_newuserdata(L, sizeof(vec3)); + luaL_getmetatable(L, glm_vec3_tname); + lua_setmetatable(L, -2); + return 1; +} + + +int glm_vec3_set(lua_State *L) +{ + vec3 *vec = luaL_checkudata(L, 1, glm_vec3_tname); + int index = luaL_checkinteger(L, 2); + double value = luaL_checknumber(L, 3); + (*vec)[index] = value; + return 0; +} -int vec3_add(lua_State *L); -int vec3_sub(lua_State *L); -int vec3_scale(lua_State *L); -int vec3_dot(lua_State *L); -int vec3_cross(lua_State *L); -const char *vec3_tname = "glm.vec3"; +int glm_vec3_get(lua_State *L) +{ + vec3 *vec = luaL_checkudata(L, 1, glm_vec3_tname); + int index = luaL_checkinteger(L, 2); + lua_pushnumber(L, (*vec)[index]); + return 1; +} -void setup_vec3(lua_State *L, int glm_tbl) +int glm_vec3_bind(lua_State *L) { - luaL_newmetatable(L, vec3_tname); - lua_pop(L, 1); + vec4 *v4 = luaL_checkudata(L, 1, glm_vec4_tname); + vec3 *dest = luaL_checkudata(L, 2, glm_vec3_tname); + glm_vec3(*v4, *dest); + return 0; +} - int tbl = hs_create_table(L, - hs_str_cfunc("vec3", vec3_create), - hs_str_cfunc("vec3_set", vec3_set), - hs_str_cfunc("vec3_get", vec3_get), - hs_str_cfunc("vec3_normalize", vec3_normalize), +int glm_vec3_copy_bind(lua_State *L) +{ + vec3 *a = luaL_checkudata(L, 1, glm_vec3_tname); + vec3 *dest = luaL_checkudata(L, 2, glm_vec3_tname); + glm_vec3_copy(*a, *dest); + return 0; +} - hs_str_cfunc("vec3_add", vec3_add), - hs_str_cfunc("vec3_sub", vec3_sub), - hs_str_cfunc("vec3_scale", vec3_scale), - hs_str_cfunc("vec3_dot", vec3_dot), - hs_str_cfunc("vec3_cross", vec3_cross), - ); - append_table(L, glm_tbl, tbl); - lua_pop(L, 1); +int glm_vec3_zero_bind(lua_State *L) +{ + vec3 *v = luaL_checkudata(L, 1, glm_vec3_tname); + glm_vec3_zero(*v); + return 0; } -int vec3_create(lua_State *L) +int glm_vec3_one_bind(lua_State *L) { - lua_newuserdata(L, 3*sizeof(float)); - luaL_getmetatable(L, vec3_tname); - lua_setmetatable(L, -2); + vec3 *v = luaL_checkudata(L, 1, glm_vec3_tname); + glm_vec3_one(*v); + return 0; +} + + +int glm_vec3_dot_bind(lua_State *L) +{ + vec3 *a = luaL_checkudata(L, 1, glm_vec3_tname); + vec3 *b = luaL_checkudata(L, 2, glm_vec3_tname); + float bind_result = glm_vec3_dot(*a, *b); + lua_pushnumber(L, bind_result); return 1; } -int vec3_set(lua_State *L) +int glm_vec3_cross_bind(lua_State *L) { - float *vec = luaL_checkudata(L, 1, vec3_tname); - int index = luaL_checkinteger(L, 2); - double value = luaL_checknumber(L, 3); - array_set(L, 3, vec, index, value); + vec3 *a = luaL_checkudata(L, 1, glm_vec3_tname); + vec3 *b = luaL_checkudata(L, 2, glm_vec3_tname); + vec3 *d = luaL_checkudata(L, 3, glm_vec3_tname); + glm_vec3_cross(*a, *b, *d); return 0; } -int vec3_get(lua_State *L) +int glm_vec3_crossn_bind(lua_State *L) { - float *vec = luaL_checkudata(L, 1, vec3_tname); - int index = luaL_checkinteger(L, 2); - array_get(L, 3, vec, index); + vec3 *a = luaL_checkudata(L, 1, glm_vec3_tname); + vec3 *b = luaL_checkudata(L, 2, glm_vec3_tname); + vec3 *dest = luaL_checkudata(L, 3, glm_vec3_tname); + glm_vec3_crossn(*a, *b, *dest); + return 0; +} + + +int glm_vec3_norm2_bind(lua_State *L) +{ + vec3 *v = luaL_checkudata(L, 1, glm_vec3_tname); + float bind_result = glm_vec3_norm2(*v); + lua_pushnumber(L, bind_result); return 1; } -int vec3_normalize(lua_State *L) +int glm_vec3_norm_bind(lua_State *L) +{ + vec3 *vec = luaL_checkudata(L, 1, glm_vec3_tname); + float bind_result = glm_vec3_norm(*vec); + lua_pushnumber(L, bind_result); + return 1; +} + + +int glm_vec3_add_bind(lua_State *L) +{ + vec3 *a = luaL_checkudata(L, 1, glm_vec3_tname); + vec3 *b = luaL_checkudata(L, 2, glm_vec3_tname); + vec3 *dest = luaL_checkudata(L, 3, glm_vec3_tname); + glm_vec3_add(*a, *b, *dest); + return 0; +} + + +int glm_vec3_adds_bind(lua_State *L) +{ + vec3 *a = luaL_checkudata(L, 1, glm_vec3_tname); + float s = luaL_checknumber(L, 2); + vec3 *dest = luaL_checkudata(L, 3, glm_vec3_tname); + glm_vec3_adds(*a, s, *dest); + return 0; +} + + +int glm_vec3_sub_bind(lua_State *L) +{ + vec3 *v1 = luaL_checkudata(L, 1, glm_vec3_tname); + vec3 *v2 = luaL_checkudata(L, 2, glm_vec3_tname); + vec3 *dest = luaL_checkudata(L, 3, glm_vec3_tname); + glm_vec3_sub(*v1, *v2, *dest); + return 0; +} + + +int glm_vec3_subs_bind(lua_State *L) +{ + vec3 *v = luaL_checkudata(L, 1, glm_vec3_tname); + float s = luaL_checknumber(L, 2); + vec3 *dest = luaL_checkudata(L, 3, glm_vec3_tname); + glm_vec3_subs(*v, s, *dest); + return 0; +} + + +int glm_vec3_mul_bind(lua_State *L) +{ + vec3 *a = luaL_checkudata(L, 1, glm_vec3_tname); + vec3 *b = luaL_checkudata(L, 2, glm_vec3_tname); + vec3 *d = luaL_checkudata(L, 3, glm_vec3_tname); + glm_vec3_mul(*a, *b, *d); + return 0; +} + + +int glm_vec3_scale_bind(lua_State *L) +{ + vec3 *v = luaL_checkudata(L, 1, glm_vec3_tname); + float s = luaL_checknumber(L, 2); + vec3 *dest = luaL_checkudata(L, 3, glm_vec3_tname); + glm_vec3_scale(*v, s, *dest); + return 0; +} + + +int glm_vec3_scale_as_bind(lua_State *L) +{ + vec3 *v = luaL_checkudata(L, 1, glm_vec3_tname); + float s = luaL_checknumber(L, 2); + vec3 *dest = luaL_checkudata(L, 3, glm_vec3_tname); + glm_vec3_scale_as(*v, s, *dest); + return 0; +} + + +int glm_vec3_div_bind(lua_State *L) { - float *vec = luaL_checkudata(L, 1, vec3_tname); - glm_vec3_normalize(vec); + vec3 *a = luaL_checkudata(L, 1, glm_vec3_tname); + vec3 *b = luaL_checkudata(L, 2, glm_vec3_tname); + vec3 *dest = luaL_checkudata(L, 3, glm_vec3_tname); + glm_vec3_div(*a, *b, *dest); return 0; } -int vec3_add(lua_State *L) +int glm_vec3_divs_bind(lua_State *L) { - float *a = luaL_checkudata(L, 1, vec3_tname); - float *b = luaL_checkudata(L, 2, vec3_tname); - float *dest = luaL_checkudata(L, 3, vec3_tname); + vec3 *v = luaL_checkudata(L, 1, glm_vec3_tname); + float s = luaL_checknumber(L, 2); + vec3 *dest = luaL_checkudata(L, 3, glm_vec3_tname); + glm_vec3_divs(*v, s, *dest); + return 0; +} + - glm_vec3_add(a, b, dest); +int glm_vec3_addadd_bind(lua_State *L) +{ + vec3 *a = luaL_checkudata(L, 1, glm_vec3_tname); + vec3 *b = luaL_checkudata(L, 2, glm_vec3_tname); + vec3 *dest = luaL_checkudata(L, 3, glm_vec3_tname); + glm_vec3_addadd(*a, *b, *dest); return 0; } -int vec3_sub(lua_State *L) +int glm_vec3_subadd_bind(lua_State *L) { - float *a = luaL_checkudata(L, 1, vec3_tname); - float *b = luaL_checkudata(L, 2, vec3_tname); - float *dest = luaL_checkudata(L, 3, vec3_tname); + vec3 *a = luaL_checkudata(L, 1, glm_vec3_tname); + vec3 *b = luaL_checkudata(L, 2, glm_vec3_tname); + vec3 *dest = luaL_checkudata(L, 3, glm_vec3_tname); + glm_vec3_subadd(*a, *b, *dest); + return 0; +} - glm_vec3_sub(a, b, dest); + +int glm_vec3_muladd_bind(lua_State *L) +{ + vec3 *a = luaL_checkudata(L, 1, glm_vec3_tname); + vec3 *b = luaL_checkudata(L, 2, glm_vec3_tname); + vec3 *dest = luaL_checkudata(L, 3, glm_vec3_tname); + glm_vec3_muladd(*a, *b, *dest); return 0; } -int vec3_scale(lua_State *L) + +int glm_vec3_muladds_bind(lua_State *L) { - float *v = luaL_checkudata(L, 1, vec3_tname); + vec3 *a = luaL_checkudata(L, 1, glm_vec3_tname); float s = luaL_checknumber(L, 2); - float *dest = luaL_checkudata(L, 3, vec3_tname); + vec3 *dest = luaL_checkudata(L, 3, glm_vec3_tname); + glm_vec3_muladds(*a, s, *dest); + return 0; +} + + +int glm_vec3_maxadd_bind(lua_State *L) +{ + vec3 *a = luaL_checkudata(L, 1, glm_vec3_tname); + vec3 *b = luaL_checkudata(L, 2, glm_vec3_tname); + vec3 *dest = luaL_checkudata(L, 3, glm_vec3_tname); + glm_vec3_maxadd(*a, *b, *dest); + return 0; +} + + +int glm_vec3_minadd_bind(lua_State *L) +{ + vec3 *a = luaL_checkudata(L, 1, glm_vec3_tname); + vec3 *b = luaL_checkudata(L, 2, glm_vec3_tname); + vec3 *dest = luaL_checkudata(L, 3, glm_vec3_tname); + glm_vec3_minadd(*a, *b, *dest); + return 0; +} + + +int glm_vec3_flipsign_bind(lua_State *L) +{ + vec3 *v = luaL_checkudata(L, 1, glm_vec3_tname); + glm_vec3_flipsign(*v); + return 0; +} + + +int glm_vec3_flipsign_to_bind(lua_State *L) +{ + vec3 *v = luaL_checkudata(L, 1, glm_vec3_tname); + vec3 *dest = luaL_checkudata(L, 2, glm_vec3_tname); + glm_vec3_flipsign_to(*v, *dest); + return 0; +} + + +int glm_vec3_inv_bind(lua_State *L) +{ + vec3 *v = luaL_checkudata(L, 1, glm_vec3_tname); + glm_vec3_inv(*v); + return 0; +} + + +int glm_vec3_inv_to_bind(lua_State *L) +{ + vec3 *v = luaL_checkudata(L, 1, glm_vec3_tname); + vec3 *dest = luaL_checkudata(L, 2, glm_vec3_tname); + glm_vec3_inv_to(*v, *dest); + return 0; +} + + +int glm_vec3_negate_bind(lua_State *L) +{ + vec3 *v = luaL_checkudata(L, 1, glm_vec3_tname); + glm_vec3_negate(*v); + return 0; +} + + +int glm_vec3_negate_to_bind(lua_State *L) +{ + vec3 *v = luaL_checkudata(L, 1, glm_vec3_tname); + vec3 *dest = luaL_checkudata(L, 2, glm_vec3_tname); + glm_vec3_negate_to(*v, *dest); + return 0; +} + + +int glm_vec3_normalize_bind(lua_State *L) +{ + vec3 *v = luaL_checkudata(L, 1, glm_vec3_tname); + glm_vec3_normalize(*v); + return 0; +} + + +int glm_vec3_normalize_to_bind(lua_State *L) +{ + vec3 *vec = luaL_checkudata(L, 1, glm_vec3_tname); + vec3 *dest = luaL_checkudata(L, 2, glm_vec3_tname); + glm_vec3_normalize_to(*vec, *dest); + return 0; +} + + +int glm_vec3_angle_bind(lua_State *L) +{ + vec3 *v1 = luaL_checkudata(L, 1, glm_vec3_tname); + vec3 *v2 = luaL_checkudata(L, 2, glm_vec3_tname); + float bind_result = glm_vec3_angle(*v1, *v2); + lua_pushnumber(L, bind_result); + return 1; +} + + +int glm_vec3_rotate_bind(lua_State *L) +{ + vec3 *v = luaL_checkudata(L, 1, glm_vec3_tname); + float angle = luaL_checknumber(L, 2); + vec3 *axis = luaL_checkudata(L, 3, glm_vec3_tname); + glm_vec3_rotate(*v, angle, *axis); + return 0; +} + + +int glm_vec3_rotate_m4_bind(lua_State *L) +{ + mat4 *m = luaL_checkudata(L, 1, glm_mat4_tname); + vec3 *v = luaL_checkudata(L, 2, glm_vec3_tname); + vec3 *dest = luaL_checkudata(L, 3, glm_vec3_tname); + glm_vec3_rotate_m4(*m, *v, *dest); + return 0; +} + + +int glm_vec3_rotate_m3_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_vec3_rotate_m3(*m, *v, *dest); + return 0; +} + + +int glm_vec3_proj_bind(lua_State *L) +{ + vec3 *a = luaL_checkudata(L, 1, glm_vec3_tname); + vec3 *b = luaL_checkudata(L, 2, glm_vec3_tname); + vec3 *dest = luaL_checkudata(L, 3, glm_vec3_tname); + glm_vec3_proj(*a, *b, *dest); + return 0; +} + - glm_vec3_scale(v, s, dest); +int glm_vec3_center_bind(lua_State *L) +{ + vec3 *v1 = luaL_checkudata(L, 1, glm_vec3_tname); + vec3 *v2 = luaL_checkudata(L, 2, glm_vec3_tname); + vec3 *dest = luaL_checkudata(L, 3, glm_vec3_tname); + glm_vec3_center(*v1, *v2, *dest); return 0; } -int vec3_dot(lua_State *L) +int glm_vec3_distance2_bind(lua_State *L) { - float *a = luaL_checkudata(L, 1, vec3_tname); - float *b = luaL_checkudata(L, 2, vec3_tname); + vec3 *v1 = luaL_checkudata(L, 1, glm_vec3_tname); + vec3 *v2 = luaL_checkudata(L, 2, glm_vec3_tname); + float bind_result = glm_vec3_distance2(*v1, *v2); + lua_pushnumber(L, bind_result); + return 1; +} - float result = glm_vec3_dot(a, b); - lua_pushnumber(L, result); + +int glm_vec3_distance_bind(lua_State *L) +{ + vec3 *v1 = luaL_checkudata(L, 1, glm_vec3_tname); + vec3 *v2 = luaL_checkudata(L, 2, glm_vec3_tname); + float bind_result = glm_vec3_distance(*v1, *v2); + lua_pushnumber(L, bind_result); return 1; } -int vec3_cross(lua_State *L) +int glm_vec3_maxv_bind(lua_State *L) +{ + vec3 *v1 = luaL_checkudata(L, 1, glm_vec3_tname); + vec3 *v2 = luaL_checkudata(L, 2, glm_vec3_tname); + vec3 *dest = luaL_checkudata(L, 3, glm_vec3_tname); + glm_vec3_maxv(*v1, *v2, *dest); + return 0; +} + + +int glm_vec3_minv_bind(lua_State *L) +{ + vec3 *v1 = luaL_checkudata(L, 1, glm_vec3_tname); + vec3 *v2 = luaL_checkudata(L, 2, glm_vec3_tname); + vec3 *dest = luaL_checkudata(L, 3, glm_vec3_tname); + glm_vec3_minv(*v1, *v2, *dest); + return 0; +} + + +int glm_vec3_ortho_bind(lua_State *L) +{ + vec3 *v = luaL_checkudata(L, 1, glm_vec3_tname); + vec3 *dest = luaL_checkudata(L, 2, glm_vec3_tname); + glm_vec3_ortho(*v, *dest); + return 0; +} + + +int glm_vec3_clamp_bind(lua_State *L) { - float *a = luaL_checkudata(L, 1, vec3_tname); - float *b = luaL_checkudata(L, 2, vec3_tname); - float *dest = luaL_checkudata(L, 3, vec3_tname); + vec3 *v = luaL_checkudata(L, 1, glm_vec3_tname); + float minVal = luaL_checknumber(L, 2); + float maxVal = luaL_checknumber(L, 3); + glm_vec3_clamp(*v, minVal, maxVal); + return 0; +} + - glm_vec3_cross(a, b, dest); +int glm_vec3_lerp_bind(lua_State *L) +{ + vec3 *from = luaL_checkudata(L, 1, glm_vec3_tname); + vec3 *to = luaL_checkudata(L, 2, glm_vec3_tname); + float t = luaL_checknumber(L, 3); + vec3 *dest = luaL_checkudata(L, 4, glm_vec3_tname); + glm_vec3_lerp(*from, *to, t, *dest); return 0; } diff --git a/src/import/notes.md b/src/import/notes.md new file mode 100644 index 0000000..bf84f32 --- /dev/null +++ b/src/import/notes.md @@ -0,0 +1,14 @@ +tinyobj notes +============= + +tinyobjloader-c is not a very well-documented library, so i'm gonna keep some notes +as i figure things out + + * the indices within a vertex_index_t object are not indices into the vertices, normals, or texcoords arrays; + rather, they are indices to 3-vectors within those arrays. To get actual indices, multiply them by three. + * "shapes" are individual meshes. + * a shape's `face_offset` is the *number of faces* into the `faces` array to go before + you find the data for the current shape, and the length is the *number of faces*. + This means that they are **NOT** indices to the `faces` array; they are indices/lengths + in the `face_num_verts` array, which you can then use to determine indices into the + faces array. -- cgit v1.2.1