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
  #1  
Old 08-16-2007, 11:04 AM
Vinicius Lima Vinicius Lima is offline
Member
 
Join Date: Jul 2007
Posts: 40
Viewpoint control

Hi,

I am working using the viewpoint control tutorial and when I am trying to make the car I modeled in 3d Max I am running into coordinate problems. It seems to work when I have the object positioned at 0,0,0 but when I move it somewhere else, the viewpoint is no longer inside the car. Here is my script:

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('ground.osg')
car = viz.add('car.osg')

#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_OR I)
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.BOD Y_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[0] += e.dx*0.1
euler[1] += -e.dy*0.1
euler[1] = viz.clamp(euler[1],-85.0,85.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.callback(viz.MOUSEBUTTON_EVENT,mousedown)

viz.mouse(viz.OFF)
viz.cursor(viz.OFF)
viz.restrictmouse(viz.ON)

Thanks,

Vinicius
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 03:07 AM.


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