Dissecting Fps Script

Hello, I came across this neat little FPS demo and I’m racking my brain trying to figure out how he did this single part:

    def mouseUpdate(self,task):
        """ this task updates the mouse """
        md = base.win.getPointer(0)
        x = md.getX()
        y = md.getY()
        if base.win.movePointer(0, base.win.getXSize()/2, base.win.getYSize()/2):
            self.node.setH(self.node.getH() -  (x - base.win.getXSize()/2)*0.1)
            base.camera.setP(base.camera.getP() - (y - base.win.getYSize()/2)*0.1)
        return task.cont

Somewhere in the script he’s made “base.win.movePointer(0, base.win.getXSize()/2, base.win.getYSize()/2)”
= True, but I can’t find where he did that. Can someone help me out?

Here is a link to the full script: https://github.com/treeform/simple-fps

movePointer is a function that moves the cursor to indicated coordinates (in this case, the centre of the window). It returns true if it was successful in doing so, but it can also return false when Panda fails to move the cursor. This usually happens when the mouse is outside of the window or the window is not in focus. In this case, you don’t want to be moving the camera around anyway.

As to where it is, it appears to be on the sixth line (including the comment) of the snippet that you posted, just after “if”. However, he doesn’t have “base.win.movePointer(0, base.win.getXSize()/2, base.win.getYSize()/2)
= True” (which doesn’t seem to make much sense: it would appear to get the result of “base.win.movePointer”, and then immediately overwrite it with the value “True”); instead he checks whether the result of “base.win.movePointer” is True by placing it in an “if” statement.

Sorry, I didn’t mean that was part of the script, I was wondering which part of the script was making it register as True.

Why wouldn’t I want to move the camera around? Also, in order to not directly move the camera, would I parent it to some other object that is affected by mouse movement?

You don’t want to move the camera around when the cursor is outside of the window, because the operating system doesn’t give you access to the mouse position (let alone allowing you to reset it). Otherwise, when your cursor leaves the window, the camera will keep spinning around rapidly.

No part in the script makes it register as True; the movePointer method is in Panda and as such that makes it register as True or False.