#1
|
|||
|
|||
Mouselook & Keyboard Navigation
We are building a virtual training environment. And we would like to implement 'mouselook' and the standard FPS keyboard movement keys. We have it set up to move with the keyboard and it works fine:
keyTracker =viztracker.Keyboard6DOF(forward='w',backward='s', left='a',right='d',turnRight='e',turnLeft='q') keyLink = viz.link(keyTracker, viz.MainView) keyLink.enable() And we can do 'mouselook' how we want it: def mousemove(e): 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) viz.callback(viz.MOUSE_MOVE_EVENT,mousemove) viz.setMouseOverride() However, when we try to implement both in the same program, one overrides the other and we only get one of the two navigation modes. I assume this is because we are implementing the two navigation modes in different ways. Does anyone have some quick and easy code that will allow for navigation using both methods? |
#2
|
|||
|
|||
So you want 6DOF movement with the keyboard and orientation with the mouse. This should work.
Code:
import vizcam viz.cam.setHandler(vizcam.KeyboardCamera(forward='w',backward='s', left='a',right='d',turnRight='e',turnLeft='q')) def mousemove(e): 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) viz.callback(viz.MOUSE_MOVE_EVENT,mousemove) |
#3
|
|||
|
|||
Thanks, that got it working great.
It does assign several other buttons on the keyboard 'g', 'h' and a couple others. We don't want these other keys mapped, and we also need some of them for other functions in our program. How can we unassign them? |
#4
|
|||
|
|||
If you want to don't want to use some of the keyboard controls you can specify None for those.
Code:
vizcam.KeyboardCamera(forward='w',backward='s',left='a',right='d',up=None,down=None,turnRight='e',turnLeft='q',pitchDown=None,pitchUp=None,rollRight=None,rollLeft=None) |
#5
|
|||
|
|||
Thanks Jeff, it's working great, I've developed a standalone class now that we can use in the future.
Code:
#Class allows typical FPS navigation controls #W,A,S,D and mouselook import viz import vizcam #Define user movement class class avatarMove: #initialization function def __init__(self): self.move = False self.view = viz.MainView self.camera = viz.cam.setHandler(vizcam.KeyboardCamera(forward=None,backward=None,left=None,right=None,turnRight=None,turnLeft=None,up=None,down=None,pitchDown=None,pitchUp=None,rollRight=None,rollLeft=None)) viz.callback(viz.MOUSE_MOVE_EVENT,self.mousemove) #enable navigation def enable(self): viz.restrictmouse(viz.ON) self.move = True self.camera = viz.cam.setHandler(vizcam.KeyboardCamera(forward='w',backward='s',left='a',right='d',turnLeft='q',turnRight='e',up=' ',down=viz.KEY_ALT_L,pitchDown=None,pitchUp=None,rollRight=None,rollLeft=None)) #disable navigation def disable(self): viz.restrictmouse(viz.OFF) self.move = False self.camera = viz.cam.setHandler(vizcam.KeyboardCamera(forward=None,backward=None,left=None,right=None,turnRight=None,turnLeft=None,up=None,down=None,pitchDown=None,pitchUp=None,rollRight=None,rollLeft=None)) #tracks mouse movements def mousemove(self,e): if self.move == True: euler = self.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) self.view.rotate(euler,viz.HEAD_ORI) #allows you to set the position of the user def setPosition(self,x,y,z): self.view.setPosition(x,y,z) #allows you to get the position of the user def getPosition(self): return self.view.getPosition() #allows you to set the rotation of the user def setRotation(self,y,p,r): self.view.setEuler(y,p,r) #allows you to get the rotation of the user def getRotation(self): return self.view.getEuler() |
#6
|
|||
|
|||
In mousemove you could try setting
Code:
euler[2] = 0 |
#7
|
|||
|
|||
hello
what to do if i want to increase the speed of keyboard navigation, i used viz.cam.setHandler(vizcam.KeyboardCamera(forward=' w',backward='s',left='a',right='d',turnLeft='q',tu rnRight='e',up=' ',down=viz.KEY_ALT_L,pitchDown=None,pitchUp=None,r ollRight=None,rollLeft=None)) and found nothing about it in the documentation, please help |
#8
|
|||
|
|||
You can apply a scale to the move and turn speeds using the sensitivity method.
Code:
import vizcam keycam = vizcam.KeyboardCamera() keycam.sensitivity(3,1) viz.cam.setHandler(keycam) |
#9
|
|||
|
|||
Is there a way to bind the mouse to the center of the viewport? But continue to enable mouselook? At the moment the mouse goes all over the viewport, which makes it a bit difficult to navigate at times.
|
#10
|
|||
|
|||
Are you saying you want the mouse to stay inside the graphics window? If so you can use:
Code:
viz.mouse.setTrap(viz.ON) |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Question about input from virtual keyboard. | yyang | Vizard | 4 | 12-23-2008 01:25 PM |
navigation in cave environment | Andy | Vizard | 4 | 03-28-2008 02:32 AM |
On Screen Keyboard | betancourtb82 | Vizard | 14 | 10-03-2006 01:38 PM |
Multiple Viewports in Vizard, Utilizing keyboard callback | shivanangel | Vizard | 2 | 02-21-2006 05:56 PM |
Navigation Speed/Too Slow | Plasma | Vizard | 2 | 01-28-2004 12:07 PM |