O'Reilly logo

Panda3D 1.6 Game Engine by Dave Mathews

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - turning the camera with the mouse position

To see this in action, we're going to set the camera's heading and pitch based on where the mouse is in the window.

  1. Add this code to the cycleControl() method right above the call to self.speedCheck:
    if(base.mouseWatcherNode.hasMouse() == True):
    mpos = base.mouseWatcherNode.getMouse()
    base.camera.setP(mpos.getY() * 30)
    base.camera.setH(mpos.getX() * -30)
    
  2. Save the file as chp04_07.py and run it.
Time for action - turning the camera with the mouse position

What just happened?

Now, the camera snaps to a new rotation based on the position of the mouse in the window. To be specific, the new rotation is equal to a percentage of 30 degrees according to how ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required