WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 01-23-2009, 05:04 AM
omidbrb omidbrb is offline
Member
 
Join Date: Dec 2008
Posts: 27
About intersect function

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:

Code:
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
Reply With Quote
  #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
  #3  
Old 01-28-2009, 05:02 PM
omidbrb omidbrb is offline
Member
 
Join Date: Dec 2008
Posts: 27
Thanks for the reply

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
Reply With Quote
  #4  
Old 01-30-2009, 03:46 AM
omidbrb omidbrb is offline
Member
 
Join Date: Dec 2008
Posts: 27
Collisions with InfiniteTerrain

I also noticed that collisions with InfiniteTerrain are not handled automatically. Is it true? This is the code that I used to enable collisions:

Code:
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
Reply With Quote
  #5  
Old 02-05-2009, 03:19 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
It looks like you'll have to handle it manually. Have you had any success creating the code to do that?
Reply With Quote
  #6  
Old 02-24-2009, 02:57 AM
omidbrb omidbrb is offline
Member
 
Join Date: Dec 2008
Posts: 27
I haven't tried yet but I'll post if I managed to do that.
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Documentating function names aaThomas Vizard 5 05-15-2007 09:50 AM
Do you know how to send a value for 'pool' to the onActionEnd function? ghazanfar Vizard 1 03-22-2007 10:25 AM
timers and director function Jerry Vizard 1 06-22-2006 09:47 AM
node3d.center function tavaksai Vizard 3 08-13-2004 11:05 AM
walkTo function poolshark Vizard 4 10-09-2003 12:45 PM


All times are GMT -7. The time now is 07:31 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC