real position

hello, i’m implementing a spherical tag cloud in panda3d.
i have tags in the sphere, all attached to a dumb nodepath.
ok. to rotate all element i have applied a billboard effect to each tag and i just change hpr to the dumb node.

how to know the effective tag that is nearest to the camera if some rotations is applied?
some other ways to do it?
because getPos giv me the position without rotations in the dumb!

Interesting, here is my thought:

Take your sphere local reference (ie x,y,z axis at the center of the sphere)

  • you should have per construction the hpr location (or direction) of each tag, right?
  • now if you get the hpr of the camera in the sphere reference, ie cam.getHpr(center), and get a dot_product with each tag direction

Then the closest tag should be the one closer to the direction (ie with the maximum positive value of the dot product)

If you want to know the position of a nodepath in the scene relative to another (such as render) you can do it like:

nodepath.getPos(render)

You might be able to save yourself some math by getting the position relative to the camera and comparing those numbers.

sorry i did not understand the two answer:

@jean-claude:
why dot product?
and dot product between what?
between hpr of the center and P (where P is the position of the tag) for each tag?
but the result of dot product is a number… so the nearest tag to camera is … what? the tag with major dot product?

i have this code for make sphere layout:

    def tags_in_sphere(self):

        tag_num = float(len(self.tags))
        radius = 100

        for i, t in enumerate(self.tags):

            phi = acos((2* (i+1) -1) / tag_num -1)
            theta = sqrt(tag_num * pi) * phi
            
            x = radius * cos(theta) * sin(phi)
            y = radius * sin(theta) * sin(phi)
            z = radius * cos(phi)

            t.updatePos(x,y,z)
            t.updateHpr(0,0,0)

@teedee

        for x in tags:
            p = x.getPos()
            p1 = x.getPos(base.camera)
            print p, p1 

p1 and p are have the same values…

EDIT:
can NodePath.getRelativePoint be usefull?

Yes they will have the same value until you move the camera.
You might try something like:

camera_pos = base.camera.getPos(render)
dists = []
for x in tags:
    dist = (x.getPos(render) - camera_pos).lengthSquared()
    dists.append((dist, x))
dists.sort()
nearest_node = dists[0][1]

for each tag you have its vector related to the center of the sphere.
vi = tag[i].getPos()

you have the vector from the center of the sphere to the camera
vc = camera.getPos(centre)

the best tag is the one whose dot product of the 2 vectors dot(vi,vc) which is the highest (if the camera is outside the sphere or the lowest if not)

So something like that (sorry I don’t really program in Python…)

vc = base.camera.getPos(centre)
best_dot = -1000000
for t in tags:
   vi = t.getPos()
   dot = dot(vi,vc)
   if dot>best_dot:
      best_dot = dot
      best_tag = t