|
Post by flassari on Feb 25, 2009 3:55:42 GMT -5
Here's a simple code to implement mouse look.
In your constructor, put:
self.heading = 0 self.pitch = 0 self.mouseSensitivity = 0.2 self.maxPitch = 45 base.win.movePointer(0, 100, 100) taskMgr.add(self.controlCamera, "camera-task")
and then add this function to your class:
def controlCamera(self, task): pointer = base.win.getPointer(0) x = pointer.getX() y = pointer.getY() if base.win.movePointer(0, 100, 100): self.heading = self.heading - (x - 100)*self.mouseSensitivity self.pitch = self.pitch - (y - 100)*self.mouseSensitivity if (self.pitch < -self.maxPitch): self.pitch = -self.maxPitch if (self.pitch > self.maxPitch): self.pitch = self.maxPitch base.camera.setHpr(self.heading, self.pitch, 0) return task.cont
This fixes the mouse pointer to the coordinates 100x100, so you should accept a key event for the user to close the program or just use alt+F4 (windows).
The mouse curser is still visible and "stuck", so to hide it put this code in your initialization function:
props = WindowProperties() props.setCursorHidden(True) base.win.requestProperties(props)
and remember to disable the default mouse controls:
base.disableMouse()
-Ari-
|
|