converting screen coordinates to world coordinates
converting screen coordinates to world coordinates
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
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
The documentation for getRayFromScreenCoordinates is at http://irrlicht.sourceforge.net/docu/cl ... er.html#a3
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;
vector3df lineVector = ray.getVector().normalize();
vector3df pos = ray.start + lineVector*x;
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
i haven't tried this but if you can get the z buffer value it should be quite easy