Skip to main content
GameDev.net gamedev.net
🔒 Locked

picking tiles

Started by Gresc Jan 26, 2004 at 11:19 PM 6 replies 1k views
Original Post
Gresc
Gresc
i was wondering what the best way to ''pick tiles''. At the the moment I am using the gametutorial''s way of object selection by defining an id, but that will not work with my tiles because i dont think it would be good practise to define 100''s of id''s. To surmarise this: I am making a tile editor and need to know what the best way to know which tile is being mouseovered, and click on by the mouse. Thanks heaps in advance. Streamline.cjb.net - Flash and Opengl Country
alchemar
alchemar
I''m doing it that way, so far I have made a map 100 X 100 and have had no problems with it.
alchemar
alchemar
My tile struct has an Id unsigned int in it. It also holds the texture Id for terrain type, transition type and feature type.
I use the Id to name the tiles for picking. yes 10000 of them. the map is variable size. but I have been using a 100 X 100 map for testing.
Someone said ray picking was a lot better then what I am doing but I could not find much info on that.
Trienco
Trienco
when you say "tiles", are you talking about flat tiles or real 3d tiles? the former would be extremely simple (get the viewdirection, solve for y=0, round down and get you array indices).

for not so flat ones its more work and the best way depends on how you store them. a quadtree could make it fast, if you store small heightmaps you could first test with a bounding volume and then (not the best way) step through the map and see if you ever end up below it (surprisingly fast, i used it for a terrain editor on 513x513 maps as a quick and dirty "make it work" way and you couldnt feel any lag).

why do i suggest that? because [personal rant]that opengl picking stuff is a horrible and inefficient thing and tempts to be used out of laziness. drawing the whole scene just to let opengl find the intersection must be the most wasteful approach right after testing every triangle in your world for intersection[/personal rant]
f@dzhttp://festini.device-zero.de
alchemar
alchemar
I have a Hex tile map. I draw in Perspective mode. I do this so I can zoom in and out on my map. so I have to use some kind of picking, because I can have up to the whole map on the screen at the same time. I then switch to ortho mode to draw the user interface.
BitMaster
BitMaster
Usually, you can give a tile a unique id without even storing it with the tile. For example if you have a width of w, you could give a tile with coordinates x, y the id y * w + x. Once you retrieve the id, you get your coordinates back by simply x'' = id % w andy'' = id / w. Others methods might be easier for you but you can usually find something like this.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.