Click-and-Drag Box

Apprentice
Posts: 19
Joined: 2005.11
Post: #1
In my Real-Time-Strategy game, I have it set up so you can click-and-drag a box around a unit or a group of units and then give them a move order, or... well that's about it so far, just moving and basic collision detection. However, when you're clicking - and - dragging the box around the units, the player doesn't actually get to see the box they've drawn. So how would you recommend I go about drawing a 2d-square in my 3d-world?

I would think the easiest way would be to somehow, after the scene has been drawn into the buffer and is about to be swaped (which at this point, if I'm not mistaken, it is nothing more than a 2d-image), to go in and draw on the buffer/image then. If that's even possible, I wouldnt know how.

Or would the best way to be to glUnProject() the mouse positions to the near-clipping plane, and put vertices at those points and connect them with lines?

The extent of my knowledge so far in OpenGL basically ends around the chapter on lighting/materials in the Redbook (covering OpenGL 1.1... and older copy). I have done some skipping around to find display lists and a few other things I've needed here and there, but I haven't found anything that would help me here. Is there a specific chapter I should read? Or a simple function I should know...?
Quote this message in a reply
Sage
Posts: 1,478
Joined: 2002.09
Post: #2
Change your view so that it matches the screen coordinates and then draw the box. Changing the viewing matrix changes how drawing is applied afterwards, things drawn before aren't affected.

Do you know about, gluOrtho2D()? It makes it trivial to do this.
Code:
gluOrtho2D(0, width, 0, height);
Is all you would need to do.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Apprentice
Posts: 19
Joined: 2005.11
Post: #3
Ahh nice... I didn't ever even think about changing the perspective. I'll go try that, thanks.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Drag to save unknown 3 2,438 Mar 11, 2006 07:45 AM
Last Post: unknown
  Help with mouse click position to OGL coords using gluUnproject hyn 14 10,999 Aug 6, 2004 07:57 AM
Last Post: GioFX