Logo Search packages:      
Sourcecode: earth3d version File versions  Download package

void MapTileTreeNode::regenerateHeightfield ( MapTileTreeNode node,
int  direction,
int  level = 0,
Point2DInt  offset = Point2DInt(0,0) 
)

Corrects the heigtfield values at the border in direction direction with the values from node. If this node here has children, they are adjusted to the values of node. It goes down to the children until it finds nodes that are selected for drawing.

Definition at line 350 of file mapTileTreeNode.cpp.

References getChildnr(), getCore(), getSelectedForDrawing(), getSelectedNeighbor(), getSimpleTileCoordinates(), and regenerateHeightfield().

Referenced by regenerateHeightfield().

                                                                                                              {
  /* get the layer that is selected for drawing */
  if (getSelectedForDrawing()) {
    /* regenerate this node 
     * the deeper node has to adapt to the other nodes heightfield, but the higher node has to restore
     * its border at this point
     */

    assert(node->getSelectedForDrawing());

    /* get heightfieldcore */
    HeightfieldTreeNodeCore *hcore = (HeightfieldTreeNodeCore *) getCore(1);
    HeightfieldTreeNodeCore *otherhcore = (HeightfieldTreeNodeCore *) node->getCore(1);

//     if (hcore) {
//       hcore->generateBorder(direction, level, direction&1 ? offset.x:offset.y, otherhcore);
//     }

    if (hcore) { // because the rootnode has none yet
      hcore->generateBorder(direction, level, direction&1 ? offset.x:offset.y, otherhcore);
    }
    if (otherhcore) {
      otherhcore->generateBorder((direction+2) % 4, -level, direction&1 ? offset.x:offset.y, hcore);
    }

    /* generate the corner of the neighbor of the neighbor */
    
    /* begin with the left side */
    int ndir = direction;
    MapPart neighbor2 = getSelectedNeighbor((ndir+3)%4);

    if (neighbor2.node) {
      /* now go to the correct selected child, we need the deepest child that is selected and has a common border */
      Point2DInt childpos = HeightfieldTreeNodeCore::getCornerCoordinates(ndir, 1, 1);
      int childposnr = getChildnr(childpos);
      while(!neighbor2.node->getSelectedForDrawing()) {
      neighbor2.node = neighbor2.node->getChild(childposnr);
      neighbor2.offset *= 2;
      neighbor2.offset += getSimpleTileCoordinates(childposnr);
      neighbor2.level--;
      }
      
      /* now generate the corner at the common border between hcore and getCore(1). The common border
       is (seen from the other tile, hcore) (ndir+1)%4
      */
      hcore = (HeightfieldTreeNodeCore *) neighbor2.node->getCore(1);
      if (hcore && getCore(1)) {
      hcore->generateCorner(ndir, -neighbor2.level, neighbor2.offset, (ndir+3)%4, (HeightfieldTreeNodeCore *) getCore(1), (ndir+1)%4);
      }
    }

    /* now the right side */
    neighbor2 = getSelectedNeighbor((ndir+1)%4);

    if (neighbor2.node) {
      Point2DInt childpos = HeightfieldTreeNodeCore::getCornerCoordinates((ndir+3)%4, 1, 1);
      int childposnr = getChildnr(childpos);
      while(!neighbor2.node->getSelectedForDrawing()) {
      neighbor2.node = neighbor2.node->getChild(childposnr);
      neighbor2.offset *= 2;
      neighbor2.offset += getSimpleTileCoordinates(childposnr);
      neighbor2.level--;
      }
      
      hcore = (HeightfieldTreeNodeCore *) neighbor2.node->getCore(1);
      if (hcore && getCore(1)) {
      hcore->generateCorner((ndir+3)%4, -neighbor2.level, neighbor2.offset, ndir, (HeightfieldTreeNodeCore *) getCore(1), (ndir+3)%4);
      }
    }
  }
  else {
    /* regenerate all children in the given direction */
    if (direction==3 || direction==0) if (getChild(0)) 
      getChild(0)->regenerateHeightfield(node, direction, level+1, offset*2+getSimpleTileCoordinates(0));
    if (direction==0 || direction==1) if (getChild(1)) 
      getChild(1)->regenerateHeightfield(node, direction, level+1, offset*2+getSimpleTileCoordinates(1));
    if (direction==2 || direction==3) if (getChild(2)) 
      getChild(2)->regenerateHeightfield(node, direction, level+1, offset*2+getSimpleTileCoordinates(2));
    if (direction==2 || direction==1) if (getChild(3)) 
      getChild(3)->regenerateHeightfield(node, direction, level+1, offset*2+getSimpleTileCoordinates(3));
  }
}


Generated by  Doxygen 1.6.0   Back to index