I am confused about the camera. I was playing around with the tutorial at the beginning of the manual. At the part where we add the spinning camera, I printed out the camera position and heading. I then turned off the spinning part, and just changed the position and heading of the camera in init to be that same position and heading. If I print out getPos and getHpr, it claims to be at the same position as at the start of when the camera spins, but it clearly is not. What about the spinCameraTask is actually causing the camera to move to the starting position, why doesn’t it do this manually from init, and why do both give the same position and heading when queried?
from direct.showbase.ShowBase import ShowBase
from direct.task import Task
from math import pi, sin, cos
# Load the environment model.
self.environ = self.loader.loadModel("models/environment")
# Reparent the model to render.
# Apply scale and position transforms on the model.
self.environ.setScale(0.25, 0.25, 0.25)
self.environ.setPos(-8, 42, 0)
self.camera.setPos(0, -20, 3)
self.camera.setHpr(0, 0, 0)
# Add the spinCameraTask procedure to the task manager.
# self.taskMgr.add(self.spinCameraTask, "SpinCameraTask")
# Define a procedure to move the camera.
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)
app = MyApp()
self.camera.setPos(x, y, z)
self.camera.setHpr(h, p, r)
work in task.
In init they didn’t work. But it works when instead of “camera” is “cam”.
In task no difference camera or cam.
The reference panda3d.org/reference/devel … e.ShowBase tells very little: cam
This is a NodePath pointing to the Camera object set up for the 3D scene.
This is usually a child of self.camera. camera
This is the NodePath that should be used to manipulate the camera.
This is the node to which the default camera is attached.
Finally figured this out. The problems is of course, not putting in the base.disableMouse() call. I had thought it would be brilliant to return the camera position when I had moved the mouse to the exact camera position that I wanted to use as the start position so I could hard code it. But, it gave strange, inconsistent results. Then I put in a key press to stop and start the camera task. Whenever the camera task was removed, the camera would jump back to its odd start position. At which point I realized that the task must make a call to base.disableMouse(), and indeed when the task is stopped, I can move the camera with the mouse, but not when the task is going. Haven’t checked yet to see what exactly is making this call. Really unfortunate this is the way things are set up, as one of the pain in the butts about Panda3d is figuring out how to get the initial positions of stuff correct, and being able to move the camera where you want it with the mouse and then save that camera position would help.
and try it again with the task added. See what happens now that the task has this priority value of -100? You should be able to use the mouse again to reposition the camera. What this means, is that the built-in camera manipulation is being handled in a task itself, with quite a high priority so that most user-defined tasks (which usually have a positive priority value, default zero) are handled afterwards. So before, your task was simply overriding the camera transformation that was previously set by the built-in camera controller if you attempted to use the mouse.
A common approach is to create a camera in the modelling program, setting it up to point at your scene appropriately, giving it a special name or tag, and then extracting the transform in the program with something like
Thanks to both of you, very helpful information! And it is true that if you use the mouse to get your favorite camera angle, and then print out the position and hpr of the camera, you can then disable the mouse, and set the camera at the found position/hpr, and the camera will show up where you expect it. You just have to remember to disable that mouse, or it goes to a default position, and ignores what you set.