History

added easier support for calculating multitouch rotating behavior including deltaAngle, isRotating, rotating(direction) properties

ZappoMan committed 12 years ago

Commit dca0b051 parent 3bf8dd85 files · +160 −31Browse files

Showing the changes to libraries/script-engine/src/EventTypes.cpp (1 of 5 files). Show all

Unified · Split

libraries/script-engine/src/EventTypes.cpp+24−20
@@ -323,14 +323,16 @@ TouchEvent::TouchEvent() : · 322 unmodified lines
323323 isControl(false),
324324 isMeta(false),
325325 isAlt(false),
326+ touchPoints(0),
326327 points(),
327328 radius(0.0f),
328329 isPinching(false),
329330 isPinchOpening(false),
330331 angles(),
331332 angle(0.0f),
332− rotatingClockwise(false),
333− rotatingCounterClockwise(false)
333+ deltaAngle(0.0f),
334+ isRotating(false),
335+ rotating("none")
334336 {
335337 };
336338
@@ -359,9 +361,9 @@ void TouchEvent::initWithQTouchEvent(const QTouchEvent& event) { · 22 unmodified lines
359361 const QList<QTouchEvent::TouchPoint>& tPoints = event.touchPoints();
360362 float touchAvgX = 0.0f;
361363 float touchAvgY = 0.0f;
362− int numTouches = tPoints.count();
363− if (numTouches > 1) {
364− for (int i = 0; i < numTouches; ++i) {
364+ touchPoints = tPoints.count();
365+ if (touchPoints > 1) {
366+ for (int i = 0; i < touchPoints; ++i) {
365367 touchAvgX += tPoints[i].pos().x();
366368 touchAvgY += tPoints[i].pos().y();
367369
@@ -369,8 +371,8 @@ void TouchEvent::initWithQTouchEvent(const QTouchEvent& event) { · 1 unmodified line
369371 glm::vec2 thisPoint(tPoints[i].pos().x(), tPoints[i].pos().y());
370372 points << thisPoint;
371373 }
372− touchAvgX /= (float)(numTouches);
373− touchAvgY /= (float)(numTouches);
374+ touchAvgX /= (float)(touchPoints);
375+ touchAvgY /= (float)(touchPoints);
374376 } else {
375377 // I'm not sure this should ever happen, why would Qt send us a touch event for only one point?
376378 // maybe this happens in the case of a multi-touch where all but the last finger is released?
@@ -384,7 +386,7 @@ void TouchEvent::initWithQTouchEvent(const QTouchEvent& event) { · 7 unmodified lines
384386 // also calculate the rotation angle for each point
385387 float maxRadius = 0.0f;
386388 glm::vec2 center(x,y);
387− for (int i = 0; i < numTouches; ++i) {
389+ for (int i = 0; i < touchPoints; ++i) {
388390 glm::vec2 touchPoint(tPoints[i].pos().x(), tPoints[i].pos().y());
389391 float thisRadius = glm::distance(center,touchPoint);
390392 if (thisRadius > maxRadius) {
@@ -397,13 +399,12 @@ void TouchEvent::initWithQTouchEvent(const QTouchEvent& event) { · 6 unmodified lines
397399 }
398400 radius = maxRadius;
399401
400− // after calculating the center point (average touch point), determine the maximum radius
402+ // after calculating the angles for each touch point, determine the average angle
401403 float totalAngle = 0.0f;
402− for (int i = 0; i < numTouches; ++i) {
404+ for (int i = 0; i < touchPoints; ++i) {
403405 totalAngle += angles[i];
404406 }
405− angle = totalAngle/numTouches;
406−
407+ angle = totalAngle/(float)touchPoints;
407408
408409 isPressed = event.touchPointStates().testFlag(Qt::TouchPointPressed);
409410 isMoved = event.touchPointStates().testFlag(Qt::TouchPointMoved);
@@ -431,15 +432,16 @@ void TouchEvent::calculateMetaAttributes(const TouchEvent& other) { · 21 unmodified lines
431432 }
432433
433434 // determine if the points are rotating...
435+ deltaAngle = angle - other.angle;
434436 if (other.angle < angle) {
435− rotatingClockwise = true;
436− rotatingCounterClockwise = false;
437+ isRotating = true;
438+ rotating = "clockwise";
437439 } else if (other.angle > angle) {
438− rotatingClockwise = false;
439− rotatingCounterClockwise = true;
440+ isRotating = true;
441+ rotating = "counterClockwise";
440442 } else {
441− rotatingClockwise = false;
442− rotatingCounterClockwise = false;
443+ isRotating = false;
444+ rotating = "none";
443445 }
444446 }
445447
@@ -456,6 +458,7 @@ QScriptValue touchEventToScriptValue(QScriptEngine* engine, const TouchEvent& ev · 10 unmodified lines
456458 obj.setProperty("isMeta", event.isMeta);
457459 obj.setProperty("isControl", event.isControl);
458460 obj.setProperty("isAlt", event.isAlt);
461+ obj.setProperty("touchPoints", event.touchPoints);
459462
460463 QScriptValue pointsObj = engine->newArray();
461464 int index = 0;
@@ -470,6 +473,7 @@ QScriptValue touchEventToScriptValue(QScriptEngine* engine, const TouchEvent& ev · 8 unmodified lines
470473 obj.setProperty("isPinchOpening", event.isPinchOpening);
471474
472475 obj.setProperty("angle", event.angle);
476+ obj.setProperty("deltaAngle", event.deltaAngle);
473477 QScriptValue anglesObj = engine->newArray();
474478 index = 0;
475479 foreach (float angle, event.angles) {
@@ -478,8 +482,8 @@ QScriptValue touchEventToScriptValue(QScriptEngine* engine, const TouchEvent& ev · 2 unmodified lines
478482 }
479483 obj.setProperty("angles", anglesObj);
480484
481− obj.setProperty("rotatingClockwise", event.rotatingClockwise);
482− obj.setProperty("rotatingCounterClockwise", event.rotatingCounterClockwise);
485+ obj.setProperty("isRotating", event.isRotating);
486+ obj.setProperty("rotating", event.rotating);
483487 return obj;
484488 }
485489