From 4ff6a6de18c7745e334176bad331be710efa0ffd Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Wed, 23 Apr 2025 17:12:04 -0500 Subject: [PATCH] wip --- example/q3bsp.cpp | 28 ++++++ model/icosphere/model.h | 197 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 225 insertions(+) create mode 100644 model/icosphere/model.h diff --git a/example/q3bsp.cpp b/example/q3bsp.cpp index 026257d..be838c2 100644 --- a/example/q3bsp.cpp +++ b/example/q3bsp.cpp @@ -63,6 +63,9 @@ #include "pk/models/mapobjects/gratelamp/gratetorch2.data.h" #include "pk/models/mapobjects/gratelamp/gratetorch2b.data.h" +#include "model/model.h" +#include "model/icosphere/model.h" + #include "font/font_bitmap.hpp" #include "font/verite_8x16/verite_8x16.data.h" #include "palette.hpp" @@ -420,6 +423,31 @@ void transfer_faces(uint8_t * buf, q3bsp_header_t * header, ta_parameter_writer& } } +void transfer_icosphere(ta_parameter_writer& writer, mat4x4& screen_trans) +{ + const struct model * model = &icosphere_model; + struct object * object = model->object[0]; + + float s = 10; + mat4x4 scale = { + s, 0, 0, 0, + 0, s, 0, 0, + 0, 0, s, 0, + 0, 0, 0, 1 + }; + + mat4x4 trans = screen_trans * scale; + + for (int i = 0; i < object->triangle_count; i++) { + const union triangle * tri = &object->triangle[i]; + vec3 a = trans * position[tri->v[0].position]; + vec3 b = trans * position[tri->v[1].position]; + vec3 c = trans * position[tri->v[2].position]; + + if (a.z < 0 && b.z < 0 && c.z < 0) return; + } +} + static inline void render_quad(ta_parameter_writer& writer, vec3 ap, vec3 bp, diff --git a/model/icosphere/model.h b/model/icosphere/model.h new file mode 100644 index 0000000..180ea3b --- /dev/null +++ b/model/icosphere/model.h @@ -0,0 +1,197 @@ +#pragma once +#include "../model.h" + +const vertex_position icosphere_position[] = { + {0.000000f, -1.000000f, 0.000000f}, + {0.723600f, -0.447215f, 0.525720f}, + {-0.276385f, -0.447215f, 0.850640f}, + {-0.894425f, -0.447215f, 0.000000f}, + {-0.276385f, -0.447215f, -0.850640f}, + {0.723600f, -0.447215f, -0.525720f}, + {0.276385f, 0.447215f, 0.850640f}, + {-0.723600f, 0.447215f, 0.525720f}, + {-0.723600f, 0.447215f, -0.525720f}, + {0.276385f, 0.447215f, -0.850640f}, + {0.894425f, 0.447215f, 0.000000f}, + {0.000000f, 1.000000f, 0.000000f}, +}; + +const vertex_texture icosphere_texture[] = { + {0.181819f, 0.000000f}, + {0.272728f, 0.157461f}, + {0.090910f, 0.157461f}, + {0.363637f, 0.000000f}, + {0.454546f, 0.157461f}, + {0.909091f, 0.000000f}, + {1.000000f, 0.157461f}, + {0.818182f, 0.157461f}, + {0.727273f, 0.000000f}, + {0.636364f, 0.157461f}, + {0.545455f, 0.000000f}, + {0.363637f, 0.314921f}, + {0.181819f, 0.314921f}, + {0.909091f, 0.314921f}, + {0.727273f, 0.314921f}, + {0.545455f, 0.314921f}, + {0.000000f, 0.314921f}, + {0.272728f, 0.472382f}, + {0.090910f, 0.472382f}, + {0.818182f, 0.472382f}, + {0.636364f, 0.472382f}, + {0.454546f, 0.472382f}, +}; + +const vertex_normal icosphere_normal[] = { + {0.1876f, -0.7947f, 0.5774f}, + {0.6071f, -0.7947f, -0.0000f}, + {-0.4911f, -0.7947f, 0.3568f}, + {-0.4911f, -0.7947f, -0.3568f}, + {0.1876f, -0.7947f, -0.5774f}, + {0.9822f, -0.1876f, -0.0000f}, + {0.3035f, -0.1876f, 0.9342f}, + {-0.7946f, -0.1876f, 0.5774f}, + {-0.7946f, -0.1876f, -0.5774f}, + {0.3035f, -0.1876f, -0.9342f}, + {0.7946f, 0.1876f, 0.5774f}, + {-0.3035f, 0.1876f, 0.9342f}, + {-0.9822f, 0.1876f, -0.0000f}, + {-0.3035f, 0.1876f, -0.9342f}, + {0.7946f, 0.1876f, -0.5774f}, + {0.4911f, 0.7947f, 0.3568f}, + {-0.1876f, 0.7947f, 0.5774f}, + {-0.6071f, 0.7947f, -0.0000f}, + {-0.1876f, 0.7947f, -0.5774f}, + {0.4911f, 0.7947f, -0.3568f}, +}; + +const union triangle icosphere_Icosphere_triangle[] = { + { .v = { + {0, 0, 0}, + {1, 1, 0}, + {2, 2, 0}, + }}, + { .v = { + {1, 1, 1}, + {0, 3, 1}, + {5, 4, 1}, + }}, + { .v = { + {0, 5, 2}, + {2, 6, 2}, + {3, 7, 2}, + }}, + { .v = { + {0, 8, 3}, + {3, 7, 3}, + {4, 9, 3}, + }}, + { .v = { + {0, 10, 4}, + {4, 9, 4}, + {5, 4, 4}, + }}, + { .v = { + {1, 1, 5}, + {5, 4, 5}, + {10, 11, 5}, + }}, + { .v = { + {2, 2, 6}, + {1, 1, 6}, + {6, 12, 6}, + }}, + { .v = { + {3, 7, 7}, + {2, 6, 7}, + {7, 13, 7}, + }}, + { .v = { + {4, 9, 8}, + {3, 7, 8}, + {8, 14, 8}, + }}, + { .v = { + {5, 4, 9}, + {4, 9, 9}, + {9, 15, 9}, + }}, + { .v = { + {1, 1, 10}, + {10, 11, 10}, + {6, 12, 10}, + }}, + { .v = { + {2, 2, 11}, + {6, 12, 11}, + {7, 16, 11}, + }}, + { .v = { + {3, 7, 12}, + {7, 13, 12}, + {8, 14, 12}, + }}, + { .v = { + {4, 9, 13}, + {8, 14, 13}, + {9, 15, 13}, + }}, + { .v = { + {5, 4, 14}, + {9, 15, 14}, + {10, 11, 14}, + }}, + { .v = { + {6, 12, 15}, + {10, 11, 15}, + {11, 17, 15}, + }}, + { .v = { + {7, 16, 16}, + {6, 12, 16}, + {11, 18, 16}, + }}, + { .v = { + {8, 14, 17}, + {7, 13, 17}, + {11, 19, 17}, + }}, + { .v = { + {9, 15, 18}, + {8, 14, 18}, + {11, 20, 18}, + }}, + { .v = { + {10, 11, 19}, + {9, 15, 19}, + {11, 21, 19}, + }}, +}; + +const union quadrilateral icosphere_Icosphere_quadrilateral[] = { +}; + +const union line icosphere_Icosphere_line[] = { +}; + +const struct object icosphere_Icosphere = { + .triangle = &icosphere_Icosphere_triangle[0], + .quadrilateral = &icosphere_Icosphere_quadrilateral[0], + .line = &icosphere_Icosphere_line[0], + .triangle_count = 20, + .quadrilateral_count = 0, + .line_count = 0, + .material = 0, +}; + +const struct object * icosphere_object[] = { + &icosphere_Icosphere, +}; + +const struct model icosphere_model = { + .position = icosphere_position, + .texture = icosphere_texture, + .normal = icosphere_normal, + .object = icosphere_object, + .object_count = 1 +}; +