converting screen coordinates to world coordinates

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
rogerdv
Posts: 93
Joined: Wed Aug 27, 2003 4:20 pm

converting screen coordinates to world coordinates

Post by rogerdv »

I need to convert screen coordinates (x,y) to the corresponding coordinate in the 3d world. I cant find in the docs any idea about how to do it. Can somebody point me in the right direction?
ru guo ni yao ai, ni jiang bu hui shi qu
Boogle
Posts: 162
Joined: Fri Nov 21, 2003 3:16 pm
Location: Toronto, Canada

Post by Boogle »

In the collision manager, you have getRayFromScreenCoordinates which will get you the ray from the camera's position all the way to the end of the field of view. The ray represents the possible positions in 3d space the 2d position could represent. You can then determine how far along the ray you want to go. The collision manager has some other functions for converting 3d to 2d or vice versa, such as selecting the scene node located at a screen position.

The documentation for getRayFromScreenCoordinates is at http://irrlicht.sourceforge.net/docu/cl ... er.html#a3
rogerdv
Posts: 93
Joined: Wed Aug 27, 2003 4:20 pm

Post by rogerdv »

I cant pick a node, because the "floor" is only one node: a bsp mesh. I need to get an aproximate 3d coordinate that corresponds to the screen 2d coordinate of the mouse click.
ru guo ni yao ai, ni jiang bu hui shi qu
Boogle
Posts: 162
Joined: Fri Nov 21, 2003 3:16 pm
Location: Toronto, Canada

Post by Boogle »

You will have to use getRayFromScreenCoordinates then and decide on a point along the ray. There is no single 3d point that corresponds to a 2d screen coordinate.
rogerdv
Posts: 93
Joined: Wed Aug 27, 2003 4:20 pm

Post by rogerdv »

Thanks. Really, there is no a single point. And as i only need x and z (y is supposed to constant), the only thing I need to know is how to extract x and z from the ray, given a constant value of y.
ru guo ni yao ai, ni jiang bu hui shi qu
Boogle
Posts: 162
Joined: Fri Nov 21, 2003 3:16 pm
Location: Toronto, Canada

Post by Boogle »

Ah, ok. Well then, after you get your ray, the ray has a property called start, which will be an x,y,z point just in front of the camera, with an offset related to the screen position. If you want a point that is x distance away from the camera at the given mouse position, you can use something like:

vector3df lineVector = ray.getVector().normalize();
vector3df pos = ray.start + lineVector*x;
stampsm
Posts: 142
Joined: Mon Nov 10, 2003 5:52 pm
Location: Las Vegas

Post by stampsm »

is there some way to obtain the z buffer value from the engine if you do this then all you have to do is follow the line you get for the value obtained from the z buffer to get the exact x,y,z value of any pixel on the screen
i haven't tried this but if you can get the z buffer value it should be quite easy
Post Reply