Dynamically Building Terrain (Meshing?)
#1

Hey guys,

I'm currently working on a League of Legends-styled gamemode with a dynamic map which is built out of 3x3 squares.
Using the RNPC Plugin the npcs (the character/player you control) moves where you click, like in LoL/Diablo/Dungeon Siege.

Currently got that far: [ame]http://www.youtube.com/watch?v=o_0ihPKKWAk[/ame]

I already have a very nice looking terrain (500x500 units, with different terrain types, like grass, stone, glass, 250k blocks in total) , but it's flat.



Now, as I don't want to have a pure flat terrain, I'm tryin to build it with some steps in the Z direction (up/down).

Doing that in the y or x direction only is simple.

But there are some requirements for the more complex "steps".

The height difference between two blocks (in any direction, up/down/diagonal) may not be greater than 0.3 units up OR down, otherwise forcing the npc to hang.


I need help for the code to build the terrain so that its not flat AND being usable.

Let's assume we have a 4x4 terrain, looking like that (seen from above):





Looking at square 6, the height difference between 1 and 6, 2 and 6, 3 and 6 (etc...) may not be greater than 0.3 or 0.2 (should be randomly between -0.3 and 0.3).

I'm currently using 2 loops, each from 0 too 500 to create the terrain.

It's basically looking like that:

Код:
for(new x; x < 500; x ++)
{
for(new y; y < 500; y++)
{
CreateObject(..., x*3.0, y*3.0, 200.0, ...);
}
}
I multiply x and y by 3.0 because the width and height of the blocks are 3.0.

I need a function/code to check the nearby block's height so that a new height for the next block can be calculated.

I thought that I maybe first should create all the blocks, then run through them, moving them up/down one by one, maybe with a different loop structrue, cause the above one might be not the best for that. But I don't know how that should look like.


I'm not expecting it's going to be easy, but I got the hope that maybe someone did something similar or got knowledge in meshing or similar algorithms.

Every help will be very appreciated!
I'm working on the terrain structure since 5 hrs and my head is going to explode....

I also know that this is maybe a bit too in depth for the samp forum, excuse me then, I just don't know where to ask.

Greetz, NaS
Reply
#2

maybe not quite what youre looking for, but hey, this algorithm is state-of-the-art: diffusion.
dont forget to initialize your mapZ array for 2 "layers". [0] being the one where the bots are walking on, and the [1] as calculating buffer for storing the diffused values. its a 2-pass algorithm. enjoy!
pawn Код:
for(new x; x < 500; x ++)
{
    for(new y; y < 500; y++)
    {
        OZ[0][X][Y]=random(300)*0.01;//randomly set each objects Z height from 0.0 to 3.0 in 0.01 steps
    }
}

new xw=(500+x-1)%500;
new xe=(500+x+1)%500;
new yn=(500+y+1)%500;
new ys=(500+y-1)%500;
for(new x; x < 500; x ++)
{
    for(new y; y < 500; y++)
    {
        xw=(500+x-1)%500;
        xe=(500+x+1)%500;
        yn=(500+y+1)%500;
        ys=(500+y-1)%500;
        OZ[1][X][Y]=(OZ[0][xw][y]+OZ[0][xe][y]+OZ[0][x][yn]+OZ[0][x][ys])/5;//each cell takes its 4 neighbours cells' values, adds them to its own, and writes the result (of 5 cells total) into the [1] layer, dividing it by 5 (number of cells)
    }
}
for(new x; x < 500; x ++)
{
    for(new y; y < 500; y++)
    {
        OZ[0][X][Y]=OZ[1][x][y];//finally, the [1] cells get written back to layer [0], where the action is
    }
}
..those %500 modulus operations will ensure that the cells accessing like [x=-1][y=0] will get converted to [x=499][y=0], due to adding 500-1, then %'it by 500...
btw, maybe it will require some more iterations to make it smooth enough, to fit a difference of 0.3 max.
Reply
#3

Thank you Babul, this looks good.

I think I can adjust the height differences in the first part.

I will play around a bit, thank you very very much!

PS: I got the idea of the algorithm. With one modification, to make it less diffuse it's pretty good for my needs.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)