Jump to content
  • Advertisement
Sign in to follow this  
hury

Get x,y,z coordinates

This topic is 3659 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

Hi, is it possible to get the coordinates of a square? What i want to do, is to check wheather the mouse position is over the square. GLUT function GLUT void keyboard ( unsigned char key, int x, int y ) provides me the x,y coordinates for the mouse position, but how to get the coordinates of the square on the screen now? Alex

Share this post


Link to post
Share on other sites
Advertisement
There are several possibilities:
1. Project the square's vertices to the screen manually and compare to the mouse coordinates.
2. Unproject the mouse coordinates to world space, i.e. unproject (mouse_x, mouse_y, 0) and (mouse_x, mouse_y, 1) and perform a ray-rectangle collision test.
3. Use the OpenGL picking API.
4. others (e.g. draw the rectangle with a unique color and read the color under the mouse position)

Share this post


Link to post
Share on other sites
Will it make things easier, when i dont use the mouse, but just move another opengl object around and see, if it´s above an other object? Or would I go for picking here too?

Share this post


Link to post
Share on other sites
I'd use the mouse since object - objection collision tests are more expensive that ray - object tests.

And you could use OpenGL picking but I didn't use it yet and I'm not fully convinced of that, too.

Share this post


Link to post
Share on other sites
After some intensive searching i found out, that working with Bounding Boxes should be what i´m looking for.

But somehow i didnt find anything, that would really explain it from the start...
Maybe anyone could explain again, how i can draw a BB around an existing square?

Thank you

Share this post


Link to post
Share on other sites
i solve that problem using opengGl picking if you want the source code and more explanation write to me at gaa02@ceis.cujae.edu.cu or vtserej@gmail.com its very simple

Share this post


Link to post
Share on other sites
Well, you could use a bounding box but unless the square is rotated it is its own bounding box. And you still have to perform checks between coordinates that are in different spaces: mouse in viewport space (screen space * viewport) and the rectangle/bounding box in world space. So you still need a conversion from one space to the other.

The OpenGL picking API will do that for you so it's an easy way to perform some picking.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!