I just managed to show one piece of puzzle using Tuio library, but failed to display the other pieces of my puzzle. i need help to display other pieces of my puzzle.
Could you please be polite when you ask for help on a forum.
You could, for example, start by "Hello / Hi " and finish by a "thank you" , it's not so hard considering the fact you ask for someone you don't know to take from its own time just for you.
It could be usefull to show us what you tryed too, and why you think it doesn't work. - you know, thinking about others, doing your best to make the work easier for us, to be able to make it easy for you )
Hi everyone,
Thanks for your comments, I have managed to display the second piece of the puzzle and now I want to add other 18 pieces. I do need help with that. Thanks
import TUIO.*;
TuioProcessing tuioClient;
HashMap<Integer, TrackedObject> objs= new HashMap<Integer, TrackedObject>();
ArrayList targets=new ArrayList();
HashMap<Integer, PImage> images= new HashMap<Integer, PImage>();
void setup() {
size(900, 700);
tuioClient = new TuioProcessing(this);
images.put(0, loadImage("image0.png"));
int targetGap=20; // gap between adjacant targets
images.put(1, loadImage("image1.png"));
}
void draw() {
background(0);
// have all targets been hit?
boolean allHit=true;
// draw targets; check if hit.
for (Target t: targets) {
t.draw();
if (!t.hit) {
allHit=false;
}
}
// draw tracked objects
for (TrackedObject o:objs.values()) {
o.draw();
}
if (allHit) {
text("All Targets Hit", 20, 20);
}
}
// called when an object is added to the scene
void addTuioObject(TuioObject tobj) {
int id = tobj.getSymbolID();
TrackedObject o= new TrackedObject(tobj.getScreenX(width), tobj.getScreenY(height), 50, 50, id);
// use same image for all tracked objects:
//o.img = loadImage("image.jpg");
if (images.containsKey(id)){
o.img=images.get(id);
}
objs.put(new Integer(id), o);
}
// called when an object is removed from the scene
void removeTuioObject(TuioObject tobj) {
objs.remove(new Integer(tobj.getSymbolID()));
}
// called when an object is moved
void updateTuioObject (TuioObject tobj) {
TrackedObject o= objs.get(new Integer(tobj.getSymbolID()));
int oldX=o.x;
int oldY=o.y;
o.x=tobj.getScreenX(width);
o.y=tobj.getScreenY(height);
// check if o is in any of the targets; if so 'hit' the target
for (Target t: targets) {
boolean wasIn = t.contains(oldX, oldY);
boolean isIn = t.contains(o.x, o.y);
if (isIn) {
t.moved(o);
// has object o moved into the target?
if (!wasIn) {
t.entered(o);
}
}
// has object o moved out of the target?
if (wasIn && !isIn) {
t.left(o);
}
Hello Processing, I have no problem in putting images in their specific place. but I do not want the image to move even when I remove the fiducial symbol from the camera. I do need help with this and I think my problem lies with the if statement and I really need help and your help will be appreciated. My codes are as followed;
Hi, when I put my code it is nicely formatted, but when I send to you the format changes and it is annoying. I did follow your advice and selected the code and hit ctrl + k, but it still didn't work. Please help me anyway as this my my course work. Many thanks
Answers
Hello Roya !
Could you please be polite when you ask for help on a forum.
You could, for example, start by "Hello / Hi " and finish by a "thank you" , it's not so hard considering the fact you ask for someone you don't know to take from its own time just for you.
It could be usefull to show us what you tryed too, and why you think it doesn't work. - you know, thinking about others, doing your best to make the work easier for us, to be able to make it easy for you )
Chill, tlecoz.
You can display one piece! Great! How are you doing that? Post your code so we know!
What trouble are you having doing the same thing for other pieces?
Hi everyone, Thanks for your comments, I have managed to display the second piece of the puzzle and now I want to add other 18 pieces. I do need help with that. Thanks
import TUIO.*; TuioProcessing tuioClient;
HashMap<Integer, TrackedObject> objs= new HashMap<Integer, TrackedObject>(); ArrayList targets=new ArrayList();
HashMap<Integer, PImage> images= new HashMap<Integer, PImage>();
void setup() { size(900, 700); tuioClient = new TuioProcessing(this);
rectMode(CENTER); ellipseMode(CENTER); imageMode(CENTER);
// set up some targets
images.put(0, loadImage("image0.png")); int targetGap=20; // gap between adjacant targets images.put(1, loadImage("image1.png"));
}
void draw() { background(0);
// have all targets been hit? boolean allHit=true;
// draw targets; check if hit. for (Target t: targets) { t.draw(); if (!t.hit) { allHit=false; } }
// draw tracked objects for (TrackedObject o:objs.values()) { o.draw(); } if (allHit) { text("All Targets Hit", 20, 20); } }
// called when an object is added to the scene void addTuioObject(TuioObject tobj) {
int id = tobj.getSymbolID(); TrackedObject o= new TrackedObject(tobj.getScreenX(width), tobj.getScreenY(height), 50, 50, id); // use same image for all tracked objects: //o.img = loadImage("image.jpg");
if (images.containsKey(id)){ o.img=images.get(id); } objs.put(new Integer(id), o); }
// called when an object is removed from the scene void removeTuioObject(TuioObject tobj) { objs.remove(new Integer(tobj.getSymbolID())); }
// called when an object is moved void updateTuioObject (TuioObject tobj) { TrackedObject o= objs.get(new Integer(tobj.getSymbolID())); int oldX=o.x; int oldY=o.y; o.x=tobj.getScreenX(width); o.y=tobj.getScreenY(height);
// check if o is in any of the targets; if so 'hit' the target for (Target t: targets) { boolean wasIn = t.contains(oldX, oldY); boolean isIn = t.contains(o.x, o.y);
} }
Edit your post, select your code, and hit Ctrl+k to format it.
Hello Processing, I have no problem in putting images in their specific place. but I do not want the image to move even when I remove the fiducial symbol from the camera. I do need help with this and I think my problem lies with the if statement and I really need help and your help will be appreciated. My codes are as followed;
import TUIO.*; TuioProcessing tuioClient;
HashMap<Integer, TrackedObject> objs= new HashMap<Integer, TrackedObject>(); HashMap<Integer, String> correctloc=new HashMap<Integer, String>(); ArrayList targets=new ArrayList();
HashMap<Integer, PImage> images= new HashMap<Integer, PImage>();
void setup() { size(790, 840); tuioClient = new TuioProcessing(this);
rectMode(CENTER); ellipseMode(CENTER); imageMode(CENTER);
Target t1= new Target(150, 100, 150, 150, "1" ); targets.add(t1); Target t2 = new Target(310, 100, 150, 150, "2"); targets.add(t2); Target t3 = new Target(470, 100, 150, 150, "3"); targets.add(t3); Target t4 = new Target(630, 100, 150, 150, "4"); targets.add(t4); Target t5 = new Target(150, 260, 150, 150, "5"); targets.add(t5); Target t6 = new Target(310, 260, 150, 150, "6"); targets.add(t6); Target t7 = new Target(470, 260, 150, 150, "7"); targets.add(t7); Target t8 = new Target(630, 260, 150, 150, "8"); targets.add(t8); Target t9 = new Target(150, 420, 150, 150, "9"); targets.add(t9); Target t10 = new Target(310, 420, 150, 150, "10"); targets.add(t10); Target t11 = new Target(470, 420, 150, 150, "11"); targets.add(t11); Target t12 = new Target(630, 420, 150, 150, "12"); targets.add(t12); Target t13 = new Target(150, 580, 150, 150, "13"); targets.add(t13); Target t14 = new Target(310, 580, 150, 150, "14"); targets.add(t14); Target t15 = new Target(470, 580, 150, 150, "15"); targets.add(t15); Target t16 = new Target(630, 580, 150, 150, "16"); targets.add(t16); Target t17 = new Target(150, 740, 150, 150, "17"); targets.add(t17); Target t18 = new Target(310, 740, 150, 150, "18"); targets.add(t18); Target t19 = new Target(470, 740, 150, 150, "19"); targets.add(t19); Target t20 = new Target(630, 740, 150, 150, "20"); targets.add(t20); images.put(0, loadImage("image0.png")); images.put(1, loadImage("image1.png")); images.put(2, loadImage("image2.png")); images.put(3, loadImage("image3.png")); images.put(4, loadImage("image4.png")); images.put(5, loadImage("image5.png")); images.put(6, loadImage("image6.png")); images.put(7, loadImage("image7.png")); images.put(7, loadImage("image8.png")); images.put(7, loadImage("image9.png")); images.put(7, loadImage("image10.png")); images.put(7, loadImage("image11.png")); images.put(7, loadImage("image12.png")); images.put(7, loadImage("image13.png")); images.put(7, loadImage("image14.png")); images.put(7, loadImage("image15.png")); images.put(7, loadImage("image16.png")); images.put(7, loadImage("image17.png")); images.put(7, loadImage("image18.png")); images.put(7, loadImage("image19.png")); }
void draw() { background(0);
boolean allHit=true; for (Target t: targets) { t.draw(); if (!t.hit) { allHit=false; } }
for (TrackedObject o:objs.values()) { o.draw(); } if (allHit) { text("All Targets Hit", 20, 20); } }
void addTuioObject(TuioObject tobj) {
int id = tobj.getSymbolID(); TrackedObject o= new TrackedObject(tobj.getScreenX(width), tobj.getScreenY(height), 50, 50, id);
if (images.containsKey(id)){ o.img=images.get(id); } objs.put(new Integer(id), o); }
void removeTuioObject(TuioObject tobj) { objs.remove(new Integer(tobj.getSymbolID())); }
void updateTuioObject (TuioObject tobj) { TrackedObject o= objs.get(new Integer(tobj.getSymbolID())); int oldX=o.x; int oldY=o.y; o.x=tobj.getScreenX(width); o.y=tobj.getScreenY(height);
for (Target t: targets) { boolean wasIn = t.contains(oldX, oldY); boolean isIn = t.contains(o.x, o.y); if (isIn) { t.moved(o);
} }
class TrackedObject {
int x, y, xSize, ySize, fiducialID; color fillCol, strokeCol; PImage img;
TrackedObject(int xx, int yy, int sx, int sy, int id) { x=xx; y=yy; xSize=sx; ySize=sy; fillCol=color(100); strokeCol=color(200); fiducialID=id; }
void draw() {
} }
class Target {
int x, y, xSize, ySize, halfXSize, halfYSize;
color fillCol, hitFillCol, strokeCol; boolean hit=false;
String name="";
PImage img;
Target(int xx, int yy, int sx, int sy, String n) { x=xx; y=yy; xSize=sx; halfXSize=sx/2; ySize=sy; halfYSize=sy/2; fillCol=color(100, 150); hitFillCol=color(200, 0, 0, 150); strokeCol=color(200); name=n; }
void draw() { pushStyle(); if (hit) { fill(hitFillCol); } else { fill(fillCol); }
stroke(strokeCol); rect(x, y, xSize+5, ySize+5); if (img!=null){ image(img, x, y); } fill(255); text(name, x-xSize/2, y-ySize/2); popStyle(); }
boolean contains(int ox, int oy) {
}
void entered(TrackedObject o) { hit=true; } void left(TrackedObject o) { hit=false; } void moved(TrackedObject o) { } }
Hi, when I put my code it is nicely formatted, but when I send to you the format changes and it is annoying. I did follow your advice and selected the code and hit ctrl + k, but it still didn't work. Please help me anyway as this my my course work. Many thanks
empty lines before and after the code?
Hello processing, I do need help with the above code and your help will be appreciated. Many thanks.
Edit your post, select your code, and hit Ctrl+k to format it.
empty lines before and after
also post in the libraries section pls
If you don't follow the given advices, it will be hard to help you...
See also the sticky: Processing forum rules and advices