加工&重新激活 - 从舞台中删除电影

时间:2014-06-16 08:01:19

标签: processing

我正在使用Processing和Reactivision制作一个交互式表格,每个符号都会播放一个视频。我遇到的问题是,当您删除符号时,视频仍然保留并且不会重置舞台,因此当添加另一个符号时,它会播放已经播放的视频。我基本上需要做的是,一旦符号被删除,舞台就会重置/清除。任何帮助将不胜感激。代码

/*
    TUIO processing demo - part of the reacTIVision project
    http://reactivision.sourceforge.net/

    Copyright (c) 2005-2009 Martin Kaltenbrunner <mkalten@iua.upf.edu>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

// we need to import the TUIO library
// and declare a TuioProcessing client variable
import TUIO.*;
import java.util.*;
import processing.video.*;
TuioProcessing tuioClient;

// these are some helper variables which are used
// to create scalable graphical feedback
float cursor_size = 15;
float object_size = 0;
float table_size = 760;
float scale_factor = 1;
PFont font;
PImage img;
Movie theMov; 
Movie theMov2;

void setup()
{
  //size(screen.width,screen.height);
  size(720,480);
  noStroke();
  fill(0);
  img = loadImage("background.jpeg");
  theMov = new Movie(this, "gibi.mov");
  theMov2 = new Movie(this, "rick.mov");

  loop();
  frameRate(30);
  //noLoop();

  font = createFont("Arial", 18);
  scale_factor = height/table_size;

  // we create an instance of the TuioProcessing client
  // since we add "this" class as an argument the TuioProcessing class expects
  // an implementation of the TUIO callback methods (see below)
  tuioClient  = new TuioProcessing(this);
}

// within the draw method we retrieve a Vector (List) of TuioObject and TuioCursor (polling)
// from the TuioProcessing client and then loop over both lists to draw the graphical feedback.
void draw()
{

  background(247,73,2);
  textFont(font,18*scale_factor);
  float obj_size = object_size*scale_factor; 


  image(theMov, 0, 0);
  image(theMov2, 0, 0);

  Vector tuioObjectList = tuioClient.getTuioObjects();
  for (int i=0;i<tuioObjectList.size();i++) {
     TuioObject tobj = (TuioObject)tuioObjectList.elementAt(i);
     pushMatrix();
     //translate(tobj.getScreenX(width),tobj.getScreenY(height));
     rotate(tobj.getAngle());
     rect(-obj_size/2,-obj_size/2,obj_size,obj_size);
     popMatrix();
     fill(255);
     text(""+tobj.getSymbolID(), tobj.getScreenX(width), tobj.getScreenY(height));
   }

}


// these callback methods are called whenever a TUIO event occurs

// called when an object is added to the scene
void addTuioObject(TuioObject tobj) {
  println("add object "+tobj.getSymbolID()+" ("+tobj.getSessionID()+") "+tobj.getX()+" "+tobj.getY()+" "+tobj.getAngle());

     if ( tobj.getSymbolID() == 0) {
      theMov.play();
  }

    if ( tobj.getSymbolID() == 5) {
      theMov2.play(); 
  }

}

// called when an object is removed from the scene
void removeTuioObject(TuioObject tobj) {
  println("remove object "+tobj.getSymbolID()+" ("+tobj.getSessionID()+")");
    if ( tobj.getSymbolID() == 0) {
      theMov.stop();

  } 
    if ( tobj.getSymbolID() == 5) {
      theMov2.stop();
  } 
}

// called when an object is moved
void updateTuioObject (TuioObject tobj) {
  println("update object "+tobj.getSymbolID()+" ("+tobj.getSessionID()+") "+tobj.getX()+" "+tobj.getY()+" "+tobj.getAngle()
          +" "+tobj.getMotionSpeed()+" "+tobj.getRotationSpeed()+" "+tobj.getMotionAccel()+" "+tobj.getRotationAccel());
}

// called after each message bundle
// representing the end of an image frame
void refresh(TuioTime bundleTime) { 
  redraw();
}

void movieEvent(Movie m) { 
  m.read(); 
}




TUIO: missing or wrong 'addTuioCursor(TuioCursor tcur)' method implementation
TUIO:missing or wrong 'removeTuioCursor(TuioCursor tcur)' method implementation
TUIO: missing or wrong 'updateTuioCursor(TuioCursor tcur)' method implementation
add object 0 (3) 0.37709242 0.8826896 0.0
update object 0 (3) 0.37709242 0.8737366 0.0742998 0.2419723 0.0 6.5397916 0.0
update object 0 (3) 0.37709242 0.867628 0.0742998 0.21064281 0.0 -1.080327 0.0
update object 0 (3) 0.37597793 0.86093885 0.0742998 0.19375265 0.0 -0.48257622 0.0
update object 0 (3) 0.37597793 0.8532117 0.0742998 0.23415594 0.0 1.2243422 0.0
update object 0 (3) 0.37896088 0.847547 0.0742998 0.15614879 0.0 -1.9026133 0.0
update object 0 (3) 0.38109976 0.84274954 0.0742998 0.1811261 0.0 0.86128664 0.0
update object 0 (3) 0.37981042 0.838495 0.0742998 0.116989255 0.0 -1.6878119 0.0
update object 0 (3) 0.38065997 0.838495 0.0742998 0.033981323 0.0 -3.3203173 0.0
update object 0 (3) 0.38252023 0.8398745 0.020077623 0.048248682 -0.17978598 0.29723665 -3.7455413
update object 0 (3) 0.38252023 0.8426642 0.020077623 0.09963129 0.0 1.835093 6.4209275
update object 0 (3) 0.38413188 0.8452217 0.020077623 0.10424032 0.0 0.1589322 0.0
update object 0 (3) 0.38413188 0.8452217 0.020077623 0.0 0.0 -4.009243 0.0
update object 0 (3) 0.38325775 0.8440129 0.020077623 0.033149652 0.0 0.73665893 0.0
update object 0 (3) 0.38325775 0.8427188 0.020077623 0.04313787 0.0 0.33294064 0.0
update object 0 (3) 0.38325775 0.8414247 0.020077623 0.05391985 0.0 0.4492492 0.0
update object 0 (3) 0.38222247 0.8414247 0.020077623 0.032352652 0.0 -0.67397493 0.0
update object 0 (3) 0.3830283 0.8414247 0.020077623 0.01714534 0.0 -0.32355985 0.0
update object 0 (3) 0.3830283 0.8424627 0.020077623 0.03992365 0.0 0.8760888 0.0
update object 0 (3) 0.3830283 0.8424627 0.020077623 0.0 0.0 -1.596946 0.0
update object 0 (3) 0.3830283 0.84123003 0.020077623 0.037354052 0.0 1.131941 0.0
update object 0 (3) 0.382105 0.84123003 0.020077623 0.026379995 0.0 -0.31354448 0.0
update object 0 (3) 0.381026 0.83904475 0.020077623 0.081238225 0.0 1.8286079 0.0
update object 0 (3) 0.381026 0.83904475 0.020077623 0.0 0.0 -2.3210924 0.0
update object 0 (3) 0.381026 0.83904475 0.020077623 0.0 0.0 0.0 0.0
update object 0 (3) 0.37948263 0.8377506 0.020077623 0.06294223 0.0 1.9669446 0.0
update object 0 (3) 0.37948263 0.8377506 0.020077623 0.0 0.0 -1.851242 0.0
update object 0 (3) 0.37948263 0.8377506 0.020077623 0.0 0.0 0.0 0.0
update object 0 (3) 0.37759778 0.8357668 0.020077623 0.08048391 0.0 2.367174 0.0
update object 0 (3) 0.37759778 0.8357668 6.280155 0.0 -0.11492891 -2.5151222 -3.5915282
update object 0 (3) 0.3761473 0.8357668 6.280155 0.04395427 0.0 1.3319477 3.4826941
update object 0 (3) 0.3761473 0.8336429 6.280155 0.060682636 0.0 0.47795326 0.0
update object 0 (3) 0.3761473 0.8336429 6.280155 0.0 0.0 -1.8963323 0.0
update object 0 (3) 0.3761473 0.8336429 6.280155 0.0 0.0 0.0 0.0
update object 0 (3) 0.37695312 0.8336429 0.0 0.02441912 0.014613922 0.7399733 0.44284612
update object 0 (3) 0.37695312 0.8336429 6.2801733 0.0 -0.013315989 -0.6783089 -0.77583086
update object 0 (3) 0.37695312 0.83588284 0.0010060358 0.072256215 0.020629212 2.3308456 1.0950066
update object 0 (3) 0.37695312 0.83588284 6.2821803 0.0 -0.010325174 -2.3308456 -0.99852866
update object 0 (3) 0.37695312 0.83588284 0.0080239 0.0 0.04105623 0.0 1.4680401
update object 0 (3) 0.37780267 0.83588284 6.2811527 0.026547907 -0.050016034 0.82962203 -2.846008
update object 0 (3) 0.37780267 0.83588284 0.0030150663 0.0 0.012552409 -0.41481102 0.97763187
update object 0 (3) 0.37780267 0.83447266 0.0030150663 0.040291037 0.0 1.1511725 -0.35864025
update object 0 (3) 0.37780267 0.83447266 0.0030150663 0.0 0.0 -1.2209406 0.0
update object 0 (3) 0.37780267 0.83447266 0.0030150663 0.0 0.0 0.0 0.0
update object 0 (3) 0.37780267 0.83548 0.0030150663 0.031478703 0.0 0.9837094 0.0
update object 0 (3) 0.37780267 0.8365726 0.0030150663 0.036420427 0.0 0.16472414 0.0
update object 0 (3) 0.37780267 0.8365726 0.0030150663 0.0 0.0 -1.0405836 0.0
update object 0 (3) 0.37780267 0.8365726 6.2781296 0.0 -0.03568064 0.0 -0.9911289
update object 0 (3) 0.37780267 0.83493704 6.2781296 0.054518383 0.0 1.8172795 1.1893547
update object 0 (3) 0.37780267 0.8339297 0.0010060358 0.02878053 0.027564982 -0.73536724 0.7875709
update object 0 (3) 0.37780267 0.8339297 6.274067 0.0 -0.051979534 -0.9284042 -2.565952
update object 0 (3) 0.37780267 0.83292246 6.274067 0.028778825 0.0 0.82225215 1.4851296
update object 0 (3) 0.37780267 0.83292246 0.001011122 0.0 0.048852257 -0.87208563 1.4803715
update object 0 (3) 0.37780267 0.83421654 6.27816 0.041744404 -0.030989556 1.3465937 -2.5755424
update object 0 (3) 0.37876967 0.83421654 0.0040691537 0.027628625 0.041355457 -0.40330797 2.0670004
update object 0 (3) 0.37876967 0.83421654 6.2811527 0.0 -0.029428765 -0.83723104 -2.1449766
update object 0 (3) 0.37876967 0.83421654 6.2811527 0.0 0.0 0.0 0.9196489
update object 0 (3) 0.37876967 0.8320927 6.2811527 0.06636977 0.0 2.0740552 0.0
update object 0 (3) 0.37876967 0.8320927 6.2811527 0.0 0.0 -1.8436048 0.0
update object 0 (3) 0.37768522 0.8320927 6.2811527 0.032862026 0.0 0.995819 0.0
update object 0 (3) 0.37768522 0.8320927 6.2811527 0.0 0.0 -1.0954009 0.0
update object 0 (3) 0.37768522 0.8320927 6.2811527 0.0 0.0 0.0 0.0
update object 0 (3) 0.37865222 0.8320927 6.2811527 0.02844123 0.0 0.8365067 0.0
update object 0 (3) 0.37865222 0.83096933 6.2811527 0.025531108 0.0 -0.06613915 0.0
update object 0 (3) 0.37865222 0.8295045 6.2811527 0.056340143 0.0 1.1849629 0.0
update object 0 (3) 0.37865222 0.8276982 6.2811527 0.0410527 0.0 -0.3474419 0.0
update object 0 (3) 0.37865222 0.8276982 6.2811527 0.0 0.0 -1.7105291 0.0
update object 0 (3) 0.37865222 0.8276982 6.2811527 0.0 0.0 0.0 0.0
update object 0 (3) 0.37865222 0.8256836 6.2811527 0.05444804 0.0 1.4715686 0.0
update object 0 (3) 0.37865222 0.8256836 6.2811527 0.0 0.0 -2.0941553 0.0
update object 0 (3) 0.37865222 0.8243041 6.2811527 0.04756862 0.0 1.6402973 0.0
update object 0 (3) 0.37865222 0.8243041 6.2811527 0.0 0.0 -1.3591034 0.0
update object 0 (3) 0.37865222 0.8262572 6.2811527 0.052787162 0.0 1.4266801 0.0
update object 0 (3) 0.38131282 0.8319766 6.2811527 0.23362696 0.0 6.697769 0.0
update object 0 (3) 0.38131282 0.8319766 6.2811527 0.0 0.0 -6.8713803 0.0
update object 0 (3) 0.38131282 0.8319766 6.2811527 0.0 0.0 0.0 0.0
remove object 0 (3)
add object 5 (4) 0.3838997 0.7569657 0.0
update object 5 (4) 0.3838997 0.74766445 1.4853827 0.26574987 0.0 7.5928535 0.0
update object 5 (4) 0.3820777 0.7410607 1.4853827 0.19572896 0.0 -2.000597 0.0
update object 5 (4) 0.3820777 0.7364408 1.4853827 0.10499765 0.0 -2.0620756 0.0
update object 5 (4) 0.3820777 0.73477453 1.4853827 0.057456825 0.0 -1.6393389 0.0
update object 5 (4) 0.38115984 0.73477453 1.4853827 0.035301536 0.0 -0.8521265 0.0
update object 5 (4) 0.38115984 0.7383939 1.4853827 0.097820885 0.0 1.6897122 0.0
update object 5 (4) 0.38267866 0.7416719 1.4853827 0.10322214 0.0 0.15432154 0.0
update object 5 (4) 0.38267866 0.7416719 1.4853827 0.0 0.0 -4.1288853 0.0
update object 5 (4) 0.38267866 0.7416719 1.4853827 0.0 0.0 0.0 0.0
update object 5 (4) 0.38355276 0.7416719 1.4853827 0.024974687 0.0 0.7135625 0.0
update object 5 (4) 0.38355276 0.74281234 1.4853827 0.04751732 0.0 0.9392763 0.0
update object 5 (4) 0.38355276 0.74281234 1.4853827 0.0 0.0 -1.3576376 0.0
update object 5 (4) 0.38355276 0.74281234 1.4853827 0.0 0.0 0.0 0.0
update object 5 (4) 0.38355276 0.7438743 1.4853827 0.03218109 0.0 0.9751846 0.0
update object 5 (4) 0.3850224 0.7457728 1.4853827 0.07275257 0.0 1.229439 0.0
update object 5 (4) 0.3850224 0.7457728 1.4853827 0.0 0.0 -2.2046237 0.0
update object 5 (4) 0.3850224 0.7457728 1.4853827 0.0 0.0 0.0 0.0
update object 5 (4) 0.3850224 0.7446494 1.4853827 0.029562335 0.0 0.77795625 0.0
update object 5 (4) 0.3850224 0.7446494 1.4853827 0.0 0.0 -0.9854112 0.0
update object 5 (4) 0.3850224 0.7446494 1.4853827 0.0 0.0 0.0 0.0
update object 5 (4) 0.3850224 0.74582744 1.4853827 0.03681332 0.0 1.1504161 0.0
update object 5 (4) 0.38592112 0.74582744 1.4853827 0.028084962 0.0 -0.27276114 0.0
update object 5 (4) 0.38592112 0.74582744 1.4853827 0.0 0.0 -0.85105944 0.0
update object 5 (4) 0.38592112 0.74703616 1.4853827 0.03555066 0.0 1.0456077 0.0
update object 5 (4) 0.38592112 0.74703616 1.4853827 0.0 0.0 -1.1109581 0.0
update object 5 (4) 0.38592112 0.7480674 1.4853827 0.029463427 0.0 0.8418122 0.0
update object 5 (4) 0.38727325 0.7480674 1.4853827 0.04097404 0.0 0.34880644 0.0
update object 5 (4) 0.38727325 0.7504541 1.4853827 0.0769919 0.0 1.1618665 0.0
update object 5 (4) 0.38846976 0.751919 1.4853827 0.054039527 0.0 -0.6557822 0.0
update object 5 (4) 0.38846976 0.751919 1.4853827 0.0 0.0 -1.1497772 0.0
update object 5 (4) 0.38846976 0.7534999 1.4853827 0.034368556 0.0 0.7471425 0.0
update object 5 (4) 0.38846976 0.7534999 1.4853827 0.0 0.0 -1.2274483 0.0
update object 5 (4) 0.38846976 0.7534999 1.4853827 0.0 0.0 0.0 0.0
update object 5 (4) 0.38846976 0.7545311 1.4853827 0.042965014 0.0 1.7902089 0.0
update object 5 (4) 0.38846976 0.75573987 1.4853827 0.048351288 0.0 0.21545097 0.0
update object 5 (4) 0.38846976 0.75573987 1.4853827 0.0 0.0 -1.4220966 0.0
update object 5 (4) 0.38846976 0.75573987 1.4853827 0.0 0.0 0.0 0.0
update object 5 (4) 0.38936844 0.75927395 1.4853827 0.11395484 0.0 3.5610886 0.0
update object 5 (4) 0.39017427 0.76237434 1.4853827 0.04928318 0.0 -0.99494874 0.0
update object 5 (4) 0.39233226 0.76737326 1.4853827 0.15556657 0.0 3.0366688 0.0
update object 5 (4) 0.3962385 0.7761623 1.4853827 0.2914553 0.0 4.11784 0.0
update object 5 (4) 0.3962385 0.7761623 1.4853827 0.0 0.0 -7.87717 0.0
update object 5 (4) 0.3962385 0.7761623 1.4853827 0.0 0.0 0.0 0.0
remove object 5 (4)

1 个答案:

答案 0 :(得分:2)

所以我多玩了一些,最后让它起作用。问题是我不断地在错误的地方绘制电影,因为它们需要在绘图部分的向量内,并且当显示某个符号时我需要一个if语句来调用它们。代码如下:

/*
    TUIO processing demo - part of the reacTIVision project
    http://reactivision.sourceforge.net/

    Copyright (c) 2005-2009 Martin Kaltenbrunner <mkalten@iua.upf.edu>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

// we need to import the TUIO library
// and declare a TuioProcessing client variable
import TUIO.*;
import java.util.*;
import processing.video.*;
TuioProcessing tuioClient;

// these are some helper variables which are used
// to create scalable graphical feedback
float cursor_size = 15;
float object_size = 0;
float table_size = 760;
float scale_factor = 1;
PFont font;
PImage img;
Movie theMov; 
Movie theMov2;
PImage bg;



void setup()
{
  //size(screen.width,screen.height);
  size(1280,720);
  noStroke();
  fill(0);
  //bg = loadImage("bg.png");
  theMov = new Movie(this, "isobar.mov");

  loop();
  frameRate(30);
  //noLoop();

  font = createFont("Arial", 18);
  scale_factor = height/table_size;

  // we create an instance of the TuioProcessing client
  // since we add "this" class as an argument the TuioProcessing class expects
  // an implementation of the TUIO callback methods (see below)
  tuioClient  = new TuioProcessing(this);
}

// within the draw method we retrieve a Vector (List) of TuioObject and TuioCursor (polling)
// from the TuioProcessing client and then loop over both lists to draw the graphical feedback.
void draw()
{

  //background(bg);
  textFont(font,18*scale_factor);
  float obj_size = object_size*scale_factor; 



  Vector tuioObjectList = tuioClient.getTuioObjects();
  for (int i=0;i<tuioObjectList.size();i++) {
     TuioObject tobj = (TuioObject)tuioObjectList.elementAt(i);
     pushMatrix();
     //translate(tobj.getScreenX(width),tobj.getScreenY(height));
     rotate(tobj.getAngle());
     rect(-obj_size/2,-obj_size/2,obj_size,obj_size);
     popMatrix();

     if (tobj.getSymbolID()==0){
     image(theMov, 0, 0);
     }

    if (tobj.getSymbolID()==5){
     image(theMov2, 0, 0);
     }

     //fill(255);
     //text(""+tobj.getSymbolID(), tobj.getScreenX(width), tobj.getScreenY(height));
   }

}


// these callback methods are called whenever a TUIO event occurs
// called when an object is added to the scene
void addTuioObject(TuioObject tobj) {
  println("add object "+tobj.getSymbolID()+" ("+tobj.getSessionID()+") "+tobj.getX()+" "+tobj.getY()+" "+tobj.getAngle());


      if (tobj.getSymbolID() == 0){
        theMov.play();
      }

      if (tobj.getSymbolID() == 5){
        theMov2.play();
      }

     if (tobj.getSymbolID()==1){
     text(""+tobj.getSymbolID(), tobj.getScreenX(width), tobj.getScreenY(height));
     fill(255);
     translate(tobj.getScreenX(width),tobj.getScreenY(height));
     }

}

// called when an object is removed from the scene
void removeTuioObject(TuioObject tobj) {
  println("remove object "+tobj.getSymbolID()+" ("+tobj.getSessionID()+")");

    if ( tobj.getSymbolID() == 0) {
      theMov.stop();
    }    

        if ( tobj.getSymbolID() == 5) {
      theMov2.stop();
    }

}

// called when an object is moved
void updateTuioObject (TuioObject tobj) {
  println("update object "+tobj.getSymbolID()+" ("+tobj.getSessionID()+") "+tobj.getX()+" "+tobj.getY()+" "+tobj.getAngle()
          +" "+tobj.getMotionSpeed()+" "+tobj.getRotationSpeed()+" "+tobj.getMotionAccel()+" "+tobj.getRotationAccel());
}

// called after each message bundle
// representing the end of an image frame
void refresh(TuioTime bundleTime) { 
  redraw();
}

void movieEvent(Movie m) { 
  m.read(); 
}