Terrain, Maths and hills

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

Dabhand(Posted 2008) [#1]
Basically, I have a terrain, and at specific points on the terrain, I want a hill(s) to grow out of it.

Creates a hill, right up to the magic terrain constant 1.0, which tapers off nicely:-

;x and y equals position on terrain
;radius equals hill base size

For xx=-radius To radius
		For zz=-radius To radius
 			x1=xx+x
 			z1=zz+z
 			e#=Sqr(xx*xx+zz*zz)
 			
			h#=1.0-(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


And I've wangled and wangled, but I still cannot get the maths to add up.

The effect I'm after is much like the first populas (Sega) effect when raising a terrain, the higher the hill, the wider the base etc etc

Anyone got any pointers as it has me stumped!?!

Tar ;)

Dabz


Dabhand(Posted 2008) [#2]
For loop = radius To 0 Step -1
		For degrees=0 To 359
			 xpos=x+(Cos(degrees)*loop)
			zpos=z-(Sin(degrees)*loop)
			h# = TerrainHeight(terra,xpos,zpos)
			h# = h# + 0.01
			If h# > TerrainHeight(terra,xpos,zpos)
				If h#<0.0 Then h#=0.0 
 				If h#>1.0 Then h#=1.0 
	 
				ModifyTerrain terra,xpos,zpos,h#
			End If
		Next
	Next


Oh, that was close(ish), but a bit rugged! Mmmmmm

Not really liking doing it that way, not very effiecent!

Dabz


Stevie G(Posted 2008) [#3]
Something like this ? You should probably add the terrain height which is at x, z to the MinHeight also.

;x and y equals position on terrain
;radius equals hill base size

For xx=-radius To radius
	For zz=-radius To radius
 		x1=xx+x
 		z1=zz+z
 		e#=Sqr(xx*xx+zz*zz)
		If e < Radius
			Angle# = ( e / radius ) * 90.0 + 90.0
			MinHeight# = Sin( Angle ) 
			If TerrainHeight(terra,x1,z1) < MinHeight
	 			ModifyTerrain terra,x1,z1, MinHeight
			End If 
		EndIf
	Next
Next



Dabhand(Posted 2008) [#4]
Thanks Steve but all that does (Before and after adding to MinHeight) is make a spikey point on the terrian.

I have come up with this:-

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


Which grows the hill, but when it begins to sprout from the ground its more of a upside down funnel than a hill until it gets half way before forming a nice roll, then when the top of the hill hits the 1.0 ceiling it then expands into a craggy mess!?!


I'll plug away, it'll come eventually, but I was just hoping someone would have something on hand...

Dabz


GIB3D(Posted 2008) [#5]
I'm not sure how you're doing it.. and I've never done it before but.. what about like

If the Y gets higher, than the radius gets bigger
and as the radius gets wider, it affects more vertices using something similar to EntityDistance

Like

Sqr(VertexX^2 + VertexY^2 + VertexZ^2)


??? hehehe ??? Maybe possible probably might work kinda sorta?


Dabhand(Posted 2008) [#6]
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


Stevie G(Posted 2008) [#7]
Ah well, I use almost the same function to modify my mesh terrain and it works just fine in my Polymaniacs level editor. Why don't you use mesh terrains - blitz terrains are awful.


Dabhand(Posted 2008) [#8]

Why don't you use mesh terrains - blitz terrains are awful.



Any chance of a quick example Steve doing this with Mesh Terrains? :)

Dabz