Game Development Community

Fix for graphical bug in selection rings

by Geom · in RTS Starter Kit · 08/06/2008 (11:30 pm) · 2 replies

Hey fellow RTS compatriots, what's up. Lately I've been lurking more than posting, but I'm still around. I recently fixed a graphical blemish in the RTS-SK's selection rings for my own game, and thought I'd share it here.

This fix address some screwiness when a selection ring lays across, or near, a sharp edge in the terrain:

redbrickgames.com/pix/080806/ringfix.jpg
The sharper the edge, the worse it looks. I saw one extreme case where a ring looked like it had Mickey Mouse ears :)

The fix is easy. In /engine/terrain/terrainRender.cc, replace the entire buildSelectionTri() function with this shorter, faster version:

void buildSelectionTri(LightTriangle* pTri, TerrSelectionInfo* pInfo)
{
   pTri->color.red   = pInfo->r;
   pTri->color.green = pInfo->g;
   pTri->color.blue  = pInfo->b;
   pTri->color.alpha = 0.9;

   F32 mr = 0.5f / pInfo->radius;
   Point2F ctr(pInfo->pos.x, pInfo->pos.y);
   pTri->texco1 = (Point2F(pTri->point1.x,pTri->point1.y) - ctr) * mr + Point2F(0.5f,0.5f);
   pTri->texco2 = (Point2F(pTri->point2.x,pTri->point2.y) - ctr) * mr + Point2F(0.5f,0.5f);
   pTri->texco3 = (Point2F(pTri->point3.x,pTri->point3.y) - ctr) * mr + Point2F(0.5f,0.5f); 

   pTri->flags = 1;
}

Fixed-o-rama!

It looks like the original code was copied-and-pasted from the code that handled lights, which is why it was doing the extra computation, and why the rings weren't rendering quite right. The code was doing a spherical projection rather than a simple, direct mapping, which is what this fix does instead.

#1
08/07/2008 (5:19 am)
Nice! thanx for sharing
#2
08/07/2008 (5:21 pm)
Very cool Geom, and glad to see you around :)