bloboland
diff src/level.cc @ 1:cfe68befb7cc
some progress
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 15 Dec 2012 23:43:03 +0200 |
parents | |
children | a39c301cdcce |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/level.cc Sat Dec 15 23:43:03 2012 +0200 1.3 @@ -0,0 +1,64 @@ 1.4 +#include "level.h" 1.5 + 1.6 +#include "opt.h" 1.7 + 1.8 +Level::Level() 1.9 +{ 1.10 + terrain = 0; 1.11 +} 1.12 + 1.13 +Level::~Level() 1.14 +{ 1.15 + delete terrain; 1.16 +} 1.17 + 1.18 +void Level::generate() 1.19 +{ 1.20 + delete terrain; 1.21 + 1.22 + int xsz = opt.world_size[0]; 1.23 + int ysz = opt.world_size[1]; 1.24 + int zsz = opt.world_size[2]; 1.25 + 1.26 + terrain = new Volume(xsz, ysz, zsz); 1.27 + 1.28 + for(int i=0; i<xsz; i++) { 1.29 + for(int j=0; j<ysz; j++) { 1.30 + float x = opt.gen_noise_scale * (float)i / (float)xsz; 1.31 + float y = opt.gen_noise_scale * (float)j / (float)ysz; 1.32 + float peak = 0.4 * noise2(x, y) * 0.5 + 0.5; 1.33 + 1.34 + for(int k=0; k<zsz; k++) { 1.35 + Vector4 voxel(1, 1, 1, 1); 1.36 + float z = (float)k / (float)zsz; 1.37 + 1.38 + if(z < 0.1) { 1.39 + // lava 1.40 + static const Vector4 col1(0.96, 0.3, 0.1, 1); 1.41 + static const Vector4 col2(0.96, 0.75, 0.1, 1); 1.42 + float t = noise3(x, y, z); 1.43 + voxel = lerp(col1, col2, t); 1.44 + } else if(z < peak - 0.05) { 1.45 + // mud 1.46 + voxel = Vector4(0.57, 0.43, 0.29, 1); 1.47 + } else if(z < 0.85) { 1.48 + // grass 1.49 + voxel = Vector4(0.68, 0.95, 0.38); 1.50 + } // else snow (default) 1.51 + 1.52 + voxel.w = z < peak ? 1.0 : 0.0; 1.53 + terrain->set_voxel(i, j, k, voxel); 1.54 + } 1.55 + } 1.56 + } 1.57 +} 1.58 + 1.59 +bool Level::load(const char *fname) 1.60 +{ 1.61 + return false; 1.62 +} 1.63 + 1.64 +bool Level::save(const char *fname) const 1.65 +{ 1.66 + return false; 1.67 +}