Archived

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

BinhNguyen

How to program a box that highlights units (XCOM style)?

Recommended Posts

Thanks for stopping and reading! I''m trying to program an XCOM clone in 3d. I''ve managed to learn how to load level meshes and character meshes. Now I''m looking for suggestions on how to program a box that highlights units when the unit is passed over it. Should I program a particle system and shape it in a box? Should I create a bitmap that moves? Should I create a polygon box? Any suggestion would be most appreciated. --- Today, is a good day to code.

Share this post


Link to post
Share on other sites
When you say a box, you mean a 3 dimensional box or a simple 2 dimensional plane?

Since you said when the unit is passed over the box...

whichever, get the units position, when the unit is at the boxes position, make the box a different color.

Share this post


Link to post
Share on other sites
Hi deathtrap!

A bit of a typo on my part, I was hoping to say "Now I'm looking for suggestions on how to program a box that highlights units when the cursor is passed over the unit".

I mean the actual game is in 3d so I need a 3d box. The way I'm trying to get it to work is as follows. When the cursor is placed over the unit, a box appears around the unit. When the player left clicks on the unit and moves the mouse to elsewhere the box follows the cursor around.

Here is a screenshot from the game I'm hoping to clone.


---
Today, is a good day to code.

[edited by - BinhNguyen on November 16, 2003 6:34:08 PM]

Share this post


Link to post
Share on other sites
or just draw a 3D box that corresponds to the bounding box (assuming you use those for collision detection) of the unit. z-buffering will nicely make the little parts of the box visible through breaks in the model. the box will be defined by the highest and lowest x,y, & z coordinates of your model. then draw it in a wireframe draw mode (in openGL that would be:

//make it wireframe mode
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

//
//draw box
//

//go back to normal draw mode
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

you could also just draw GL_LINES between all the vertices of the box.

-me

Share this post


Link to post
Share on other sites
Thanks UeberBobo and Palidine for the reply.

The game is in 3d and I''m planning to allow for rotation, panning, strafing and zooming. I''m working in DirectX so I''ll have to find corresponding functions. Thanks for the suggestions as it confirms that I haven''t missed some really obvious way to do it.

If anybody knows how to draw in wireframe draw mode in DirectX please let me know!

---
Today, is a good day to code.

Share this post


Link to post
Share on other sites
Wireframe isn''t very helpful, you''d have to draw a solid box eg. red without textures. Then still it would show something like:

+-----+
| /|
| / |
| / |
| / |
|/ |
+-----+

because a box/cube is made out of triangles.
It would be better to define a cube as a linelist, 12 lines (24 points) with a red material. If you use models call D3DXComputeBoundingBox on the vertices of a vertexbuffer to get the bounding box, then get its world matrix, use D3DXMatrixTranslate and D3DXMatrixScale to scale/move the 1x1x1 box to it, call settransform with the result matrix and draw the box as a linelist.

Share this post


Link to post
Share on other sites