summaryrefslogtreecommitdiff
path: root/src/geometry.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/geometry.c')
-rw-r--r--src/geometry.c39
1 files changed, 20 insertions, 19 deletions
diff --git a/src/geometry.c b/src/geometry.c
index 05414d3..46bb058 100644
--- a/src/geometry.c
+++ b/src/geometry.c
@@ -1,12 +1,5 @@
#include <celeritas.h>
-typedef struct static_3d_vert {
- vec4 pos;
- vec4 norm;
- vec2 uv;
- vec2 pad;
-} static_3d_vert;
-
vertex_desc static_3d_vertex_format() {
vertex_desc desc;
desc.label = "Static 3D Vertex";
@@ -19,18 +12,23 @@ vertex_desc static_3d_vertex_format() {
return desc;
}
+void print_static_3d_vert(static_3d_vert* vertex_data) {
+ printf("Pos (%.2f, %.2f %.2f)\n", vertex_data->pos.x, vertex_data->pos.y, vertex_data->pos.z);
+}
+
geometry geo_cuboid(f32 x_scale, f32 y_scale, f32 z_scale) {
- vec4 BACK_BOT_LEFT = (vec4){ 0, 0, 0, 0 };
- vec4 BACK_BOT_RIGHT = (vec4){ 1, 0, 0, 0 };
- vec4 BACK_TOP_LEFT = (vec4){ 0, 1, 0, 0 };
- vec4 BACK_TOP_RIGHT = (vec4){ 1, 1, 0, 0 };
- vec4 FRONT_BOT_LEFT = (vec4){ 0, 0, 1, 0 };
- vec4 FRONT_BOT_RIGHT = (vec4){ 1, 0, 1, 0 };
- vec4 FRONT_TOP_LEFT = (vec4){ 0, 1, 1, 0 };
- vec4 FRONT_TOP_RIGHT = (vec4){ 1, 1, 1, 0 };
+ vec4 BACK_BOT_LEFT = (vec4){ 0, 0, 0, 1 };
+ vec4 BACK_BOT_RIGHT = (vec4){ 1, 0, 0, 1 };
+ vec4 BACK_TOP_LEFT = (vec4){ 0, 1, 0, 1 };
+ vec4 BACK_TOP_RIGHT = (vec4){ 1, 1, 0, 1 };
+ vec4 FRONT_BOT_LEFT = (vec4){ 0, 0, 1, 1 };
+ vec4 FRONT_BOT_RIGHT = (vec4){ 1, 0, 1, 1 };
+ vec4 FRONT_TOP_LEFT = (vec4){ 0, 1, 1, 1 };
+ vec4 FRONT_TOP_RIGHT = (vec4){ 1, 1, 1, 1 };
// allocate the data
- static_3d_vert* vertices = malloc(36 * 64);
+ size_t buffer_length = 36 * 64;
+ static_3d_vert* vertices = malloc(buffer_length);
vertices[0] = (static_3d_vert){ .pos = BACK_TOP_RIGHT, .norm = (v3tov4(VEC3_NEG_Z)), .uv = { 0, 0 } };
vertices[1] = (static_3d_vert){ .pos = BACK_BOT_LEFT, .norm = v3tov4(VEC3_NEG_Z), .uv = { 0, 1 } };
@@ -79,7 +77,10 @@ geometry geo_cuboid(f32 x_scale, f32 y_scale, f32 z_scale) {
vertices[34] = (static_3d_vert){ .pos = FRONT_BOT_LEFT, .norm = v3tov4(VEC3_NEG_X), .uv = { 0, 0 } };
vertices[35] = (static_3d_vert){ .pos = FRONT_TOP_LEFT, .norm = v3tov4(VEC3_NEG_X), .uv = { 0, 0 } };
- return (geometry){
- .vertex_format = static_3d_vertex_format(), .vertex_data = vertices, .has_indices = false, .indices = NULL
- };
+ return (geometry){ .vertex_format = static_3d_vertex_format(),
+ .vertex_data = vertices,
+ .data_length = buffer_length,
+ .n_vertices = 36,
+ .has_indices = false,
+ .indices = NULL };
} \ No newline at end of file