用tuio处理

时间:2012-12-16 10:51:57

标签: image-processing processing

嗨,我是处理新手,我正试图弄清楚如何使用标记而不是鼠标使球体从左向右移动。你能帮我吗?我可以使用标记拍摄,但我不能通过拍摄移动球体

import TUIO.*;
TuioProcessing tuioClient;
HashMap symbols=new HashMap();

PFont fontA;
int sphereDiameter = 50;
boolean shoot = false;

 float obj_size = 60;


 int randx()
 {
return int(random(600));
 }

 int[] sphereXCoords = { randx(), randx(), randx(), randx(), randx() };
 int[] sphereYCoords = { 0, 0, 0, 0, 0 };

 void setup()
{
size(1000,700);

tuioClient  = new TuioProcessing(this);
}

void draw()
{ 
Vector<TuioObject> tuioObjectList =tuioClient.getTuioObjects();
 Collections.sort(tuioObjectList, comp);

  for (TuioObject tobj:tuioObjectList) {
  fill(50, 50, 100);

  int id = tobj.getSymbolID();
  int x = tobj.getScreenX(width);
  int y = tobj.getScreenY(height);
  rect(x, y, obj_size, obj_size);

  String txt="?";
  if (symbols.containsKey(id)) {// if it's one in symbols, then look it up
  txt = (String)symbols.get(id);
  } 
  fill(255);
  text(txt, x, y);
  }   

 int[] sphereXCoords = { randx(), randx(), randx(), randx(), randx() };
      fill(100, 0, 0);
      // draw the answer box
    //  ellipse(answerX, answerY, obj_size, obj_size);
      fill(255);
      // write the answer text
    // text(""+answer, answerX, answerY);



  background(1);
  fill(color(255,255,0));
  stroke(color(0,255,0));
  triangle(mouseX-8, 580, mouseX+8, 580, mouseX, 565);
  fill(color(255,0,0));
  stroke(color(255,0,0));

if(shoot==true)
{
  sphereKiller( mouseX);
  shoot = false;
  }

  sphereDropper();
  //gameEnder();  
 }

   Comparator<TuioObject> comp = new Comparator<TuioObject>() {
   // Comparator object to compare two TuioObjects on the basis of their x position
 // Returns -1 if o1 left of o2; 0 if they have same x pos; 1 if o1 right of o2
 public int compare(TuioObject o1, TuioObject o2) {
  if (o1.getX()<o2.getX()) { 
    return -1;
    }  
  else if (o1.getX()>o2.getX()) { 
  return 1;
  }  
    else { 
  return 0;
  }
  }
  };

    void mousePressed()
   {
  shoot = true;
  }




  void sphereDropper()
  {  
  stroke(255);
  fill(255);

   for (int i=0; i<5; i++)
  {
  ellipse(sphereXCoords[i], sphereYCoords[i]++,
          sphereDiameter, sphereDiameter);

   }
  }

  void sphereKiller(int shotX)
  {
   boolean hit = false;
   for (int i = 0; i < 5; i++)
    {
     if((shotX >= (sphereXCoords[i]-sphereDiameter/2)) && 
        (shotX <= (sphereXCoords[i]+sphereDiameter/2)))
     {
      hit = true;
    line(mouseX, 565, mouseX, sphereYCoords[i]);
    ellipse(sphereXCoords[i], sphereYCoords[i],
            sphereDiameter+25, sphereDiameter+25);
    sphereXCoords[i] = randx();
    sphereYCoords[i] = 0;
  }    
  }

  if(hit == false)
  {
    line(mouseX, 565, mouseX, 0);
   }  

   }

     /* void gameEnder()
  {
   for (int i=0; i< 5; i++)
    {
    if(sphereYCoords[i]==600)
  {
    fill(color(255,0,0));
    noLoop();
    }
   }
     }*/

  void addTuioObject(TuioObject tobj) {


    }

 // called when an object is removed from the scene
     void removeTuioObject(TuioObject tobj) {
     }

/    / called when an object is moved
    void updateTuioObject (TuioObject tobj) {

  if(tobj.getSymbolID() == 32)
   {
    shoot = true;
   }
   }

   // called when a cursor is added to the scene
   void addTuioCursor(TuioCursor tcur) {
   }

  // called when a cursor is moved
  void updateTuioCursor (TuioCursor tcur) {


   }

   // called when a cursor is removed from the scene
  void removeTuioCursor(TuioCursor tcur) {
   }

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

  //redraw();
   }

1 个答案:

答案 0 :(得分:0)

“射击”是什么意思?

所以你有tuioClient并在setup()中初始化它。这很好,因为只要你的草图收到TUIO消息,就会触发回调方法(addTuioObject,removeTuioObject,updateTuioObject,addTuioCursor,updateTuioCursor,removeTuioCursor,refresh)。

请记住,TUIO基于通过UDP传输的OSC。这意味着跟踪器(reactivision&amp; co)必须发送到草图正在监听的IP和端口。如果两者都在同一台机器上,请使用127.0.0.1和端口3333(默认)。 看看这些例子。您将在处理“IDE”中找到它们点击: “文件 - &gt;示例” 并导航到 “贡献的图书馆 - &gt; TUIO”