Archived

This topic is now archived and is closed to further replies.

Khaos Dragon

picking

Recommended Posts

Ok I am trying to make a map editor and have thus far succeeded in making a landmass which can be raised and lowered at any single tile, however to select a specific tile now you need to use the arrow keys. I would like to get it to where a person may merely click on a tile to select it as this would be so much more convenient (imagine the sim city 2000 editor for example), but this is a bit complicated because this is all in 3d space and the camera can be at any point. Now I read about and think I understand fairly well how the selection mode works together with a name stack, the gluPickMatrix function, and etc. to gather all the hits (all object selections in a scene). However I notice in doing this you have to first draw the scene in selection mode and then draw it in render mode, will having to do both of these each frame considerably slow my code down? I suppose I would only execute this selection/picking code when I know that the mouse has been clicked anyways, so it shouldn't be that bad then right? Before I go along with this there was one simple little thing I wasn't sure about. Say I want each tile to be its own unique object, then I would basically do the following right:? I'm not sure exactly what this will but does basically set a bounding box around the polygons I just drew and when its gathers selection hits checks to see if anything fell within that box? If I am not making sense I apologize, I am just still confused. loop through all tiles { glPushName( tile.id ); draw_tile(); } this is assuming i already set up my selection buffer [edited by - Khaos Dragon on July 2, 2003 1:58:13 PM]

Share this post


Link to post
Share on other sites
For my picking code, I have a separate drawing code for selection mode that doesn''t use lighting, textures, etc., and I see pretty much no noticable speed difference.

As for each tile being a unique object, yes, your code is correct. Anything rendered after a new call to pushname gets that name assigned to them.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Since nothing is actually rendered, the selection mode doesn''t use any fill rate, doesn''t do texturing math and is generally pretty fast. (It just clips the triangles to the picking frustum and sets a flag if the triangle is visible)

Share this post


Link to post
Share on other sites
Ok I got it to work, a lot easier than I thought! Except for one thing, I can only pick each separate row of tiles, this is because each row is drawn as a continous triangle strip between a glBegin and glEnd and apparently I cannot use the functions glLoadName or glPushName inside a glBegin/glEnd.

Anybody have a solution or will I just need to draw each tile separately?

Also on a nonrelated matter what do I do if I want to texture each tile separate with glBind, I haven't exactly used vertex arrays yet so can do they solve this problem? For example is the following code viable using vertex arrays.

//lets assume all these arrays are enabled
create and fill texture array;
create and fill vertex array;
create and fill normal array;

loop through all tiles
{
glBind(..... tiles[k].tex_id );
drawArrayElement( k );
}

If I understand this correctly drawElement would render using the corresponding positions from the texture, vertex, and normal arrays I just created.

And perhaps may this be a solution to my earlier problem?:

//lets assume all these arrays are enabled
create and fill texture array;
create and fill vertex array;
create and fill normal array;

loop through all tiles
{
glLoadName( k );
glBind(..... tiles[k].tex_id );
drawArrayElement( k );
}


Thanks for all your help, my questions may seem trivial but the people on this forum have been a great help in my understanding of all the various concepts and ideas invo

[edited by - Khaos Dragon on July 3, 2003 5:18:32 PM]

Share this post


Link to post
Share on other sites