Finding where I clicked in 3d versus where I clicked in 2d

Started by
4 comments, last by toogle 20 years, 5 months ago
In VB, I''m making a small game similar to red alert. I''ve got the rendering working properly, but I need to figure out where I clicked in the 3d image versus where I clicked on the form. Like in Red Alert or Warcraft, you click on a person or an object, i want to know what coordinates i clicked on in the 3d world. Also note, i want to know where I clicked on a plane in space which is flat. If you need more details just ask. Thanks.
Regards,Ross
Advertisement
Thats called picking, and I think theres an example of it in the documentation. Basically, it is ray tracing from screen coords to world coords.

Source: (SDK root)\Samples\Multimedia\Direct3D\Pick
Executable: (SDK root)\Samples\Multimedia\Direct3D\Bin
normal_toes@hotmail.com
I saw a tutorial about this on gametutorials.com... let me find it...

http://www.gametutorials.com/Tutorials/opengl/OpenGL_Pg3.htm

Down the page...
It's openGL and C++ but the maths behind it should be the same as in D3D and VB

[edited by - structural on November 9, 2003 7:08:27 AM]
STOP THE PLANET!! I WANT TO GET OFF!!
The way I did it was to translate the 3D coords to 2D then find the closest 2D point to the mouse.

Mark
---------------------------------------------------------------
In some great dawn, a palisade,
eight pillars stand of stone and dust
surrounded by a lifeless sea
of roaming sand and closing dusk.
Ok, these are helpful, but I was thinking there might be an equation to find it.

(im on a right-handed 3d coordinate system)

Lets say im looking from 45 points back and 30 points up from the point im looking at.

And the point im looking at should in theory be at the center of my form.

Is there an equation to find where i clicked based on where i am and what point im looking at? It''s most likely a proportion of some sort.
Regards,Ross
aslong as you have the x y and z of the screen, you can use a matrix to get back to 3D (or even trig).

If your using OpenGL, its already in there in glunproject();
Beer - the love catalystgood ol' homepage

This topic is closed to new replies.

Advertisement