Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Integrate 3D map and Proscene Library (Cameras Paths for Map)

$
0
0

Hello!

I am using a new library (github.com/dimr/mapzen-processing) developed by Dimitris Rongotis in order to generate a 3D map with open data. I'd like to generate a camera path through that map. Basically so that people can "site see" along the map. I'll be embedding poems inside the map, and zooming up to look at them. Also thinking about scraping tweets, embedding them into the map in real time, and setting the camera to look at new ones that show up on the map (they're geo-located). Thing is, for some reason, pro-scene is cutting off sections of the map and I can't figure out why? Does anybody have any idea why this is happening?

import main.Mapzen;
import main.net.MapzenUrl;
import main.net.MapzenUrlBuilder;
//import peasy.PeasyCam;
import toxi.geom.Vec3D;
import toxi.processing.ToxiclibsSupport;
import java.util.List;

import remixlab.proscene.*;
import remixlab.bias.core.*;
import remixlab.bias.event.*;
import remixlab.dandelion.geom.Vec.*;


/**
 * Created by dimitris on 4/7/16.
 */

//PeasyCam cam;
private Mapzen mapzen;
ToxiclibsSupport toxi;

Scene scene;
ArrayList buttons;
float h;
PFont buttonFont;

float xCounter;
float yCounter;
float rCounter;
float clickCounter;
PFont font;
int camPosition = 0;

//***THIS IS WHERE YOU WILL PLUG IN COORDINATES;
//This is coordinates from your tweets, Vec3D is similar to PVector
Vec3D TweetCoordinate = new Vec3D(-122.408162, 37.755468, 0);
//this will hold coordinates converted to application dimensions
Vec3D convertedTweetCoordiante;
PGraphics pg;

public void setup() {
  // **do not** use setLayrers("roads")...only buildings
  MapzenUrl url = new MapzenUrlBuilder().setLongitude(-122.409531f).setLatitude(37.782281f).setZoom(13).setLayer("buildings").setKey("vector-tiles-PADQnWp").buildUrl();
  mapzen =  new Mapzen(this, url); //this PApplet size

  //scene.setBoundingBox(new Vec(0, 0, 0), new Vec(width, height, 1000));
  //scene.setRadius(1500);
  //scene.setCenter(new Vec(width/2, height/2));
  //scene.camera().setPosition(new Vec(width/2, height/2, 1000));

  scene = new Scene(this);
  //create a camera path and add some key frames:
  //key frames can be added at runtime with keys [j..n]
  scene.camera().setPosition(80, 0, 0);
  scene.camera().lookAt( scene.camera().sceneCenter() );
  scene.camera().addKeyFrameToPath(1);

  scene.camera().setPosition(30, 30, -80);
  scene.camera().lookAt( scene.camera().sceneCenter() );
  scene.camera().addKeyFrameToPath(1);

  scene.camera().setPosition(-30, -30, -80);
  scene.camera().lookAt( scene.camera().sceneCenter() );
  scene.camera().addKeyFrameToPath(1);

  scene.camera().setPosition(-80, 0, 0);
  scene.camera().lookAt( scene.camera().sceneCenter() );
  scene.camera().addKeyFrameToPath(1);

  //re-position the camera:
  scene.camera().setPosition(0, 0, 1);
  scene.camera().lookAt( scene.camera().sceneCenter() );
  scene.showAll();

  //this is the speed;
  scene.camera().keyFrameInterpolator(1).setInterpolationSpeed(0.1f);

  //drawing of camera paths are toggled with key 'r'.
  scene.setPathsVisualHint(true);

  buttons = new ArrayList(6);
  for (int i=0; i<5; ++i)
    buttons.add(null);

  buttonFont = loadFont("FreeSans-16.vlw");

  Button2D button = new ClickButton(scene, new PVector(10, 5), buttonFont, 0);
  h = button.myHeight;
  buttons.set(0, button);

  toxi=new ToxiclibsSupport(this);
  smooth();

  //coordinate convertion takes place
  convertedTweetCoordiante=mapzen.convert(TweetCoordinate);

  font = createFont("A.vlw", 200);
  textFont(font, 200);
  textMode(SCREEN);
}



public void draw() {
  background(0);

  //TEXT MANIPULATION;
  fill(255, 255);
  textSize(12);

  //#1; THIS IS THE TESTIMONY-TEXT;
  pushMatrix();
  translate(854, 1000, 5);
  rotateZ(-.0459);
  translate(-854, -1000, -5);
  text("1033 York St. : out of state partners, flipping the property, the Ellis eviction process, adversarial, unprofessional, renovations on a vacant unit, harassment, off the power without notice - settlement.", 854, 1000, 200, 200);
  popMatrix();

  //#2; THIS IS THE QUESTION-TEXT;
  pushMatrix();
  translate(1500+100, 500, 250);
  rotateZ(-.0459);
  rotateX(-1.6549987);
  rotateY(0.9099993);
  translate(-1500-100, -500, -250);
  translate(0, 0, 250);
  text("Is this the future we want or is it another, one where we manage the space and the data together?", 1500, 500, 200, 200);
  translate(0, 0, -250);
  popMatrix();

  //#3; THIS IS THE ADVERTISING-TEXT;
  pushMatrix();
  translate(1100, -100, 100);
  rotateZ(3.0100214);
  rotateX(4.71506);
  translate(-1100, +100, -100);
  translate(0, 0, 100);
  text("Anti-Eviction: antievictmap.com Data-Protection: ssd.eff.org Broadcasting: saitogroup.info 415-617-9782", 1000, -100, 200, 200);
  translate(0, 0, -100);
  popMatrix();

  //THIS IS THE MARKER OF THE HOUSE;
  pushMatrix();
  pushStyle();
  strokeWeight(2);
  stroke(255, 255, 255);
  translate(convertedTweetCoordiante.x(), convertedTweetCoordiante.y(), 0);
  float t=map(sin(frameCount*.2), -1, 1, 0, 200);
  line(0, 0, 0, 0, 0, t);
  popStyle();
  popMatrix();

  //THIS IS THE CAMERA STEERING APPARATUS;
  //COUNTERS;
  //pCounter++;
  //rCounter+=.00002;
  //DISCOVERY;
  //.getRotations();
  //.getPosition();
  //.getDistance();
  //IMPLEMENTATION;
  //cam.rotateX(rCounter);
  //cam.rotateY(rCounter);
  //cam.rotateZ(rCounter);
  //cam.setDistance(z);
  //cam.pan(x,y);
  //GET A POSITION;
  //println(cam.getLookAt());
  //println(cam.getRotations());
  //THIS IS A VERY SHITTY WAY OF STEERING THE CAMERA;
  //println(cam.getRotations());
  //println(cam.getPosition());
  //println(cam.getDistance());

  // for now: renderPolygons(red,green,blue,opacity) -->fill of the buildings, all sides of the building get the same fill color you set here
  mapzen.renderPolygons(255, 255, 255, 150);
  // drawGeoRoads(red,green,blue,strokeWeight)
  mapzen.drawGeoRoads(100, 100, 100, 1);

  updateButtons();
  displayButtons();
}

public void settings() {
  //        size(1300,850);
  size(1900, 1050, "processing.opengl.PGraphics3D");
  //        fullScreen(P3D,2);
}


void updateButtons() {
  for (int i = 1; i < buttons.size(); i++) {
    // Check if CameraPathPlayer is still valid
    if ((buttons.get(i) != null) && (scene.camera().keyFrameInterpolator(i) == null ) )
      buttons.set(i, null);
    // Or add it if needed
    if ((scene.camera().keyFrameInterpolator(i) != null) && (buttons.get(i) == null))
      buttons.set(i, new ClickButton(scene, new PVector(10, + ( i ) * ( h + 7 )), buttonFont, i));
  }
}

void displayButtons() {
  for (int i = 0; i < buttons.size(); i++) {
    Button2D button = (Button2D) buttons.get(i);
    if ( button != null )
      button.display();
  }
}

/**
 * Button 2D.
 * by Jean Pierre Charalambos.
 *
 * Base class of "2d buttons" that shows how simple is to implement
 * a MouseGrabber which can enable complex mouse interactions.
 */

public abstract class Button2D extends GrabberObject {
  public Scene scene;
  String myText;
  PFont myFont;
  float myWidth;
  float myHeight;
  PVector position;

  public Button2D(Scene scn, PVector p, PFont font) {
    this(scn, p, font, "");
  }

  public Button2D(Scene scn, PVector p, PFont font, String t) {
    scene = scn;
    position = p;
    myText = t;
    myFont = font;
    textFont(myFont);
    textAlign(LEFT);
    setText(t);
    scene.motionAgent().addGrabber(this);
  }

  public void setText(String text) {
    myText = text;
    myWidth = textWidth(myText);
    myHeight = textAscent() + textDescent();
  }

  public void display() {
    pushStyle();
    fill(255);
    if (grabsInput(scene.motionAgent()))
      fill(255);
    else
      fill(100);
    scene.beginScreenDrawing();
    text(myText, position.x, position.y, myWidth+1, myHeight);
    scene.endScreenDrawing();
    popStyle();
  }

  @Override
  public boolean checkIfGrabsInput(DOF2Event event) {
    float x = event.x();
    float y = event.y();
    return ((position.x <= x) && (x <= position.x + myWidth) && (position.y <= y) && (y <= position.y + myHeight));
  }
}

public class ClickButton extends Button2D {
  int path;

  public ClickButton(Scene scn, PVector p, PFont font, int index) {
    this(scn, p, font, "", index);
  }

  public ClickButton(Scene scn, PVector p, PFont font, String t, int index) {
    super(scn, p, font, t);
    path = index;
  }

  @Override
    public void performInteraction(ClickEvent event) {
    if (event.clickCount() == 1)
      if (path == 0)
        scene.togglePathsVisualHint();
      else
        scene.eye().playPath(path);
  }

  public void display() {
    String text = new String();
    if (path == 0)
      if (scene.pathsVisualHint())
        text = "don't edit camera paths";
      else
        text = "edit camera paths";
    else {
      if (grabsInput(scene.motionAgent())) {
        if (scene.eye().keyFrameInterpolator(path).numberOfKeyFrames() > 1)
          if (scene.eye().keyFrameInterpolator(path).interpolationStarted())
            text = "stop path ";
          else
            text = "play path ";
        else
          text = "restore position ";
      } else {
        if (scene.eye().keyFrameInterpolator(path).numberOfKeyFrames() > 1)
          text = "path ";
        else
          text = "position ";
      }
      text += ((Integer) path).toString();
    }
    setText(text);
    super.display();
  }
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles