Examples of Point2DInt


Examples of org.earth3d.jearth.math.Point2DInt

      // copy children
      for(int i=0; i<4; i++) {
        MapTile child;
        try {
          child = getMapTileChild(i);
          Point2DInt pos = MapTileXML.getSubmaptilePos(MapTileXML.getSubmaptileConstant(i));
          BufferedImage unscaledImage = child.getImg();
          if (unscaledImage == null) unscaledImage = new BufferedImage(Global.SOURCEWIDTH, Global.SOURCEHEIGHT, getMapTileChild(0).getImageType());
          BufferedImage sourcescaled = ImageUtil.scaleImage(Global.SOURCEWIDTH/2, Global.SOURCEHEIGHT/2, unscaledImage);
//          ImageIO.write(child.getImg(), "jpeg", new FileOutputStream("/tmp/debugorig"+i+".jpg"));
//          ImageIO.write(sourcescaled, "jpeg", new FileOutputStream("/tmp/debug"+i+".jpg"));
View Full Code Here

Examples of org.earth3d.jearth.math.Point2DInt

   * @return
   */
  public static Point2DInt getSubmaptilePos(SubmaptilePos pos) {
    switch(pos) {
    case LEFT_UP:
      return new Point2DInt(0,0);
    case LEFT_DOWN:
      return new Point2DInt(0,1);
    case RIGHT_UP:
      return new Point2DInt(1,0);
    case RIGHT_DOWN:
      return new Point2DInt(1,1);
    }
   
    return null;
  }
View Full Code Here

Examples of org.earth3d.jearth.math.Point2DInt

      x = maxx;
      y = 0;
      break;
    }

    return (new Point2DInt(x, y));
  }
View Full Code Here

