Hello all!
I'm using WLGfx's (at least I believe it is his, tell me if I'm wrong!) perlin noise generator plugin to generate heightmaps, which I then use for advanced terrain.
This works really well for a single terrain but I want to use paging (if that's the right term) terrain and so need to be able to use multiple terrains side by side, the noise generator is fine, the terrains are fine but for some reason they don't line up at the edges, as if there's a bit missing. I've searched the forums but am still none the wiser as how one goes about stitching the seperate terrains together? Can anyone help?
I was thinking maybe the way to do it would be to add an extra line of verticies at the right and bottom of each terrain and set their positions to be the same as the verticies along the edge of the neibouring terrain tile.
How would I add an extra line of verticies and how can I get the vertex indexes of these extra verticies so I can use them with 'set ertex position V_ID,X,Y,Z'?
For what it's worth here's the code I've been messing around with:
// sync rate 60
// sync on
// sync
autocam off
Global Size=128
Global NumTilesX=2
Global NumTilesY=2
Global SeedX as integer
Global SeedY as integer
global tmpbmp as integer =1
global tmpimg as integer =1
global basimg as integer
global teximg as integer
//Terrain textures
// basimg= find free image()
// load image "Media/texture.bmp", basimg
// teximg= find free image()
// load image "Media/detail.tga", teximg
//Seeds
SeedX=1
SeedY=1
while scancode() <> 27
//Time the proc.
time = timer()
//Generate as tiles
for oy=0 to NumTilesY-1
for ox=0 to NumTilesX-1
//Setup to make heightmap
//Switch to temp bitmap
create bitmap tmpbmp,Size,Size
set current bitmap tmpbmp
//Lock the pixels for fast editing
lock pixels
//Noise position
x = SeedX + ((ox*Size))
y = SeedY + ((oy*Size))
for w = 0 to Size
for h = 0 to Size
px# = w + x
py# = h + y
` change the first value (octaves for detail)
` This call scales down the noise value and returns
` the value between the lo and hi boundary range
v = simplex scaled 2d( 3, 1.0, 0.01, 0.0, 255, px#, py# )
` This call returns a value between -1.0 and +1.0
`v = int( simplex noise 2d( 1, 1, 0.1, px#, py# ) * 255.0 )
//ConvertBase(v,10,256)
c = rgb( v, v, v )
dot w , h, c
next h
NEXT w
//unlock pixels again
unlock pixels
//save bitmap
get image tmpimg,0,0,Size, Size
if file exist("media/tmp_heightmap.bmp")=1 then delete file "media/tmp_heightmap.bmp"
save image "media/tmp_heightmap.bmp",tmpimg
delete image tmpimg
set current bitmap 0
delete bitmap tmpbmp
//Make terrain using heightmap
ter = find free object()
make object terrain ter ` create the terrain object
set terrain heightmap ter, "Media/tmp_heightmap.bmp" ` set the heightmap
set terrain scale ter, 1, 0.1, 1 ` set the scale
set terrain split ter, 16 ` split value by 16 * 16
set terrain tiling ter, 4 ` detail map tiling
set terrain light ter, 1, -0.25, 0, 1, 1, 0.78, 0.5 ` light - xdir, ydir, zdir, red, green, blue, intensity
set terrain texture ter, basimg, teximg ` base and detail texture
build terrain ter ` finally build the terrain
//Position terrain
position object ter, (ox*object size x(ter)),0,-1*(oy*object size z(ter))
//Scale the object
//ScaleObject(ter,Size,-1,Size)
//Delete tmp file
//if file exist("media/tmp_heightmap.bmp")=1 then delete file "media/tmp_heightmap.bmp"
load image "Media/tmp_heightmap.bmp",9,1
next ox
next oy
time = timer() - time
sync rate 60
sync on
sync
//View loop
// position camera 128,50,-128
make mesh from object 1,1
repeat
gosub PlayerControl
text 0,0, "Seed value X: "+str$(SeedX)
text 0,10,"Seed value Y: "+str$(SeedY)
text 0,20,"Tiles: "+str$((NumTilesX)*(NumTilesY))
text 0,30,"Tile size (pixels): "+str$(Size)+"x"+str$(Size)
text 0,40,"Time taken: "+str$(time)+"ms"
text 0,50,"FPS: " + str$(screen fps())
text 0,60,"Polies: "+str$(statistic(1))
text 0,70,"x size:" + str$(object size x(ter))
paste image 9,screen width()-256, 0
sync
until keystate(28)<>0
//END
END
if leftkey()=1 then dec SeedX,Size
if rightkey()=1 then inc SeedX,Size
if upkey()=1 then dec SeedY,Size
if downkey()=1 then inc SeedY,Size
endwhile
although it's far too messy to really show anybody, so I'm kind of embarassed to put this up here!
Any help would be appreciated,
BC