user3674001
user3674001

Reputation: 31

Image Cursor in Tuio Code

I'm looking to make an external image cursor to track the fiducial codes in tuio for my graffiti wall. Since I need background to not be run constantly in void draw(), the image cursor leaves a trail of the image around the stage. Anyone know how I can stop it from doing this without placing background in void draw()?

This is my code;

  // 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;

}

Upvotes: 0

Views: 306

Answers (1)

v.k.
v.k.

Reputation: 2854

Maybe using layers, draw your cursor and/or the other stuff in different layers. Erase one layer and not other as you need, display all them in draw. This is usually done with PGraphics objects. Search processing + layers to see samples. Here and/or in processing forum something like this:

EDIT: Actually I think that the way to do it is to move all non refreshing draw to a PGraphics and do refresh draw with background(), where you can draw refreshing stuff without a trail. I changed the code to reflect that.

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

Upvotes: 1

Related Questions