chore: adjusting terrain logic
This commit is contained in:
parent
a10e6d8ad4
commit
ed1d045ab1
4 changed files with 41 additions and 32 deletions
|
|
@ -18,29 +18,6 @@ void Terrain::update_modifier_list() {
|
|||
}
|
||||
}
|
||||
|
||||
void Terrain::construct_chunk_grid() {
|
||||
size_t const chunks_per_side{ this->side_length / this->chunk_size };
|
||||
Vector3 const origin{ -(float)chunks_per_side / 2.f * (float)this->chunk_size, 0.f, -(float)chunks_per_side / 2.f * (float)this->chunk_size };
|
||||
for (size_t y{ 0 }; y < chunks_per_side; ++y) {
|
||||
for (size_t x{ 0 }; x < chunks_per_side; ++x) {
|
||||
TerrainChunkMesh *chunk{ memnew(TerrainChunkMesh) };
|
||||
chunk->set_size(this->chunk_size);
|
||||
chunk->set_detail(this->detail);
|
||||
chunk->set_terrain(this);
|
||||
chunk->set_position(origin + Vector3{ (float)this->chunk_size * (float)x, 0.f, (float)this->chunk_size * (float)y });
|
||||
add_child(chunk);
|
||||
chunk->set_owner(this);
|
||||
this->meshes.push_back(chunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Terrain::generate_meshes() {
|
||||
for (TerrainChunkMesh *mesh : this->meshes) {
|
||||
mesh->update_mesh();
|
||||
}
|
||||
}
|
||||
|
||||
void Terrain::child_entered(Node *node) {
|
||||
if (cast_to<TerrainModifier>(node)) {
|
||||
update_modifier_list();
|
||||
|
|
@ -71,6 +48,29 @@ void Terrain::_notification(int what) {
|
|||
}
|
||||
}
|
||||
|
||||
void Terrain::construct_chunk_grid() {
|
||||
size_t const chunks_per_side{ this->side_length / this->chunk_size };
|
||||
Vector3 const origin{ -(float)this->side_length / 2.f, 0.f, -(float)this->side_length / 2.f };
|
||||
for (size_t y{ 0 }; y < chunks_per_side; ++y) {
|
||||
for (size_t x{ 0 }; x < chunks_per_side; ++x) {
|
||||
TerrainChunkMesh *chunk{ memnew(TerrainChunkMesh) };
|
||||
chunk->set_size(this->chunk_size);
|
||||
chunk->set_detail(this->detail);
|
||||
chunk->set_terrain(this);
|
||||
chunk->set_position(origin + Vector3{ (float)this->chunk_size * (float)x, 0.f, (float)this->chunk_size * (float)y });
|
||||
add_child(chunk);
|
||||
chunk->set_owner(this);
|
||||
this->meshes.push_back(chunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Terrain::generate_meshes() {
|
||||
for (TerrainChunkMesh *mesh : this->meshes) {
|
||||
mesh->update_mesh();
|
||||
}
|
||||
}
|
||||
|
||||
float Terrain::height_at(Vector2 world_coordinate) {
|
||||
float height{ 0 };
|
||||
for (TerrainModifier *mod : this->modifiers) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue