selecting units in a 3d game

Started by
6 comments, last by Fonz 21 years, 8 months ago
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
Advertisement
i agree with your suggestion... how about simply creating a line between the camera position and the place you click and then seeing which is the first unit (away from the camera) that the line intercepts...

don't sit back and let life take you where it will...
grab it by the horns and wrestle it to the ground...
you'll only end up talking about missed chances if you don't...
[paulfucius, 2002]
just a quick addition... try the opengl forum... i''ve not been in there (''cos i''ve never used opengl) but i''d guess they''d have something answering that sort of question...

don't sit back and let life take you where it will...
grab it by the horns and wrestle it to the ground...
you'll only end up talking about missed chances if you don't...
[paulfucius, 2002]
Check out the opengl picking tutorials.
Picking is quite easy in OGL.

http://www.lighthouse3d.com/opengl/picking/

<a href="http://www.purplenose.com>purplenose.com
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]
It's not what you're taught, it's what you learn.
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...
don't sit back and let life take you where it will...
grab it by the horns and wrestle it to the ground...
you'll only end up talking about missed chances if you don't...
[paulfucius, 2002]
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.
hey,

Thanks for all the suggestions. I''ll look into them all.

cheers,
Fonz

This topic is closed to new replies.

Advertisement