Basic rendering of asthenosphere and lithosphere.
This commit is contained in:
45
src/render.c
45
src/render.c
@@ -3,16 +3,17 @@
|
||||
|
||||
#include <raylib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
Vector2 PointToVector2(Pt p) {
|
||||
Vector2 v;
|
||||
v.x = (float)p.x * CELL_SZ;
|
||||
v.y = (float)p.y * CELL_SZ;
|
||||
v.x = (float)(p.x * 100) + 50;
|
||||
v.y = (float)(p.y * 100) + 50;
|
||||
return v;
|
||||
}
|
||||
|
||||
void render() {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
for (int i = 0; i < NPLATES; i++) {
|
||||
Plate plate = lith[i];
|
||||
|
||||
// Skip plates with less than 3 vertices (can't form a polygon).
|
||||
@@ -25,35 +26,23 @@ void render() {
|
||||
screen_verts[j] = PointToVector2(plate.verts[j]);
|
||||
}
|
||||
|
||||
if (plate.nverts == 3) {
|
||||
DrawTriangle(
|
||||
screen_verts[0], screen_verts[1], screen_verts[2],
|
||||
(Color){plate.col.r, plate.col.g, plate.col.b, plate.col.a}
|
||||
);
|
||||
|
||||
} else if (plate.nverts == 4) {
|
||||
// Draw a quadrilateral (split into two triangles for filling)
|
||||
// Triangle 1: V0, V1, V2
|
||||
DrawTriangle(
|
||||
screen_verts[0], screen_verts[1], screen_verts[2],
|
||||
(Color){plate.col.r, plate.col.g, plate.col.b, plate.col.a}
|
||||
|
||||
);
|
||||
// Triangle 2: V0, V2, V3 (Uses V0 and V2 as the base diagonal)
|
||||
DrawTriangle(
|
||||
screen_verts[0], screen_verts[2], screen_verts[3],
|
||||
(Color){plate.col.r, plate.col.g, plate.col.b, plate.col.a}
|
||||
);
|
||||
}
|
||||
|
||||
// OPTIONAL: Draw the plate outline to make it clearer
|
||||
/*
|
||||
for (int j = 0; j < plate.nverts; j++) {
|
||||
Vector2 p1 = screen_verts[j];
|
||||
Vector2 p2 =
|
||||
screen_verts[(j + 1) % plate.nverts]; // Loop back to the first
|
||||
// point
|
||||
DrawLineV(p1, p2, BLACK);
|
||||
}*/
|
||||
DrawLineV(p1, p2, WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
for (int x = 0; x < WORLD_SZ; x++) {
|
||||
for (int y = 0; y < WORLD_SZ; y++) {
|
||||
Vector2 v = PointToVector2((Pt){x, y});
|
||||
DrawCircleV(v, 4.f, WHITE);
|
||||
DrawLineV(
|
||||
v, (Vector2){v.x + asth[x][y].x * 8, v.y + asth[x][y].y * 8},
|
||||
WHITE
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user