World 0,0 is now at the center of the node texture

This commit is contained in:
Piotrek
2021-05-14 14:25:12 +02:00
parent 05b62d4b90
commit e6329d568c
6 changed files with 24 additions and 12 deletions
+10 -8
View File
@@ -1,3 +1,4 @@
use std::time::Instant;
use cgmath::Vector3;
use noise::{Perlin, NoiseFn};
use rand::{Rng, prelude::ThreadRng};
@@ -16,21 +17,22 @@ impl WorldGen {
/*
* Generate height map for given block position
*/
fn gen_height_map(x: usize, z: usize, rand: &mut ThreadRng, noise: &Perlin) -> ([[usize;block::SIZE]; block::SIZE], usize) {
let x = x * block::SIZE;
let z = z * block::SIZE;
fn gen_height_map(x: i32, z: i32, rand: &mut ThreadRng, noise: &Perlin) -> ([[usize;block::SIZE]; block::SIZE], usize) {
let size = block::SIZE as i32;
let x = x * size;
let z = z * size;
// Generate map
let mut max: usize = 0;
let mut map = [[0_usize; block::SIZE]; block::SIZE];
for lx in 0..block::SIZE {
for lz in 0..block::SIZE {
for lx in 0..size {
for lz in 0..size {
let value = (noise.get([(x + lx) as f64 / SCALE, (z + lz) as f64 /SCALE]) + 1.0) / 2.0;
let mut h = (value * 30.0) as usize;
h += (rand.gen::<f32>() * 2.0) as usize;
if h == 0 { h = 1; }
if h > max { max = h; }
map[lx][lz] = h;
map[lx as usize][lz as usize] = h;
}
}
(map, max)
@@ -44,8 +46,8 @@ impl WorldGen {
let noise = Perlin::new();
// Generate height map
let (map, _max) = WorldGen::gen_height_map(block_pos.x as usize, block_pos.z as usize, &mut rng, &noise);
let (map, _max) = WorldGen::gen_height_map(block_pos.x, block_pos.z, &mut rng, &noise);
// Fill
for x in 0..block::SIZE {
for z in 0..block::SIZE {