Skip to main content
gamedev.net
🔒 Locked

Recursion

Started by daniel_i_l Apr 4, 2006 at 5:05 AM 0 replies 400+ views
Original Post
daniel_i_l
daniel_i_l
I have a BSP tree and want to get the min and max heights (of the heightmap) of each area. The BSP class looks like this:

struct BSP{
 float height, width, depth;
 float centerX, centerY, centerZ;
 MinMax limits;
 BSP *p_sec1, *p_sec2, *p_sec3, *p_sec4;
 bool found_limits;
 bool is_leaf;
};

class CBspTree{
 public: 
   CBspTree();
  ~CBspTree();
   int number_of_parts;
   void GetHeightMap(BYTE *pH){p_HeightMap = pH;}
   void GetBoxes(){map->limits = FindLimits(map);}
   void RenderMap();
   VERTEX PickedCenter;
   void Picking(CVector3 line[]);
 private:
   BSP* map;
   BYTE* p_HeightMap;
   bool color;
   void InitTree(BSP* node, float x, float y, float h, float w);
   void EraseBSP(BSP* node);
   void Render(BSP* node);
   void PickCenter(BSP* node);
   CVector3 v_Line[2];
   MinMax FindLimits(BSP* node);
   MinMax FindLimitsOfArea(float blX, float blY, float trX, float trY);
};

And the code to implement the height finding looks like this:

MinMax CBspTree :: FindLimitsOfArea(float blX, float trX, float blY, float trY)
{
  MinMax limit;
  float y;
  
  limit.min = 10000;  limit.max = -10000;
  for(int i = blX; i <= trX; i+=STEP_SIZE)
   {
     for(int j = blY; j <= trY; j+=STEP_SIZE)
      {
        y = (float)(SCALE_HEIGHT*Height(p_HeightMap, (float)i, (float)j ));  
        if(y>limit.max)
         limit.max = y;
        if(y<limit.min)
         limit.min = y;
         }
         
   }
  //limit.max=500;
  return(limit);
}



MinMax CBspTree :: FindLimits(BSP* node)
{
   if(!node->is_leaf)
    {
      node->limits.min = Smallest(FindLimits(node->p_sec1).min,
                                  FindLimits(node->p_sec2).min,
                                  FindLimits(node->p_sec3).min,
                                  FindLimits(node->p_sec4).min);
      
      node->limits.max =  Biggest(FindLimits(node->p_sec1).max,
                                  FindLimits(node->p_sec2).max,
                                  FindLimits(node->p_sec3).max,
                                  FindLimits(node->p_sec4).max);
      
      node->centerY = (node->limits.min + node->limits.max)/2;
      node->height = node->limits.max - node->limits.min;
      node->found_limits = true;
      return(node->limits);
    }
   else
    {
      //node->limits.max = Height(p_HeightMap, node->centerX, node->centerZ);
      //node->limits.min = 20;
      node->limits = FindLimitsOfArea(node->centerX - node->width/2, node->centerX + node->width/2,
                                      node->centerZ - node->depth/2, node->centerZ + node->depth/2);

      //limits.max=200;
      node->centerY = (node->limits.min + node->limits.max)/2;
      node->height = node->limits.max - node->limits.min;
      node->found_limits = true;
      return(node->limits);
    }
}

But for some reason for limits.max of for example: (node->p_sec1->limits.max) I'm getting 10000 for every heightmap and even if I enable (//limits.max=200; ) towards the end. What could the problem be? Thanks.
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky
moeron
moeron
Walk through it in your debugger and watch the values as you proceed through the function. Thats probabbly the easiest way to determine whats going on.
moe.ron

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.