Basic rendering of asthenosphere and lithosphere.
This commit is contained in:
@@ -84,7 +84,10 @@ Vec2 asth[WORLD_SZ][WORLD_SZ] = {
|
||||
},
|
||||
};
|
||||
|
||||
Plate lith[2] = {
|
||||
(Plate){COL_BLU, 4, {(Pt){0, 0}, (Pt){4, 0}, (Pt){0, 8}, (Pt){4, 8}}},
|
||||
(Plate){COL_RED, 4, {(Pt){4, 0}, (Pt){8, 0}, (Pt){8, 8}, (Pt){4, 8}}}
|
||||
Plate lith[NPLATES] = {
|
||||
(Plate){.col = COL_BLU,
|
||||
.nverts = 4,
|
||||
.verts = {(Pt){0, 0}, (Pt){7, 0}, (Pt){7, 5}, (Pt){4, 4}}},
|
||||
(Plate){COL_RED, 4, {(Pt){0, 0}, (Pt){4, 4}, (Pt){2, 7}, (Pt){0, 7}}},
|
||||
(Plate){COL_GRN, 4, {(Pt){4, 4}, (Pt){7, 5}, (Pt){7, 7}, (Pt){2, 7}}},
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#define WORLD_SZ 8
|
||||
#define NPLATES 3
|
||||
|
||||
// A two dimensional vector.
|
||||
typedef struct {
|
||||
@@ -30,7 +31,7 @@ typedef struct {
|
||||
// The asthenosphere; contains a grid of force vectors.
|
||||
extern Vec2 asth[WORLD_SZ][WORLD_SZ];
|
||||
// The lithosphere; contians a list of plates.
|
||||
extern Plate lith[2];
|
||||
extern Plate lith[NPLATES];
|
||||
|
||||
void gen(void);
|
||||
|
||||
|
||||
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