Ejemplo n.º 1
0
static VALUE touch_zone(VALUE self)
{
  Leap::Pointable * pointer;

  Data_Get_Struct(self, Leap::Pointable, pointer);

  switch(pointer->touchZone()) {
    case(Leap::Pointable::ZONE_NONE):
      return ID2SYM(rb_intern("none"));
    case(Leap::Pointable::ZONE_HOVERING):
      return ID2SYM(rb_intern("hovering"));
    case(Leap::Pointable::ZONE_TOUCHING):
      return ID2SYM(rb_intern("touching"));
  };

  return Qfalse;
}
void LeapSample03App::draw()
{
    gl::clear( Color( .97, .93, .79 ) );
    Leap::PointableList pointables = leap.frame().pointables();
    Leap::InteractionBox iBox = leap.frame().interactionBox();

    for ( int p = 0; p < pointables.count(); p++ ) {
        Leap::Pointable pointable = pointables[p];
#if 1
        // ここから追加
        // 伸びている指、ツール以外は無視する
        if ( !pointable.isExtended() ) {
            continue;
        }
        // ここまで追加
#endif

        Leap::Vector normalizedPosition =
            iBox.normalizePoint( pointable.stabilizedTipPosition() );
        float x = normalizedPosition.x * windowWidth;
        float y = windowHeight - normalizedPosition.y * windowHeight;

        // ホバー状態
        if ( (pointable.touchDistance() > 0) &&
            (pointable.touchZone() != Leap::Pointable::Zone::ZONE_NONE) ) {
            gl::color(0, 1, 0, 1 - pointable.touchDistance());
        }
        // タッチ状態
        else if ( pointable.touchDistance() <= 0 ) {
            gl::color(1, 0, 0, -pointable.touchDistance());
        }
        // タッチ対象外
        else {
            gl::color(0, 0, 1, .05);
        }

        gl::drawSolidCircle( Vec2f( x, y ), 40 );
    }
}
void DefaultQtLeapMouseHandler::onFrame(const Leap::Frame &frame)
{
    /////// MOUSE EVENTS /////////
    // MOUSE BUTTON PRESSED
    // MOUSE BUTTON RELEASED
    // MOUSE MOVE

    if (this->listeners.empty())
        return ;

    Leap::Pointable pointer = frame.pointable(this->savedMousePointableId);
    if (!pointer.isValid())
    {
        pointer = frame.pointables().frontmost();
        this->savedMousePointableId = pointer.id();
    }

    bool forceRelease = (frame.pointables().count() == 0 && this->mousePressed);
    QMouseEvent::Type frameMouseEvent = QMouseEvent::None;
    QPointF globalPointerPos = QtLeapUtils::convertPointablePosToScreenPos(frame.interactionBox(), pointer);
    Qt::MouseButton button = Qt::NoButton;
    Qt::MouseButtons buttons = Qt::NoButton;

    // FINGER TOUCHING AND NO PREVIOUS PRESS -> SETTING BUTTON PRESS
    if (pointer.touchDistance() <= 0 &&
            pointer.touchZone() == Leap::Pointable::ZONE_TOUCHING &&
            !this->mousePressed)
    {
        this->mousePressed = true;
        frameMouseEvent = QMouseEvent::MouseButtonPress;
        button = Qt::LeftButton;
    }
    else if (this->mousePressed && (pointer.touchDistance() > 0 ||
                                    pointer.touchZone() == Leap::Pointable::ZONE_NONE ||
                                    forceRelease))         // FINGER NOT TOUCHING AND PREVIOUS PRESS -> RELEASING BUTTON PRESS
    {
        frameMouseEvent = QMouseEvent::MouseButtonRelease;
        this->mousePressed = false;
        button = Qt::LeftButton;
    }
    else if (frameMouseEvent == QMouseEvent::None &&     // FINGER IN TOUCHING OR HOVERING ZONE AND NO BUTTON PRESS / RELEASE CHANGE -> MouseMove
             pointer.touchZone() != Leap::Pointable::ZONE_NONE
             && globalPointerPos.toPoint() != this->previousPos)
    {
        frameMouseEvent = QMouseEvent::MouseMove;
        this->previousPos = globalPointerPos.toPoint();
        QCursor::setPos(this->previousPos);
    }

    if (this->mousePressed)
        buttons |= Qt::LeftButton;

    if (frameMouseEvent != QMouseEvent::None)
        foreach (QObject *listener, this->listeners)
            QCoreApplication::postEvent(listener, new QMouseEvent(frameMouseEvent,
                                                                  QtLeapUtils::convertGlobalPosToLocalPos(listener, globalPointerPos),
                                                                  globalPointerPos,
                                                                  button,
                                                                  buttons,
                                                                  Qt::NoModifier));
}