Determine the direction a face is pointing

I need to determine the direction one of the faces of my cubes is pointing relative to its parent node. I need to just determine is it facing: left, right, up, down, back or forward.

sceneOrigin = render.attachNewNode("Scene Origin") 
vecY = sceneOrigin.getRelativeVector(block1,Vec3(0,1,0))

vecY returns numbers in the range of -.5 to .5, but I’m not fully understanding how to use this vector to determine my general direction like left, right, up, etc.

Hi, unless I misunderstand your problem, you’re making things over difficult.

myParentNode = <your parent node>
myChildNode = <your child node>

print myChildNode.getH()
print myChildNode.getP()
print myChildNode.getR()
print myChildNode.getHpr()

hpr (heading, pitch, roll) are the rotations of the object (in degrees from what I’ve seen)
Look here for an explanation of each rotation:

Perhaps I’ve misunderstood your question entirely however… the example I gave gives the rotation of the object, do you want it relative to the parent or something? If so, getHpr() takes in a nodepath to be ‘relative to’ if you like. For instance:

myParentNode = <your parent node>
myChildNode = <your child node>

print myChildNode.getH(myParentNode)
print myChildNode.getP(myParentNode)
print myChildNode.getR(myParentNode)
print myChildNode.getHpr(myParentNode)

Hope this helps,

As far as I know there are many different combinations of h,p,r that could result in the face of my model pointing to say the left side of the screen.

I’m looking for a simple way to determine if the face is pointing left, right, up, down, forward, backward.

My guess is that you will find one axis in the vector you get back will be positive or negative depending if the positive Y face on the cube is pointing towards or away from the parent. If you normalize it then 0 should mean it is sideways, 1 should mean it is facing towards, and -1 should mean it is facing away.

Thanks, that’s definitely leading me in the right direction.

I’m also looking at what the other axis are doing and it is hard to tell which one to use. I keep thinking I’m seeing the pattern and then I twist my model in one way and I get nothing from one of the relative vectors axis. I guess that makes sense though that one should stay relatively static, but it is making it harder to come up with the pattern.


See solution here