Colors. Lines.
This commit is contained in:
@@ -24,3 +24,8 @@ bool tri_within(Pt pt, Tri* tri) {
|
|||||||
double c = 1 - a - b;
|
double c = 1 - a - b;
|
||||||
return 0 <= a && a <= 1 && 0 <= b && b <= 1 && 0 <= c && c <= 1;
|
return 0 <= a && a <= 1 && 0 <= b && b <= 1 && 0 <= c && c <= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Pt tri_center(Tri* tri) {
|
||||||
|
return (Pt){(tri->a.x + tri->b.x + tri->c.x) / 3.0,
|
||||||
|
(tri->a.y + tri->b.y + tri->c.y) / 3.0};
|
||||||
|
}
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ void tri_destroy(Tri* tri);
|
|||||||
// Check if a point is within the triangle. Uses barycentric coordinate system.
|
// Check if a point is within the triangle. Uses barycentric coordinate system.
|
||||||
bool tri_within(Pt pt, Tri* tri);
|
bool tri_within(Pt pt, Tri* tri);
|
||||||
|
|
||||||
|
// Get the center point of a Tri.
|
||||||
|
Pt tri_center(Tri* tri);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Color col;
|
Color col;
|
||||||
size_t ntris;
|
size_t ntris;
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#ifndef UTIL_H
|
#ifndef UTIL_H
|
||||||
#define UTIL_H
|
#define UTIL_H
|
||||||
|
|
||||||
#define MAX(a, b) a ? a > b : b
|
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||||
#define MAX3(a, b, c) MAX(a, MAX(b, c))
|
#define MAX3(a, b, c) (MAX((a), MAX((b), (c))))
|
||||||
#define MIN(a, b) a ? a < b : b
|
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||||
#define MIN3(a, b, c) MIN(a, MIN(b, c))
|
#define MIN3(a, b, c) (MIN((a), MIN((b), (c))))
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
19
src/render.c
19
src/render.c
@@ -27,16 +27,19 @@ void draw_tri(Tri* tri) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// bad.
|
|
||||||
void draw_tri_inside(Tri* tri, Color col) {
|
void draw_tri_inside(Tri* tri, Color col) {
|
||||||
// int maxx = MAX3(tri->a.x, tri->b.x, tri->c.x);
|
int maxx = MAX3(tri->a.x, tri->b.x, tri->c.x);
|
||||||
// int maxy = MAX3(tri->a.y, tri->b.y, tri->c.y);
|
int maxy = MAX3(tri->a.y, tri->b.y, tri->c.y);
|
||||||
// int minx = MIN3(tri->a.y, tri->b.y, tri->c.y);
|
int minx = MIN3(tri->a.x, tri->b.x, tri->c.x);
|
||||||
// int miny = MIN3(tri->a.y, tri->b.y, tri->c.y);
|
int miny = MIN3(tri->a.y, tri->b.y, tri->c.y);
|
||||||
for (int x = 0; x <= WORLD_SZ; x++) {
|
for (int x = minx; x <= maxx; x++) {
|
||||||
for (int y = 0; y < WORLD_SZ; y++) {
|
for (int y = miny; y <= maxy; y++) {
|
||||||
if (tri_within((Pt){x, y}, tri)) {
|
if (tri_within((Pt){x, y}, tri)) {
|
||||||
DrawCircleV(PointToVector2((Pt){x, y}), 4.f, col);
|
// DrawCircleV(PointToVector2((Pt){x, y}), 4.f, col);
|
||||||
|
DrawLineV(
|
||||||
|
PointToVector2((Pt){x, y}), PointToVector2(tri_center(tri)),
|
||||||
|
col
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user