How to get a 3D position from 2D screen 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
Anteater
Posts: 266
Joined: Thu Jun 01, 2006 4:02 pm
Location: Earth
Contact:

How to get a 3D position from 2D screen coordinates

Post by Anteater »

How would I get a 3D position from 2D screen coordinates? For example, how would I take the position of the mouse cursor and get a vector3df of the 3D position it's hovering over?
Swarmer
Posts: 100
Joined: Mon Apr 16, 2007 7:23 am

Post by Swarmer »

I think tutorial 7 (http://irrlicht.sourceforge.net/tut007.html) will explain it.
Tanuva
Posts: 54
Joined: Tue Oct 10, 2006 6:49 pm
Location: 200 metres behind the moon
Contact:

Post by Tanuva »

A little variation of the question: How do I get a vector3df from a vector2df? I gonna work with 2d values in my game (2d math - 3d gfx) and the scenenodes want 3d vectors for their positions... Since simply reading the two directional values from the vector2df doesnt work (no methods to access them), how do I realize such?
Tanuva
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

If you keep in 2 dimensions you can set the third value of the vector to 0. so you can convert the vector like this:

Code: Select all

vector2df pos2d(10,14);
vector3df pos3d(pos2d.X,0,pos2d.Y);
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
Tanuva
Posts: 54
Joined: Tue Oct 10, 2006 6:49 pm
Location: 200 metres behind the moon
Contact:

Post by Tanuva »

Arr! I tried that way, but wrote vector2df.x instead of *.X - case sensitiveness can be damn tricky... Thanks! :D
Tanuva
Post Reply