IPAD - > TUIO -> TOXI PHYSICS2D ConcurrentModificationException
in
Integration and Hardware
•
2 years ago
Hi list. I'm working with my ipad and processing. the basic idea is to connect several ipad via TUIO to a processing sketch.
I started with the particle example of toxi libs and I connecected the mouse position to TUIO variables. But sometimes I got this error " ConcurrentModificationException" that make me crazy.
In other words I'm trying in those firsts steps to merge the the particle example of toxi with the TUIO demo example.
On Ipad is running TUIOpad 1.0
I have this error with Ipad and TUIO simulator as well.
Help me please!!
here the code
I started with the particle example of toxi libs and I connecected the mouse position to TUIO variables. But sometimes I got this error " ConcurrentModificationException" that make me crazy.
In other words I'm trying in those firsts steps to merge the the particle example of toxi with the TUIO demo example.
On Ipad is running TUIOpad 1.0
I have this error with Ipad and TUIO simulator as well.
Help me please!!
here the code
/**
* <p>Usage: Click and drag mouse to attract particles</p>
*/
/*
* Copyright (c) 2010 Karsten Schmidt
*
*some modifications by pixelorchestra
*
*http://creativecommons.org/licenses/LGPL/2.1/
*
*/
import processing.opengl.*;
import toxi.geom.*;
import toxi.physics2d.*;
import toxi.physics2d.behaviors.*;
int NUM_PARTICLES = 500;
VerletPhysics2D physics;
AttractionBehavior mouseAttractor;
Vec2D mousePos;
void setup() {
size(680, 382, OPENGL);
// setup physics with 10% drag
physics = new VerletPhysics2D();
physics.setDrag(0.05f);
physics.setWorldBounds(new Rect(0, 0, width, height));
// the NEW way to add gravity to the simulation, using behaviors
// physics.addBehavior(new GravityBehavior(new Vec2D(0, 0)));
// init the TUIO protocol
setupTUIO();
}
void addParticle() {
VerletParticle2D p = new VerletParticle2D(Vec2D.randomVector().scale(5).addSelf(width / 2, height/2));
physics.addParticle(p);
// add a negative attraction force field around the new particle
physics.addBehavior(new AttractionBehavior(p, 20, -1.2f, 0.01f));
}
void draw() {
background(0, 0, 0);
noStroke();
fill(255);
if (physics.particles.size() < NUM_PARTICLES) {
addParticle();
}
physics.update(); // <----- HERE I GOT THE ERROR
stroke(255);
for (VerletParticle2D p : physics.particles) {
ellipse(p.x, p.y, 10, 10);
//point(p.x, p.y);
}
drawTUIO(); // call the TUIO function
}
// this is just to test with mouse
void mousePressed() {
initDrag(mouseX, mouseY);
}
void mouseDragged() {
dragging(mouseX, mouseY);
}
void mouseReleased() {
removeDrag();
}
void initDrag(int posX, int posY) {
mousePos = new Vec2D(posX, posY);
// create a new positive attraction force field around the mouse position (radius=250px)
mouseAttractor = new AttractionBehavior(mousePos, 250, 0.9f);
physics.addBehavior(mouseAttractor);
}
void dragging(int posX, int posY) {
// update mouse attraction focal point
mousePos.set(posX, posY);
}
void removeDrag() {
// remove the mouse attraction when button has been released
physics.removeBehavior(mouseAttractor);
}- // we need to import the TUIO library
// and declare a TuioProcessing client variable
import TUIO.*;
TuioProcessing tuioClient;
// these are some helper variables which are used
// to create scalable graphical feedback
float cursor_size = 15;
float object_size = 60;
float table_size = 760;
float scale_factor = 1;
PFont font;
void setupTUIO(){
hint(ENABLE_NATIVE_FONTS);
font = createFont("Arial", 18);
scale_factor = height/table_size;
// 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 (see below)
tuioClient = new TuioProcessing(this);
}
void drawTUIO()
{
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());
rect(-obj_size/2,-obj_size/2,obj_size,obj_size);
popMatrix();
fill(255);
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);
}
}
}
// 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) {
initDrag(tcur.getScreenX(width), tcur.getScreenY(height) ); // INIT DRAG
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());
dragging(tcur.getScreenX(width), tcur.getScreenY(height) );
}
// called when a cursor is removed from the scene
void removeTuioCursor(TuioCursor tcur) {
removeDrag();
println("remove cursor "+tcur.getCursorID()+" ("+tcur.getSessionID()+")");
}
// called after each message bundle
// representing the end of an image frame
void refresh(TuioTime bundleTime) {
redraw();
}
1