base.camLens.project() problems. [SOLVED]

I’m working on the last bit of my HUD, which is placing bars for enemy shield strength above the enemies.

I’m trying to get position I need to place the elements on render2d so they will appear above the enemies. I looked up a mouse picking script involving planes and the camLens.extrude() method that I had used previously and knew worked. That gave me the idea to look at the available methods of camLens for something that would do the opposite of extrude: find the 2d point in the window that corresponds to a point in 3d space.

I found the camLens.project() method which claims to do exactly that. I set up a script to use it, but even when I’ve got the camera pointed right at the point in 3d space I’m trying to sync with, project() claims the point is not in the viewing frustrum and fills my point with nothing useful.

Do I need to specify a viewing frustrum before I can use the project() method? If so, how would I do that for a mobile camera such that it covers everything my camera is feeding to the render window?

You do have to convert the 3-d point into the coordinate space of the camera first, before you pass it into the lens.project() method. You can use camera.getRelativePoint() for this.

David

Yup, that fixed it.

It also works if I pass base.camera into the getPos() of the node I’m locating, to get the relative point that way, which is a little easier. Like so:

pos2d = Point3()
inView = base.camLens.project(enemy.getPos(base.camera), pos2d)