Jump to content
  • Advertisement
Sign in to follow this  
crackingod

Selection in OpenGL for tile based game

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

Advertisement
If you're using an orthographic top-down mode, you can just take raw mouse positions with an offset of where the viewer is.

If you're using a 3D perspective mode, then you will have to create a ray out of the mouse/world coordinates. You will then collide the ray against the tiles in your map, and you'll probably want to use a quadtree algorithm to greatly speed things up. This is called ray picking, and if you search GDnet for that you'll come up with a bunch of material.

Share this post


Link to post
Share on other sites
Hidden
Yeah I'm using ortho projection. I can get mouseposition and openGL position but how do I get to return the object I just clicked at (so I can transform it or whatever)?

Share this post


Link to post
You CAN use selection via the OpenGL API, but it requires another rendering pass. However, I would recommend taking the coordinates you have for the mouse and then just plugging them into your map and determining which tile they correspond to.

Share this post


Link to post
Share on other sites
Hidden
Yep I already have that implemented (Which returns the position of the tile). But what I want is to get for example an object ID or something so I can basically change some attributes of the object (make it selected somehow, change color or I don't know...)....Any idea?

Share this post


Link to post
You'll want to implement that into map object in system memory and separate it from the graphics code. You'll want to give tiles attributes, like selected, or keep a selected tile variable to point to a particular tile. Then, when you draw that tile, you can draw the tile blended with a solid color to show it is highlighted or draw a marker on the tile.

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!