Archived

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

Fonz

selecting units in a 3d game

Recommended Posts

hey, Just pondering how much work it would be to select units in a 3d opengl (linux) game. If the game is 3d then you cannot simply select the unit that is located at the point of clicking b/c that will select nothing or a unit behind the one you selected in all probability..*breath*. So.. what do you do? Scan the area of the click for the best matching unit? I was thinking that you could create a plane and project onto it.. or something. then select the unit (from the 2 coords) which is "on top" anyone else have any ideas? cheers, Fonz

Share this post


Link to post
Share on other sites
Striking the first unit within a certain distance with a ray is a good idea.

You could also put a visible indicator around the object you are about to click, just to be sure you're clicking the right one (which of course requires you to calculate the first object struck every frame where the mouse is).

[edited by - Waverider on August 13, 2002 11:44:48 AM]

Share this post


Link to post
Share on other sites
i was asking a guy at work here who''s done stuff in directx... i don''t know if opengl has a similar function but it''s actually a feature of the language that will return the nearest object that your mouse is over as soon as you mouse over it... if opengl can do that then i''d suggest it''s the way to go... obviously...

Share this post


Link to post
Share on other sites
In OpenGL you would use glPushName( x ) before you rendered each unit. Then you look at the backbuffer which is now a 2D surface and make a list of all the triangles that were rendered where the mouse was clicked x/y. Then run a loop through those triangles to find the nearest one. That triangle will have a number asociated with it that matches the ''x'' you assigned as a name before drawing that unit, and thus you can select it.

Share this post


Link to post
Share on other sites