PDA

View Full Version : X,Y coordinates of a point on a 3d plane...



sonicmouse
04-06-2013, 10:33 PM
I know I am over thinking this which is why I am here.

I have a very simple program where I create a glRect(0,0,6,6), then rotate it about 80 degrees on the Y axis.

Then on MouseMove i use glUnProject()/glReadPixels() method to get the position on the plane and then draw it with another rect.

Here is an example of the output:

Mouse is hovering over the bottom right of the plane:
1006
Mouse is hovering over the upper left of the plane:
1007
Mouse is hovering over the upper right of the plane:
1008

So, what I would like to get is WHERE that point is on the rect/plane. So if the rectangle was drawn glRectf(0,0,6,6) and the mouse is over the upper right (like the 3rd picture), then how would I take the point (returned by glUnproject()) and convert back it to ~(6,6)

Thanks in advance for any info you can give me on doing this.

-andy.

sonicmouse
04-07-2013, 10:04 AM
I think I may have a theory -- and it seems to be checking out (but only in small preliminary tests).

Is this how you would tackle it:

1) Get the click coordinates using the tried and true gluUnProject (http://nehe.gamedev.net/article/using_gluunproject/16013/) method.
2) Get an Inverted MODELVIEW matrix
3) Multiply the click coordinates by the inverted MODELVIEW matrix

This should be the proper way to do this, correct?