ofxMSAInteractiveObject and ofxTuio

Hi all,
i’m working on a fiducial and multitouch app using reactivision and was hoping to use ofxMSAInteractiveObject for the finger functionality.

At present I have hacked ofxMSAInteractiveObject to add the ofxTuio events. basically any fiducial or finger ends up acting as the mouse cursor.

  
void ofxMSAInteractiveObject::tuioMoved(int x, int y, long id) {  
	mouseDragged(x,y,0);  
}  
void ofxMSAInteractiveObject::tuioDown(int x, int y, long id){  
	mousePressed(x,y,0);  
}  
void ofxMSAInteractiveObject::tuioUp(int x, int y, long id){  
	mouseReleased(x,y,0);  
}  

This works for my purposes now but is clearly not the best way to do this. eventually it would be great to extend ofxMSAInteractiveObject so that it supports multiple cursors/fingers and add methods for two-finger scale and rotation.

Just thought I’d try my luck and see if anyone had already implemented anything similar.

cheers,
nay.

Hi nay, a multitouch ofxMSAInteractiveObject is indeed a good idea. I’m guessing your hacked ofxMSAInteractiveObject will work pretty well, but you will run into problems if you have 2 fingers on the same object and lift one. You will receive the onRelease() as expected, but if you then check isMouseDown() it will return false even though you have another finger on it. I’m sure though with minimal changes it could be adapted possibly by changing the state variables into vectors of state variables or something?

offtopic:

didn’t the whole event handling thing change for OF 0.6? If yes, where can I grab 0.6 because I would like to update it’s events and some other things pretty soon.

Thx

yea its changed quite a a bit, but its even cooler now, you can register any method for any event, its pretty much like AS3 now, ofAddListener(ofEvents.mousePressed, this, MyClass::mousePressHandler);

it’s on the SVN btw

okay thanks. I think I will wait till a finaliized version is online though before I start overworking my addons. Could you mabe post the link to the SVN?

Hey moka i’ve adapted ofxTuio to work with the new event system, also now the events receive the updated object or cursor so every posible information is there, not only up /down / moved…

http://65.111.166.199/openframeworks/tuioExample.zip

okay kool! Does your update work with the newest OFXOSC?

edit:

could you upload it somewhere else? the link does not really seem to work, thank you!

http://arturocastro.net/files/tuioExample.zip

i think i’ve tested only with ofxOsc 002 only, not with 003, but shouldn’t be much more different.

Ah that loooks really sweet.- The event systems seems to be so much easier now! Thanks

thanks for the heads up memo. sorry for the late reply but think i accidentally un-subscribed to notifications from this thread.

should be able to spend some time on this later this week, will hopefully post back soon. will also grab 006 from github and try the new ofxTuio (thanks arturo and moka)

memo, are you planning to update your interactive object class to work with 006 anytime soon? wondering if i should use 006 for this project as it’s the first time i’m dealing with any event handling.

off topic but when is 006 set to be released anyway?

best,
nay.

Hi Nay, yea I uploaded v2.0 about a week ago, that works with OF 006 (and the current version in SVN).

http://addons.openframeworks.cc/project-…-nteractive

thanks memo

as a first step i have started writing a simple class to check for mouse events in relation to a vector location of my buttons. I have done this to simplify things as my buttons are drawn after translation and rotation (now i’m just checking the distance of the cursor from the vector location of my buttons to test over states). I have tried to base the event handling code as closely to the new ofxMSAInteractiveObject as possible and it compiles fine but receives no mouse events.

Any idea what I’m doing wrong? code below:

  
  
#ifndef _BUTTON_VEC  
#define _BUTTON_VEC  
  
#include "ofMain.h"  
#define OF_ADDON_USING_OFXVECTORMATH  
#include "ofAddons.h"  
  
class buttonVec {  
public:  
	  
	int x_off, y_off, x, y;  
	float angle;  
	ofxVec2f loc;  
	int thresh;  
	  
	//vars same as ofxMSAInteractiveObject:  
	int _mouseX, _mouseY, _mouseButton;  
	bool _mouseOver, _mouseDown;  
	  
	buttonVec(){  
		thresh = 10;  
		_mouseOver	= false;  
		_mouseDown	= false;  
		  
		enableMouseEvents();  
	}  
	  
	~buttonVec() {  
		disableMouseEvents();  
	}  
	  
	void set(int x_off, int y_off, int x, int y, float angle) {  
		loc.set(x, y); //button pos inside rotated section  
		loc.rotate(angle); //rotation of section  
		loc.set(x+x_off,y+y_off); //add position of rotated section as offset   
	}  
	  
	bool hitTest(int tx, int ty) {  
		int dist = distance(tx,loc.x,ty,loc.y);  
		if (dist < thresh) {  
			_mouseOver = true;  
			cout<<"over"<<endl;  
		} else {  
			_mouseOver = false;  
		}  
	}  
	  
