summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--height-map-display/src/main.c54
-rw-r--r--height-map-display/src/map/square.c20
-rw-r--r--height-map-display/src/map/square.h8
3 files changed, 51 insertions, 31 deletions
diff --git a/height-map-display/src/main.c b/height-map-display/src/main.c
index 4fe377f..648cae0 100644
--- a/height-map-display/src/main.c
+++ b/height-map-display/src/main.c
@@ -14,7 +14,7 @@
float camera_pos_x = 0.0f;
float camera_pos_y = 0.0f;
float camera_pos_z = 0.0f;
-float camera_yaw = 20.0f; // rotation around y-axis
+float camera_yaw = 50.0f; // rotation around y-axis
float camera_pitch = -50.0f; // rotation aroudn x-axis
bool draw_grid = true;
@@ -53,29 +53,24 @@ void renderHeightMap(Square **squares) {
logger("Init rendering...");
for (int x = 0; x < MAP_WIDTH - 1; x++) {
- glBegin(GL_TRIANGLE_STRIP);
for (int y = 0; y < MAP_HEIGHT - 1; y++) {
- float x0 = x;
- float y0 = squares[x][y].nodes[0]->elevation * scale_factor;
- float z0 = y;
-
- float x1 = x + 1;
- float y1 = squares[x][y].nodes[2]->elevation * scale_factor;
- float z1 = y;
-
+ // TODO: Fix color to fill full square as opposed to line
float* color = colors[0];
if (squares[x][y].terrain == TERRAIN_FAIRWAY) { color = colors[1]; }
if (squares[x][y].terrain == TERRAIN_ROUGH) { color = colors[2]; }
if (squares[x][y].terrain == TERRAIN_GREEN) { color = colors[3]; }
glColor3fv(color);
- glVertex3f(x0, y0, z0);
- glVertex3f(x1, y1, z1);
+ glBegin(GL_QUADS);
+ glVertex3f(x, squares[x][y].node_tl->elevation * scale_factor, y);
+ glVertex3f(x + 1, squares[x][y].node_tr->elevation * scale_factor, y);
+ glVertex3f(x + 1, squares[x][y].node_bl->elevation * scale_factor, y + 1);
+ glVertex3f(x, squares[x][y].node_br->elevation * scale_factor, y + 1);
+ glEnd();
}
- glEnd();
}
@@ -88,17 +83,19 @@ void renderHeightMap(Square **squares) {
for (int x = 0; x <= MAP_WIDTH - 2; x++) {
for (int y = 0; y < MAP_HEIGHT - 2; y++) {
- glVertex3f(x, squares[x][y].nodes[0]->elevation * scale_factor, y);
- glVertex3f(x, squares[x][y + 1].nodes[0]->elevation * scale_factor, y + 1);
+ glVertex3f(x, squares[x][y].node_tl->elevation * scale_factor, y);
+ glVertex3f(x, squares[x][y + 1].node_tl->elevation * scale_factor, y + 1);
}
}
for (int y = 0; y <= MAP_HEIGHT - 2; y++) {
for (int x = 0; x < MAP_WIDTH - 2; x++) {
- glVertex3f(x, squares[x][y].nodes[0]->elevation * scale_factor, y);
- glVertex3f(x + 1, squares[x + 1][y].nodes[0]->elevation * scale_factor, y);
+ glVertex3f(x, squares[x][y].node_tl->elevation * scale_factor, y);
+ glVertex3f(x + 1, squares[x + 1][y].node_tl->elevation * scale_factor, y);
}
}
+
+ // TODO: Draw final column of grid manually
}
logger("Init end...");
@@ -128,10 +125,10 @@ Square** initialize_squares(Node ***nodes, int X, int Y) {
squares[i] = (Square *)malloc((Y - 1) * sizeof(Square));
for (int j = 0; j < Y - 1; j++) {
// Assign pointers to nodes to create the Square
- squares[i][j].nodes[0] = nodes[i][j];
- squares[i][j].nodes[1] = nodes[i][j+1];
- squares[i][j].nodes[2] = nodes[i+1][j];
- squares[i][j].nodes[3] = nodes[i+1][j+1];
+ squares[i][j].node_tl = nodes[i][j];
+ squares[i][j].node_tr = nodes[i][j+1];
+ squares[i][j].node_bl = nodes[i+1][j];
+ squares[i][j].node_br = nodes[i+1][j+1];
squares[i][j].terrain = TERRAIN_ROUGH;
}
}
@@ -197,9 +194,21 @@ int main(int argc, char *argv[]) {
Square **squares = initialize_squares(nodes, MAP_WIDTH, MAP_HEIGHT);
// Debug stuff
- squares[0][0].nodes[0]->elevation = 20.0f;
+ squares[0][0].node_tl->elevation = 20.0f;
change_square_height(&squares[3][3], 5.0f);
+ change_square_terrain(&squares[3][5], TERRAIN_FAIRWAY);
change_square_height(&squares[5][5], -5.0f);
+ change_square_terrain(&squares[5][5], TERRAIN_FAIRWAY);
+
+ printf("Node 34 tl height = %f\n", squares[3][4].node_tl->elevation);
+ printf("Node 34 tr height = %f\n", squares[3][4].node_tr->elevation);
+ printf("Node 34 bl height = %f\n", squares[3][4].node_tl->elevation);
+ printf("Node 34 br height = %f\n", squares[3][4].node_br->elevation);
+
+ printf("Node 33 tl height = %f\n", squares[3][3].node_tl->elevation);
+ printf("Node 33 tr height = %f\n", squares[3][3].node_tr->elevation);
+ printf("Node 33 bl height = %f\n", squares[3][3].node_tl->elevation);
+ printf("Node 33 br height = %f\n", squares[3][3].node_br->elevation);
while (!glfwWindowShouldClose(window)) {
logger("Entering main loop...");
@@ -210,6 +219,7 @@ int main(int argc, char *argv[]) {
glfwSwapBuffers(window); // Swap buffers to display the rendered image
+ camera_yaw = camera_yaw + 0.5f;
// Poll for and process events, wait for events if none are pending
glfwWaitEventsTimeout(0.01); // Add a slight delay to reduce CPU usage
}
diff --git a/height-map-display/src/map/square.c b/height-map-display/src/map/square.c
index 1d74ff5..f963fa3 100644
--- a/height-map-display/src/map/square.c
+++ b/height-map-display/src/map/square.c
@@ -5,17 +5,23 @@
#include <stdlib.h>
#include <malloc.h>
-Square* init_square(Node *nodes[4], Terrain_Type terrain) {
+Square* init_square(Node *tl, Node *tr, Node *bl, Node *br, Terrain_Type terrain) {
Square* square;
- for (int i; i < 4; i++) {
- square->nodes[i] = nodes[i];
- }
+ square->node_tl = tl;
+ square->node_tr = tr;
+ square->node_bl = bl;
+ square->node_br = br;
square->terrain = terrain;
return square;
}
void change_square_height(Square* square, float diff) {
- for (int i = 0; i < 4; i++) {
- square->nodes[i]->elevation = square->nodes[i]->elevation + diff;
- }
+ square->node_tl->elevation = square->node_tl->elevation + diff;
+ square->node_tr->elevation = square->node_tr->elevation + diff;
+ square->node_bl->elevation = square->node_bl->elevation + diff;
+ square->node_br->elevation = square->node_br->elevation + diff;
+}
+
+void change_square_terrain(Square* square, Terrain_Type terrain) {
+ square->terrain = terrain;
}
diff --git a/height-map-display/src/map/square.h b/height-map-display/src/map/square.h
index d40e7d1..2654eb5 100644
--- a/height-map-display/src/map/square.h
+++ b/height-map-display/src/map/square.h
@@ -13,12 +13,16 @@ typedef enum {
// Define the Square struct
typedef struct Square {
Terrain_Type terrain;
- Node *nodes[4]; // Array of Node pointers
+ Node *node_tl;
+ Node *node_tr;
+ Node *node_bl;
+ Node *node_br;
} Square;
// Function prototypes
-Square* init_square(Node *nodes[4], Terrain_Type terrain);
+Square* init_square(Node *tl, Node *tr, Node *bl, Node *br, Terrain_Type terrain);
void change_square_height(Square* square, float diff);
+void change_square_terrain(Square* square, Terrain_Type terrain);
#endif