PDA

View Full Version : About intersect function


omidbrb
01-23-2009, 05:04 AM
Hi Everyone,

I have a question about the intersect function. I have an InfiniteTerrain object and since it's not flat, I want to find the y coordinate of a point at the InfiniteTerrain. I do the following and I always get 0:


x = SOME_X
z = SOME_Z
hillLevel = 6
terrain = viz.add('InfiniteTerrain.dlc',1,'456',hillLevel,6, 15000,0.0005)
intersection = terrain.intersect([x,100,z],[x,-100,z], True, viz.ABS_GLOBAL)
for p in intersection:
print p.point


and the result is:

[SOME_X, 0.0, SOME_Z]

But I think it shouldn't be 0.0. Am I missing something?

Best,
Omid

farshizzo
01-26-2009, 05:12 PM
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: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)

omidbrb
01-28-2009, 05:02 PM
Thanks a lot for the reply. I wonder why all the advanced commands are not documented in the manual, while they look quite useful in certain situations.

Best,
Omid

omidbrb
01-30-2009, 03:46 AM
I also noticed that collisions with InfiniteTerrain are not handled automatically. Is it true? This is the code that I used to enable collisions:


view = viz.add(viz.VIEWPOINT)
view.collision(viz.ON)
view.collisionbuffer(1)


but the viewer goes through the terrain. Should I handle it manually?

Best Regards,
Omid

Jeff
02-05-2009, 03:19 PM
It looks like you'll have to handle it manually. Have you had any success creating the code to do that?

omidbrb
02-24-2009, 02:57 AM
I haven't tried yet but I'll post if I managed to do that.