WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

 
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 08-17-2007, 03:49 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
I tried your script but there were some errors with it. I fixed the errors and it works for me now. Can you try the following code:
Code:
import viz
viz.go()

#Changing the background color to SKYBLUE
viz.clearcolor(0.5,0.5,1)

#Defining the move and the turn speeds
MOVE_SPEED = 5
TURN_SPEED = 60

#Adding the objects to the world
ground = viz.add('tut_ground.wrl')
car = viz.add('mini.osgx')

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

def mytimer(num):
    
    if viz.iskeydown(viz.KEY_UP):
        view.move(0,0,MOVE_SPEED*viz.elapsed(),viz.BODY_ORI)
    elif viz.iskeydown(viz.KEY_DOWN):
        view.move(0,0,-MOVE_SPEED*viz.elapsed(),viz.BODY_ORI)
        
    if viz.iskeydown(viz.KEY_RIGHT):
        view.rotate(0,1,0,TURN_SPEED*viz.elapsed(),viz.BODY_ORI,viz.RELATIVE_WORLD)
    elif viz.iskeydown(viz.KEY_LEFT):
        view.rotate(0,1,0,-TURN_SPEED*viz.elapsed(),viz.BODY_ORI,viz.RELATIVE_WORLD)

    updatecar()
    
def updatecar():
  car.translate(view.get(viz.HEAD_POS))
  car.rotate(view.get(viz.BODY_AXISANGLE))
  car.translate(0.35,-1.2,0.2,viz.RELATIVE_LOCAL)
#def updatecar():
#    car.translate(view.get())
#    car.rotate(view.getAxisAngle(viz.BODY_ORI))
#    car.translate(0.35,-1.2,0.2,viz.RELATIVE_LOCAL)
    
def mousemove(e):
    #euler = view.getEuler(viz.HEAD_ORI)
    euler = view.get(viz.HEAD_EULER)
    euler[0] += e.dx*0.1
    euler[1] += -e.dy*0.1
    euler[1] = viz.clamp(euler[1],-90.0,90.0)
    view.rotate(euler,viz.HEAD_ORI)

def mousedown(button):
    if button == viz.MOUSEBUTTON_LEFT:
        view.reset(viz.HEAD_ORI)
    elif button == viz.MOUSEBUTTON_RIGHT:
        view.reset(viz.BODY_ORI|viz.HEAD_POS)
        updatecar()


viz.callback(viz.TIMER_EVENT,mytimer)
viz.starttimer(0,0.01,viz.FOREVER)

viz.callback(viz.MOUSE_MOVE_EVENT,mousemove)

viz.setMouseOverride()
viz.cursor(viz.OFF)

viz.callback(viz.MOUSEBUTTON_EVENT,mousedown)

viz.mouse(viz.OFF)
viz.restrictmouse(viz.ON)
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 05:55 PM.


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