Back to Parent

// Import Libraries for Video and Projection Mapping
import processing.video.*;
import deadpixel.keystone.*;
import processing.serial.*;

// The serial port
Serial myPort;  
// Keystone
Keystone ks;
// Create Surfaces to put media 
CornerPinSurface surface;
CornerPinSurface surface2;


// Movies and Images
Movie menu;

PImage starter; //2
PImage main; // 3
PImage side1; //4
PImage side2; //5
PImage dessert; //6
PImage defaultImg; //7

String id = "";
String buff = "";
// Create three screen to draw on
PGraphics offscreen;
PGraphics offscreen2;

// Switch screen on and off
boolean on1 = false;
boolean on2 = false;
boolean on3 = false;
boolean on4 = false;
boolean on5 = false;
boolean on6 = false;
boolean on7 = false;

//-----INCOMING VALUES-----
String incomingString; // setting string from serial 
int incomingState;
int swapState;

void setup() {
  // Keystone will only work with P3D or OPENGL renderers, 
  // since it relies on texture mapping to deform
  // Fullscreen 
  //fullScreen(P3D, 1); // FOR SCREEN ONE PROJECTOR
  fullScreen(P3D, 2); // FOR SCREEN TWO PROJECTOR
  //size(1500, 900, P3D);
  printArray(Serial.list());
  myPort = new Serial(this, Serial.list()[3], 9600);

  //// Load Movies for offscreen
  //movie = new Movie(this, "transit.mov");
  //movie.loop();
  //offscreen = createGraphics(640, 360, P3D);

  // Load images for menu interaction (CONVERT TO MOVIE)
  //menu = new Movie(this, "menu.mov");
  //menu.play();
  //offscreen2 = createGraphics(menu.width, menu.height, P3D);

  // Load images for MAIN DISH interaction (CONVERT TO MOVIE)
  main = loadImage("main.png");
  offscreen = createGraphics(main.width, main.height, P3D);

  // Load images for STARTER interaction (CONVERT TO MOVIE)
  starter = loadImage("starter.png");
  offscreen = createGraphics(starter.width, starter.height, P3D);

  // Load images for SIDE 01 interaction (CONVERT TO MOVIE)
  side1 = loadImage("side01.png");
  offscreen = createGraphics(side1.width, side1.height, P3D);

  // Load images for SIDE 02 interaction (CONVERT TO MOVIE)
  side2 = loadImage("side02.png");
  offscreen = createGraphics(side2.width, side2.height, P3D);

  // Load images for menu interaction (CONVERT TO MOVIE)
  dessert = loadImage("dessert.png");
  offscreen = createGraphics(dessert.width, dessert.height, P3D);

  // Load images for menu interaction (CONVERT TO MOVIE)
  defaultImg = loadImage("default.png");
  offscreen = createGraphics(defaultImg.width, defaultImg.height, P3D);

  //// Load Movie for offscreen3
  //movie2 = new Movie(this, "boidRME.mov");
  //movie2.loop();
  //offscreen3 = createGraphics(1920, 1080, P3D);

  // Create an instance of Keystone
  ks = new Keystone(this);

  surface = ks.createCornerPinSurface(main.width, main.height, 20);
  surface2 = ks.createCornerPinSurface(1080, 720, 20);
}

void draw() {
  background(0);
  while (myPort.available() > 0) {
    serialEvent(myPort.read());
  }

  sceneSwap();
}

void movieEvent(Movie m) {
  // read the video
  m.read();
}


void sceneSwap() {

  switch(swapState) {
  case 1:
    offscreen.beginDraw();
    offscreen.image(menu, 0, 0); 
    offscreen.endDraw();
    surface2.render(offscreen);
    break;
  case 2:
    offscreen.beginDraw();
    offscreen.image(starter, 0, 0); 
    offscreen.endDraw();
    surface.render(offscreen);
    break;
  case 3:
    offscreen.beginDraw();
    offscreen.image(main, 0, 0); 
    offscreen.endDraw();
    surface.render(offscreen);
    break;
  case 4:
    offscreen.beginDraw();
    offscreen.image(side1, 0, 0); 
    offscreen.endDraw();
    surface.render(offscreen);
    break;
  case 5:
    offscreen.beginDraw();
    offscreen.image(side2, 0, 0); 
    offscreen.endDraw();
    surface.render(offscreen);
    break;
  case 6:
    offscreen.beginDraw();
    offscreen.image(dessert, 0, 0); 
    offscreen.endDraw();
    surface.render(offscreen);
    break;
  case 7:
    offscreen.beginDraw();
    offscreen.image(defaultImg, 0, 0); 
    offscreen.endDraw();
    surface.render(offscreen);
    break;
  default:
    offscreen.beginDraw();
    offscreen.image(defaultImg, 0, 0); 
    offscreen.endDraw();
    surface.render(offscreen);
    break;
  }
}

void keyPressed() {
  switch(key) {
  case 'c':
    // enter/leave calibration mode, where surfaces can be warped 
    // and moved
    ks.toggleCalibration();
    break;

  case 'l':
    // loads the saved layout
    ks.load();
    break;

  case 's':
    // saves the layout
    ks.save();
    break;
  }
}

void serialEvent(int serial) {
  if (serial != '\n') { 
    buff += char(serial);
  } else {   
    id = trim(buff.substring(0));
    incomingState = int(id);
    if (incomingState == 1) { // MENU
      menu = new Movie(this, "menu.mov");
      menu.play();
      offscreen2 = createGraphics(menu.width, menu.height, P3D);
      swapState = 1;
    } else if (incomingState == 2) { // STARTER
      swapState = 2;
    } else if (incomingState == 3) { // MAIN
      swapState = 3;
    } else if (incomingState == 4) { // SIDE O1
      swapState = 4;
    } else if (incomingState == 5) { // SIDE 02
      swapState = 5;
    } else if (incomingState == 6) { // DESSERT
      swapState = 6;
    } else if (incomingState == 7) { // DEFAULT
      swapState = 7;
    }
    buff = "";
  }
  println(incomingState);
  println(swapState);
  println(" ");
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0