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

Started by
7 comments, last by BinhNguyen 20 years, 5 months ago
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.
---"Some men see things as they are and say why? I dream things that never were and say "Why not?" - Robert Francis Kennedy (1925-68), US Attorney General||Please try alpha002.zip(663k)
Advertisement
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.

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]
---"Some men see things as they are and say why? I dream things that never were and say "Why not?" - Robert Francis Kennedy (1925-68), US Attorney General||Please try alpha002.zip(663k)
lol, im playing xcom now actually.

if you have a fixed camera you could use a 2d sprite. would work to zoom in but not to rotate the world.

a simple textured cube would work, wouldnt it?
//---------//Ueberbobo//*********
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
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.
---"Some men see things as they are and say why? I dream things that never were and say "Why not?" - Robert Francis Kennedy (1925-68), US Attorney General||Please try alpha002.zip(663k)
set wireframe with:

pDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_WIREFRAME );

and back:

pDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID );

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Thanks Endurion! Very cool, I''ll try it right away

---
Today, is a good day to code.
---"Some men see things as they are and say why? I dream things that never were and say "Why not?" - Robert Francis Kennedy (1925-68), US Attorney General||Please try alpha002.zip(663k)
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.

This topic is closed to new replies.

Advertisement