|
ofxMultitouch
Platform independent C++ API for dealing with multitouch devices and systems. iPhone implementation can be found in ofxiPhone.
Featured OverviewThe idea behind ofxMultitouch is to allow multitouch capable code independent of hardware and tracker implementations. This means that you can create a multitouch application which can run on iphone, and on a TUIO Client and on a custom tracker without any modifications. Also libraries developed for ofxMultitouch (e.g. a multitouch GUI) can be used on any such platform without any modifications. How it worksFirst your app should include ofxMultitouch.h: #include "ofxMultiTouch.h" Then create an object which will respond to multitouch events: (this could be your main app class - testApp, or any other object) class MyTouchListener : public ofxMultiTouchListener
{
public:
void touchDown(float x, float y, int touchId, ofxMultiTouchCustomData *data = NULL);
void touchMoved(float x, float y, int touchId, ofxMultiTouchCustomData *data = NULL);
void touchUp(float x, float y, int touchId, ofxMultiTouchCustomData *data = NULL);
void touchDoubleTap(float x, float y, int touchId, ofxMultiTouchCustomData *data = NULL);
};Then register an instance of this class as a listener (e.g. in testApp::setup() or anywhere else): MyTouchListener touchListener; ofxMultiTouch.addListener(touchListener); And thats it! Now in MyTouchListener you can override the touchDown, touchMoved, touchUp and touchDoubleTap methods and write the code you want. Bear in mind that there is no bounds checking, i.e. the methods will always get called regardless of whether the event happened inside or outside of the object, as the object has no concept of inside or outside. That kind of hittest checking and behaviour can be built into higher classes (classes extending ofxMultiTouchListener). Is that it?No. You may be wondering how on earth does ofxMultiTouch know when to call the events when there is no reference to blob tracking, tuio, iphone sdk or any other multitouch tracking code? It doesn't and ofxMultitouch does not contain any of that. You will also need an additional code to interface ofxMultitouch to your tracking code. I.e. platform dependent code that receives the events from the system, and sends them to ofxMultiTouch, which in turn sends them to all the registered listeners. On iPhone this is already implemented in ofxiPhone. If you look in EAGLView.mm and look at the UIView touch callbacks, this is exactly what is happening. The UIView receives the touch events from the iPhone SDK, and calls the relevant ofxMultiTouch.touchMoved, touchUp, touchDown etc. The same can be done with TUIO (in fact I probably will do soon). I.e. write a little TUIO client which simply call the relevant ofxMultiTouch.touchMoved, touchUp, touchDown etc. Using this system, multitouch applications and libraries can be developed to work on any multitouch platform. |