	int distance(int x1, int x2, int y1, int y2){  
		return sqrt(pow(x2-x1,2) + pow(y2-y1,2));  
	}  
  
	//events from ofxMSAInteractiveObject:  
	  
	void _mouseMoved(ofMouseEventArgs &e) {  
		int x = e.x;  
		int y = e.y;  
		int button = e.button;  
		  
		_mouseX = x;  
		_mouseY = y;  
		  
		if(hitTest(x, y)) {						// if mouse is over the object  
			if(!_mouseOver) {						// if wasn't over previous frame  
				_mouseOver = true;						// update flag  
			}  
		} else if(_mouseOver) {					// if mouse is not over the object, but the flag is true (From previous frame)  
			_mouseOver = false;						// update flag  
		}  
	}  
	  
	  
	void _mousePressed(ofMouseEventArgs &e) {  
		  
		cout<<"I hear mice!"<<endl;  
		  
		int x = e.x;  
		int y = e.y;  
		int button = e.button;  
		  
		_mouseX = x;  
		_mouseY = y;  
		_mouseButton = button;  
		  
		if(hitTest(x, y)) {						// if mouse is over  
			if(!_mouseDown) {						 // if wasn't down previous frame  
				_mouseDown = true;						// update flag  
			}  
		} else {								// if mouse is not over  
		}  
	}  
	  
	void _mouseDragged(ofMouseEventArgs &e) {  
		int x = e.x;  
		int y = e.y;  
		int button = e.button;  
		  
		_mouseX = x;  
		_mouseY = y;  
		_mouseButton = button;  
		  
		if(hitTest(x, y)) {						// if mouse is over the object  
			if(!_mouseOver) {						// if wasn't over previous frame  
				_mouseOver = true;						// update flag  
			}  
		} else {  
			if(_mouseOver) {					// if mouse is not over the object, but the flag is true (From previous frame)  
				_mouseOver = false;						// update flag  
			}  
			if(_mouseDown) {  
			}  
		}  
	}  
	  
	void _mouseReleased(ofMouseEventArgs &e) {  
		int x = e.x;  
		int y = e.y;  
		int button = e.button;  
		  
		_mouseX = x;  
		_mouseY = y;  
		_mouseButton = button;  
		  
		if(hitTest(x, y)) {  
		} else {  
			if(_mouseDown) ;  
		}  
		_mouseDown = false;  
	}  
	  
	void enableMouseEvents() {  
		ofAddListener(ofEvents.mousePressed, this, &buttonVec::_mousePressed);  
		ofAddListener(ofEvents.mouseMoved, this, &buttonVec::_mouseMoved);  
		ofAddListener(ofEvents.mouseDragged, this, &buttonVec::_mouseDragged);  
		ofAddListener(ofEvents.mouseReleased, this, &buttonVec::_mouseReleased);  
	}  
  
	void disableMouseEvents() {  
		ofRemoveListener(ofEvents.mousePressed, this, &buttonVec::_mousePressed);  
		ofRemoveListener(ofEvents.mouseMoved, this, &buttonVec::_mouseMoved);  
		ofRemoveListener(ofEvents.mouseDragged, this, &buttonVec::_mouseDragged);  
		ofRemoveListener(ofEvents.mouseReleased, this, &buttonVec::_mouseReleased);  
	}  
  
  
	  
};  
#endif  
  

* EDIT * i dropped in a couple global variables to use for mouse states until i get this working but was getting erroneous data from the mouse event handling in my testApp instance with the latest from SVN. had to go back to 00573 to get that to work.

**EDIT ** no problems with event handling in the official 06 pre-release!

I’ve noticed MSAInteractiveObject being used on memo’s kinect 3d drawing, cant seem to get mines to work or understand how it works =(

Hi, are you having problems with the kinect drawing app? or ofxMSAInteractiveObject in general? You can see how to use MSAInteractiveObject here
https://github.com/memo/msalibs/tree/ma-…-ample/src/

The critical difference between an ofxMSAInteractiveObject and an object in Flash, is that the ofxMSAInteractiveObject doesn’t automatically know it’s position and size, it’s upto you to make sure x,y,width and height are updated.

Hi memo!

I got the interactive thing to work, where I can change the levels and stuff,
I just cannot get the kinect drawing to work. any Ideas? I just dont have the one for the one where it is actually drawing. The “kinect3ddraw” I got working but all I saw was how to change levels, no actually drawing can be done =(

I really am looking for that one demo that shows me how to achieve simple interaction with stuff that might be more interface based.

I noticed you have the msa interactive object in there and i see you also have a hit test, I was wondering if you had an example of this already it would be extremely helpful!

My project is basically a interactive learning experience about the solar system. Basic functions are the hand acting like a mouse, so hit areas are super critical for my project. The most interactive element is probably swiping your hand to spin the planet around.

Any help would be most appreciated. Thank you :slight_smile: