Re: certainly already asked

New Message Reply Date view Thread view Subject view Author view

Thomas Hudson (hudson++at++cs.unc.edu)
Thu, 6 Jun 1996 12:14:58 -0400 (EDT)


> This is something that I am interested in too. I have seen a few posts
> asking this in the past, but never any answers. For myself I need to be
> able to compute the size (e.g. projected bounding sphere diameter) and
> position of objects in (2D) screen coordinates.
>
> I gather that this is not possible in Performer? (but I'd love to be
> proved wrong). As a result I am considering re-inventing the wheel and
> manually performing perspective projections on each of my objects. In
> order to ensure that I'm doing the same calculations that Performer is
> doing to display the object, can anyone on the Performer Team direct me
> towards a source (or better yet, source code) which Performer uses to
> implement its perspective projection (is it just your standard algorithm
> ala Foley & van Dam?).
>
> As a future feature suggestion, I would think that being able to access or
> compute the 2D projected coords for objects would be a fairly useful API
> feature?? Just my opinion :-)

Never found an API feature for it. I'll append source code to show what I do.
(This code is used for dynamically tesselating various curved objects based on
their screen size, but most of the interesting objects (trimmed Bezier surfaces)
are far from stable enough to release). I've run a little post-draw loop that
verifies that the coordinates I project are identical to those that OpenGL
draws. Originally derived from code by David Luebke of pfPortals, another
UNC student.

Tom
UNC-Chapel Hill Walkthrough and Modeling Groups
// hudson++at++cs.unc.edu

  // global matrix to hold the projection matrix, which we calculate once
  // per frame
  pfMatrix * gVPMat;

  static pfFrustum * baseFrust;
  static pfMatrix * rotMat; // convert from Performer to GL coord systems

In the initialization routines...

  baseFrust = new (arena) pfFrustum;
  rotMat = new (arena) pfMatrix;
  rotMat->makeRot(-90.0f, 1.0f, 0.0f, 0.0f);

A callback called every frame... If called as an APP traversal,
it lags one frame behind the actual viewpoint, but we do this because
of problems with multiprocessing.

  // cbUpdateDynamicTesselationState
  //
  // Sets up global variable gVPMat, which is the product of the
  // inverse viewing matrix and the projection matrix. Does other
  // frame-by-frame maintenance. Should be attached to a node in
  // the graph that is the parent of all dynamic tesselation objects
  // (or promoted from a callback to a regular function in the
  // application loop)

  int cbUpdateDynamicTesselationState (pfTraverser * trav, void *) {
    pfChannel * chan = trav->getChan();

    pfMatrix frustMat, projMat;
    chan->getBaseFrust(baseFrust);
    baseFrust->getGLProjMat(frustMat);
    projMat.mult(*rotMat, frustMat);

    pfMatrix invMat, viewMat;
    chan->getViewMat(invMat);

    viewMat.invertOrtho(invMat);

    gVPMat->mult(viewMat, projMat);

    return PFTRAV_CONT;
  }

Now we have our bounding box in item->corners[]; the following may produce
crazy numbers if your bounding box is being clipped by the hither plane,
but we clamp the output anyway so having large numbers doesn't bother us.
A safer approach would be to use two different matrices (a slower proecss),
as the comment notes.

  pfVec3 pbverts [8]; // vertices of bounding prism

  for (i = 0; i < 8; i++) {
    pbverts[i].fullXformPt(item->corners[i], *gVPMat);
    // probably ought to use viewMat, do a hither clip, and then
    // use projMat
  }

=======================================================================
List Archives, FAQ, FTP: http://www.sgi.com/Technology/Performer.html
            Submissions: info-performer++at++sgi.com
        Admin. requests: info-performer-request++at++sgi.com


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:52:59 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.