Fix wrapping
This commit is contained in:
23
renderer.c
23
renderer.c
@@ -5,7 +5,6 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <xf86drm.h>
|
#include <xf86drm.h>
|
||||||
@@ -31,9 +30,7 @@ static void page_flip_handler(int, unsigned, unsigned, unsigned, void *)
|
|||||||
|
|
||||||
static void set_pixel(uint32_t x, uint32_t y)
|
static void set_pixel(uint32_t x, uint32_t y)
|
||||||
{
|
{
|
||||||
x %= width;
|
const uint32_t offset = y * (fbs[back].pitch / 4) + x;
|
||||||
y %= height;
|
|
||||||
const uint32_t offset = y * (fbs[back].pitch / 4) + x;
|
|
||||||
fbs[back].buf[offset] = 0xff'ff'ff;
|
fbs[back].buf[offset] = 0xff'ff'ff;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,8 +42,22 @@ static void draw_line(vec3_t v1, vec3_t v2)
|
|||||||
if (step != 0.0) {
|
if (step != 0.0) {
|
||||||
const float step_x = delta_x / step;
|
const float step_x = delta_x / step;
|
||||||
const float step_y = delta_y / step;
|
const float step_y = delta_y / step;
|
||||||
for (unsigned i = 0; i <= step; ++i)
|
|
||||||
set_pixel(roundf(v1.x + i * step_x), roundf(v1.y + i * step_y));
|
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;
|
||||||
|
|
||||||
|
set_pixel(x, y);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
set_pixel(roundf(v1.x), roundf(v1.y));
|
set_pixel(roundf(v1.x), roundf(v1.y));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user