Skip to content

Commit bfe5fae

Browse files
committed
adaptive y_scale
1 parent 35fc80e commit bfe5fae

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

tongseng.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ static std::string host("localhost");
4343
static int port = 3333;
4444
static int protocol = TUIO_UDP;
4545
static int dev_id = 0;
46+
static float y_scale;
4647

4748
// Sensitivity
4849
#define MIN_DISTANCE 0.00001f
@@ -156,6 +157,11 @@ typedef void (*MTPathCallbackFunction)(MTDeviceRef device, long pathID, long sta
156157
// Process incoming events
157158
static void callback(MTDeviceRef device, MTTouch touches[], size_t numTouches, double timestamp, size_t frame) {
158159

160+
161+
/*int width,height;
162+
MTDeviceGetSensorSurfaceDimensions(device, &width, &height);
163+
std::cout << width << " " << height << std::endl;*/
164+
159165
if (!running || !sampling_interval_passed()) {
160166
return;
161167
}
@@ -170,8 +176,9 @@ static void callback(MTDeviceRef device, MTTouch touches[], size_t numTouches, d
170176
MTTouch *f = &touches[i];
171177
int id = f->pathIndex;
172178

179+
if (f->normalizedVector.position.y>y_scale) y_scale = f->normalizedVector.position.y;
173180
float x = f->normalizedVector.position.x;
174-
float y = 1.0f - f->normalizedVector.position.y/1.15f; // reverse y axis, work around scaling
181+
float y = 1.0f - f->normalizedVector.position.y/y_scale; // reverse y axis, work around scaling
175182

176183
if (x<0) x=0; else if (x>1) x=1;
177184
if (y<0) y=0; else if (y>1) y=1;
@@ -251,6 +258,8 @@ static void mt_start()
251258
dev = (MTDeviceRef)CFArrayGetValueAtIndex(devList, dev_id);
252259
MTRegisterContactFrameCallback(dev, callback);
253260
MTDeviceStart(dev, 0);
261+
262+
y_scale = 1;
254263
}
255264

256265
// Stop handling multitouch events

0 commit comments

Comments
 (0)