Selection in OpenGL for tile based game

Started by
2 comments, last by Daishim 17 years, 5 months ago
.........
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.

I know only that which I know, but I do not know what I know.
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)?
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.

I know only that which I know, but I do not know what I know.
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?
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.

I know only that which I know, but I do not know what I know.
Yeah was thinking about doing something like that but hoped something simpler existed.
Anyway thanks a lot ;)

This topic is closed to new replies.

Advertisement