Archived

This topic is now archived and is closed to further replies.

Selecting a point on a 3D plane

This topic is 5776 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In OpenGL, I created a X-Z plane with some rotations. ... glRotatef(20, 1, 0, 0); glRotatef(-45, 0, 1, 0); glBegin(GL_LINES); glColor3f(1.0, 0.0, 0.0); for (int i = -10; i <= 10; i=i+2) { glVertex3f(-10.0, 0.0, i); glVertex3f(10.0, 0.0, i); glVertex3f(i, 0.0, -10.0); glVertex3f(i, 0.0, 10.0); } glEnd(); ... So I have a 10x10 grid on the screen. Now, is there anyway I can calculate the (x,y,z) coordinate on the grid when I press a mouse button on certain point say (x1, y1)?

Share this post


Link to post
Share on other sites
hello,

of course you can,
you need to do some mathematic, geometric transformation and it depends on the way you want to do this.

the simplest way is to transform your click coordinate in relation with the transformations you have made (rotations, translations, care of the sense !).

Normally (i don''t use it), gluUnProject can give you the coordinate of the point where you have clicked.

i can''t say more,

i hope this help you a bit.

Fratt

Share this post


Link to post
Share on other sites
Thanks.

glGetDoublev(GL_MODELVIEW_MATRIX, model);
glGetDoublev(GL_PROJECTION_MATRIX, proj);
glGetIntegerv(GL_VIEWPORT, view);

gluUnProject(xPos, yPos, 0, model, proj, view, &objX, &objY, &objZ);

I tried the code above, and it works, but it seems that the coordinates returned are those after translation.

Is there any calculation such that I can find its absolute coordinate in the world? I mean, if I draw a triangle

glVertex3f(0.0, 0.0, 0.0);
glVertex3f(1.0, 0.0, 0.0);
glVertex3f(0.0, 1.0, 0.0);

I want the return value to be (0, 0, 0) when I click on the point at the 90 degree angle no matter how the triangle is transformed.

Thanks a lot.

Share this post


Link to post
Share on other sites