Edit from my previous post (deleted) since I was wrong on the issue:
I use this code to display a grid (each box of the grid has an ID like A2,C8 etc) and to display the ID of each Box containing a fiducial marker (http://ift.tt/MyZNy5). I use the last if statement to verify if there is a fiducial marker or not in the box:
if( ( a>= x && a <= (x + videoScale)) && //check horizontal
(b >= y && b <= (y + videoScale))){
//coordinates are within a box, do something about it
System.out.println(coordinates[k][l]);
}
The console always displays "A0" when a fiducial is detected, even if it has never been placed in A0, or when it is moved elsewhere.
Here is the whole code:
import TUIO.*;
TuioProcessing tuioClient;
int cols = 15, rows = 15;
boolean[][] states = new boolean[cols][rows];
String[][] coordinates = new String[cols][rows];
int videoScale = 50;
// these are some helper variables which are used
// to create scalable graphical feedback
int x, y, i, j, k, l;
float cursor_size = 15;
float object_size = 60;
float table_size = 760;
float scale_factor = 1;
PFont font;
boolean verbose = false; // print console debug messages
boolean callback = true; // updates only after callbacks
void setup(){
size(500,500);
noCursor();
noStroke();
fill(0);
// periodic updates
if (!callback) {
frameRate(60); //<>//
loop();
} else noLoop(); // or callback updates
font = createFont("Arial", 18);
scale_factor = height/table_size;
// finally 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 in this class (see below)
tuioClient = new TuioProcessing(this);
}
void draw(){
// Begin loop for columns
for ( k = 0; k < cols; k++) {
// Begin loop for rows
for ( l = 0; l < rows; l++) {
// Scaling up to draw a rectangle at (x,y)
int x = k*videoScale;
int y = l*videoScale;
fill(255);
stroke(0);
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
coordinates[i][j] = String.valueOf((char)(i+65)) + String.valueOf(j).toUpperCase();
}
}
rect(x,y,videoScale,videoScale);
textFont(font,18*scale_factor);
float obj_size = object_size*scale_factor;
float cur_size = cursor_size*scale_factor;
ArrayList<TuioObject> tuioObjectList = tuioClient.getTuioObjectList();
for (int i=0;i<tuioObjectList.size();i++) {
TuioObject tobj= tuioObjectList.get(i);
stroke(0);
fill(0,0,0);
pushMatrix();
translate(tobj.getScreenX(width),tobj.getScreenY(height));
rotate(tobj.getAngle());
rect(-20,-20,20,obj_size);
popMatrix();
fill(255);
text(""+tobj.getSymbolID(), tobj.getScreenX(width), tobj.getScreenY(height));
System.out.println(tobj.getSymbolID ()+ " " + tobj.getX());
float a = tobj.getX ();
float b = tobj.getY ();
System.out.println(a + " " + b);
if( ( a>= x && a <= x + videoScale) && //check horizontal
(b >= y && b <= y + videoScale)){
//coordinates are within a box, do something about it
System.out.println(coordinates[k][l]);
}
}
}
rect(x,y,videoScale,videoScale);
}
}
// --------------------------------------------------------------
// called at the end of each TUIO frame
void refresh(TuioTime frameTime) {
if (verbose) println("frame #"+frameTime.getFrameID()+" ("+frameTime.getTotalMilliseconds()+")");
if (callback) redraw();
}
Does my statement seem wrong ?
Thanks for your help and for taking the time to read
Aucun commentaire:
Enregistrer un commentaire