View Single Post
  #2  
Old 04-20-2016, 01:13 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
You could detect the ground height using an intersection test and then adjust the height of the viewpoint or object that is flying above. Here is a basic example:

Code:
'''
Use up/down arrows to move view
'''

import viz
import vizact
import vizinfo

viz.setMultiSample(4)
viz.fov(60)
viz.go()

vizinfo.InfoPanel(align=viz.ALIGN_RIGHT_TOP)

viz.clearcolor(viz.SLATE)
viz.addChild('ground.osgb')
viz.move([0,0,-2])

quad = viz.addTexQuad(pos=[0,0,4.5],euler=[0,65,0],scale=[2,10,1],color=viz.RED)
quad2 = viz.addTexQuad(pos=[0,0,13.55],euler=[180,65,0],scale=[2,10,1],color=viz.RED)

vizact.whilekeydown(viz.KEY_UP,viz.MainView.setPosition,[0,0,0.05],viz.REL_LOCAL)
vizact.whilekeydown(viz.KEY_DOWN,viz.MainView.setPosition,[0,0,-0.05],viz.REL_LOCAL)

def adjustHeight():
	x,y,z = viz.MainView.getPosition()
	info = viz.intersect([x,y+0.5,z],[x,y-4,z])
	groundHeight = info.point[1]
	viz.MainView.setPosition([x,groundHeight+3,z])
	
vizact.onupdate(0,adjustHeight)
Reply With Quote