summaryrefslogtreecommitdiff
path: root/src/maths/primitives.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/maths/primitives.c')
-rw-r--r--src/maths/primitives.c261
1 files changed, 135 insertions, 126 deletions
diff --git a/src/maths/primitives.c b/src/maths/primitives.c
index 55ff5fc..310fc98 100644
--- a/src/maths/primitives.c
+++ b/src/maths/primitives.c
@@ -1,4 +1,5 @@
#include "primitives.h"
+#include "maths.h"
// vertices
f32 plane_vertex_positions[] = {
@@ -13,9 +14,9 @@ geometry_data geo_create_plane(f32x2 extents) {
vertex_format format = VERTEX_STATIC_3D;
vertex_darray* vertices = vertex_darray_new(4);
- vertex_darray_push(vertices, (vertex){ .static_3d = { .position = } });
+ // vertex_darray_push(vertices, (vertex){ .static_3d = { .position = } });
- return (geometry_data) { .format = format, .vertices =.has_indices = true, }
+ // return (geometry_data) { .format = format, .vertices =.has_indices = true, }
}
// OLD
@@ -33,130 +34,132 @@ 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;
- }
+ // // 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;
@@ -174,4 +177,10 @@ static model_handle prim_cube_new(core* core) {
u32 index = (u32)model_darray_len(core->models);
model_darray_push_copy(core->models, &model);
return (model_handle){ .raw = index };
+}
+
+// --- Spheres
+
+geometry_data geo_create_uvsphere(f32 radius, f32 north_south_lines, f32 east_west_lines) {
+ // TODO
} \ No newline at end of file