Examples of org.earth3d.jearth.math.Point2DInt

  protected void generateCorner(int direction, int level, Point2DInt offset,
      int othertiledirection, HeightfieldTreeNodeCore otherhcore,
      int matchingborder) throws IOException {
    // return;
    Point2DInt thisCorner, otherCorner;

    /* calculate offset */
    if (level < 0) {
      Point2DInt poffset = new Point2DInt(0, 0);

      if ((matchingborder & 1) != 0) {
        poffset.x = (int) (offset.x * ((getWidth() - 1) / Math.pow(2,
            -level)));
        thisCorner = getCornerCoordinates(direction,
View Full Code Here

Examples of org.earth3d.jearth.math.Point2DInt

  public Point2DInt offset;

  public MapPart() {
    level = 0;
    node = null;
    offset = new Point2DInt(0, 0);
  };
View Full Code Here

Examples of org.earth3d.jearth.math.Point2DInt

  }

  Point2DInt getSimpleTileCoordinates(int childnr) {
    switch(childnr) {
    case 0:
      return new Point2DInt(1,0);
    case 1:
      return new Point2DInt(1,1);
    case 2:
      return new Point2DInt(0,0);
    case 3:
      return new Point2DInt(0,1);
    default:
      throw new IllegalArgumentException("wrong child nr ("+childnr+")");
    }
  }
View Full Code Here

Examples of org.earth3d.jearth.math.Point2DInt

  }

  public Point2DInt getSimpleTileDirections(int direction) {
    switch(direction) {
    case 0:
      return(new Point2DInt(1,0));
    case 1:
      return(new Point2DInt(0,1));
    case 2:
      return(new Point2DInt(-1,0));
    case 3:
      return(new Point2DInt(0,-1));
    default:
      throw new IllegalArgumentException("wrong direction ("+direction+")");
    }
  }
View Full Code Here

Examples of org.earth3d.jearth.math.Point2DInt

    return(owndirection);
  }

  public MapPart getNeighbor(int direction) {
    if (getParent() == null) return(new MapPart(0, this, new Point2DInt(0,0))); // loop the root tile

    /* test which child this tile is */
    Point2DInt ownposition = getSimpleTileCoordinates(getThisChildnr());

    /* if we can reach the neighbor directly using the parent then do so */
    Point2DInt godirection = getSimpleTileDirections(direction);
    Point2DInt newposition = ownposition.add(godirection);
    if (newposition.x>=0 && newposition.x<=1 &&
        newposition.y>=0 && newposition.y<=1) {
      MapTileTreeNode result = getParent().getChild(getChildnr(newposition));
      if (result==null) { // child does not exist, use parent and difference level of 1
        return(new MapPart(1, getParent(), newposition));
      }
      else { // child does exist, use it with level difference of 0
        return(new MapPart(0, getParent().getChild(getChildnr(newposition)), new Point2DInt(0,0)));
      }
    }

    /* otherwise we need to get the right neighbor from the parent tile */
    MapPart parentNeighbor = getParent().getNeighbor(direction);

    /* from the parentNeighbor we need the child that is in the opposite direction */
    Point2DInt searchposition = ownposition.add(getSimpleTileDirections((direction + 2) % 4));
    assert(searchposition.x>=0 && searchposition.x<=1 && searchposition.y>=0 && searchposition.y<=1);

//    /* by getting this parent neighbor, we moved two times in that direction
//    and need to correct our search position accordingly */
//    newposition = newposition - godirection*2;

    if (parentNeighbor.node==null) { // neighbor does not exist
      return(new MapPart(0, null, new Point2DInt(0,0)));
    }

    if (parentNeighbor.level==0 && !parentNeighbor.node.getSelectedForDrawing()) { // more childs exist
      /* now get this child */
      MapTileTreeNode result = parentNeighbor.node.getChild(getChildnr(searchposition));
      if (result != null) { // has a child
        return(new MapPart(0, result, new Point2DInt(0,0)));
      }
      else { // has no child, use parent
        return(new MapPart(1, parentNeighbor.node, searchposition));
      }
    }
View Full Code Here

Examples of org.earth3d.jearth.math.Point2DInt

      return(new MapPart(parentNeighbor.level+1, parentNeighbor.node, parentNeighbor.offset));
    }
  }

  public MapPart getCornerNeighbor() {
    if (getParent() == null) return(new MapPart(0, this, new Point2DInt(0,0))); // loop the root tile

    /* test what child this tile is */
    Point2DInt ownposition = getSimpleTileCoordinates(getThisChildnr());

    /* if we can reach the neighbor directly using the parent then do so */
    Point2DInt godirection = new Point2DInt(1,1);
    Point2DInt newposition = ownposition.add(godirection);
    if (newposition.x>=0 && newposition.x<=1 &&
        newposition.y>=0 && newposition.y<=1) {
      MapTileTreeNode result = getParent().getChild(getChildnr(newposition));
      if (result==null) { // child does not exist, use parent and difference level of 1
        return(new MapPart(1, getParent(), newposition));
      }
      else { // child does exist, use it with level difference of 0
        return(new MapPart(0, getParent().getChild(getChildnr(newposition)), new Point2DInt(0,0)));
      }
    }

    MapPart parentNeighbor = new MapPart();
    Point2DInt searchposition = new Point2DInt();

    try {
      if (newposition.x>1 && newposition.y>1) {
        /* otherwise we need to get the right neighbor from the parent tile */
        parentNeighbor = (MapPart) getParent().getCornerNeighbor().clone();
        searchposition = new Point2DInt(0,0);

      }
      else {
        if (newposition.x>1) {
          parentNeighbor = (MapPart) getSelectedNeighbor(0).clone();
          searchposition = new Point2DInt(0,1);
        }
        else {
          if (newposition.y>1) {
            parentNeighbor = (MapPart) getSelectedNeighbor(1).clone();
            searchposition = new Point2DInt(1,0);
          }
        }
      }
    } catch (CloneNotSupportedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    /* from the parentNeighbor we need the child that is in the opposite direction */
    if (parentNeighbor.node==null) { // neighbor does not exist
      return(new MapPart(0, null, new Point2DInt(0,0)));
    }

    if (parentNeighbor.level==0 && !parentNeighbor.node.getSelectedForDrawing()) { // more childs exist
      /* now get this child */
      MapTileTreeNode result = parentNeighbor.node.getChild(getChildnr(searchposition));
      if (result != null) { // has a child
        return(new MapPart(0, result, new Point2DInt(0,0)));
      }
      else { // has no child, use parent
        return(new MapPart(1, parentNeighbor.node, searchposition));
      }
    }
View Full Code Here

Examples of org.earth3d.jearth.math.Point2DInt

      int ndir = direction;
      MapPart neighbor2 = getSelectedNeighbor((ndir+3)%4);

      if (neighbor2.node != null) {
        /* 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 = neighbor2.offset.multiply(2);
          neighbor2.offset = neighbor2.offset.add(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 != null && getCore(1) != null) {
          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 != null) {
        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 = neighbor2.offset.multiply(2);
          neighbor2.offset = neighbor2.offset.add(getSimpleTileCoordinates(childposnr));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.