Screen coordinate conversion with getRelativePoint()

I have two objects that I want to interact with each other, but one of them gets its data externally and the x,z coordinates are in screen coordinates (-1,-1) to (1,1). There is also a Y component that represents the scale, usually from 0 to 2.

I’m trying to use getRelativePoint():

#object1's coordinates are received in screen coordinates 
#(x,z)(-1,-1) to (1,1), but also a Y component representing scale
object1= loader.loadModel("object1.egg")

#object2 has 3D position coordinates
object2= loader.loadModel("object2.egg")

##--- loop via task manager  --- ##
#convert object1's data input to 3D, z & y are flipped
object1Pos = object1.getRelativePoint(, Point3(x, z, y))
##--- end loop ----- ##

The position seems to work correct until the second pass through of the loop, otherwise the data goes wild and the object moves all over the screen. The data stays consistent if I comment out object1.setPos(object1Pos).

I imagine that I’m using getRelativePoint incorrectly and I’ve tried using render, render2D and swapping in different nodes, but can’t anything to work.

You’re trying to convert from 2-d screen coordinates to 3-d world coordinates? You can’t use getRelativePoint() for this, but you can use camLens.extrude(). This is often done, for instance, to implement picking, where the user indicates a point on the screen with the mouse and you wish to determine which object in the scene he has clicked on.

Note that every point on 2-d coordinates corresponds to an infinite number of points (all the points along that line) in the 3-d scene. So a straightforward one-to-one conversion is not possible, unless you constrain the answer to a particular plane or you use collisions or something like that.

There are plenty of examples of using picking in the examples, in the manual, and in the forum. But it’s a complicated subject.


I was able to switch my data so it is coming in as world coordinates, but in meters. Once I convert these to centimeters I believe it is behaving correctly in Panda.

Is that the preferred unit of measure? Or is it just as long as all my elements are in the same unit of measure I’ll be ok?

Units in Panda are whatever you say they are, as long as you’re consistent.