WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #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
  #2  
Old 08-16-2007, 02:24 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Can you please repost the code using the [code][/code] tags. It will preserve the formatting and make it easier for me to test your script. Thanks.
Reply With Quote
  #3  
Old 08-16-2007, 02:30 PM
Vinicius Lima Vinicius Lima is offline
Member
 
Join Date: Jul 2007
Posts: 40
PHP 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('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_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] += x*0.1
    euler
[1] += -y*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.MOUSEMOVE_EVENT,mousemove)
viz.mousedata(viz.RELATIVE,viz.RELATIVE)
viz.setMouseOverride()
viz.cursor(viz.OFF)

viz.callback(viz.MOUSEBUTTON_EVENT,mousedown)

viz.mouse(viz.OFF)
viz.restrictmouse(viz.ON
Reply With Quote
  #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
  #5  
Old 08-17-2007, 04:20 PM
Vinicius Lima Vinicius Lima is offline
Member
 
Join Date: Jul 2007
Posts: 40
HI farshizzo,

Thanks for your help. I tried your script using the files I modeled in 3ds Max instead of the ones with the tutorials and the problem remained. I'll double check my models and I'll let you know.

Thanks

Vinicius
Reply With Quote
  #6  
Old 08-20-2007, 08:53 AM
Vinicius Lima Vinicius Lima is offline
Member
 
Join Date: Jul 2007
Posts: 40
Hello,

Even after double checking the files and the script it is not working. So, I was wondering if when I am exporting as .osg files I am not clicking one of the options or I am not doing it right. This has happened a couple of times already and I tried everything thinking the problem was in the script but my script is exactly like the one I got from you. So, I am guessing the problem is in the modeling. Could you help me?

Thanks,

Vinicius
Reply With Quote
  #7  
Old 08-20-2007, 05:51 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
I don't really understand what the problem is. You will need to post your model so I can test it out myself. If you prefer, you can email the model to lashkari@worldviz.com
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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 02:35 PM.


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