Beispiel #1
0
void TestHelper::processTouchStatus(CursorEventPtr pEvent)
{
    map<int, TouchStatusPtr>::iterator it = m_Touches.find(pEvent->getCursorID());
    switch (pEvent->getType()) {
        case Event::CURSOR_DOWN: {
                AVG_ASSERT(it == m_Touches.end());
                TouchStatusPtr pTouchStatus(new TouchStatus(pEvent));
                m_Touches[pEvent->getCursorID()] = pTouchStatus;
            }
            break;
        case Event::CURSOR_MOTION:
        case Event::CURSOR_UP: {
                if (it == m_Touches.end()) {
                    cerr << "borked: " << pEvent->getCursorID() << ", " << 
                            pEvent->typeStr() << endl;
                }
                AVG_ASSERT(it != m_Touches.end());
                TouchStatusPtr pTouchStatus = (*it).second;
                pTouchStatus->pushEvent(pEvent);
            }
            break;
        default:
            AVG_ASSERT(false);
            break;
    }
}
Beispiel #2
0
void Contact::addEvent(CursorEventPtr pEvent)
{
    pEvent->setCursorID(m_CursorID);
    pEvent->setContact(boost::dynamic_pointer_cast<Contact>(shared_from_this()));
    calcSpeed(pEvent, m_Events.back());
    updateDistanceTravelled(m_Events.back(), pEvent);
    m_Events.back()->removeBlob();
    m_Events.back()->setNode(NodePtr());
    m_Events.push_back(pEvent);
}
Beispiel #3
0
void Contact::sendEventToListeners(CursorEventPtr pCursorEvent)
{
    switch (pCursorEvent->getType()) {
        case Event::CURSOR_DOWN:
            break;
        case Event::CURSOR_MOTION:
            notifySubscribers("CURSOR_MOTION", pCursorEvent);
            break;
        case Event::CURSOR_UP:
            notifySubscribers("CURSOR_UP", pCursorEvent);
            removeSubscribers();
            break;
        default:
            AVG_ASSERT_MSG(false, pCursorEvent->typeStr().c_str());
    }
    m_bSendingEvents = true;
    AVG_ASSERT(pCursorEvent->getContact() == shared_from_this());
    EventPtr pEvent = boost::dynamic_pointer_cast<Event>(pCursorEvent);
    m_bCurListenerIsDead = false;
    for (map<int, Listener>::iterator it = m_ListenerMap.begin(); 
            it != m_ListenerMap.end();)
    {
        Listener listener = it->second;
        m_CurListenerID = it->first;
        m_bCurListenerIsDead = false;
        switch (pCursorEvent->getType()) {
            case Event::CURSOR_MOTION:
                if (listener.m_pMotionCallback != Py_None) {
                    py::call<void>(listener.m_pMotionCallback, pEvent);
                }
                break;
            case Event::CURSOR_UP:
                if (listener.m_pUpCallback != Py_None) {
                    py::call<void>(listener.m_pUpCallback, pEvent);
                }
                break;
            default:
                AVG_ASSERT(false);
        }
        map<int, Listener>::iterator lastIt = it;
        ++it;
        if (m_bCurListenerIsDead) {
            m_ListenerMap.erase(lastIt);
            m_bCurListenerIsDead = false;
        }
    }
    m_bSendingEvents = false;
}
Beispiel #4
0
void TUIOInputDevice::processUserID(ReceivedMessageArgumentStream& args)
{
    osc::int32 tuioID;
    osc::int32 userID;
    osc::int32 jointID;
    args >> tuioID >> userID >> jointID;
    TouchStatusPtr pTouchStatus = getTouchStatus(tuioID);
    if (!pTouchStatus) {
        AVG_TRACE(Logger::category::EVENTS, Logger::severity::WARNING,
                "Received /tuioext/userid, but tuio id " << tuioID <<
                " doesn't correspond to a contact.");
        return;
    }
    CursorEventPtr pEvent = pTouchStatus->getLastEvent();
    pEvent->setUserID(userID, jointID);
}
Beispiel #5
0
Contact::Contact(CursorEventPtr pEvent)
    : Publisher("Contact"),
      m_bSendingEvents(false),
      m_bCurListenerIsDead(false),
      m_CursorID(pEvent->getCursorID()),
      m_DistanceTravelled(0)
{
    m_Events.push_back(pEvent);
}
Beispiel #6
0
// From InputDevice
std::vector<EventPtr> TestHelper::pollEvents()
{
    vector<EventPtr> events = m_Events;
    map<int, TouchStatusPtr>::iterator it;
    for (it = m_Touches.begin(); it != m_Touches.end(); ) {
        TouchStatusPtr pTouchStatus = it->second;
        CursorEventPtr pEvent = pTouchStatus->pollEvent();
        if (pEvent) {
            events.push_back(pEvent);
            if (pEvent->getType() == Event::CURSOR_UP) {
                m_Touches.erase(it++);
            } else {
                ++it;
            }
        } else {
            ++it;
        }
    }

    m_Events.clear();
    return events;
}
Beispiel #7
0
void TUIOInputDevice::processAlive(ReceivedMessageArgumentStream& args, 
        Event::Source source)
{
    std::set<int> liveTUIOIDs;
    int32 tuioID;
    while (!args.Eos()) {
        args >> tuioID;
        liveTUIOIDs.insert(tuioID);
    }

    // Create up events for all ids not in live list.
    set<int> deadTUIOIDs;
    getDeadIDs(liveTUIOIDs, deadTUIOIDs, source);
    set<int>::iterator it;
    for (it = deadTUIOIDs.begin(); it != deadTUIOIDs.end(); ++it) {
        int id = *it;
        TouchStatusPtr pTouchStatus = getTouchStatus(id);
        CursorEventPtr pOldEvent = pTouchStatus->getLastEvent();
        CursorEventPtr pUpEvent = pOldEvent->cloneAs(Event::CURSOR_UP);
        pTouchStatus->pushEvent(pUpEvent);
        removeTouchStatus(id);
    }
}
vector<EventPtr> MultitouchInputDevice::pollEvents()
{
    lock_guard lock(*m_pMutex);

    vector<EventPtr> events;
    vector<TouchStatusPtr>::iterator it;
//    cerr << "--------poll---------" << endl;
    for (it = m_Touches.begin(); it != m_Touches.end(); ) {
//        cerr << (*it)->getID() << " ";
        CursorEventPtr pEvent = (*it)->pollEvent();
        if (pEvent) {
            events.push_back(pEvent);
            if (pEvent->getType() == Event::CURSOR_UP) {
                it = m_Touches.erase(it);
            } else {
                ++it;
            }
        } else {
            ++it;
        }
    }
//    cerr << endl;
    return events;
}
Beispiel #9
0
void Contact::calcSpeed(CursorEventPtr pEvent, CursorEventPtr pOldEvent)
{
    if (pEvent->getSpeed() == glm::vec2(0,0)) {
        glm::vec2 posDiff = pEvent->getPos() - pOldEvent->getPos();
        long long timeDiff = pEvent->getWhen() - pOldEvent->getWhen();
        if (timeDiff != 0) {
            pEvent->setSpeed(posDiff/float(timeDiff));
        }
    }
}
Beispiel #10
0
void TUIOInputDevice::setEventSpeed(CursorEventPtr pEvent, glm::vec2 speed)
{
    const glm::vec2 size = getTouchArea();
    glm::vec2 screenSpeed(int(speed.x*size.x+0.5), int(speed.y*size.y+0.5));
    pEvent->setSpeed(screenSpeed/1000.f);
}
Beispiel #11
0
void Contact::updateDistanceTravelled(CursorEventPtr pEvent1, CursorEventPtr pEvent2)
{
    float dist = glm::length(pEvent2->getPos() - pEvent1->getPos());
    m_DistanceTravelled += dist;
}