# Thread: Get vertex 3D coordinates

1. ## Get vertex 3D coordinates

Hello!
Is there a function which can return a vertex x, y, z coordinates if I use the mouse to select a specific vertex? I found a function which returns the x and y coordinates of the mouse, i.e. void glutMotionFunc(void (*func)(int x, int y)); but the x and y coordinates of the mouse aren't the same as the x and y coordinates of the vertex. More specific, I need to find this function in order to get a certain distance from the initial vertex to the final vertex position after I pull it using the mouse. Sorry if the post doesn't contain enough information, or information written in a basic language, but I am new to OpenGL and I am trying to learn as many things as possible. I have found a way to implement what I need, but using VTK functions, i.e. :
d[0]=this->MoveActor->GetPosition()[0]-Position[0];
d[1]=this->MoveActor->GetPosition()[1]-Position[1];
d[2]=this->MoveActor->GetPosition()[2]-Position[2];

where MoveActor->GetPosition()[0] is the x coordinate of the moved vertex, MoveActor->GetPosition()[1] is the y coordinate of the moved vertex etc. Position[0], [1], [2] are the initial vertex x,y and z coordinates, and d[0], [1], [2] are the distance's x, y and z coordinates.
Waiting for some help. Thanks a lot for your time, guys .

2. Hi,

What you need to do is convert the 2D screen coordinates (Mouse X,Y) to world coordinates.
Google for opengl camera unproject coordinates. If you are using GLM, you could use glm::unProject() or use gluUnProject.

Carlos.

3. Thanks, I wrote the function using gluUnProject.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•