organized project directory. makefile broken

This commit is contained in:
2026-07-07 08:09:54 -07:00
parent 1fce028eea
commit f09db214cc
20 changed files with 32 additions and 63 deletions
+95
View File
@@ -0,0 +1,95 @@
#pragma once
#include <stdint.h>
#include "../datatypes.cpp"
#include "../helpers.cpp"
#include "../buffer.cpp"
namespace UwU {
// line
class Line {
private:
// plot lines if m <= 1
void lineLow(int16_t ix0, int16_t iy0, int16_t ix1, int16_t iy1, Buffer buffer, Color color) {
int16_t dx = ix1 - ix0;
int16_t dy = iy1 - iy0;
int16_t yi = 1;
if (dy < 0) {
yi = -1;
dy = -dy;
}
int16_t d = (2 * dy) - dx;
int16_t y = iy0;
for (int16_t x = ix0; x < ix1; x++) {
buffer.drawPixel(Coord2((uint16_t)x, (uint16_t)y), color);
if (d > 0) {
y += yi;
d += (2 * (dy - dx));
} else {
d += (2 * dy);
}
}
return;
}
// plot lines if m >1
void lineHigh(int16_t ix0, int16_t iy0, int16_t ix1, int16_t iy1, Buffer buffer, Color color) {
int16_t dx = ix1 - ix0;
int16_t dy = iy1 - iy0;
int16_t xi = 1;
if (dx < 0) {
xi = -1;
dx = -dx;
}
int16_t d = (2 * dx) - dy;
int16_t x = ix0;
for (int16_t y = iy0; y < iy1; y++) {
buffer.drawPixel(Coord2((uint16_t)x, (uint16_t)y), color);
if (d > 0) {
x += xi;
d += (2 * (dx - dy));
} else {
d += (2 * dx);
}
}
return;
}
public:
Line(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
this->x0 = x0;
this->y0 = y0;
this->x1 = x1;
this->y1 = y1;
}
Line() {}
uint16_t x0;
uint16_t y0;
uint16_t x1;
uint16_t y1;
// Uses Bresenham's line algorithm to draw line of any slope
void draw (Buffer buffer, Color color) {
if (x0 > buffer.width || y0 > buffer.height || x1 > buffer.width || y1 > buffer.height) {return;};
int16_t ix0 = x0;
int16_t iy0 = y0;
int16_t ix1 = x1;
int16_t iy1 = y1;
if (abs(iy1 - iy0) < abs(ix1 - ix0)) {
if (ix0 > ix1) {
lineLow(ix1, iy1, ix0, iy0, buffer, color);
} else {
lineLow(ix0, iy0, ix1, iy1, buffer, color);
}
} else {
if (iy0 > iy1) {
lineHigh(ix1, iy1, ix0, iy0, buffer, color);
} else {
lineHigh(ix0, iy0, ix1, iy1, buffer, color);
}
}
return;
}
};
}
+28
View File
@@ -0,0 +1,28 @@
#pragma once
#include <stdint.h>
#include "../datatypes.cpp"
#include "../helpers.cpp"
#include "../buffer.cpp"
namespace UwU {
// point
class Point {
public:
Point(uint16_t x, uint16_t y) {
this->x = x;
this->y = y;
}
Point() {}
uint16_t x;
uint16_t y;
// Draw a rectangle
void draw (Buffer buffer, Color color) {
if (x > buffer.width || y > buffer.height) {return;};
buffer.drawPixel(Coord2(x, y), color);
return;
}
};
}
+37
View File
@@ -0,0 +1,37 @@
#pragma once
#include <stdint.h>
#include "../datatypes.cpp"
#include "../helpers.cpp"
#include "../buffer.cpp"
#include "../shaders/shader.cpp"
namespace UwU {
// rectangle
class Rectangle {
public:
Rectangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
this->x0 = x0;
this->y0 = y0;
this->x1 = x1;
this->y1 = y1;
}
Rectangle() {}
uint16_t x0;
uint16_t y0;
uint16_t x1;
uint16_t y1;
// Draw a rectangle
void draw (Buffer buffer, Shader shader) {
if (x0 > buffer.width || y0 > buffer.height || x1 > buffer.width || y1 > buffer.height) {return;};
for (uint16_t y = y0; y < y1; y++) {
for (uint16_t x = x0; x < x1; x++) {
buffer.drawPixelShader(Coord2(x, y), shader);
}
}
return;
}
};
}
+59
View File
@@ -0,0 +1,59 @@
#pragma once
#include <stdint.h>
#include "../datatypes.cpp"
#include "../helpers.cpp"
#include "../buffer.cpp"
namespace UwU {
// trapezoid (horizontally constrained)
class Trapezoid {
public:
Trapezoid(uint16_t y0, uint16_t y1, uint16_t xl0, uint16_t xl1, uint16_t xr0, uint16_t xr1) {
this->y0 = y0;
this->y1 = y1;
this->xl0 = xl0;
this->xl1 = xl1;
this->xr0 = xr0;
this->xr1 = xr1;
}
Trapezoid() {}
uint16_t y0;
uint16_t y1;
uint16_t xl0;
uint16_t xl1;
uint16_t xr0;
uint16_t xr1;
// Draw a horizontally bounded trapezoid
// y1 >= y0
// todo move to private and add public checks
void draw (Buffer buffer, Color color) {
// printf("(%u, %u, %u, %u, %u, %u)", coords.y0, coords.y1, coords.xl0, coords.xl1, coords.xr0, coords.xr1);
uint16_t height = 1 + y1 - y0;
int16_t LeftBound[height];
int16_t RightBound[height];
Helpers::bresenham(0, xl0, y1 - y0, xl1, LeftBound);
Helpers::bresenham(0, xr0, y1 - y0, xr1, RightBound);
// printf("leftbound\n");
for (uint16_t i = 0; i < height; i++) {
// printf("(%u, %u)\n", i, LeftBound[i]);
}
// printf("rightbound\n");
for (uint16_t i = 0; i < height; i++) {
// printf("(%u, %u)\n", i, RightBound[i]);
}
for (uint16_t i = 0; i < height; i++) {
for (uint16_t x = LeftBound[i]; x <= RightBound[i]; x++) {
// printf("(%u, %u)", x, i + coords.y0);
buffer.drawPixel(Coord2(x, i + y0), color);
}
}
return;
}
};
}
+125
View File
@@ -0,0 +1,125 @@
#pragma once
#include <stdint.h>
#include "../datatypes.cpp"
#include "../helpers.cpp"
#include "../buffer.cpp"
namespace UwU {
class Triangle {
private:
public:
Triangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) {
this->x0 = x0;
this->y0 = y0;
this->x1 = x1;
this->y1 = y1;
this->x2 = x2;
this->y2 = y2;
}
Triangle() {}
uint16_t x0;
uint16_t y0;
uint16_t x1;
uint16_t y1;
uint16_t x2;
uint16_t y2;
// Draw a triangle
void draw (Buffer buffer, Color color) {
Coord2 top = Coord2();
Coord2 mid = Coord2();
Coord2 btm = Coord2();
// cases: left-handed, right-handed
if (y0 <= y1 && y0 <= y2) {
top.x = x0;
top.y = y0;
if (y1 < y2) {
mid.x = x1;
mid.y = y1;
btm.x = x2;
btm.y = y2;
} else {
mid.x = x2;
mid.y = y2;
btm.x = x1;
btm.y = y1;
}
} else if (y1 <= y0 && y1 <= y2) {
top.x = x1;
top.y = y1;
if (y0 < y2) {
mid.x = x0;
mid.y = y0;
btm.x = x2;
btm.y = y2;
} else {
mid.x = x2;
mid.y = y2;
btm.x = x0;
btm.y = y0;
}
} else {
top.x = x2;
top.y = y2;
if (y0 < y1) {
mid.y = y0;
mid.x = x0;
btm.x = x1;
btm.y = y1;
} else {
mid.x = x1;
mid.y = y1;
btm.x = x0;
btm.y = y0;
}
}
// printf("top: (%u, %u)\n", top.x, top.y);
// printf("mid: (%u, %u)\n", mid.x, mid.y);
// printf("btm: (%u, %u)\n", btm.x, btm.y);
uint16_t height = 1 + btm.y - top.y;
int16_t longBound[height];
int16_t splitBound[height];
// int16_t rightBound[height];
Helpers::bresenham(0, top.x, height - 1, btm.x, longBound);
// printf("longBound\n");
if ((int16_t)mid.x < longBound[mid.y - top.y]) {
// left-handed triangle
// printf("left-handed\n");
// rightBound = longBound;
Helpers::bresenham(0, top.x, mid.y - top.y, mid.x, splitBound);
// printf("splitTop\n");
Helpers::bresenham(mid.y - top.y, mid.x, height - 1, btm.x, splitBound);
// printf("splitBtm\n");
// for (uint16_t i = 0; i < height; i++) {
// printf("(%u, %u)\n", i, splitBound[i]);
// }
for (uint16_t i = 0; i < height; i++) {
for (uint16_t x = (uint16_t)splitBound[i]; x <= (uint16_t)longBound[i]; x++) {
// Helpers::putPixel(buffer, x, i + (uint32_t)top.y, color.r, color.g, color.b, color.a);
buffer.drawPixel(Coord2(x, i + (uint16_t)top.y), color);
}
}
} else {
// right-handed triangle
// printf("right-handed\n");
// leftBound = longBound;
Helpers::bresenham(0, top.x, mid.y - top.y, mid.x, splitBound);
// printf("splitTop\n");
Helpers::bresenham(mid.y - top.y, mid.x, height - 1, btm.x, splitBound);
// printf("splitBtm\n");
for (uint16_t i = 0; i < height; i++) {
for (uint16_t x = (uint16_t)longBound[i]; x <= (uint16_t)splitBound[i]; x++) {
// Helpers::putPixel(buffer, x, i + (uint32_t)top.y, color.r, color.g, color.b, color.a);
buffer.drawPixel(Coord2(x, i + (uint16_t)top.y), color);
}
}
}
return;
}
};
}