summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2020-10-27 23:23:22 -0500
committersanine-a <sanine.not@pm.me>2020-10-27 23:23:22 -0500
commitf0a6a17e4fba3510c8ba8f6b114012873035a4a1 (patch)
treebcc30d768b1ccf515936cc821ac30a21b5ed9ea7 /src
parentc3698446644365283fcd3d3f47f3eea67cad8331 (diff)
fix minor bugs, add cube primitive binding, and implement basic first-person camera
Diffstat (limited to 'src')
-rw-r--r--src/cglm_bindings.c34
-rw-r--r--src/cglm_bindings.h20
-rw-r--r--src/primitives/primitives.c19
3 files changed, 69 insertions, 4 deletions
diff --git a/src/cglm_bindings.c b/src/cglm_bindings.c
index f8f6c8a..947c394 100644
--- a/src/cglm_bindings.c
+++ b/src/cglm_bindings.c
@@ -8,6 +8,7 @@ void honey_setup_cglm(lua_State* L)
{ "norm", HONEY_FUNCTION, { .function = honey_cglm_vec3_norm } },
{ "add", HONEY_FUNCTION, { .function = honey_cglm_vec3_add } },
{ "adds", HONEY_FUNCTION, { .function = honey_cglm_vec3_adds } },
+ { "sub", HONEY_FUNCTION, { .function = honey_cglm_vec3_sub } },
{ "mul", HONEY_FUNCTION, { .function = honey_cglm_vec3_mul } },
{ "muls", HONEY_FUNCTION, { .function = honey_cglm_vec3_muls } },
{ "normalize", HONEY_FUNCTION, { .function = honey_cglm_vec3_normalize } },
@@ -21,6 +22,7 @@ void honey_setup_cglm(lua_State* L)
{ "norm", HONEY_FUNCTION, { .function = honey_cglm_vec4_norm } },
{ "add", HONEY_FUNCTION, { .function = honey_cglm_vec4_add } },
{ "adds", HONEY_FUNCTION, { .function = honey_cglm_vec4_adds } },
+ { "sub", HONEY_FUNCTION, { .function = honey_cglm_vec4_sub } },
{ "mul", HONEY_FUNCTION, { .function = honey_cglm_vec4_mul } },
{ "muls", HONEY_FUNCTION, { .function = honey_cglm_vec4_muls } },
{ "normalize", HONEY_FUNCTION, { .function = honey_cglm_vec4_normalize } },
@@ -69,15 +71,15 @@ void honey_setup_cglm(lua_State* L)
{ "set_value", HONEY_FUNCTION, { .function = honey_cglm_array_set_value } },
{ "get_value", HONEY_FUNCTION, { .function = honey_cglm_array_get_value } },
{ "copy_array", HONEY_FUNCTION, { .function = honey_cglm_array_copy } },
- { "vec3", HONEY_TABLE, { .table = { 10, vec3_elements } } },
- { "vec4", HONEY_TABLE, { .table = { 10, vec4_elements } } },
+ { "vec3", HONEY_TABLE, { .table = { 11, vec3_elements } } },
+ { "vec4", HONEY_TABLE, { .table = { 11, vec4_elements } } },
{ "mat3", HONEY_TABLE, { .table = { 8, mat3_elements } } },
{ "mat4", HONEY_TABLE, { .table = { 10, mat4_elements } } },
{ "affine", HONEY_TABLE, { .table = { 3, affine_elements } } },
{ "camera", HONEY_TABLE, { .table = { 3, camera_elements } } },
};
- honey_lua_create_table(L, cglm_elements, 9);
+ honey_lua_create_table(L, cglm_elements, 10);
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
@@ -202,6 +204,19 @@ int honey_cglm_vec3_add(lua_State* L)
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+int honey_cglm_vec3_sub(lua_State* L)
+{
+ float* a, *b, *dest;
+ honey_lua_parse_arguments(L, 3,
+ HONEY_USERDATA, &a,
+ HONEY_USERDATA, &b,
+ HONEY_USERDATA, &dest);
+ glm_vec3_sub(a, b, dest);
+ return 0;
+}
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+
int honey_cglm_vec3_adds(lua_State* L)
{
float a, *v, *dest;
@@ -359,6 +374,19 @@ int honey_cglm_vec4_adds(lua_State* L)
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+int honey_cglm_vec4_sub(lua_State* L)
+{
+ float* a, *b, *dest;
+ honey_lua_parse_arguments(L, 3,
+ HONEY_USERDATA, &a,
+ HONEY_USERDATA, &b,
+ HONEY_USERDATA, &dest);
+ glm_vec4_sub(a, b, dest);
+ return 0;
+}
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+
int honey_cglm_vec4_mul(lua_State* L)
{
float *a, *b, *dest;
diff --git a/src/cglm_bindings.h b/src/cglm_bindings.h
index ba7714e..61554e3 100644
--- a/src/cglm_bindings.h
+++ b/src/cglm_bindings.h
@@ -102,6 +102,16 @@ int honey_cglm_vec3_norm(lua_State* L);
*/
int honey_cglm_vec3_add(lua_State* L);
+/** @brief Subtract one vector from another.
+ *
+ * @param[in] a The first vector.
+ * @param[in] b The second vector.
+ * @param[out] dest Vector to fill with a - b
+ *
+ * @returns Nothing.
+ */
+int honey_cglm_vec3_sub(lua_State* L);
+
/** @brief Add a scalar to a vector.
*
* @param[in] a The scalar.
@@ -215,6 +225,16 @@ int honey_cglm_vec4_add(lua_State* L);
*/
int honey_cglm_vec4_adds(lua_State* L);
+/** @brief Subtract one vector from another.
+ *
+ * @param[in] a The first vector.
+ * @param[in] b The second vector.
+ * @param[out] dest vec4 to fill with a - b.
+ *
+ * @returns Nothing.
+ */
+int honey_cglm_vec4_sub(lua_State* L);
+
/** @param Component-wise multiply two vectors together.
*
* @param[in] a The first vector.
diff --git a/src/primitives/primitives.c b/src/primitives/primitives.c
index 1bfbe14..8293d4d 100644
--- a/src/primitives/primitives.c
+++ b/src/primitives/primitives.c
@@ -15,13 +15,30 @@ static int honey_mesh_lua_plane(lua_State* L)
return 1;
}
+static int honey_mesh_lua_cube(lua_State* L)
+{
+ float width, height, depth;
+ honey_lua_parse_arguments(L, 3,
+ HONEY_NUMBER, &width,
+ HONEY_NUMBER, &height,
+ HONEY_NUMBER, &depth);
+
+ honey_mesh* mesh = lua_newuserdata(L, sizeof(honey_mesh));
+ if (honey_mesh_new_textured_cube(mesh, width, height, depth) != HONEY_OK) {
+ lua_pushstring(L, "error encountered while building plane");
+ lua_error(L);
+ }
+ return 1;
+}
+
void honey_setup_primitives(lua_State* L)
{
honey_lua_element primitive_elements[] = {
{ "plane", HONEY_FUNCTION, { .function = honey_mesh_lua_plane } },
+ { "cube", HONEY_FUNCTION, { .function = honey_mesh_lua_cube } },
};
- honey_lua_create_table(L, primitive_elements, 1);
+ honey_lua_create_table(L, primitive_elements, 2);
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */