PDA

View Full Version : Mouselook & Keyboard Navigation


EnvisMJ
06-29-2009, 11:31 AM
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?

Jeff
06-29-2009, 03:36 PM
So you want 6DOF movement with the keyboard and orientation with the mouse. This should work.

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)

EnvisMJ
07-08-2009, 02:46 PM
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?

Jeff
07-08-2009, 03:35 PM
If you want to don't want to use some of the keyboard controls you can specify None for those.
vizcam.KeyboardCamera(forward='w',backward='s',lef t='a',right='d',up=None,down=None,turnRight='e',tu rnLeft='q',pitchDown=None,pitchUp=None,rollRight=N one,rollLeft=None)

EnvisMJ
07-09-2009, 01:58 PM
Thanks Jeff, it's working great, I've developed a standalone class now that we can use in the future.


#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=N one,backward=None,left=None,right=None,turnRight=N one,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',tu rnRight='e',up=' ',down=viz.KEY_ALT_L,pitchDown=None,pitchUp=None,r ollRight=None,rollLeft=None))
#disable navigation
def disable(self):
viz.restrictmouse(viz.OFF)
self.move = False
self.camera = viz.cam.setHandler(vizcam.KeyboardCamera(forward=N one,backward=None,left=None,right=None,turnRight=N one,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()


After navigating for a while, the camera always develops a little bit of a roll, is there a way to lock the roll at 0? So the camera will always stay level, regardless of mouse movement?

Jeff
07-09-2009, 07:05 PM
In mousemove you could try setting
euler[2] = 0

dwaik
03-02-2010, 01:29 AM
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

Jeff
03-02-2010, 03:34 PM
You can apply a scale to the move and turn speeds using the sensitivity method.
import vizcam
keycam = vizcam.KeyboardCamera()
keycam.sensitivity(3,1)
viz.cam.setHandler(keycam)

EnvisMJ
06-22-2010, 03:38 PM
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.

Jeff
06-22-2010, 04:52 PM
Are you saying you want the mouse to stay inside the graphics window? If so you can use:
viz.mouse.setTrap(viz.ON)