summaryrefslogtreecommitdiff
path: root/src/maths
diff options
context:
space:
mode:
authoromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-08-15 13:06:27 +1000
committeromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-08-15 13:06:27 +1000
commit938e3944fd7d55951e794224e6346488d3c701ea (patch)
tree74b1ffd98099a69392f3472768ea99ebe18c4586 /src/maths
parentd4df846c97a7fd216748806abdb729a11a0ce2ec (diff)
cone wip
Diffstat (limited to 'src/maths')
-rw-r--r--src/maths/primitives.c37
-rw-r--r--src/maths/primitives.h1
2 files changed, 38 insertions, 0 deletions
diff --git a/src/maths/primitives.c b/src/maths/primitives.c
index 05c31ca..3387084 100644
--- a/src/maths/primitives.c
+++ b/src/maths/primitives.c
@@ -2,6 +2,7 @@
#include "colours.h"
#include "log.h"
#include "maths.h"
+#include "maths_types.h"
#include "ral_types.h"
#include "render_types.h"
@@ -232,3 +233,39 @@ Geometry Geo_CreateUVsphere(f32 radius, u32 north_south_lines, u32 east_west_lin
return geo;
}
+
+Geometry Geo_CreateCylinder(f32 radius, f32 height, u32 resolution) {
+ TODO("implement cylinder meshing");
+}
+
+Geometry Geo_CreateCone(f32 radius, f32 height, u32 resolution) {
+ Vertex_darray* vertices = Vertex_darray_new(1);
+ u32_darray* indices = u32_darray_new(1);
+
+ // tip
+ VERT_3D(vertices, vec3(0.0, height, 0.0), VEC3_Y, vec2(0, 0)); // TODO: fix uvs
+
+ // base center
+ VERT_3D(vertices, VEC3_ZERO, VEC3_NEG_Y, vec2(0, 0)); // TODO: fix uvs
+
+ // base circle
+ f32 step = TAU / resolution;
+ for (u32 i = 0; i < resolution; i++) {
+ f32 x = cos(step * i) * radius;
+ f32 z = sin(step * i) * radius;
+ VERT_3D(vertices, vec3(x, 0.0, z), VEC3_NEG_Z, vec2(0, 0));
+ }
+
+ // sides
+ for (u32 i = 0; i < resolution; i++) {
+ }
+
+ Geometry geo = {
+ .format = VERTEX_STATIC_3D,
+ .vertices = vertices,
+ .has_indices = true,
+ .index_count = indices->len,
+ .indices = indices,
+ };
+ return geo;
+} \ No newline at end of file
diff --git a/src/maths/primitives.h b/src/maths/primitives.h
index bcf71c8..4965545 100644
--- a/src/maths/primitives.h
+++ b/src/maths/primitives.h
@@ -9,6 +9,7 @@
Geometry Geo_CreatePlane(f32x2 extents, u32 tiling_u, u32 tiling_v);
Geometry Geo_CreateCuboid(f32x3 extents);
Geometry Geo_CreateCylinder(f32 radius, f32 height, u32 resolution);
+Geometry Geo_CreateCone(f32 radius, f32 height, u32 resolution);
Geometry Geo_CreateUVsphere(f32 radius, u32 north_south_lines, u32 east_west_lines);
Geometry Geo_CreateIcosphere(f32 radius, f32 n_subdivisions);