Terrain, Maths and hills

Blitz3D Forums/Blitz3D Beginners Area/Terrain, Maths and hills

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Heres a quick bit of code you can copy and paste to see for yourself:-


Graphics3D 640,480,16,2
SetBuffer BackBuffer()

TerraSize=128
x_scale=10
y_scale=50
z_scale=10 

radius# = 1

camera=CreateCamera()
PositionEntity camera,(TerraSize*x_scale)/2,50,-10
RotateEntity camera,30,0,0

light=CreateLight()
RotateEntity light,90,0,0

terra=CreateTerrain(TerraSize)
TerrainDetail terra,3000
ScaleEntity terra,x_scale,y_scale,z_scale
EntityPickMode terra,2

; Texture terrain
grass_tex=LoadTexture("tex.jpg")
EntityTexture terra,grass_tex

While Not KeyDown(1)

If KeyHit( 17 )=True Then enable=1-enable : WireFrame enable

If MouseDown(1)
	CameraPick(camera,MouseX(),MouseY())
	TFormPoint(PickedX(), PickedY(), PickedZ(), 0, Terra)
	x = TFormedX()
	z = TFormedZ()
	radius = 1
End If 

If KeyDown(30) 
	radius = radius + (TerrainHeight(terra,x,z));+0.3
		For xx=-radius*5 To radius*5
			For zz=-radius*5 To radius*5
 				x1=xx+x
 				z1=zz+z
 				e#=Sqr(xx*xx+zz*zz)
 			
				h#=(radius#/10)-(e/Sqr( (radius)*(radius) + (radius)*(radius) ) )
				If h# > TerrainHeight(terra,x1,z1)
 					h1#=-Cos(h*180.0)/2.0+0.5
					If h1<0.0 Then h1=0.0 
 			        If h1>1.0 Then h1=1.0 
	
 					ModifyTerrain terra,x1,z1,h1
				End If 
			Next
		Next
End If

RenderWorld 
Text 0,40,"Terrain Height: "+ TerrainHeight(terra,x,z)
Flip

Wend

End


First, click somewhere on the terrain in front of the camera, then hold down A to make it grow, and you'll see what I mean.

Its a poser, it really is!

Dabz