View Single Post
  #2  
Old 01-26-2009, 05:12 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Unfortunately the current version of the InfiniteTerrain plugin does not work with the intersect function. If you were to supply your own terrain generation function to the plugin, then you would be able to determine the height of the terrain at any given (x,z) coordinate. Here is a sample script showing how to use your own function to generate the terrain:
Code:
import viz
import math
viz.go()

#Add a skybox
sky = viz.add('skydome.dlc')
env = viz.add(viz.ENVIRONMENT_MAP,'sky.jpg')
sky.texture(env)
sky.disable(viz.FOG)

grass = viz.add('grass.jpg')

#Need to set texture mode to repeat for terrain texture
grass.wrap(viz.WRAP_S,viz.REPEAT)
grass.wrap(viz.WRAP_T,viz.REPEAT)

# Initialize random number generator with string '456'
# Set tesselation level to 7 (default is 6) Smaller value means less detail, faster rendering
# Set texture repeat level to 6 (default is 4)
# Set viewing distance to 15000 (default is 4096)
# Set LOD factor to 0.0005 (default is 0.001) Smaller numbers mean LOD changes further away, 
# (i.e 'popping' will be less noticeable)
#terrain = viz.add('InfiniteTerrain.dlc',1,'456',7,6,15000,0.0005)
terrain = viz.add('InfiniteTerrain.dlc',1,'456',4,4,15000,0.0001)
terrain.texture(grass)

#Set heightscale1 to 150
#Set heightscale2 to 5
#Height scales are used for generating terrain height
#Formula = heightscale1 * random() + heightscale2 * random();
terrain.command(1,'',150,5)


# Large a, steep curve
# http://astronomy.swin.edu.au/~pbourke/analysis/sigmoid/
def sigmoid(x, a):
	y = 1.0 / ( 1 + math.exp(-a * x))
	return y



def sumsines(theta, periods):
	sum = 0.0
	for p in periods:
		sum += math.sin(theta/p)
	return sum
	
p1 = [500, 1000]
p2 = [500, 1000]

def terrainfunc(x,z):
	#Input: x,z position of terrain
	#Output: height of terrain at that position
	
	height = (sumsines(x,p1) + sumsines(z,p2) +5) * 100
	
	distance = abs(x - math.sin(z/1500)*850) 
	weight = sigmoid(distance - 800, .006)		
	
	return height * weight

#Use the python function 'terrainfunc' instead of builtin random height generator
terrain.command(3,'terrainfunc')

#Hide ground plane
terrain.command(5)

#Create fog
viz.fogcolor(0.784,0.867,0.941)
viz.fog(0.00007,-1)

#Create static lighting
light = viz.add(viz.LIGHT)
light.position(-0.5,0.4,0.5,0)
light.enable()
viz.get(viz.HEAD_LIGHT).disable()

#Crank up sensitivity
viz.sensitivity(1000,1)
Reply With Quote