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.
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)
chp04_07.py
and run it.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 far the mouse is from the center of the window.
base.mouseWatcherNode.getMouse()
when the mouse isn't in the window? base.mouseWatcherNode.hasMouse()
commonly used for?Take some time to play with setting up control schemes. Change the keys that are being used, add keys to change the colour or scale of things, and so on. Try different ideas, like changing the colour of the cycle based on the mouse position within the window, until you feel comfortable with handling user input. Make sure you save the files containing these changes with new names!