All I am trying to do right now is load a model, get the camera and set the camera position and direction. So I started with this (which doesn’t work):
from pandac.PandaModules import *
#Load the first environment model
environ = loader.loadModel("mymodel.egg")
base.accept( "escape" , sys.exit)
camera.setHpr(30.0, 30.0, -30.0)
A roundabout way to do it would be to orient my model to the camera with…
environ.setHpr(30.0, 30.0, -30.0)
… but I really want to just control the camera. How would I do that?
Thanks in advance for your help!
You control the base.camera object, in the same way as any other object. ^^
Isn’t environ technically “any other object”?
If so, why wouldn’t camera.setHpr(30.0, 30.0, -30.0) work if environ.setHpr(30.0, 30.0, -30.0) works? What am I not understanding here?
Yes, but it has to be “base.camera”, not just camera.
That’s why I have this line in there:
Even if I switch it to be…
base.camera.setHpr(30.0, 30.0, -30.0)
…it still doesn’t work.
Oh… what the…
It’s base.cam … not base.camera. I read in some other example that it was base.camera but I suppose it must have changed to base.cam since then. Ok! Now this is making more sense to me!
No, it’s not base.cam. It’s base.camera.
But before you can set the position of base.camera, you have to disable the built-in trackball task with:
If you don’t do this, then the trackball will just snap the camera right back where it was every frame, no matter where you move it, making it appear that you didn’t move it at all.
You shouldn’t move base.cam around. That might seem to work at first, but since that movement is actually relative to base.camera, it will just get you in trouble later.
Alright… but I did already try that…
I did do base.disableMouse() and still couldn’t get my camera to point at an angle with base.camera.setHpr(30.0, 30.0, -30.0).
What’s the difference between base.cam and base.camera?
base.cam is an internal reference object, and base.camera is the one that you actually do things to. Technically it should work with either, but wierd things could happen if you mess with base.cam.
As for the fact that it didn’t work, I’m kinda nooby too, so no idea.
Thanks for the feedback. Hm, looks like I’m not the only one that ran into this:
discourse.panda3d.org/viewtopic.php … ght=camera
AHA! I see.
I did do base.disableMouse(), but I suppose by using base.useDrive() I re-enabled it (which would make sense with what drwr is saying).
Once I took that line out it worked. Cool. Thanks for the help!
Though you called base.disableMouse(), which turns off the camera tracking, you also called base.useDrive(), which turns on the camera tracking again. If you want to set an initial position of the camera and still use the drive interface, you need to load that onto the drive interface object, not onto the camera, like:
That will tell the drive interface where it should put the initial position, and you can drive around from there with the keyboard and mouse. Each frame, the drive interface will copy that position onto the camera. But if you just set the camera directly, the drive interface doesn’t know you’ve done that, and it copies its original position back onto the camera.
base.camera is an ordinary NodePath, base.cam is a child of that NodePath that contains the actual Camera object. The reason there are two different NodePaths is in case you want to have multiple Cameras joined together as a single camera rig: all of the Cameras will be parented to base.camera, and when you move base.camera, it will move all of your Cameras together.
Because of the parent/child relationship, it appears to work if you move around base.cam. The drive interface isn’t changing the position of base.cam every frame, so whatever transform you put there sticks; but base.cam also inherits the position of base.camera (since that’s the parent), so you can still move your point-of-view around with the drive interface. Unfortunately, you’ll get into trouble if you want to do anything more advanced with this configuration, like enable collisions or something, because the origin of your “position” as the drive interface thinks of it is no longer your actual viewpoint.
The intended design is that you always manipulate the position of base.camera. You normally shouldn’t do anything at all with base.cam, except in very special cases when you actually want to do something with the Camera itself (for instance, replace the lens properties or something).
That’s making a lot more sense to me now, thanks! Such a helpful and responsive community.