[comp.sys.sgi] NudgeCloser and NudgeFarther

pepke@gw.scri.fsu.edu (Eric Pepke) (06/28/91)

Here's a neat hack.

Sometimes, you want to draw two things which occupy the same coordinates, 
but you always want one to be drawn on top of the other.  For example, say 
you have a smooth colored triangular mesh and you want to draw lines on 
top of it.  This is easy to do unless you have to use Z-buffering.  In 
that case, you can do this:

#define NUDGESIZE       200             /*Size of one nudge*/
#define MAXNNUDGES      3               /*Maximum number of nudges*/
long zMin = 0 + NUDGESIZE * MAXNNUDGES;
long zMax = 0x7fffff - NUDGESIZE * MAXNNUDGES;
long curZMin, curZMax;

void NudgeCloser()
/*Nudges objects to be drawn closer*/
{
    curZMax -= NUDGESIZE;
    curZMin -= NUDGESIZE;
    lsetdepth(curZMin, curZMax);
}

void NudgeFarther()
/*Nudges objects to be drawn farther*/
{
    curZMax += NUDGESIZE;
    curZMin += NUDGESIZE;
    lsetdepth(curZMin, curZMax);
}

NUDGESIZE is determined by trial and error.  This value works fairly well 
for a near clipping plane at 0.1 and a far clipping plane at 5.  
(Obviously you shouldn't hard-code the Z range, but this is for the 
purposes of illustration.)

When you get ready to use the z-buffer, you do

curZMin = zMin + NUDGESIZE * MAXNNUDGES;
curZMax = zMax - NUDGESIZE * MAXNNUDGES;
lsetdepth(curZMin, curZMax);

Then, when you want something to be drawn a bit closer, you do a 
NudgeCloser() before you draw it and a NudgeFarther() after you draw it.  
Reverse the calls to draw something a bit farther.

Eric Pepke                                    INTERNET: pepke@gw.scri.fsu.edu
Supercomputer Computations Research Institute MFENET:   pepke@fsu
Florida State University                      SPAN:     scri::pepke
Tallahassee, FL 32306-4052                    BITNET:   pepke@fsu

Disclaimer: My employers seldom even LISTEN to my opinions.
Meta-disclaimer: Any society that needs disclaimers has too many lawyers.