I’m wondering if there’s a way to easily place 3D Models at screen coordinate locations for a 1920x1200 monitor. There seems to be no easy way to convert from Panda3D’s 3D coordinate system to a pixel screen coordinate system. For example, I want to place models in succession at screen coordinates (480, 300), (1440, 300), (480, 900), and (1440, 900) and animate them from point to point using LerpIntervals. I have to use render instead of render2D because I want to animate the models.
If you want to place things at specific 2-D coordinates onscreen, you really need to use render2d. The 3-D scene graph, by its nature, has no relation to 2-D onscreen coordinates. (But if you really do want to do this, you can calculate where your object should be on a given point, by using a ray through the camera, similar to the example given in Picking. You can place your object anywhere along this ray, and it will be in the corresponding point onscreen.)
But you don’t have to use render just because you want to animate objects. All of the animation features are available to objects in render2d just as well.
In render2d, you can find a particular pixel location by dividing by your window size. The default render2d coordinate system is -1 … 1 in X, and -1 … 1 in Y (with -1 at the bottom), so it means the point (480, 300) in a 1920x1200 window is at render2d coordinates (480.0 / 1920.0 * 2 - 1, 1 - 300.0 / 1200.0 * 2).
David
Where is this example “Picking”? I couldn’t find a Panda3D sample by that name.
Also, if I were to use render2d to place 3D models, I wouldn’t be able to use LerpIntervals to, lets say, move the object from one 2D point to another 2D point through a parabola function, because LerpIntervals require Point3(x, y, z) for positions?
Thanks for taking the time to respond
I guess he meant ‘looking and gripping’,
for moving the object from one 2D point to another 2D use x and z and keep fixed y.
I think he meant the Chessboard sample.
Also, see this thread:
discourse.panda3d.org/viewtopic.php?t=5409
Right, sorry, the Chessboard sample used to be called Picking.
Also note that render2d uses Point3(x, y, z) coordinates, just like render. It just doesn’t do much with the y coordinate, which is usually 0.
David