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:

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:
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.
This fix address some screwiness when a selection ring lays across, or near, a sharp edge in the terrain:

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
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.
About the author
My email address is my GG handle, at redbrickgames.com.
Torque 3D Owner JANR