#### Archived

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

# Selecting a point on a 3D plane

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

## 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 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,

Fratt

##### 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 on other sites
Just a note:
gluUnproject on my card is etremely slow. Try using picking instead...

http://www.lighthouse3d.com/opengl/picking/

1. 1
2. 2
Rutin
17
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633735
• Total Posts
3013593
×