# Find node's appox direction with getRelativeVector?

I’m looking for a more advanced but easier way to determine the direction my node is pointing. I’m using ARToolkit to move my node and it is getting too complicated with my current method to determine its direction.

I’m currently using getRelativeVector (my old post about this), but I have a lot of hard coded values that are hard to understand and maintain and don’t always work. I want to come up with something that more easily determines the approximate direction I’m pointing (e.g. +x,-x,+y,-y,+z,-z) (relative to another node)

Edit - see coppertops better approach below
[color=red]I’m wondering if I can put a cube around my model and then use a CollisionRay that casts out of my model. When the ray collides with the bottom of the cube, I know I’m pointing down.

Any thoughts on using this type of approach or could you think of a better way of doing this?

Thanks!

That sounds like a terribly inefficient approach. Panda provides the lookAt function (in the global scope) to convert a vector into a set of rotation angles. getRelativeVector would be if you want it as a vector.

This sounds more like terribly overcomplicated then simple…

If I understand correctly, and I’m not sure, what you want is not the exact direction, but rather it’s approximation. As in, going from an exact vector down to generalized directions of type up, down, north, south, east, west; which would translate to +z, -z, +y, -y, +x, -x. Is that what you need? Trying to use a cube would suggest that.

Here’s a piece of code that I use for planar texture mapping:

``````normal = space.getRelativeVector(myNode, Vec3(0, 1, 0))
axis = Vec3()
for i in range(3):
v = Vec3()
v[i] = 1
if abs(normal.dot(v)) > abs(normal.dot(axis)):
axis = v * cmp(normal.dot(v), 0)``````

which, if I understand correctly, should do what you need done.

@rdb, I think I had tried lookAt in the past and it didn’t work for me, but thank you.

@coppertop - this is exactly what I was looking for.

I had to change to normal = space.getRelativeVector(myNode, Vec3(0, 0, 1)) to match the coordinate system that ARToolkit is bringing in for me, but otherwise it works perfect. Thank you!

Edit: I edited the post’s title to better reflect the solution.