Mouse driven interface and detecting locations

I have an idea of how to detect an object when we click on the screen but how do we compute a point in empty space. Let’s say that the scene is view from above with the camera making an angle with the world and all objects are placed at z=0. How do we translate screen coordinates to a point in the plane z=0?

Well, I’m afraid there’s no other way than by picking. Create a CollisionRay at the preferred screen position.
The manual contains some information how to do this.

That’s not strictly true. You can easily convert from 2-d coordinates to 3-d coordinates. base.camLens.extrude() is the function to do this.

In fact, the picking code does this with the setFromLens() call. If you just want to get the coordinates without doing the full picking, you can either use a CollisionRay just to provide the setFromLens() call (and then extract the starting point and direction from your ray), or you can do the work that setFromLens() is doing yourself, which is really just a call to lens.extrude().

If you then want to figure out where that ray intersects the plane z = 0, you’ll have to compute that point of intersection yourself. But you might find the Plane.intersectsLine() method helpful. You’ll have to be comfortable with converting between different coordinate spaces.


Ok thanks. I think i know how to do this now.

So the extrude method gives two points in 3d space that define the picking line under the mouse (for the current camera) and then i only have to interpolate a point between these two where z=0.