New geometry data structures.
This commit is contained in:
33
src/gen.c
33
src/gen.c
@@ -1,5 +1,4 @@
|
||||
#include "include/gen.h"
|
||||
#include "include/col.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
@@ -107,25 +106,17 @@ Pt world_edge_idx_to_pt(int idx) {
|
||||
void gen_lith() {
|
||||
srand(time(NULL));
|
||||
|
||||
Pt p1 = {(rand() % 6) + 1, 0};
|
||||
Pt p2 = {(rand() % 6) + 1, 7};
|
||||
|
||||
lith[0] = (Plate){
|
||||
.col = COL_RED,
|
||||
.nverts = 4,
|
||||
.verts = {
|
||||
(Pt){0, 0},
|
||||
p1,
|
||||
p2,
|
||||
(Pt){0, 7},
|
||||
},
|
||||
Tri tri1 = {
|
||||
(Pt){0, 0},
|
||||
(Pt){0, 7},
|
||||
(Pt){7, 0},
|
||||
};
|
||||
lith[1] = (Plate){.col = COL_RED,
|
||||
.nverts = 4,
|
||||
.verts = {
|
||||
p1,
|
||||
(Pt){7, 0},
|
||||
(Pt){7, 7},
|
||||
p2,
|
||||
}};
|
||||
Tri tri2 = {
|
||||
(Pt){7, 0},
|
||||
(Pt){0, 7},
|
||||
(Pt){7, 7},
|
||||
};
|
||||
|
||||
lith[0] = (Plate){.tris = {tri1}};
|
||||
lith[1] = (Plate){.tris = {tri2}};
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef GEN_H
|
||||
#define GEN_H
|
||||
|
||||
#include "col.h"
|
||||
#include "geom.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -14,20 +14,6 @@ typedef struct {
|
||||
int y;
|
||||
} Vec2;
|
||||
|
||||
// A point on the world.
|
||||
typedef struct {
|
||||
int x;
|
||||
int y;
|
||||
} Pt;
|
||||
|
||||
// A plate; contains a list of points on the world representing the plate's
|
||||
// vertices.
|
||||
typedef struct {
|
||||
Col col; // The color the plate should be drawn as.
|
||||
uint8_t nverts; // The number of vertices the plate has.
|
||||
Pt verts[10]; // The vertices of the plate.
|
||||
} Plate;
|
||||
|
||||
// The asthenosphere; contains a grid of force vectors.
|
||||
extern Vec2 asth[WORLD_SZ][WORLD_SZ];
|
||||
// The lithosphere; contians a list of plates.
|
||||
|
||||
36
src/render.c
36
src/render.c
@@ -3,12 +3,18 @@
|
||||
|
||||
#include <raylib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
Vector2 PointToVector2(Pt p) {
|
||||
Vector2 v;
|
||||
v.x = (float)(p.x * 100) + 50;
|
||||
v.y = (float)(p.y * 100) + 50;
|
||||
v.x = (float)(p.x * 100) + 50.;
|
||||
v.y = (float)(p.y * 100) + 50.;
|
||||
return v;
|
||||
}
|
||||
|
||||
Vector2 PointpToVector2(Pt* p) {
|
||||
Vector2 v;
|
||||
v.x = (float)(p->x * 100) + 50;
|
||||
v.y = (float)(p->y * 100) + 50;
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -16,23 +22,13 @@ void render() {
|
||||
for (int i = 0; i < NPLATES; i++) {
|
||||
Plate plate = lith[i];
|
||||
|
||||
// Skip plates with less than 3 vertices (can't form a polygon).
|
||||
if (plate.nverts < 3) continue;
|
||||
|
||||
// Convert the vertices from world coordinates (Pt) to screen
|
||||
// coordinates (Vector2).
|
||||
Vector2 screen_verts[10];
|
||||
for (int j = 0; j < plate.nverts; j++) {
|
||||
screen_verts[j] = PointToVector2(plate.verts[j]);
|
||||
}
|
||||
|
||||
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, WHITE);
|
||||
}
|
||||
DrawTriangleLines(
|
||||
PointToVector2(plate.tris[0].a), PointToVector2(plate.tris[0].b),
|
||||
PointToVector2(plate.tris[0].c), RED
|
||||
);
|
||||
printf(
|
||||
">>>>>>>>>>>>>>>>>>%i %i\n", plate.tris[0].a.x, plate.tris[0].a.y
|
||||
);
|
||||
}
|
||||
|
||||
for (int x = 0; x < WORLD_SZ; x++) {
|
||||
|
||||
Reference in New Issue
Block a user