summaryrefslogtreecommitdiff
path: root/src/maths/primitives.h
diff options
context:
space:
mode:
authoromnisci3nce <omniscient.oce@gmail.com>2024-04-27 15:37:52 +1000
committeromnisci3nce <omniscient.oce@gmail.com>2024-04-27 15:37:52 +1000
commit4e6897aa8c8769a556ad58081eba5a90226e551d (patch)
tree8b87c4e75d07248360636ab6df3562f8871fb569 /src/maths/primitives.h
parentf5c7f55fcfb4df4b9aa67b11a847340f0d8c95c4 (diff)
wip
Diffstat (limited to 'src/maths/primitives.h')
-rw-r--r--src/maths/primitives.h162
1 files changed, 6 insertions, 156 deletions
diff --git a/src/maths/primitives.h b/src/maths/primitives.h
index ed52c8c..3e0cc5f 100644
--- a/src/maths/primitives.h
+++ b/src/maths/primitives.h
@@ -3,161 +3,11 @@
#include <assert.h>
#include <stdlib.h>
#include "core.h"
-#include "maths.h"
+#include "maths_types.h"
#include "render_types.h"
-static const vec3 BACK_BOT_LEFT = (vec3){ 0, 0, 0 };
-static const vec3 BACK_BOT_RIGHT = (vec3){ 1, 0, 0 };
-static const vec3 BACK_TOP_LEFT = (vec3){ 0, 1, 0 };
-static const vec3 BACK_TOP_RIGHT = (vec3){ 1, 1, 0 };
-static const vec3 FRONT_BOT_LEFT = (vec3){ 0, 0, 1 };
-static const vec3 FRONT_BOT_RIGHT = (vec3){ 1, 0, 1 };
-static const vec3 FRONT_TOP_LEFT = (vec3){ 0, 1, 1 };
-static const vec3 FRONT_TOP_RIGHT = (vec3){ 1, 1, 1 };
-
-static mesh prim_cube_mesh_create() {
- mesh cube = { 0 };
- cube.vertices = vertex_darray_new(36);
-
- // back faces
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = BACK_BOT_LEFT, .normal = VEC3_NEG_Z, .uv = (vec2){ 0, 1 } });
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = BACK_TOP_LEFT, .normal = VEC3_NEG_Z, .uv = (vec2){ 0, 0 } });
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = BACK_TOP_RIGHT, .normal = VEC3_NEG_Z, .uv = (vec2){ 1, 0 } });
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = BACK_TOP_RIGHT, .normal = VEC3_NEG_Z, .uv = (vec2){ 1, 0 } });
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = BACK_BOT_RIGHT, .normal = VEC3_NEG_Z, .uv = (vec2){ 1, 1 } });
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = BACK_BOT_LEFT, .normal = VEC3_NEG_Z, .uv = (vec2){ 0, 1 } });
-
- // front faces
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = FRONT_BOT_LEFT, .normal = VEC3_Z, .uv = (vec2){ 0, 1 } });
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = FRONT_TOP_RIGHT, .normal = VEC3_Z, .uv = (vec2){ 1, 0 } });
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = FRONT_TOP_LEFT, .normal = VEC3_Z, .uv = (vec2){ 0, 0 } });
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = FRONT_BOT_LEFT, .normal = VEC3_Z, .uv = (vec2){ 0, 1 } });
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = FRONT_BOT_RIGHT, .normal = VEC3_Z, .uv = (vec2){ 1, 1 } });
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = FRONT_TOP_RIGHT, .normal = VEC3_Z, .uv = (vec2){ 1, 0 } });
-
- // top faces
- vertex_darray_push(cube.vertices,
- (vertex){ .position = BACK_TOP_LEFT, .normal = VEC3_Y, .uv = (vec2){ 0, 0 } });
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = FRONT_TOP_LEFT, .normal = VEC3_Y, .uv = (vec2){ 0, 1 } });
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = FRONT_TOP_RIGHT, .normal = VEC3_Y, .uv = (vec2){ 1, 1 } });
- vertex_darray_push(cube.vertices,
- (vertex){ .position = BACK_TOP_LEFT, .normal = VEC3_Y, .uv = (vec2){ 0, 0 } });
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = FRONT_TOP_RIGHT, .normal = VEC3_Y, .uv = (vec2){ 1, 1 } });
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = BACK_TOP_RIGHT, .normal = VEC3_Y, .uv = (vec2){ 1, 0 } });
-
- // bottom faces
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = BACK_BOT_LEFT, .normal = VEC3_NEG_Y, .uv = (vec2){ 0 } });
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = FRONT_BOT_RIGHT, .normal = VEC3_NEG_Y, .uv = (vec2){ 0 } });
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = FRONT_BOT_LEFT, .normal = VEC3_NEG_Y, .uv = (vec2){ 0 } });
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = BACK_BOT_LEFT, .normal = VEC3_NEG_Y, .uv = (vec2){ 0 } });
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = BACK_BOT_RIGHT, .normal = VEC3_NEG_Y, .uv = (vec2){ 0 } });
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = FRONT_BOT_RIGHT, .normal = VEC3_NEG_Y, .uv = (vec2){ 0 } });
-
- // right faces
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = FRONT_TOP_RIGHT, .normal = VEC3_X, .uv = (vec2){ 0, 0 } });
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = BACK_BOT_RIGHT, .normal = VEC3_X, .uv = (vec2){ 1, 1 } });
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = BACK_TOP_RIGHT, .normal = VEC3_X, .uv = (vec2){ 1, 0 } });
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = BACK_BOT_RIGHT, .normal = VEC3_X, .uv = (vec2){ 1, 1 } });
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = FRONT_TOP_RIGHT, .normal = VEC3_X, .uv = (vec2){ 0, 0 } });
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = FRONT_BOT_RIGHT, .normal = VEC3_X, .uv = (vec2){ 0, 1 } });
-
- // left faces
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = FRONT_TOP_LEFT, .normal = VEC3_NEG_X, .uv = (vec2){ 0 } });
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = BACK_TOP_LEFT, .normal = VEC3_NEG_X, .uv = (vec2){ 0 } });
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = BACK_BOT_LEFT, .normal = VEC3_NEG_X, .uv = (vec2){ 0 } });
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = BACK_BOT_LEFT, .normal = VEC3_NEG_X, .uv = (vec2){ 0 } });
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = FRONT_BOT_LEFT, .normal = VEC3_NEG_X, .uv = (vec2){ 0 } });
- vertex_darray_push(
- cube.vertices,
- (vertex){ .position = FRONT_TOP_LEFT, .normal = VEC3_NEG_X, .uv = (vec2){ 0 } });
-
- cube.indices_len = cube.vertices->len;
- cube.indices = malloc(sizeof(u32) * cube.indices_len);
-
- for (u32 i = 0; i < cube.indices_len; i++) {
- cube.indices[i] = i;
- }
-
- cube.has_indices = true;
-
- return cube;
-}
-
-/** @brief create a new model with the shape of a cube */
-static model_handle prim_cube_new(core* core) {
- model model = { 0 };
- mesh cube = prim_cube_mesh_create();
-
- mesh_darray_push(model.meshes, cube);
- assert(mesh_darray_len(model.meshes) == 1);
-
- u32 index = (u32)model_darray_len(core->models);
- model_darray_push_copy(core->models, &model);
- return (model_handle){ .raw = index };
-} \ No newline at end of file
+geometry_data geo_create_plane(f32x2 extents);
+geometry_data geo_create_cuboid(f32x3 extents);
+geometry_data geo_create_cylinder(f32 radius, f32 height, u32 resolution);
+geometry_data geo_create_uvsphere(f32 radius, f32 north_south_lines, f32 east_west_lines);
+geometry_data geo_create_icosphere(f32 radius, f32 n_subdivisions); \ No newline at end of file