View Single Post
  #2  
Old 08-30-2011, 04:13 AM
andrewjworz andrewjworz is offline
Member
 
Join Date: Apr 2011
Posts: 11
Also, I am trying to have the view point "walk" along the surface of the terrain generated by the InfiniteTerrain.dlc at a fixed height (let's say, the height of an avatar). I would like to move in the x and z directions with the arrows on the keyboard, while the viewpoint adjusts to the proper height about the terrain. Does anyone have any idea how to do this? Given below is the viewpoint controls that I have been using.

# Viewpoint keyboard controls
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%

## Turn off built-in mouse navigation
#viz.mouse(viz.OFF)
## Hide mouse cursor
#viz.mouse.setVisible(False)

MOVE_SPEED = 19
TURN_SPEED = 60

male = viz.addAvatar( 'vcc_male.cfg' )
male.scale([10,10,10])
#male.collideCapsule()

viz.MainView.setPosition(0,terrainmaker.terrainfun c(0,0)+17,0)
viz.MainView.setEuler([0,0,0])
## Extract the main viewpoint
view = viz.MainView

## Make function which calls back for keyboard event
pos_init = view.getPosition()

def updatemale():
if viz.key.isDown('d'):
view.move([0,-MOVE_SPEED*viz.elapsed(),0],viz.BODY_ORI)
if viz.key.isDown('f'):
view.move([0,MOVE_SPEED*viz.elapsed(),0],viz.BODY_ORI)
if viz.key.isDown(viz.KEY_UP):
male.state(2)
view.move([0,0,MOVE_SPEED*viz.elapsed()],viz.BODY_ORI)
if viz.key.isDown(viz.KEY_RIGHT):
view.setEuler([TURN_SPEED*viz.elapsed(),0,0],viz.BODY_ORI,viz.REL_PARENT)
elif viz.key.isDown(viz.KEY_LEFT):
view.setEuler([-TURN_SPEED*viz.elapsed(),0,0],viz.BODY_ORI,viz.REL_PARENT)

elif viz.key.isDown(viz.KEY_DOWN):
male.state(2)
view.move([0,0,-MOVE_SPEED*viz.elapsed()],viz.BODY_ORI)
if viz.key.isDown(viz.KEY_RIGHT):
view.setEuler([TURN_SPEED*viz.elapsed(),0,0],viz.BODY_ORI,viz.REL_PARENT)
elif viz.key.isDown(viz.KEY_LEFT):
view.setEuler([-TURN_SPEED*viz.elapsed(),0,0],viz.BODY_ORI,viz.REL_PARENT)

elif viz.key.isDown(viz.KEY_RIGHT):
view.setEuler([TURN_SPEED*viz.elapsed(),0,0],viz.BODY_ORI,viz.REL_PARENT)
if viz.key.isDown(viz.KEY_UP):
male.state(2)
view.move([0,0,MOVE_SPEED*viz.elapsed()],viz.BODY_ORI)
elif viz.key.isDown(viz.KEY_DOWN):
male.state(2)
view.move([0,0,-MOVE_SPEED*viz.elapsed()],viz.BODY_ORI)
elif viz.key.isDown(viz.KEY_LEFT):
view.setEuler([-TURN_SPEED*viz.elapsed(),0,0],viz.BODY_ORI,viz.REL_PARENT)
if viz.key.isDown(viz.KEY_UP):
male.state(2)
view.move([0,0,MOVE_SPEED*viz.elapsed()],viz.BODY_ORI)
elif viz.key.isDown(viz.KEY_DOWN):
male.state(2)
view.move([0,0,-MOVE_SPEED*viz.elapsed()],viz.BODY_ORI)

# Attach the male to the viewpoint BODY_ORI
male.setPosition(view.getPosition())
male.setEuler(view.getEuler(viz.BODY_ORI))
male.setPosition([0,0,25],viz.REL_LOCAL) #[0.35,-1.7,-0.13]
Reply With Quote