#1
|
|||
|
|||
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 |
#2
|
|||
|
|||
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.
|
#3
|
|||
|
|||
PHP Code:
|
#4
|
|||
|
|||
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) |
#5
|
|||
|
|||
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 |
#6
|
|||
|
|||
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 |
#7
|
|||
|
|||
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
|
|
|