question about camera

Can someone give me a tip how to make FPS-like camera rotation with mouse ?
In my program I have sth. like this :

 if base.mouseWatcherNode.hasMouse():
          mpos = base.mouseWatcherNode.getMouse()

          if mpos.getX()>.15 and mpos.getX()<1:
                   self.angle += .15

	  if mpos.getX()<-.15 and mpos.getX()>-1:
		   self.angle -= .15
         camera.setHpr(-self.angle, self.pan, 0)

this works, but in the middle of scrren is a square in which when you move mouse nothing happens - because without this square the camera always rotates and pans

my problem is that I need ‘smooth’ camera like in FPS games - with mouse cursor always in the middle of screen, not moving around the screen

how should I do this ? or do you know better way than returning mouse to center ? let me know…


Record the initial pos, then check against that to see whether the mouse has moved and in what direction. You could also code in mouse sensitivity that way.

Some quick sample:

def __init__(self):

    self.oldpos = base.mouseWatcherNode.getMouse() 

def movement(self):
    if base.mouseWatcherNode.hasMouse():

              newpos = base.mouseWatcherNode.getMouse() 

             # check agains previous mouse pos - 0.15 so its not to sensitive
             # Just a sample, expand on it... You could also check the 
             # amout of displacement done, so you turn quicker when the 
             # mouse is moved faster.

              if newpos.getX()-0.15>self.oldpos.getX(): 
                       self.angle += .15 
             camera.setHpr(-self.angle, self.pan, 0) 
             self.oldpos = newpos

download the airblade source code and look at

they do a pretty good job on mouse input