Jump to content
  • Advertisement
Sign in to follow this  
Elqno

OpenGL something like picking objects

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

Hello there, In general I had looked for some post related with I am doing now, but I couldn't find anything (maybe the topic query is wrong, and it has a special name...), I hope the people that is reading this will understand me and will have time to give me a hand. The problem is the next, I'm doing a simple RTS, and what I did so far is the picking objects (which is working without problems), so with it, I can pick any character/building/etc, but now I got myself a challenge which I tried but I can't come with a solution, when a character (small fighter) is selected, I want to do that when clicking with the right button of the mouse at any place over the land/field of the game, this fighter will go there, I don't have problem with the right mouse button or doing an alghorithm finding the shortest path, my problem is that I don't know how to get the coordinates of the field object, I don't know if Picking Objects will be usefull at this point, because i don't wanna choose the field, I just wanna obtain the coordinates, like the fighter is at 0,0,0 (this coordinates are saved in the fighter's class), and I right click in a right upper side (that means that the new coordinates will be positive), so I hope i descibed already my problem very good. If does make a difference I'm programming using Glut and OpenGL. In summary: getting the 3D coordinates of the field (e.g. -100 in X and Z, to 100 in X and Z, Y = 0), by the clicking of the mouse (which gives of course just the x and y coordinates). Thxs so far for reading my post :)

Share this post


Link to post
Share on other sites
Advertisement
If you have already picking functionality up and running I assume you can project a ray to 3d space from a 2d mouse position? Now you only need to do a ray against X intersection with your fields whereas X is the approximate shape closes to your fields such as a rectangle in 3d space. This intersection test returns a 3d position where you ray hits your fields.

Share this post


Link to post
Share on other sites
thank you very much with the help, I swear I couldn't come with an idea of how to do it. Sometimes is hard to think individually...

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!