title: Multitouch code for mac
body: <p>Hi I am unfamiliar with anything outside of Java and having some difficulties with the source code I've included. I think it is C++. I've since installed Xcode however it does not just plug and play. So is this actually C++? Is Xcode currently worth putting effort into? The end goal is to integrate into Touch Designer so is this even the right track?</p>
  
  <p>"#include &lt; math.h>"</p>
  
  <p>"#include &lt; unistd.h>"</p>
  
  <p>"#include &lt; CoreFoundation/CoreFoundation.h>"</p>
  
  <pre><code>typedef struct { float x,y; } mtPoint;
  typedef struct { mtPoint pos,vel; } mtReadout;
  
  typedef struct {
    int frame;
    double timestamp;
    int identifier, state, foo3, foo4;
    mtReadout normalized;
    float size;
    int zero1;
    float angle, majorAxis, minorAxis; // ellipsoid
    mtReadout mm;
    int zero2[2];
    float unk2;
  } Finger;
  
  typedef void *MTDeviceRef;
  typedef int (*MTContactCallbackFunction)(int,Finger*,int,double,int);
  
  MTDeviceRef MTDeviceCreateDefault();
  void MTRegisterContactFrameCallback(MTDeviceRef, MTContactCallbackFunction);
  void MTDeviceStart(MTDeviceRef, int); // thanks comex
  
  
  int callback(int device, Finger *data, int nFingers, double timestamp, int 
  frame) {
    for (int i=0; i&lt;nFingers; i++) {
      Finger *f = &amp;data[i];
      printf("Frame %7d: Angle %6.2f, ellipse %6.3f x%6.3f; "
             "position (%6.3f,%6.3f) vel (%6.3f,%6.3f) "
             "ID %d, state %d [%d %d?] size %6.3f, %6.3f?\n",
         f-&gt;frame,
         f-&gt;angle * 90 / atan2(1,0),
         f-&gt;majorAxis,
         f-&gt;minorAxis,
         f-&gt;normalized.pos.x,
         f-&gt;normalized.pos.y,
         f-&gt;normalized.vel.x,
         f-&gt;normalized.vel.y,
         f-&gt;identifier, f-&gt;state, f-&gt;foo3, f-&gt;foo4,
         f-&gt;size, f-&gt;unk2);
    }
    printf("\n");
    return 0;
  }
  
  int main() {
    MTDeviceRef dev = MTDeviceCreateDefault();
    MTRegisterContactFrameCallback(dev, callback);
    MTDeviceStart(dev, 0);
    printf("Ctrl-C to abort\n");
    sleep(-1);
    return 0;
  }
  run: test
      ./test
  test: test.m
      gcc -F/System/Library/PrivateFrameworks -framework MultitouchSupport $^ -o $@ -std=c99
  </code></pre>