Package org.osm2world.core.math

Examples of org.osm2world.core.math.VectorXZ


      return (int)((this.getHeight()*0.95) - (v.z - minZ) / (maxZ - minZ) * (this.getHeight()*0.9));
    }
   
    private VectorXZ inverseCoord(int x, int y) {
     
      double relX = ( x - coordX(new VectorXZ(minX, maxZ)) ) / (this.getWidth() * 0.9);
      double relZ = ( y - coordY(new VectorXZ(minX, maxZ)) ) / (this.getHeight() * 0.9);
     
      double totalX = maxX - minX;
      double totalZ = maxZ - minZ;
     
      return new VectorXZ(
          minX + relX * totalX,
          maxZ - relZ * totalZ);
     
    }
 
View Full Code Here


    for (QuadLeaf leaf : mapQuadtree.getLeaves()) {
     
      /* draw leaf boundary */
     
      VectorXZ[] vs = new VectorXZ[5];
      vs[0] = new VectorXZ(leaf.minX, leaf.minZ);
      vs[1] = new VectorXZ(leaf.maxX, leaf.minZ);
      vs[2] = new VectorXZ(leaf.maxX, leaf.maxZ);
      vs[3] = new VectorXZ(leaf.minX, leaf.maxZ);
      vs[4] = vs[0];
      target.drawLineStrip(LEAF_BORDER_COLOR, 1,
          listXYZ(Arrays.asList(vs),0));
     
      if (arrowsEnabled) {
       
        /* draw arrows from leaf center to elements */
       
        VectorXZ leafCenter = new VectorXZ(
            (leaf.minX + leaf.maxX)/2,
            (leaf.minZ + leaf.maxZ)/2);
       
        for (MapElement e : leaf) {
         
          if (e instanceof MapNode) {
           
            VectorXZ nodePos = ((MapNode)e).getPos();
           
            drawArrow(target, NODE_ARROW_COLOR,
                (float) min(1,
                    distance(leafCenter, nodePos) * 0.3),
                leafCenter.xyz(0), nodePos.xyz(0));
           
          } else if (e instanceof MapWaySegment) {
           
            VectorXZ lineStart =
              ((MapWaySegment)e).getStartNode().getPos();
            VectorXZ lineEnd =
              ((MapWaySegment)e).getEndNode().getPos();
           
            VectorXZ lineCenter = lineStart.add(lineEnd).mult(0.5f);
           
            float headLength = (float)
                min(1, distance(leafCenter, lineCenter) * 0.3);
            drawArrow(target,
                LINE_ARROW_COLOR, headLength,
                leafCenter.xyz(0), lineCenter.xyz(0));
           
          } else if (e instanceof MapArea) {
           
            VectorXZ areaCenter =
              ((MapArea)e).getOuterPolygon().getCenter();
           
            float headLength = (float)
                min(1, distance(leafCenter, areaCenter) * 0.3);
            drawArrow(target,
                AREA_ARROW_COLOR, headLength,
                leafCenter.xyz(0), areaCenter.xyz(0));
         
          }
        }
       
      }
View Full Code Here

    for (QuadLeaf leaf : mapQuadtree.getLeaves()) {
     
      /* draw leaf boundary */
     
      VectorXZ[] vs = new VectorXZ[5];
      vs[0] = new VectorXZ(leaf.minX, leaf.minZ);
      vs[1] = new VectorXZ(leaf.maxX, leaf.minZ);
      vs[2] = new VectorXZ(leaf.maxX, leaf.maxZ);
      vs[3] = new VectorXZ(leaf.minX, leaf.maxZ);
      vs[4] = vs[0];
      target.drawLineStrip(LEAF_BORDER_COLOR, 1,
          listXYZ(Arrays.asList(vs),0));
     
      if (arrowsEnabled) {
       
        /* draw arrows from leaf center to elements */
       
        VectorXZ leafCenter = new VectorXZ(
            (leaf.minX + leaf.maxX)/2,
            (leaf.minZ + leaf.maxZ)/2);
       
        for (MapElement e : leaf) {
         
          if (e instanceof MapNode) {
           
            VectorXZ nodePos = ((MapNode)e).getPos();
           
            drawArrow(target, NODE_ARROW_COLOR,
                (float) min(1,
                    distance(leafCenter, nodePos) * 0.3),
                leafCenter.xyz(0), nodePos.xyz(0));
           
          } else if (e instanceof MapWaySegment) {
           
            VectorXZ lineStart =
              ((MapWaySegment)e).getStartNode().getPos();
            VectorXZ lineEnd =
              ((MapWaySegment)e).getEndNode().getPos();
           
            VectorXZ lineCenter = lineStart.add(lineEnd).mult(0.5f);
           
            float headLength = (float)
                min(1, distance(leafCenter, lineCenter) * 0.3);
            drawArrow(target,
                LINE_ARROW_COLOR, headLength,
                leafCenter.xyz(0), lineCenter.xyz(0));
           
          } else if (e instanceof MapArea) {
           
            VectorXZ areaCenter =
              ((MapArea)e).getOuterPolygon().getCenter();
           
            float headLength = (float)
                min(1, distance(leafCenter, areaCenter) * 0.3);
            drawArrow(target,
                AREA_ARROW_COLOR, headLength,
                leafCenter.xyz(0), areaCenter.xyz(0));
         
          }
        }
       
      }
View Full Code Here

    VectorXYZ slastV = VectorXYZ.xyz(vs[vs.length-2]);
   
    VectorXYZ endDir = lastV.subtract(slastV).normalize();
    VectorXYZ headStart = lastV.subtract(endDir.mult(headLength));
   
    VectorXZ endDirXZ = endDir.xz();
    if (endDirXZ.lengthSquared() < 0.01) { //(almost) vertical vector
      endDirXZ = VectorXZ.X_UNIT;
    } else {
      endDirXZ = endDirXZ.normalize();
    }
    VectorXZ endNormalXZ = endDirXZ.rightNormal();
   
   
    ImmutableMaterial colorMaterial =
        new ImmutableMaterial(Lighting.FLAT, color);
   
    target.drawTriangleStrip(colorMaterial, asList(
        lastV,
        headStart.subtract(endDirXZ.mult(headLength/2)),
        headStart.add(endDirXZ.mult(headLength/2))),
        null);
   
    target.drawTriangleStrip(colorMaterial, asList(
        lastV,
        headStart.subtract(endNormalXZ.mult(headLength/2)),
        headStart.add(endNormalXZ.mult(headLength/2))),
        null);
   
  }
View Full Code Here

  @Override
  public void fillTarget(JOGLTarget target) {
   
    AxisAlignedBoundingBoxXZ bound = map.getDataBoundary();
   
    double minLon = toDegrees(mapProjection.calcLon(new VectorXZ(bound.minX, bound.minZ)));
    double minLat = toDegrees(mapProjection.calcLat(new VectorXZ(bound.minX, bound.minZ)));
    double maxLon = toDegrees(mapProjection.calcLon(new VectorXZ(bound.maxX, bound.maxZ)));
    double maxLat = toDegrees(mapProjection.calcLat(new VectorXZ(bound.maxX, bound.maxZ)));
   
    for (int x = (int)floor(minLon / LINE_DIST); x < (int)ceil(maxLon / LINE_DIST); x++) {
      for (int z = (int)floor(minLat / LINE_DIST); z < (int)ceil(maxLat / LINE_DIST); z++) {
       
        int widthLat = (z % 3600 == 0) ? 6
View Full Code Here

         * often there are nodes that are only added to join one building to another
         * but these interfere with proper triangulation.
         * TODO: do the same for holes */
        List<VectorXZ> vertices = polygon.getOuter().getVertexLoop();
        List<VectorXZ> simplified = new ArrayList<VectorXZ>();
        VectorXZ vPrev = vertices.get(vertices.size() - 2);
       
        for (int i = 0, size = vertices.size() - 1; i < size; i++ ){
          VectorXZ v = vertices.get(i);
         
          if (i == 0 || roofHeightMap.containsKey(v) || nodeSet.contains(v)) {
            simplified.add(v);
            vPrev = v;
            continue;
          }
          VectorXZ vNext = vertices.get(i + 1);
          LineSegmentXZ l = new LineSegmentXZ(vPrev, vNext);
         
          // TODO define as static somewhere: 10 cm tolerance
          if (distanceFromLineSegment(v, l) < 0.01){
            continue;
View Full Code Here

    @Override
    public void renderTo(Target<?> target) {
     
      /* calculate a vector that points out of the building */
     
      VectorXZ outOfBuilding = VectorXZ.Z_UNIT;
     
      for (SimplePolygonXZ polygon :
        buildingPart.polygon.getPolygons()) {
       
        final List<VectorXZ> vs = polygon.getVertexLoop();
        int entranceI = vs.indexOf(node.getPos());
       
        if (entranceI != -1) {
         
          VectorXZ posBefore = vs.get((vs.size() + entranceI - 1) % vs.size());
          VectorXZ posAfter = vs.get((vs.size() + entranceI + 1) % vs.size());
         
          outOfBuilding = posBefore.subtract(posAfter).rightNormal();
          if (!polygon.isClockwise()) {
            outOfBuilding = outOfBuilding.invert();
          }
View Full Code Here

     
      if (outline != null) return;

      lowerCenter = node.getPos();
     
      VectorXZ toRight = tunnelContent.getStartCutVector()
          .mult(tunnelContent.getWidth() * 0.5f);
     
      lowerLeft = lowerCenter.subtract(toRight);
      lowerRight = lowerCenter.add(toRight);
     
      VectorXZ toBack = tunnelContent.segment.getDirection().mult(0.1);
      if (tunnelContent.segment.getEndNode() == node) {
        toBack = toBack.invert();
      }
     
      upperLeft = lowerLeft.add(toBack);
      upperCenter = lowerCenter.add(toBack);
      upperRight = lowerRight.add(toBack);
View Full Code Here

            // at a common node with this building part's outline.
            // (otherwise, the subtract polygon will probably
            // not exactly line up with the polygon boundary)
           
            WaySegmentWorldObject waySegmentWO = (WaySegmentWorldObject)o;
            VectorXZ start = waySegmentWO.getStartPosition();
            VectorXZ end = waySegmentWO.getEndPosition();
           
            boolean startCommonNode = false;
            boolean endCommonNode = false;
           
            for (SimplePolygonXZ p : polygon.getPolygons()) {
              startCommonNode |= p.getVertexCollection().contains(start);
              endCommonNode |= p.getVertexCollection().contains(end);
            }
           
            VectorXZ direction = end.subtract(start).normalize();
           
            if (startCommonNode) {
              subtractPolygons.add(subtractPoly.shift(direction));
            }
           
            if (endCommonNode) {
              subtractPolygons.add(subtractPoly.shift(direction.invert()));
            }
           
          }
         
        }
View Full Code Here

      double accumulatedLength = 0;
      double[] previousS = new double[textureDataList.size()];
     
      for (int i = 0; i < vertices.size(); i++) {
       
        final VectorXZ coord = vertices.get(i);
       
        /* update accumulated wall length */
       
        if (i > 0) {
          accumulatedLength += coord.distanceTo(vertices.get(i-1));
        }
       
        /* add wall vectors */
       
        final VectorXYZ upperVector = coord.xyz(roof.getRoofEleAt(coord));
        final VectorXYZ middleVector = coord.xyz(baseEle + heightWithoutRoof);
       
        double upperEle = upperVector.y;
        double middleEle = middleVector.y;
       
        mainWallVectors.add(middleVector);
        mainWallVectors.add(new VectorXYZ(coord.x,
            min(floorEle, middleEle), coord.z));
       
        roofWallVectors.add(upperVector);
        roofWallVectors.add(new VectorXYZ(coord.x,
            min(middleEle, upperEle), coord.z));
       
       
        /* add texture coordinates */
       
        for (int texLayer = 0; texLayer < textureDataList.size(); texLayer ++) {
         
          TextureData textureData = textureDataList.get(texLayer);
          List<VectorXZ> texCoordList = mainWallTexCoordLists.get(texLayer);
         
          double s, lowerT, middleT;
         
          // determine s (width dimension) coordinate
         
          if (textureData.height > 0) {
            s = accumulatedLength / textureData.width;
          } else {
            if (i == 0) {
              s = 0;
            } else {
              s = previousS[texLayer] + round(vertices.get(i-1)
                  .distanceTo(coord) / textureData.width);
            }
          }
         
          previousS[texLayer] = s;
         
          // determine t (height dimension) coordinates
         
          if (textureData.height > 0) {
           
            lowerT = (floorEle - baseEle) / textureData.height;
            middleT = (middleEle - baseEle) / textureData.height;
           
          } else {
           
            lowerT = buildingLevels *
              (floorEle - baseEle) / (middleEle - baseEle);
            middleT = buildingLevels;
           
          }
         
          // set texture coordinates
         
          texCoordList.add(new VectorXZ(s, middleT));
          texCoordList.add(new VectorXZ(s, lowerT));
         
        }
               
      }

View Full Code Here

TOP

Related Classes of org.osm2world.core.math.VectorXZ

Copyright © 2018 www.massapicom. 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.