setting heading and pitch on a node

I am having an issue where I have this camera

self.mFirstPersonCamera = Camera("FirstPersonCamera")
		self.mFirstPersonCameraNode = self.myParent.FirstPersonDummyNode.attachNewNode(self.mFirstPersonCamera)

attached to this node

self.FirstPersonDummyNode = render.attachNewNode("FirstPersonDummyNode")

that is attached to a joint node

self.TurretJoint = self.mModel.controlJoint(None, "modelRoot","turret_main")

of which mModel is an actor parented to the world.

When I set the heading

self.myParent.TurretJoint.setH(self.myParent.TurretJoint, elapsed * (self.myParent.C1_LStickInfo.getX() * -Globals.TurretSensitivity))

the turret will start pitching, but the camera will adjust its heading like expected.

I would think its an issue with the model part I am parenting to, but I thought if you parented a camera to a model part, it will assume position and rotation of that parent? Or do I have to manually update that?

Not sure what you’re describing, but yes, when you parent a camera (or anything else) to a model part (or anything else), it will inherit the position and orientation of its parent.


Yes the camera seems to be fine. I even verified this by drawing an axis and watching it from a third person cam.

I guess the issue that I am having is, when I set the heading of the turret node, the geometry of the turret pitches, but the camera (and the node itself) are rotating just fine.

To compound the problem, the turret node (and consequently the camera node) is nowhere near the point at where the actual turret is rotating around. The camera behaves correctly (as in it doesn’t translate while I adjust the heading of the turret node), but it is offset underneath the vehicle.

I checked the export, and the person I have doing the art assures me its ok… but I am a programmer, so by my nature I don’t trust artists.

So you’re changing the heading of the turret, but it’s pitching not turning, but the camera does turn like it should. I don’t know what’s wrong, but try to write your code clearer, like instead of

self.FirstPersonDummyNode = render.attachNewNode("FirstPersonDummyNode")


self.FirstPersonDummyNode = self.TurretJoint.attachNewNode("FirstPersonDummyNode")

You should remove all that indentation too, it’s unnessesary. You redefined mFirstPersonCamera which may save some time typing but makes the code confusing. You described the camera and then said that attached to that node was the FirstPersonDummyNode but it looks like it’s the other way around. I’m not trying to be rude, I’m just saying it would be easier to understand

p.s. How did you set mFirstPersonCamera to be the active camera?

its based on viewports

I uploaded a quick video explaining my issue.

As for the code, its messy due to numerous attempts at figuring this problem out. It was a lot cleaner at the start :wink:

Also the indentation comes from copying from different classes, its not all in one spot unfortunately. I only did that to illustrate the functions I am using, not how I am accessing the members.

The first person camera is actually represented by the axis I am drawing, where the green line is the forward. I am viewing this from another third person camera elsewhere in the scene (basically a vehicle where third person is vieweing it from behind, and first is a birds eye from the turret itself… or at least thats the goal)

edit: I see where you are coming from on that code change. I did exactly what you suggested, but it made no difference. Thanks for the tip anyhow!

All nodes rotate about their origins: the (0, 0, 0) point of the model. If the turret is rotating about a different point than you expect, it must be because the origin is in the wrong place. You can either have the artist move the origin in the modeling package, or you can create an intervening node that moves the relative origin via a setPos() offset.

Similarly, if you’re applying a change to H, and the turret appears to be moving in P, it must be that the turret has a local rotation that is 90 degrees from what you expect.

You can examine the transforms in the scene graph with ls(). For instance, use to see everything you’ve got under render, and their transforms. This may provide some insight.


     stryker_root  hpr 0 -13.16 -90 trans 0 0 1
       frnt_lft_suspension_01  hpr -13.16 -1.13549 -90 trans -0.076969 1.99263 0.752339
         frnt_lft_axil_end_01  hpr -1.13549 13.16 90 trans 0.365512 -0.00724469 0.000647391
       frnt_lft_suspension_02  hpr -13.16 0.754779 -90 trans -0.346135 0.841425 0.731441
         frnt_lft_axil_end_02  hpr 0.754779 0 90 trans 0.388308 0.00511563 0.000647391
       frnt_lft_suspension_03  hpr -13.1601 -2.53216 -90 trans -0.6672 -0.506982 0.729302
         frnt_lft_axil_end_03  hpr -2.53216 13.1601 90 trans 0.376517 -0.0166508 0.000647391
       frnt_lft_suspension_04  hpr -13.16 -0.117124 -90 trans -0.930876 -1.65947 0.743062
         frnt_lft_axil_end_04  hpr -0.117124 13.16 90 trans 0.374155 -0.000764695 0.000647391
       frnt_rt_suspension_01  hpr 30.8728 2.38132 91.1708 trans -0.076969 1.99263 -0.753082
         frnt_rt_axil_end_01  hpr -1.83438 -13.16 -90 trans 0.367196 -0.0117598 -0.000647391
       frnt_rt_suspension_02  hpr -13.16 0.12192 90 trans -0.346135 0.841425 -0.753082
         frnt_rt_axil_end_02  hpr -0.12192 -13.16 -90 trans 0.362172 -0.000770745 -0.000647391
       frnt_rt_suspension_03  hpr -13.16 0.603645 90 trans -0.66171 -0.508266 -0.753082
         frnt_rt_axil_end_03  hpr -0.603644 -13.16 -90 trans 0.359038 -0.00378282 -0.000647391
       frnt_rt_suspension_04  hpr -13.16 0.324321 90 trans -0.930876 -1.65947 -0.753082
         frnt_rt_axil_end_04  hpr -0.324321 -13.1601 -90 trans 0.363649 -0.00205783 -0.000647391
       turret_main  hpr -13.16 -2.01469 0 trans 1.01153 0.0134811 -0.424464
         weapon_pitch  hpr -0.468675 0 0 trans 0.525939 0 0
           weapon_end  hpr 0.468675 0 90 trans 0.115252 0.000161273 0

hmm… there seems to be a lot of rotation information in those nodes.
I knew I couldn’t trust an artist…

Thanks David

EDIT: So is there a tool that will wash an egg to get rid of the rotational information?

There is a tool that can help you with orienting object called ‘directtools’ use this code to enable it

from pandac.PandaModules import loadPrcFileData
loadPrcFileData("", "want-directtools #t")
loadPrcFileData("", "want-tk #t")

or if you just want to clear rotation on certain nodes, write a script that sets the HPR of the desired nodes to (0, 0, 0) and then save the scene graph to an egg file

or open up the egg file in a text editor, and manually edit the rotation out of every matrix (sounds like fun, doesn’t it!)

Calling works too, that automatically opens up a directtools dialog for placing that model.

The biggest part of the confusion is that all of this is under an animated character model, which Panda has to rotate specially when it gets loaded. In particular, it has to apply the coordinate-system transform, Y-up to Z-up, on every node. This is no doubt the 90-degree rotation that’s confusing you.

One way to see what’s happening is to hand-edit the egg file to change the first line from “Y-up” to “Z-up”. Then when you load it, the tank will be on its side. Now you can observe that when you apply a heading change to the turret, it will actually rotate in what appears to be the “pitch” plane relative to the tank (because the whole tank is sideways).