Tuio代码中的图像光标

时间:2014-06-02 09:48:31

标签: processing

我正在制作一个外部图像光标,以便在我的涂鸦墙上跟踪tuio中的基准代码。由于我需要在void draw()中不经常运行背景,因此图像光标会在舞台周围留下图像的轨迹。任何人都知道我怎么能阻止它这样做而不在void draw()中放置背景?

这是我的代码;

  // background(255);
  textFont(font, 18*scale_factor);
  float obj_size = object_size*scale_factor; 
  float cur_size = cursor_size*scale_factor; 

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


if (mp == true)

    {
      if (tobj.getSymbolID()==66) {
        fill(#FF00FF);
        noStroke();
        tint(255,127);
        ellipse(tobj.getScreenX(width), tobj.getScreenY(height), 50, 50);
        fill(#FF00FF);
        text(""+tobj.getSymbolID(), tobj.getScreenX(width), tobj.getScreenY(height));


 }

      if (tobj.getSymbolID()==23) {
        fill(#0000FF);
        noStroke();
        tint(255,127);
        ellipse(tobj.getScreenX(width), tobj.getScreenY(height), 50, 50);
        fill(#0000FF);
        text(""+tobj.getSymbolID(), tobj.getScreenX(width), tobj.getScreenY(height));
      }

      if (tobj.getSymbolID()==22) {
        fill(#00FF00);
        noStroke();
        tint(255,127);
        ellipse(tobj.getScreenX(width), tobj.getScreenY(height), 50, 50);
        fill(#00FF00);
        text(""+tobj.getSymbolID(), tobj.getScreenX(width), tobj.getScreenY(height));
      }
    }
  }




  Vector tuioCursorList = tuioClient.getTuioCursors();
  for (int i=0;i<tuioCursorList.size();i++) {
    TuioCursor tcur = (TuioCursor)tuioCursorList.elementAt(i);
    Vector pointList = tcur.getPath();

    if (pointList.size()>0) {
      stroke(0, 0, 255);
      TuioPoint start_point = (TuioPoint)pointList.firstElement();
      ;
      for (int j=0;j<pointList.size();j++) {
        TuioPoint end_point = (TuioPoint)pointList.elementAt(j);
        line(start_point.getScreenX(width), start_point.getScreenY(height), end_point.getScreenX(width), end_point.getScreenY(height));
        start_point = end_point;
      }

      stroke(192, 192, 192);
      fill(192, 192, 192);
      ellipse( tcur.getScreenX(width), tcur.getScreenY(height), cur_size, cur_size);
      fill(0);
      text(""+ tcur.getCursorID(), tcur.getScreenX(width)-5, tcur.getScreenY(height)+5);
    }
  }
  }




void mousePressed () {
  bDrawFullSize = true;

  mp = true;

player.play();

 if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h) {
    button = !button;
  }  
}

/*if(mousePressed) {
  if(mouseX>x && mouseX <x+w && mouseY>y && mouseY <y+h){
  image(stencil1,200,100,FULL_SIZE, FULL_SIZE);
  }
  else
  { 

    if(mouseX>x && mouseX <x+w && mouseY>y && mouseY <y+h){
      image(stencil2,200,100,FULL_SIZE, FULL_SIZE);
    }
  }
  }
}*/


void mouseReleased() {
  mp = false;

  player.close();

   //since close closes the file, we need to load the sound effect again.
  player = minim.loadFile("spray_close.wav");

}

void mouseDragged() {
  drag = true;
}

// 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());
}

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

// 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 when a cursor is added to the scene
void addTuioCursor(TuioCursor tcur) {
  println("add cursor "+tcur.getCursorID()+" ("+tcur.getSessionID()+ ") " +tcur.getX()+" "+tcur.getY());
}

// called when a cursor is moved
void updateTuioCursor (TuioCursor tcur) {
  println("update cursor "+tcur.getCursorID()+" ("+tcur.getSessionID()+ ") " +tcur.getX()+" "+tcur.getY()
    +" "+tcur.getMotionSpeed()+" "+tcur.getMotionAccel());
}

// called when a cursor is removed from the scene
void removeTuioCursor(TuioCursor tcur) {
  println("remove cursor "+tcur.getCursorID()+" ("+tcur.getSessionID()+")");
}

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

void keyPressed() {
  endRecord();
  background(bg1);
  bDrawFullSize = false;

  button = false;

}

1 个答案:

答案 0 :(得分:1)

也许使用图层,在不同的图层中绘制光标和/或其他内容。根据需要删除一个图层而不是其他图层,在绘图中显示所有图层。这通常使用PGraphics对象完成。搜索处理+图层以查看样本。在这里和/或processing forum 像这样的东西:

编辑:实际上我认为这样做的方法是将所有非刷新绘制移动到PGraphics并使用background()进行刷新绘制,在那里可以绘制清爽的东西没有踪迹。我更改了代码以反映这一点。

 PGraphics l1;


void setup() {
  size(200, 200);
  l1 = createGraphics(200, 200, JAVA2D);
  background(255);
  noStroke();
}

void draw() {
  background(255);

  l1.beginDraw();
  l1.fill(255, 0, 255);
  l1.noStroke();
  if (frameCount%100 == 0) {
    l1.rect(random(width), random(height), 20, 20);
  }
  l1.endDraw();

  image(l1, 0, 0);
  fill(230);
  ellipse(mouseX, mouseY, 30, 30);
}