Wrap all entities and shapes

This commit is contained in:
Camden Dixie O'Brien
2025-10-14 19:03:02 +01:00
parent ce6328e135
commit c4d0266673
3 changed files with 32 additions and 50 deletions

View File

@@ -32,7 +32,7 @@ static void set_pixel(uint32_t x, uint32_t y)
fbs[back].buf[offset] = 0xff'ff'ff;
}
static void draw_line(vec3_t v1, vec3_t v2, uint8_t flags)
static void draw_line(vec3_t v1, vec3_t v2)
{
const float delta_x = v2.x - v1.x;
const float delta_y = v2.y - v1.y;
@@ -43,20 +43,16 @@ static void draw_line(vec3_t v1, vec3_t v2, uint8_t flags)
for (unsigned i = 0; i <= step; ++i) {
float x = roundf(v1.x + i * step_x);
float y = roundf(v1.y + i * step_y);
if (x >= width)
x -= width;
else if (x < 0)
x += width;
if (flags & WRAP) {
if (x >= width)
x -= width;
else if (x < 0)
x += width;
if (y >= height)
y -= height;
else if (y < 0)
y += height;
} else if (x >= width || x < 0 || y >= height || y < 0) {
continue;
}
float y = roundf(v1.y + i * step_y);
if (y >= height)
y -= height;
else if (y < 0)
y += height;
set_pixel(x, y);
}
@@ -146,7 +142,7 @@ void renderer_swap()
}
void renderer_draw(
const vec2_t *vs, unsigned count, mat3_t model, uint8_t flags)
const vec2_t *vs, unsigned count, mat3_t model, bool connect)
{
mat3_t transform = mat3_mul_mat3(view, model);
assert(count < MAX_VERTS);
@@ -154,8 +150,7 @@ void renderer_draw(
for (unsigned i = 0; i < count; ++i)
vert_buf[i] = mat3_mul_vec3(transform, vec2_extend(vs[i]));
for (unsigned i = 1; i < count; ++i)
draw_line(vert_buf[i - 1], vert_buf[i], flags);
if (flags & CONNECT)
draw_line(vert_buf[count - 1], vert_buf[0], flags);
draw_line(vert_buf[i - 1], vert_buf[i]);
if (connect)
draw_line(vert_buf[count - 1], vert_buf[0]);
}