problems with modifyterrain command

Blitz3D Forums/Blitz3D Programming/problems with modifyterrain command

L&L(Posted 2003) [#1]
im trying to make a map editor for my game and i get this problem when i try to use the modifyterrain command. i want to make it so that when you press the + key, the program will raise the level of the terrain at the pointers location. the longer you hold it, the higher it will become. instead of this all i get is the terrain rising a little bit, but then falling down... try the code and see for yourself.









_________________________________________________

Graphics3D 1024,768,0,1
SetBuffer BackBuffer()

Global terrasize
Global terraintype

grass=LoadTexture("grass.bmp")

pointer=CreateSphere(3)
RotateEntity pointer,180,0,0
PositionEntity pointer,10,0,10

cam=CreateCamera()
CameraZoom cam, "1.6"
PositionEntity cam,-1,4,6
EntityRadius cam, 2


light=CreateLight()
PositionEntity light,0,0,0


terrasize=Input("Terrain size>")
terraintype=Input("Terrain Type (water1/rock2/grass3/dirt4)>")

terrain=CreateTerrain(terrasize)

If terraintype="3" Then
EntityTexture terrain,grass
End If






While Not KeyDown(1)

RotateEntity cam,MouseY(),(MouseX()*-1),0
If KeyDown( 200 )=True Then MoveEntity cam,0,0,1
If KeyDown( 17 )=True Then MoveEntity pointer,0,0,0.1
If KeyDown( 31 )=True Then MoveEntity pointer,0,0,-0.1
If KeyDown( 30 )=True Then MoveEntity pointer,0.1,0,0
If KeyDown( 32 )=True Then MoveEntity pointer,-0.1,0,0



If KeyDown(13)=True Then ModifyTerrain terrain,EntityX(pointer),EntityZ(pointer),TerrainHeight(terrain,5,10)+10,True





RenderWorld

Text 0,10,"CAMX:"+EntityX(cam)
Text 0,20,"CAMY:"+EntityY(cam)
Text 0,30,"CAMZ:"+EntityZ(cam)
frames=frames+1
If MilliSecs()-render_time=>1000 Then fps=frames : frames=0 : render_time=MilliSecs()
Text 0,0,"FPS:" + fps
Text 0,80,"Pointer Position:"+""+EntityX(pointer)+", "+EntityY(pointer)+", "+EntityZ(pointer)
Flip
Wend
End


Sunteam Software(Posted 2003) [#2]
You do know that your getting the TerrainHeight from the same position all the time instead of the pointer location right?

i.e. should be:

If KeyDown(13)=True Then ModifyTerrain terrain,EntityX(pointer),EntityZ(pointer),TerrainHeight(terrain,EntityX(pointer),EntityZ(pointer))+10,True 


Of course I can't check this works because I don't have your terrain files but that certainly looks like a mistake :)


GfK(Posted 2003) [#3]
With ModifyTerrain you have to use a float value between 0 and 1. The *actual* height of the terrain is determined by the y-scale of the terrain.


L&L(Posted 2003) [#4]
ok u both were right, i got it to work now :).

1 more question really quick... will i be able to record the height of each tile in the terrain by making a loop that will get the terrainheight(etc) for each position on the terrain?


GfK(Posted 2003) [#5]
I'm not sure exactly what you mean...

Firstly, terrains are modified at vertex level rather than being a tile-based thing.

If for some reason you want to store your terrain data in an array, you can do something like this:-
Terrain = CreateTerrain(256)
Dim TerrainArray(TerrainSize(Terrain),TerrainSize(Terrain))
For X = 0 to TerrainSize(Terrain) - 1
  For Y = 0 to TerrainSize(Terrain) - 1
    TerrainArray(X,Y) = TerrainHeight(Terrain,X,Y)
  Next
Next



L&L(Posted 2003) [#6]
sorry, yea thats what i meant.


John Blackledge(Posted 2003) [#7]
Or you could save your changes out as a bitmap?
(Forget where I got this but it was somewhere on this forum, again thanks, guys.)

f1$ = "bmp\terrain\height.bmp"
f2$ = "bmp\terrain\heightbak1.bmp"
If FileType(f1$)=1 Then CopyFile f1$,f2$
gridsize = TerrainSize(hEntTerrain)
img = CreateImage(gridsize,gridsize)
ib = ImageBuffer(img)
LockBuffer ib
For x=1 To gridsize
For y=1 To gridsize
WritePixel x, gridsize-y-1, Floor(TerrainHeight#(hEntTerrain,x,y)*16777215.0),ib
Next
Next
UnlockBuffer ib
filename$ = "bmp\terrain\height.bmp"
SaveImage(img,filename$)
FreeImage img