# Coordinate conversion from render2d to 3d

Hey everyone,

I’m working on an RTS-style game, and want to draw a selection box on the screen. I am able to draw such a box with render2d using the LineSegs class, but since that box is anchored to screen coordinates, it moves with the camera when I scroll around. I need it to be anchored to a specific point in 3d space. So I’m working on drawing the box and parenting to render, but am having trouble converting the 2d mouse coordinates to the corresponding coordinates in 3d to be used in drawing the box. I’ve seen a couple of Python examples which go the opposite direction (3d to 2d), but I’m a little confused about Panda’s methods for this stuff, particularly the get_relative_point function. Aside from my need to anchor to a point independent of camera location, I’d be happy to use render2d to keep things simpler. Any ideas?

2d-to-3d is usually called “picking”, the selection of a point on an object below a given pixel onscreen. There are plenty of examples of picking in the forums, and in the sample programs.

But if you want to compute a point in the 3d scene graph that’s not necessarily on the surface of an object, then you have some ambiguity to resolve: there is an infinite number of 3-d points (that is, a line, that passes through the eyepoint and heads to infinity) that correspond to each 2-d point.

David

There is a terrain map, so I do have a surface to work off of, although it’s going to be uneven. What about creating an invisible plane above the terrain on which to place the box?

Sure, but if you just want to intersect with a flat plane, you don’t need the overhead of the full picking algorithm. I believe the chess example demonstrates this.

I’ll look into it. Thanks.