Пример #1
0
  public void draw() {
    background(0);
    strokeWeight(3);
    stroke(222);
    noStroke();
    if (!paused) myHolder.execute();
    myHolder.draw();
    noStroke();

    PP.execute();
    PP.draw();

    strokeWeight(5);
    stroke(100);
    for (int j = 0; j < start.size(); j++) {
      gfx.point(start.get(j));
      gfx.point(end.get(j));
    }

    strokeWeight(0.1f);
    stroke(255, 55);
    fill(222, 222);
    gfx.mesh(aMesh);
    fill(200, 222);
    gfx.mesh(terrain);

    if (frameCount % 4 == 0 && video) screenShot = true;

    if (screenShot) screenShot();
  }
  public void showVoronoi() {
    voronoi = new Voronoi();
    for (String btsID : BTS2Location.keySet()) {
      Location location = BTS2Location.get(btsID);
      float xy[] = this.map.getScreenPositionFromLocation(location);
      if (xy[0] > width * 2
          || xy[0] < -(width * 2)
          || xy[1] > height * 2
          || xy[1] < -(height * 2)) {
        // avoid errors in toxiclib
        continue;
      }
      try {
        voronoi.addPoint(new Vec2D(xy[0], xy[1]));
      } catch (Exception e) {
        logger.debug(e);
      }
    }

    noFill();
    stroke(0xFF40a6dd);
    strokeWeight(1);

    for (Polygon2D polygon : voronoi.getRegions()) {
      gfx.polygon2D(polygon);
    }

    fill(255, 0, 255);
    noStroke();
    for (Vec2D c : voronoi.getSites()) {
      ellipse(c.x, c.y, 5, 5);
    }
  }
Пример #3
0
  ///////////////////////////////
  /// GLOBE RENDERING
  ////////////////////////////////
  private void renderGlobe() {
    // smoothly interpolate camera rotation
    // to new rotation vector based on mouse position
    // each frame we only approach that rotation by 25% (0.25 value)

    lights();
    /* this looks pink
    ambientLight(255, 0, 0);
    specular(255, 0, 0);
    */
    // store default 2D coordinate system
    pushMatrix();
    // switch to 3D coordinate system and rotate view based on mouse
    translate(width / 2, height / 2, 0);

    ///// CHECK FOR MOUSE INPUT TO SET CAMERA
    if (mousePressed) {
      camRot.interpolateToSelf(new Vec3D(mouseY * 0.01f, mouseX * 0.01f, 0), 0.25f / currZoom);
      // println("MOUSEX: " + mouseX);
      // println("MouseY " + mouseY);
      theCamX = camRot.x;
      theCamY = camRot.y;

      ///// CHECK FOR OSC INPUT TO SET CAMERA
    } else if (hasOsc == true) {
      /// map(value, low1, high1, low2, high2)

      println("rotate dammit!");
      float newX = map(oscX0, 0, 1, 0, screenWidth); // /// maps our input to 1024
      float oscY = map(oscY0, 0, 1, 0, screenHeight); // ///
      camRot.interpolateToSelf(new Vec3D(oscY * 0.01f, newX * 0.01f, 0), 0.25f / currZoom);
      theCamX = camRot.x;
      theCamY = camRot.y;
      // rotateX(camRot.x);
      // rotateY(camRot.y);
      // currZoom += (targetZoom - currZoom) * 0.25;
      // */

    }

    theOldCamX = theCamX;
    theOldCamY = theCamY;

    hasOsc = false; // /switch off osc input until we get another osc signal
    float newCamX =
        map(new Float(theCamX), 0, 7, 2, 4); // narrow the range of vertical camera movement

    currZoom += (targetZoom - currZoom) * 0.25;
    // theCamX = newCamX;

    rotateX(new Float(theCamX));
    rotateY(new Float(theCamY));

    // apply zoom factor
    scale(currZoom);
    // compute the normalized camera position/direction
    // using the same rotation setting as for the coordinate system
    // this vector is used to figure out if images are visible or not
    // (see below)
    Vec3D camPos =
        new Vec3D(0, 0, 1)
            .rotateX(new Float(theCamX))
            .rotateY(new Float(theCamY)); // / changed from cam.x and cam.y
    camPos.normalize();
    noStroke();
    fill(255);
    // use normalized UV texture coordinates (range 0.0 ... 1.0)
    textureMode(NORMAL);
    // draw earth
    gfx.texturedMesh(globe, earthTex, true);

    ////////////////////////////////////////
    // /// SET GPS MARKERS ON THE SPHERE

    // check marker position
    for (int i = 0; i < GPSArray.size(); i++) {
      GPSArray.get(i).updateScreenPos(this, camPos);
    }
    // check destroyer position
    if (isVideoPlaying == false) {
      // if(thePopUp.isVideoPlaying == true){
      theDestroyer.updateScreenPos(this, camPos);
    }

    /////////////////////////////////////////
    // switch back to 2D coordinate system
    popMatrix();
    // disable depth testing to ensure anything drawn next
    // will always be on top/infront of the globe
    hint(DISABLE_DEPTH_TEST);
    // draw images centered around the given positions
    imageMode(CENTER);

    // now that they're in position, draw them
    for (int i = 0; i < GPSArray.size(); i++) {
      GPSArray.get(i).drawAsImage(IMG_SIZE * currZoom * 0.9f, showLabels);
    }
    // draw the destroyer
    try {
      theDestroyer.drawAsImage(this, IMG_SIZE * currZoom * 0.9f, showLabels);
    } catch (Exception e) {
      println("Cant draw destroyer" + e);
    }
    setDestroyer();
    ////////////////////////////////////////
    // restore (default) depth testing
    hint(ENABLE_DEPTH_TEST);
  }