Re: Gound coordinates with the mouse

New Message Reply Date view Thread view Subject view Author view

Randy Stiles (stiles++at++aic.lockheed.com)
Wed, 22 Feb 95 09:18:20 PST


   From: "Ole Martin Bjoerndalen" <olem++at++indigo.mti.sgi.com>
   Date: Thu, 23 Feb 1995 15:09:56 +0000
   X-Mailer: Z-Mail (3.1.0 22feb94 MediaMail)
   Content-Type: text/plain; charset=us-ascii
   Mime-Version: 1.0

   I have a similar problem to Martin Roth's, who had a similar problem to David
   Luebke's. However, it's a bit different.

   I would like to place geometry on the ground using the mouse, in much the same
   way as you place models on the grid in programs like MultiGen and Medit. I just
   can't figure out excacly where on the ground the mouse is pointing.

   I have read through the documentation, but haven't found functions that do
   this.

   Can somebody help me?

Intersections in performer can return the local XYZ if you ask for it.
Using the mouse intersection routine in performer, set its flags to
collect local xyz. After a mouse button is pressed, call the mouse
intersection routine. Then query pfHit data to get the local xyz.
Then reparent your object to the pfGroup of the ground, with the object's
dcs translation values being the local xyz returned from intersection.

-Randy

# Randy Stiles Lockheed AI Center
# stiles++at++aic.lockheed.com Orgn 9620 Bldg 254F
# Office: 415.354.5256 3251 Hanover Street
# Fax: 415.354.5235 Palo Alto, CA 94304-1191
# Lab: 415.424.2690

typedef struct pickstruct
{
     pfScene *scene;
     pfChannel **chan;
     pfNode *picked;
     pfPath *path;
     char *pathname;
     float pickX;
     float pickY;
     long ch_xo;
     long ch_yo;
     long ch_xs;
     long ch_ys;
     long traverse;
} Pick;

Pick *
NewPick(pfScene *S, pfChannel **C)
{
    Pick *P = (Pick *)pfMalloc(sizeof(Pick), pfGetSharedArena());

    P->chan = C;
    P->scene = S;
    P->pathname = (char *)pfMalloc(sizeof(char) *300, pfGetSharedArena());

    P->traverse = PFTRAV_IS_PRIM | PFPK_M_NEAREST;
    return P;
}

void
mouseManip(void)
{
  static pfNode *tmpnode;
  static long count;
  static ulong pathFlag = PFQHIT_PATH;
  pfVec3 hitXYZ;
  pfVec3 whitXYZ;
  pfMatrix hitMat;

  pfHit **hits[32];
  pfPath *thePath;
  ulong nfy = pfGetNotifyLevel();
  int i;
  Pick *P = NewPick(ViewState->scene, &ViewState->masterChan);
  char *parName;

  pfNotifyLevel(PFNFY_DEBUG);

  if (!(ViewState->mouse.flags & PFUDEV_MOUSE_LEFT_DOWN))
    return;
   
  pfNodePickSetup(ViewState->scene);
  pfuCalcNormalizedChanXY(&P->pickX, &P->pickY, *P->chan,
                          ViewState->mouse.clickDownX,
                          ViewState->mouse.clickDownY);

  count = pfChanPick(*P->chan, P->traverse, P->pickX, P->pickY, 0.0f, hits);
  for (i = 0; i < count; i++) {
    pfQueryHit(*hits[i],PFQHIT_NODE,&P->picked);
    pfQueryHit(*hits[i],PFQHIT_PATH,&P->path);
    pfQueryHit( hits[i][0], PFQHIT_POINT, (float *)&hitXYZ );

    // used to do world coords of hit into whitXYZ, but local coords more useful
    // for things like snapping objects. Be sure to change participant hits too.
    pfQueryHit( hits[i][0], PFQHIT_XFORM, (float *)hitMat );

    // calc and store world pts for inquiry
    pfXformPt3( whitXYZ, hitXYZ, hitMat );
    // local pts in vrPick message
    hitNotify(P->picked, hitXYZ[0], hitXYZ[1], hitXYZ[2]);

    if (P->path != NULL) {
      tmpnode =
          findNamedTypeOnPath(P->path, PFTYPE_DCS);
      if (tmpnode != NULL)
        cerr << " found hit for " << pfGetNodeName(tmpnode);
    }
    else cerr << "Path was null\n";
  }
  pfNotifyLevel(nfy);
  pfFree(P);
}


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:50:59 PDT

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