1 /************************************************************************
3 * voxelands - 3d voxel world sandbox game
4 * Copyright (C) Lisa 'darkrose' Milne 2016 <lisa@ltmnet.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>
18 ************************************************************************/
24 static int seed
= 12345;
26 static float noise(int x
, int z
)
28 int a
= (x
*43695)+(z
*43721)+seed
;
31 float d
= ((float)(b
%1000)/1000.0);
39 static float smooth_noise(int x
, int z
)
45 sides
+= noise(x
-1,z
);
46 sides
+= noise(x
,z
+1);
47 sides
+= noise(x
,z
-1);
53 return (sides
+centre
);
56 static float interpolated_noise(int x
, int z
, float devisor
)
64 float fx
= (float)x
/devisor
;
65 float fz
= (float)z
/devisor
;
75 v1
= smooth_noise(ix
,iz
);
76 v2
= smooth_noise(ix
+1,iz
);
77 v3
= smooth_noise(ix
,iz
+1);
78 v4
= smooth_noise(ix
+1,iz
+1);
80 i1
= (v1
*(1.0-fx
))+(v2
*fx
);
81 i2
= (v3
*(1.0-fx
))+(v4
*fx
);
83 return (i1
*(1.0-fz
))+(i2
*fz
);
86 void mapgen_seed(int s
)
91 float noise_height(int x
, int z
)
93 float n
= interpolated_noise(x
,z
,60.0)*70.0;
95 n
+= interpolated_noise(x
,z
,20.0)*20.0;
96 n
+= interpolated_noise(x
,z
,10.0)*4.0;