Compare commits

..

No commits in common. "65dcd66f76074be8f977ca5cd08ee61d5fc03e30" and "9f4137dac9e33e9d8522e71412c5c5e7c08372e3" have entirely different histories.

5 changed files with 13 additions and 41 deletions

View File

@ -1,6 +0,0 @@
#ifndef MISC_UTILS_H
#define MISC_UTILS_H
#define ARR_LEN(ARR) sizeof(ARR) / sizeof(ARR[0])
#endif // !MISC_UTILS_H

View File

@ -4,11 +4,6 @@
#include "vector/vec.h"
#include "window/window.h"
typedef struct {
vec2i_t p0;
vec2i_t p1;
} line_t;
void draw_line(window_t *wnd, line_t line, colour_t colour);
void draw_line(window_t *wnd, vec2i_t p0, vec2i_t p1, colour_t colour);
#endif // !RASTERISER_H

View File

@ -1,4 +1,3 @@
#include "misc/misc_utils.h"
#include "rasteriser/rasteriser.h"
#include "vector/vec.h"
#include "window/window.h"
@ -23,22 +22,8 @@ int main(void) {
// i32 h_min = ((i32)window.half_height) * -1;
// i32 h_max = (i32)window.half_height;
line_t lines[] = {
(line_t){
(vec2i_t){.x = -300, .y = 0},
(vec2i_t){.x = 300, .y = 250},
},
(line_t){
(vec2i_t){.x = -200, .y = -100},
(vec2i_t){.x = 240, .y = 120},
},
(line_t){
(vec2i_t){.x = -50, .y = -200},
(vec2i_t){.x = 60, .y = 240},
},
};
u32 count = ARR_LEN(lines);
vec2i_t a = {.x = -300, .y = 0};
vec2i_t b = {.x = 300, .y = 250};
while (running) {
while (SDL_PollEvent(&event)) {
@ -51,9 +36,7 @@ int main(void) {
clear_window(&window, bg);
for (u32 i = 0; i < count; ++i) {
draw_line(&window, lines[i], (colour_t){.colour = 0xffffffff});
}
draw_line(&window, a, b, (colour_t){.colour = 0xffffffff});
swap_buffers(&window);
}

View File

@ -1,17 +1,16 @@
#include "rasteriser/rasteriser.h"
#include "c_cpp_aliases/aliases.h"
#include "vector/vec.h"
#include "window/window.h"
void draw_line(window_t *wnd, line_t line, colour_t colour) {
if (line.p1.x < line.p0.x) {
vec_swap(vec2i_t, line.p0, line.p1);
void draw_line(window_t *wnd, vec2i_t p0, vec2i_t p1, colour_t colour) {
if (p1.x < p0.x) {
vec_swap(vec2i_t, p0, p1);
}
i32 x0 = line.p0.x;
i32 y0 = line.p0.y;
i32 x1 = line.p1.x;
i32 y1 = line.p1.y;
i32 x0 = p0.x;
i32 y0 = p0.y;
i32 x1 = p1.x;
i32 y1 = p1.y;
f32 a = ((f32)y1 - y0) / ((f32)x1 - x0);
f32 y = y0;

View File

@ -1,6 +1,7 @@
#include "scene/scene.h"
#include "c_cpp_aliases/aliases.h"
#include "misc/misc_utils.h"
#define ARR_LEN(ARR) sizeof(ARR) / sizeof(ARR[0])
internal const sphere_t spheres[] = {
(sphere_t){