RE: Performer bug with HAT isectors

New Message Reply Date view Thread view Subject view Author view

From: Braun, Tom (tom.braun++at++lmco.com)
Date: 08/09/2000 05:45:28


>>>Apparently my code snippet didn't make it the first time arround so I am
>>>sending it again.

Hello all,

  I have been struggling for quite some time with a problem that I have with
Performer giving me invalid isector intersection values when it intersects
with the terrain. Most of the time the intersection values are correct.
However, there are places in my database where it seems like isect is not
filing in the hits[] array. I say this because, during the times when I get
invalid results, I view the hits[] array before and after isect is called
and the values do not change. This hits[] array is passed into MQuery and
MQuery gives me predictably invalid "points" intersection values. However,
isect returns a 1 meaning that my isector has intersected with the terrain.
There is nothing noticeably different about the places that my TerrainHeight
routine works and where it doesn't work. My routine may not work at one
location, but if I move my intersection segment over by 0.5 meters, it will
again give me valid HAT values. I have also independently verified in
MultiGen that the location where I set my segment is, in fact, above
terrain. By the way, all of my terrain is flagged as terrain in MultiGen.
I'm hoping someone else may have run into this problem as well.

Thank you in advance for any help you can provide. I have included a code
snippet at the end of this email.

Tom

/* In my main code, I make the following call: */

TerrainHeight = PerformerDisplayGetTerrainHeightFunc(Mak_Ptr->Target.Pos_E,
                      Mak_Ptr->Target.Pos_N); // find TerrainHeight for this
X and Y. Remember performer in ENU

// *************************************************************************
// GET TERRAIN HEIGHT FUNCTION.
float PerformerDisplayGetTerrainHeightFunc(float x, float y)
{
  float TerrainHeight=0;

  TerrainHeight = Pfcurrent->GetTerrainHeight(x,y);
  return (TerrainHeight);
}

float PerformerDisplayWindow::GetTerrainHeight (float x, float y)
{
  pfSegSet se gset; // Isector segment
  long num_i sect;
  pfHit **hits[32]; //results from up to 32 isectors
  float z = 10000.0f; // place TerrainHeight isector arbitrarily high in
the sky
  float TerrainHeight = -99999.0f;
  struct
  {
    int flags;
    pfVec3 point;
    pfSeg segment;
  } result;

  segset.activeMask = 0x01; //one segment specified
  segset.isectMask = 0xFFFF; //~0; //Intersect with everything
  segset.discFunc = NULL;
  segset.bound = NULL;
  segset.mode = PFTRAV_IS_PRIM|PFTRAV_IS_NORM|PFTRAV_IS_CULL_BACK;
  segset.segs[0].dir.set(0.0f, 0.0f, -1.0f); // pointing down
  segset.segs[0].length = 50000.0f;

  // Update location of intersection segment
  segset.segs[0].pos.set(x,y,z);
  cout << "Segment placed: x= "<<x<<" y= "<<y<<" z= "<<z<<endl;

  // do an intersection test against the scene graph
  num_isect = Shared->scene->isect(&segset, hits); // Returns the number of
isectors. Should always be 1 since I have only defined 1.

  if(num_isect > 0){
    uint query[] = { (uint)PFQHIT_FLAGS, (uint)PFQHIT_POINT,
(uint)PFQHIT_SEG, (uint)NULL };
    pfMQueryHit(*hits[0], query, &result);
    
    if (result.flags & PFHIT_ISECT){
      //Valid intersection
      TerrainHeight = result.point[PF_Z];
   
      cout<<"*result.segment.pos[0] = "<<result.segment.pos[0]<<"
result.segment.pos[1] = "<<result.segment.pos[1]<<" result.segment.pos[2] =
"<<result.segment.pos[2]<<endl;
      cout<<"*result.segment.dir[0] = "<<result.segment.dir[0]<<"
result.segment.dir[1] = "<<result.segment.dir[1]<<" result.segment.dir[2] =
"<<result.segment.dir[2]<<endl;

    } // end if result.flags
    else {
      cout << "Warning: No terrain found at this location. TerrainHeight is
being set to zero."<<endl;
      TerrainHeight = 0;
    }
  } // end if num_isect
  
  cout<<"TerrainHeight = "<<TerrainHeight<<endl;
  cout<<"X and Y intersect location = "<<result.point[PF_X]<<"
"<<result.point[PF_Y]<<endl;
  return(TerrainHeight);
}


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Wed Aug 09 2000 - 05:49:16 PDT

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