bettola/srv/game/world_collision.cpp
Ritchie Cunningham fa7159587d [Add] Terrain lighting.
* Chunks are now rendered as solid, lit meshes instead of wireframe.
* The GLSL shaders have been updated to a directional lighting model.
* Chunkmes now calculates normal vectors for each vertex to enable the
  lighting.
* Shader class now has a 'set_vec3' method for sending lighting date to
  the GPU.

Bug Fix:
* Resolves visual artifacts and "seams" at chunk boundaries.

Next up:
* To calculate the correct angle for a vertex at the edge of chunk A, we
  need to know the height of the terrain in the neighboiring Chunk B.
Since it doesn't have that information, the GPU's making an appoximate
guess. We need to generate and send a small "border" of height data
along with each chunk, I'll do this by increasing the size of the
heightmap array in the network message so it can hold the 32x32 chunk
plus 1 vertex border all around. MAking it 34x34 for each chunk.
2025-09-16 23:58:03 +01:00

24 lines
755 B
C++

#include <cmath>
#include "world.h"
#include "bettola/game/chunk.h"
#include "bettola/game/terrain.h"
float World::get_height(float world_x, float world_z) {
/*
* Mesh generation uses (WIDTH-1), so account for it
* when calculating the chunk and local coords.
*/
float chunk_width = (float)(BettolaLib::Game::CHUNK_WIDTH -1);
float chunk_height = (float)(BettolaLib::Game::CHUNK_HEIGHT-1);
int chunk_x = floor(world_x / chunk_width);
int chunk_z = floor(world_z / chunk_height);
float local_x = world_x - (chunk_x * chunk_width);
float local_z = world_z - (chunk_z * chunk_height);
BettolaLib::Game::Chunk& chunk = get_chunk(chunk_x, chunk_z);
return BettolaLib::Game::Terrain::get_height_at(chunk, local_x, local_z);
}