void makeRandomHills ShTlTerrainSceneNode node s32 hillCount s32 maxRa

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
void makeRandomHills(ShTlTerrainSceneNode* node, s32 hillCount, s32 maxRadius)
{
double pi = 3.1415926535;
// make hills
vector<vector<s32> > map;
vector<s32> line;
int high = 128;
int size = getSize().Width;
int n = size-1;
for(int i=0; i<2*size-1; i++)
{
for(int j=0; j<2*size-1; j++)
{
line.push_back(0);
}
map.push_back(line);
line.clear();
}
map[n/2][n/2] = rand() %high;
map[n/2][n+n/2] = rand() %high;
map[n+n/2][n/2] = rand() %high;
map[n+n/2][n+n/2] = rand() %high;
int it = 2;
while(it<=n)
{
int centri = n/it;
for(int i = centri; i<n; i+=centri*2 )
for(int j = centri; j<n; j+=centri*2 )
map[i+n/2][j+n/2] = (map[i+n/2-centri][j+n/2-centri]+map[i+n/2-centri][j+n/2+centri]+map[i+n/2+centri][j+n/2-centri]+map[i+n/2+centri][j+n/2+centri])/4 + rand()%high/it;
for(int i = centri; i<n; i+=centri*2 )
for(int j = centri; j<n; j+=centri*2 )
{
map[i+n/2][j+n/2-centri] = (map[i+n/2+centri][j+n/2-centri]+map[i+n/2-centri][j+n/2-centri]+map[i+n/2][j+n/2-2*centri]+map[n/2+1][n/2+1])/4 + rand()%high/(2*it);
map[i+n/2][j+n/2+centri] = (map[i+n/2+centri][j+n/2+centri]+map[i+n/2-centri][j+n/2+centri]+map[i+n/2][j+n/2]+map[i+n/2][j+n/2+2*centri])/4 + rand()%high/(2*it);
map[i+n/2-centri][j+n/2] = (map[i+n/2][j+n/2]+map[i+n/2-2*centri][j+n/2]+map[i+n/2-centri][j+n/2-centri]+map[i+n/2-centri][j+n/2+centri])/4 + rand()%high/(2*it);
map[i+n/2+centri][j+n/2] = (map[i+n/2+2*centri][j+n/2]+map[i+n/2][j+n/2]+map[i+n/2+centri][j+n/2-centri]+map[i+n/2+centri][j+n/2+centri])/4 + rand()%high/(2*it);
}
it=it*2;
}
for(int i=0; i<size; i++)
{
for(int j=0; j<size; j++)
{
node->setHeight(i,j,map[i+n/2][j+n/2];
}
}
/* for(int n=0; n<hillCount; n++)
{
s32 radius = maxRadius-1;
f32 height = radius+10;
height = height/10;
core::vector2d<s32> pos;
pos.X = rand()%node->getSize().Width - radius;
pos.Y = rand()%node->getSize().Height-radius;
// decide if add or substract
if(rand()%2==1) height = -height;
// create hill using sinus and distance to center
for(int j=0; j<=radius*2; j++)
for(int i=0; i<=radius*2; i++)
{
f32 distance = core::vector2d<s32>(i-radius, j-radius).getLength();
if(distance <= radius)
{
f32 v = radius;
v = v - distance;
v = v / radius;
v = v * pi / 2;
v = sin(v);
if(pos.X+i>=0 && pos.X+i<node->getSize().Width+1 && pos.Y+j>=0 && pos.Y+j<node->getSize().Height+1)
node->setHeight(pos.X+i, pos.Y+j, node->getHeight(pos.X+i, pos.Y+j)+v*height*node->getTileSize());
}
}
} */
}