vialab / SMT

Simple Multi-Touch (SMT) Toolkit
http://vialab.science.uoit.ca/smt
GNU General Public License v3.0
43 stars 18 forks source link

define own touch event listener handlers such as touch pressed, touch released, touch dragged #228

Closed ashleyjamesbrown closed 6 years ago

ashleyjamesbrown commented 6 years ago

There wasn't anything in the tutorials or examples and a look through of the javadoc hinted but didn't give me the confidence I needed to implement.

Looking to basically write own functions to replace single touch such as mousePressed, mouseDragged, mosueReleased but for multi touch.

Touch pressed is easy to tap into with a loop through SMT.getTouches() but can you advise of equivalent other methods and how to implement.

I'm adding behaviours on touch and want to remove when touch is released but cant seem to reference.

mshancock commented 6 years ago

You can override touchUp, touchMove, and touchDown separately, if you like. An example that overrides touchUp is here: http://vialab.science.uoit.ca/smt/examples/Basic/TouchUp.php

ashleyjamesbrown commented 6 years ago

Ok so you have to use zones then is that right ?

I was trying

public void touchDown() {
  println("touch detected");
}

public void touchMoved() { 
}

public void touchUp() { 
}

which does work but then i need to grab the cursor.id ... which I can do inside a loop of course

public void touchMoved() { 
 for ( vialab.SMT.Touch touch : SMT.getTouches ()) {
    println("moving touch of "+touch.cursorID);
  }
}

however the following of course gives me no data... thats what was confusing me.

public void touchUp() {
  for ( vialab.SMT.Touch touch : SMT.getTouches ()) {
    println("touch "+touch.cursorID +" has been removed");
  }
}

Is there no possible parameters to add to these functions to form an event listener or callback? Or do I have to use a custom zone to fill the entire screen and use it that way ?

mshancock commented 6 years ago

You should be able to add a Zone and a Touch parameter to these functions, like in the example above (if it's inside a Zone rather than in the PApplet, then just the Touch parameter, I think).

ashleyjamesbrown commented 6 years ago

Using a single custom zone for the entire screen with

void touchUpCustom(Zone z, Touch t) {
  println("removed - "+t.cursorID);
}

for example does exactly what I need. I can then iterate through my class and perform an ID match based on the cursorID.

My other issue is that for some reason when using a touchMoved to update an emitter and create particles from is that the entire screen / zone seems to translate including particles I have already emitted into the system.

Is there some sort of default on the zone that I need to override to stop rst()?

mshancock commented 6 years ago

It should only do rst() if you call the rst() method on the Zone. A lot of the examples have this happen, so if you're working from one of those, maybe you have that line somewhere in your code still?

If you can't find that, the method also takes booleans to indicate the r, s, and t, so you can always turn it off with:

zoneName.rst(false, false, false);
ashleyjamesbrown commented 6 years ago

Nope. I wrote code from scratch. However.

I put the following inside the drawCustom(Zone z)

z.rst(false, false, false);

And now it works.

Interested that without the line, drawing a customzone seems to put z.rst() as true even if you dont call it explicitly. Worth a look in the source.

Appreciate your help on this by the way.