Re: [info-performer] drawing close and far objects with differing near far clip plains

Date view Thread view Subject view Author view

Simon.Mills++at++esa.int
Date: 04/15/2005 07:42:56


Hi Iberto,

I had to solve the same problem. I wanted to draw the earth at real-world
size in meters(!). I tried a similar idea but went to OpenGL level to
temporarily extend out the near clipping plane while drawing this far away
object. Seems to work for me but I did wonder how "legal" it was. Hope it
helps.

//
// Work-around for flickering when drawing earth due to insufficient Z-buffer
// resolution when drawing ISS and Earth to ACTUAL SCALE. It involves setting
// draw callbacks to increase the near plane distance temporarily.
//
static void
setEarthNearFarAdjust()
{
    if (EarthDCS) {
      EarthDCS->setTravFuncs(PFTRAV_DRAW, preDrawEarthCB, postDrawEarthCB);
    }
}

//
// -- Callbacks --
//

static int
preDrawEarthCB(pfTraverser *trav, void *)
{
    // Get current near, far distances
    float near, far;
    pfChannel *chan = trav->getChan();
    chan->getNearFar(&near, &far);

    // Get GL projection matrix
    float projMat[16];
    glGetFloatv(GL_PROJECTION_MATRIX, projMat);

    // Scale near place distance up by factor
    static const float nearScaleFactor = 1000.0f;
    float newNear = nearScaleFactor * near;

    // Scale elements of projection matrix that are near plane scale
dependent.
    // This is only elements [2][2] and [2][3] or [10] and [14] if referred
    // to as a 1D GL matrix. See glFrustum man page.
    //
    float frustDepth = far - newNear;
    projMat[10] = - (far + newNear) / frustDepth;
    projMat[14] = - (2.0f * far * newNear) / frustDepth;

    // Push adjusted projection matrix
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadMatrixf(projMat);
    glMatrixMode(GL_MODELVIEW);

    return PFTRAV_CONT;
}

static int
postDrawEarthCB(pfTraverser *, void *)
{
    // Pop adjusted projection matrix
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);

    return PFTRAV_CONT;
}

Regards, Simon
_______________________________________________________________________

Simon Mills
Modelling & Simulation Section (TEC-SWM) Tel: +31 (0)71 565 3725
European Space Agency (ESA/ESTEC) Fax: +31 (0)71 565 5420
Postbus 299, 2200AG Noordwijk e-mail: Simon.Mills++at++esa.int
The Netherlands http://www.estec.esa.nl/wmwww/EMM
_______________________________________________________________________

|---------+------------------------------------------->
| | lberto++at++adelphia.net |
| | Sent by: |
| | owner-info-performer++at++performer.e|
| | ngr.sgi.com |
| | |
| | |
| | 14/04/2005 19:26 |
| | |
|---------+------------------------------------------->
>---------------------------------------------------------------------------------------------------------------------|
  | |
  | To: info-performer++at++sgi.com |
  | cc: |
  | Subject: [info-performer] drawing close and far objects with differing near far clip plains |
>---------------------------------------------------------------------------------------------------------------------|

I am trying to change the near far clipplane in an objects draw callback to
cut down on z fighting on objects far aw aye while
maintaining close objects rendering ability.
It seems that when I change the clip planes by setting the chan->setNearFar()
command, the channel says that the clip plains are set appropriately
but the close object dose not draw as expected.

My question is, is this leagle to do?
If so then why dose my close object draw as if the near clip plane in out to
far.
if Not then what is the correct way to draw near and far objects without z
fighting?

-----------------------------------------------------------------------
   List Archives, Info, FAQ: http://www.sgi.com/software/performer/
   Open Development Project: http://oss.sgi.com/projects/performer/
                Submissions: info-performer++at++sgi.com
            Admin. requests: info-performer-request++at++sgi.com
-----------------------------------------------------------------------


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Fri Apr 15 2005 - 07:44:25 PDT