@Test
  public void testAddAFewWindCoordinates() {
    Mesh3D mesh = reader.readGlobe(GlobeType.Full);
    Collection<Face> allFaces = mesh.getFaces();
    int oldCount = allFaces.size();

    TriangleMesh newMesh = new TriangleMesh();
    newMesh.addMesh(mesh);
    // TriangleMesh offers easier access to the faces,
    // unfortunately it is also significantly slower when adding faces

    for (int i = 0; i < 100; i++) {
      Face face = newMesh.faces.get(i);

      Vec3D cloudPoint = face.getCentroid();
      cloudPoint.x += 7;
      cloudPoint.y += 7;
      cloudPoint.z += 7;
      mesh.addFace(cloudPoint, face.a, face.b);
      mesh.addFace(cloudPoint, face.b, face.c);
      mesh.addFace(cloudPoint, face.c, face.a);
    }

    mesh.computeFaceNormals();
    int newCount = mesh.getNumFaces();
    assertFalse(oldCount == newCount);

    String path = getClass().getResource(".").getFile();
    File file = new File(path, "manipulated.stl");
    TriangleMesh meshforWriting = new TriangleMesh();
    meshforWriting.addMesh(mesh);
    writer.write(file, meshforWriting);
  }
예제 #2
0
  void flow(VoxelGrid volume) {

    // get the value of the current voxel
    float v = volume.getValue(this);

    // check neighbouring voxels for difference
    Vec3D from = volume.repelFromValue(this, 0, 1, 0.1f).limit(0.1f);
    if (!from.isZeroVector()) {
      lastSub += 1;
    } else {
      lastSub = 0;
    }
    addForce(from);
  }
예제 #3
0
 public VerletParticle3D setPreviousPosition(Vec3D p) {
   prev.set(p);
   return this;
 }
예제 #4
0
 public VerletParticle3D scaleVelocity(float scl) {
   prev.interpolateToSelf(this, 1f - scl);
   return this;
 }
예제 #5
0
 public VerletParticle3D clearVelocity() {
   prev.set(this);
   return this;
 }
예제 #6
0
 public VerletParticle3D clearForce() {
   force.clear();
   return this;
 }
예제 #7
0
 protected void applyForce() {
   temp.set(this);
   addSelf(sub(prev).addSelf(force.scale(weight)));
   prev.set(temp);
   force.clear();
 }
예제 #8
0
 public VerletParticle3D addVelocity(Vec3D v) {
   prev.subSelf(v);
   return this;
 }
예제 #9
0
 public VerletParticle3D addForce(Vec3D f) {
   force.addSelf(f);
   return this;
 }
예제 #10
0
  public void setDestroyer() {
    // convert cur mouse pos to lat and long
    // map(value, low1, high1, low2, high2)

    if (doCursor == true) {
      // theLat = map(oscY1, 1, 0, 0, 90);
      // theLong = map(oscX1, 0, 1, -180, 180);

      /// change osc values to mouse-parsed
      float newOscY = map(oscY1, 0, 1, 0, screenHeight);
      float newOscX = map(oscX1, 0, 1, 0, screenWidth);

      desRot.interpolateToSelf(new Vec3D(newOscX * 0.51f, newOscY * 0.51f, 0), 0.25f / currZoom);
      theLat = desRot.y; // map(mouseY, 0, screenHeight, 0, 90);
      theLong = desRot.x; // map(mouseX, 0, screenWidth, -180, 180);

    } else {
      // theLat = map(mouseY, 600, 0, 0, 90);
      // theLong = map(mouseX, 200, 800, -180, 180);

    }
    if (!mousePressed && useKeyboard == true) {

      /// *
      desRot.interpolateToSelf(new Vec3D(mouseX * 0.51f, mouseY * 0.51f, 0), 0.25f / currZoom);
      theLat = desRot.y; // map(mouseY, 0, screenHeight, 0, 90);
      theLong = desRot.x; // map(mouseX, 0, screenWidth, -180, 180);
      // */

    }
    doCursor = false;

    /*
    * theCamX = camRot.x;
    theCamY = camRot.y;
    */

    //

    theDestroyer.setSpherePosition(theLong, theLat);
    theDestroyer.computePosOnSphere(EARTH_RADIUS);

    //// CHECK FOR INTERSECTION with other markers
    boolean isPopupVisible = false;
    for (int i = 0; i < GPSArray.size(); i++) {
      // for(int i=0; i<2; i++){

      /// DESTROYER LAT AND LONG
      float dlat = theDestroyer.theLat;
      float dlong = theDestroyer.theLong; // theDestroyer.theLat;

      //// MARKER LAT AND LONG
      float mlat = GPSArray.get(i).theLat;
      float mlong = GPSArray.get(i).theLong;
      // println("dlat " + dlat + " mlat: " + mlat);
      // println("dlong " + dlong + " mlong: " + mlong);
      //// check to see if the destroyer is within the range of the current lat and long
      /// if (dlat >= (mlat -1) && dlat <= (mlat + 1) &&  dlong <= (mlong + 1) && dlong >= (mlong -
      // 1)){

      //// CHECK INTERSECTION of MARKER AND DESTROYER
      GPSMarker tMark = GPSArray.get(i);
      if (isPopupVisible == false
          && theDestroyer.pos.y <= (tMark.pos.y + 10)
          && theDestroyer.pos.y >= (tMark.pos.y - 10)
          && theDestroyer.pos.x <= (tMark.pos.x + 10)
          && theDestroyer.pos.x >= (tMark.pos.x - 10)) {

        tMark.doHit();

        //// init popup data
        thePopUp.theName = "";
        thePopUp.theText = "";

        thePopUp.theHeader = headerList.get(tMark.theID);
        thePopUp.theName = nameList.get(tMark.theID);
        thePopUp.theText = blurbList.get(tMark.theID);
        // thePopUp.theVideoPath = videoPathList.get(tMark.theID);

        /// swtich video if it's different than the current
        if (curID != tMark.theID) {
          // println("Cur ID: " + curID + " new ID: " + tMark.theID);
          /// stop current, switch
          thePopUp.stopVideo();
          thePopUp.switchCurVideo(tMark.theID);
          curID = tMark.theID;
        }

        //// showing popup data
        thePopUp.drawPopup(tMark.theID);
        isPopupVisible = true;
      }
    }
  }
예제 #11
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);
  }
 /** @param force the force to set */
 public void setForce(Vec3D force) {
   this.force = force;
   scaledForce = force.scale(timeStep);
 }