From 13949ca02bcf9fcdfcc48ea7949f617553a260b6 Mon Sep 17 00:00:00 2001 From: omniscient <17525998+omnisci3nce@users.noreply.github.com> Date: Tue, 13 Aug 2024 17:25:13 +1000 Subject: allow UV tiling for plane geometry --- src/maths/primitives.c | 21 +++++++++++---------- src/maths/primitives.h | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) (limited to 'src/maths') diff --git a/src/maths/primitives.c b/src/maths/primitives.c index 1e1e673..13fa81b 100644 --- a/src/maths/primitives.c +++ b/src/maths/primitives.c @@ -20,7 +20,8 @@ Vec3 plane_vertex_positions[] = { (Vec3){ 0.5, 0, 0.5 }, }; -Geometry Geo_CreatePlane(f32x2 extents) { +Geometry Geo_CreatePlane(f32x2 extents, u32 tiling_u, u32 tiling_v) { + CASSERT(tiling_u >= 1 && tiling_v >= 1); Vertex_darray* vertices = Vertex_darray_new(4); u32_darray* indices = u32_darray_new(vertices->len); @@ -30,15 +31,15 @@ Geometry Geo_CreatePlane(f32x2 extents) { vert_pos[i].x *= extents.x; vert_pos[i].z *= extents.y; } - VERT_3D(vertices, vert_pos[0], VEC3_Y, vec2(0, 0)); // back left - VERT_3D(vertices, vert_pos[1], VEC3_Y, vec2(1, 0)); // back right - VERT_3D(vertices, vert_pos[2], VEC3_Y, vec2(0, 1)); // front left - VERT_3D(vertices, vert_pos[3], VEC3_Y, vec2(1, 1)); // front right - - push_triangle(indices, 0, 1, 2); - push_triangle(indices, 2, 1, 3); - // push_triangle(indices, 2, 1, 0); - // push_triangle(indices, 3, 2, 1); + VERT_3D(vertices, vert_pos[0], VEC3_Y, vec2(0, 0)); // back left + VERT_3D(vertices, vert_pos[1], VEC3_Y, vec2(1 * tiling_u, 0 * tiling_v)); // back right + VERT_3D(vertices, vert_pos[2], VEC3_Y, vec2(0, 1 * tiling_v)); // front left + VERT_3D(vertices, vert_pos[3], VEC3_Y, vec2(1 * tiling_u, 1 * tiling_v)); // front right + + // push_triangle(indices, 0, 1, 2); + // push_triangle(indices, 2, 1, 3); + push_triangle(indices, 2, 1, 0); + push_triangle(indices, 1,2,3); for (int i = 0; i < 4; i++) { printf("Vertex %d: (%f, %f, %f)\n", i, vert_pos[i].x, vert_pos[i].y, vert_pos[i].z); diff --git a/src/maths/primitives.h b/src/maths/primitives.h index f7b390d..bcf71c8 100644 --- a/src/maths/primitives.h +++ b/src/maths/primitives.h @@ -6,7 +6,7 @@ #include "maths_types.h" #include "render_types.h" -Geometry Geo_CreatePlane(f32x2 extents); +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_CreateUVsphere(f32 radius, u32 north_south_lines, u32 east_west_lines); -- cgit v1.2.3-70-g09d2