WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rating: Thread Rating: 6 votes, 5.00 average. Display Modes
  #1  
Old 06-29-2009, 11:31 AM
EnvisMJ EnvisMJ is offline
Member
 
Join Date: May 2009
Location: Purdue University, West Lafayette, Indiana
Posts: 44
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?
Reply With Quote
  #2  
Old 06-29-2009, 03:36 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
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)
Reply With Quote
  #3  
Old 07-08-2009, 02:46 PM
EnvisMJ EnvisMJ is offline
Member
 
Join Date: May 2009
Location: Purdue University, West Lafayette, Indiana
Posts: 44
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?
Reply With Quote
  #4  
Old 07-08-2009, 03:35 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
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)
Reply With Quote
  #5  
Old 07-09-2009, 01:58 PM
EnvisMJ EnvisMJ is offline
Member
 
Join Date: May 2009
Location: Purdue University, West Lafayette, Indiana
Posts: 44
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()
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?
Reply With Quote
  #6  
Old 07-09-2009, 07:05 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
In mousemove you could try setting
Code:
euler[2] = 0
Reply With Quote
  #7  
Old 03-02-2010, 01:29 AM
dwaik dwaik is offline
Member
 
Join Date: Feb 2010
Posts: 26
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
Reply With Quote
  #8  
Old 03-02-2010, 03:34 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
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)
Reply With Quote
  #9  
Old 06-22-2010, 03:38 PM
EnvisMJ EnvisMJ is offline
Member
 
Join Date: May 2009
Location: Purdue University, West Lafayette, Indiana
Posts: 44
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.
Reply With Quote
  #10  
Old 06-22-2010, 04:52 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
Are you saying you want the mouse to stay inside the graphics window? If so you can use:
Code:
viz.mouse.setTrap(viz.ON)
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about input from virtual keyboard. yyang Vizard 4 12-23-2008 12:25 PM
navigation in cave environment Andy Vizard 4 03-28-2008 01:32 AM
On Screen Keyboard betancourtb82 Vizard 14 10-03-2006 12:38 PM
Multiple Viewports in Vizard, Utilizing keyboard callback shivanangel Vizard 2 02-21-2006 04:56 PM
Navigation Speed/Too Slow Plasma Vizard 2 01-28-2004 11:07 AM


All times are GMT -7. The time now is 10:32 AM.


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