2D Coordinates

Hello again everyone :slight_smile:

Could you help me out on this little problem:

How could I translate 3d coordinates of an Actor visible on screen into screen coordinates? I searched for some get2DCoordinate function on actor class, I’m guessing there’s none?


was posted on the forum already, the topic pops up from time to time:

    def map3dToRender2d(node, point=Point3(0,0,0)):
        p3 = base.cam.getRelativePoint(node,point)
        p2 = Point2()
        if not base.camLens.project(p3, p2):
            return None
        return p2

something like this should work.
be sure to do

from pandac.PandaModules import Point3,Point2

or it wont work

One more question though, should I use it like this?

map3dToRender2d(base.camera, p1.getPos())


nope. just throw in your actor-node as argument.
the point argumentis optional and you can think of it as an “offset” relative to the node you pass.


should be enough i most cases. but it will most likely give you the point on the caracters feet. if those are offscreen it will return none. so you might want to do

map3dToRender2d(youractornode, point3(0,0, characterheigth/2) )

where characterheigth would be size of your character.