WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 06-30-2006, 02:22 PM
spacefarer spacefarer is offline
Member
 
Join Date: Dec 2004
Location: Cambridge, MA
Posts: 17
3d viewpoint movement

I just tried the script for R2.5 as shown below which was given by Farshid, but it doesn't work with R3. Could anyone tell what's wrong with it, please?

import viz
viz.go()

#Add a ground
viz.add('tut_ground.wrl')

#Get main viewpoint object
view = viz.get(viz.MAIN_VIEWPOINT)

#Create a variable that will tell whether viewpoing is currently moving/turning
view.animating = 0

#Variable that holds current destination value
final = [0,0,0,0]

def rotateview(x,y,z,angle):
#Make sure view is not animating
if not view.animating:
#Compute rotation of turning body 90 degrees to right
xform = viz.Transform(view.get(viz.BODY_MAT))
xform.preRot(x,y,z,angle)
final[:] = xform.getRot()[:]
#Start animating viewpoint
view.spinmask(viz.BODY_ORI) #Spin the body orientation
view.spinto(final,2,viz.TIME) #Spin for 2 seconds
view.animating = 1

def onkeydown(key):
if key == viz.KEY_UP:
#Make sure view is not animating
if not view.animating:
pos = view.get(viz.HEAD_POS)
trans = view.get(viz.BODY_LOOK)
#Round values to nearest integer
final[0] = int(round(pos[0] + trans[0]))
final[1] = int(round(pos[1] + trans[1]))
final[2] = int(round(pos[2] + trans[2]))
#Start animating viewpoint
view.goto(final,1,viz.TIME)
view.animating = 1
elif key == '6': #yaw right
rotateview(0,1,0,90)
elif key == '4': #yaw left
rotateview(0,1,0,-90)
elif key == '8': #pitch up
rotateview(1,0,0,-90)
elif key == '2': #pitch down
rotateview(1,0,0,90)
elif key == '9': #roll right
rotateview(0,0,1,-90)
elif key == '7': #roll left
rotateview(0,0,1,90)

viz.callback(viz.KEYDOWN_EVENT,onkeydown)

def onstop(object, type):
if type == viz.MOVE:
#Viewpoint is done moving, translate it to the final value just to be sure
view.translate(final)
view.animating = 0
elif type == viz.SPIN:
#Viewpoint is done spinning, rotate it to the final value just to be sure
view.rotate(final,viz.BODY_ORI)
view.animating = 0

view.callback(viz.STOP_EVENT,onstop)
Reply With Quote
 


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


All times are GMT -7. The time now is 12:59 PM.


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