Panda3D Hello World Tutorial Questions

Hi,
I’m reading Panda3D “Hello World Tutorial”, and I have several questions:
1.

My mouse has only left and right button, but has no middle button. How can I simulate these two middle button operations?
2. What is the coordinate that Panda3D uses? Do I draw right (figure 1)?
3.

def spinCameraTask(self, task):
        angleDegrees = task.time * 6.0
        angleRadians = angleDegrees * (pi / 180.0)
        self.camera.setPos(20 * sin(angleRadians), -20.0 * cos(angleRadians), 3)
        self.camera.setHpr(angleDegrees, 0, 0)
        return Task.cont

What is the type of variable “task”, and what is the meaning of the “task.time”?
4.

   self.camera.setPos(20 * sin(angleRadians), -20.0 * cos(angleRadians), 3)

Why we need to compute the camera’s x and y coordinates as this? I understand that z = 3 as to move the camera up a bit along the vertical axis.
5. What the default position of the camera, like this (figure 2)?
6.

 self.camera.setPos(20 * sin(angleRadians), -20.0 * cos(angleRadians), 3)
        self.camera.setHpr(angleDegrees, 0, 0)

Does the order of “setPos” and “setHpr” matter? For example, first translation, second rotation is different as first rotation, second translation in OpenGL.
7. I don’t understand this tutorial well, and I want to know where is the camera’s position in every frame, and the direction it look at (figure 3). May someone explain it in more detail?
Thanks!





  1. Sorry, dont know. In your apps you’ll probably just use other keys for this, but might it be an option to buy a mouse with mouse button? :smiley:

  2. Panda uses a Z-up right handed coordinate system, so your drawing is correct.

  3. Panda uses a task manager. You can write a function yourself and ‘supply’ this to the task manager. The task manager will then create a ‘task’, linked to your function. Every frame the task manager then checks if the functions linked to these tasks have to be executed. Linking a function to the task manager is done with the line:

self.taskMgr.add(self.spinCameraTask,"SpinCameraTask")

One of the things you have to do to make a function suitable to be linked to a task is to add the ‘task’ variable to the input, so ‘(self, task)’ in this case. You can then use this variable to acces information on the task that is linked to the function. An example you gave yourself was task.time. the task variable hold for instance information on how long this task has been running (which can be since the beginning of the game, but can also be later). panda3d.org/manual/index.php/Tasks

  1. So this function is run every frame (which can be seen from the return-statement, which says ‘return Task.cont’, instead of for intance ‘Task.done’), and the task variable is accessed to find out how long this task has been executed at each specific frame. To make the camera rotate around the scene (which is the anwser to your last question), it has to be undated to jump to a new position every frame. This new position is determined by increasing the angle at which the camera is located wrt the origin with time
angleDegrees = task.time*6.0
angleRadians = angleDegrees*(pi/180.)

Sines and Cosines are then used to determine its position at this new angle, and its direction is set to this angle to make the camera point to the origin each frame.

  1. If you do not link the camera to anything, then yes the camera would be at the origin (if i am not mistaken), pointing in the direction of the y-axis.

  2. No it does not, the setPos method changes the position of the object (in this case the camera) wrt the axis system of its parent, in this case the global axis system. setHpr only changes the orientation of the axis system of the object. In OpenGL setPos would work on the axis system of the object itself; if you would first rotate this axis system you would, after that, translate in a totaly different direction.

  3. It feels like you have not yet run the application? Anyway, the camera is traveling in a circle around the origin, always pointing towards the origin.

Hope that helps, good luck