RTS - box in units

Started by
2 comments, last by MARS_999 15 years, 10 months ago
Hey, ive been trying to figure out how to do this but i cant think of anything. i need to be able to draw a box with a health bar around selected units, like in most RTS games, but im not sure how to. im guessing something to do with selection mode, but i cant be sure. Whats the usual way to approach this? thanks
Advertisement
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, windowwidth, 0.0, windowheight, -1000.0, 1000.0);

With this kind of projection, it becomes easy to position 2D things on screen.

Quote:im guessing something to do with selection mode

Selection mode doesn't draw anything on screen.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
ok, i guess i didnt really explain what the problem i was having was.

drawing in ortho mode isnt the issue, its working out where in 2d coordinates a unit is, finding its boundaries in 2d terms, and drawing a box around it.
Ok follow along on this as I haven't done this, but this is how I would do it.

You can use glUnProject or do the math yourself with rays to get the units that you clicked on. Now that unit should have its own position x,y,z coordinates stored somewhere. You now build a box around it with the box bottom is where the units bottom is at and the size of the box you can decide to make a set size which may cause issues with larger units or you determine the largest size each individual unit is and make the box taylored to each unit that way. You can make your own function e.g. DrawBox(float x, float y, float z, float size) and call this to make the box around the units....

HTH and you are following what I am suggesting.

This topic is closed to new replies.

Advertisement