Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
I should have really checked the docs. Thanks! –  andrew Apr 13 '13 at 20:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.