View Single Post
  #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