Camera angle in the panda hello world tutorial

I use the code here exactly as it is on the tutorial:
panda3d.org/manual/index.php … _the_Panda

And it runs just fine, I start it and I see the panda walking on the ground. The camera angle is nice (i.e. not ‘above’ or ‘below’ the ground, spins slowly, etc.)

Now… say if I want to remove the spinning. i tried a few things, and now I’m rather confused about how camera angles work.

The first thing I tried was to remove the line:

This stops the spinning, as I expected, it also makes the starting camera angle a little wierd. Here’s a screenshot of what I see:

So the camera is slightly below the ground, panda is going off the screen and so on. I guess this must be some kind of ‘default’ camera position and angle.

I liked the initial camera position set by spinCameraTask. That’s the camera positionw here you are zoomed out and looking down at the panda. I just wanted to remove the spinning.

From my understanding of how spinCameraTask works, task.time starts at 0 and increases. That value is used to calculate the camera position. Since circular functions (sin or cos) are used you get spinning.

So I commented out this line:

and added this code

Basically copied from spinCameraTask with “task.time” replaced by “0”.

The result is that when I run the program, it looks exactly the same as the above screenshot.

If I replace “task.time” with any other number, it’s exactly the same.

Why does it seem like I’m unable to set the camera position manually? I understand that spinCameraTask was ran every frame to update the camera angle. But all I need is a way to set the camera angle once at the start of the program.

What am I doing wrong?

Try calling:

base.disableMouse()

This turns off the default camera-control task that is also competing to put the camera to where the trackball controls say it should be. I guess when the cameraSpinTask is running, both tasks are setting the camera every frame, and the cameraSpinTask is the second one to set the camera, so that position sticks, and we don’t notice that the trackball task is still running.

David

Try adding the following:

    from pandac.PandaModules import Vec3
    # import the Vec3 functions, which handle xyz coordinates really easily

    base.disableMouse() 
    # disables the mouse camera controls, required to shift the camera

    taskMgr.add( self.cameraFollowTask, 'cameraFollowTask')
    # initiates the task shown below


    def cameraFollowTask( self, task ): 
        # we want the camera to follow the panada
        # it will stay 75 units behind and 20 units 
        # up from the pandaActor
        desiredPos = self.pandaActor.getPos( ) + self.pandaActor.getQuat( ).xform( Vec3(0, 75, 20) ) 
        # once we know where the camera should be
        # use setPost to put the camera there
        # this only works if base.disableMouse() has been called previously
        camera.setPos(desiredPos) 
        # tell the camera to look at the panda
        camera.lookAt(self.pandaActor)       
        return task.cont 

Vec3 is a special library that lets you deal with xyz coordinates really easily.

base.disableMouse() breaks the mouse camera functions, which is essential if you are trying to change how the camera moves. Once this has been called, you can easily use camera.setPos(x, y, z) to move the camera wherever you want.

The extra code I added creates a task that will make the camera follow the panda and keep looking at it, so it if the panda moves it will follow him. You might need to adjust the numbers in the Vec3 part though to change where you want the camera.

Try this:

base.camera.setPos(self.environ.getX(),self.environ.getY()+100,2)# 10 = distance between cam and point 
         dummy.setH(10) #this will rotate it 60 degrees around the point