Add levelling
This commit is contained in:
38
renderer.c
38
renderer.c
@@ -20,6 +20,8 @@ static int front, back;
|
||||
static uint32_t width, height;
|
||||
static mat3_t view;
|
||||
|
||||
static bool wrap;
|
||||
|
||||
static vec3_t vert_buf[MAX_VERTS];
|
||||
|
||||
static void page_flip_handler(int, unsigned, unsigned, unsigned, void *)
|
||||
@@ -34,6 +36,13 @@ static void set_pixel(uint32_t x, uint32_t y)
|
||||
|
||||
static void draw_line(vec3_t v1, vec3_t v2)
|
||||
{
|
||||
v1.x /= v1.z;
|
||||
v1.y /= v1.z;
|
||||
v1.z = 1;
|
||||
v2.x /= v2.z;
|
||||
v2.y /= v2.z;
|
||||
v2.z = 1;
|
||||
|
||||
const float delta_x = v2.x - v1.x;
|
||||
const float delta_y = v2.y - v1.y;
|
||||
const float step = fmaxf(fabsf(delta_x), fabsf(delta_y));
|
||||
@@ -43,16 +52,20 @@ static void draw_line(vec3_t v1, vec3_t v2)
|
||||
|
||||
for (unsigned i = 0; i <= step; ++i) {
|
||||
float x = roundf(v1.x + i * step_x);
|
||||
if (x >= width)
|
||||
x -= width;
|
||||
else if (x < 0)
|
||||
x += width;
|
||||
|
||||
float y = roundf(v1.y + i * step_y);
|
||||
if (y >= height)
|
||||
y -= height;
|
||||
else if (y < 0)
|
||||
y += height;
|
||||
|
||||
if (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;
|
||||
}
|
||||
|
||||
set_pixel(x, y);
|
||||
}
|
||||
@@ -89,6 +102,8 @@ renderer_params_t renderer_init()
|
||||
width = mode.hdisplay;
|
||||
height = mode.vdisplay;
|
||||
|
||||
wrap = true;
|
||||
|
||||
const float aspect = (float)width / (float)height;
|
||||
const float scale = (float)height / 2.0f;
|
||||
view = (mat3_t) {
|
||||
@@ -136,6 +151,11 @@ void renderer_swap()
|
||||
back = (back + 1) & 1;
|
||||
}
|
||||
|
||||
void renderer_set_wrap(bool enable)
|
||||
{
|
||||
wrap = enable;
|
||||
}
|
||||
|
||||
void renderer_clear()
|
||||
{
|
||||
memset(fbs[back].buf, 0, fbs[back].size);
|
||||
|
||||
Reference in New Issue
Block a user