# How can I convert screen coordinates to world coordinates on the floor (when the y component = 0)?

I am using the Irrlicht Engine and would like to convert the coordinates of the mouse on the screen to the floor of my world. I am currently trying to use

getRayFromScreenCoordinates()


which returns a "Ray starting from the position of the camera and ending at a length of the far value of the camera at a position which would be behind the 2d screen coodinates." Then I do this to get the position:

    core::line3df line = getRayFromScreenCoordinates(receiver.mousePos, device);
irr::core::vector3df lineVector = line.getVector().normalize();
irr::core::vector3df pos = line.start + lineVector*x;


x would be the magnitude from camera to the coordinate. However I do not know how to calculate x (as I don't know the coordinate yet).

The page I got the code from, written in 2003

What you need to do is get a ray intersection against a plane which is your floor. I'm not certain how this is done in Irrlicht, but my guess is that there's some function such as:

vector3df plane::getIntersectionWithRay(line3df)

You can then discard the y part of the vector (or z, depending on your co-ordinate system ) as it will be equal to zero, and use the other two for a 2D vector.