Пример #1
0
bool QtTapGestureRecognizer::recognize(const QTouchEvent* event, qint64 eventTimestampMillis)
{
    ASSERT(m_eventHandler);

    if (event->touchPoints().size() != 1) {
        reset();
        return false;
    }

    const QTouchEvent::TouchPoint& touchPoint = event->touchPoints().first();

    switch (event->type()) {
    case QEvent::TouchBegin:
        m_doubleTapTimer.stop(); // Cancel other pending single tap event.

        ASSERT(!m_tapAndHoldTimer.isActive());
        m_tapAndHoldTimer.start(tapAndHoldTime, this);

        if (m_lastTouchEvent && withinDistance(touchPoint, maxDoubleTapDistance))
            m_candidate = DoubleTapCandidate;
        else {
            m_candidate = SingleTapCandidate;
            // The below in facts resets any previous single tap event.
            m_eventHandler->handlePotentialSingleTapEvent(touchPoint);
            m_lastTouchEvent = adoptPtr(new QTouchEvent(*event));
            m_doubleTapTimer.start(maxDoubleTapInterval, this);
        }
        break;

    case QEvent::TouchUpdate:
        // If the touch point moves further than the threshold, we cancel the tap gesture.
        if (m_candidate != Invalid && !withinDistance(touchPoint, maxPanDistance))
            reset();
        break;

    case QEvent::TouchEnd:
        m_tapAndHoldTimer.stop();

        if (m_candidate == Invalid)
            break;

        if (m_candidate == DoubleTapCandidate) {
            m_eventHandler->handlePotentialSingleTapEvent(QTouchEvent::TouchPoint());
            m_eventHandler->handleDoubleTapEvent(touchPoint);
        }

        break;

    default:
        break;
    }

    return false;
}
Пример #2
0
float WayPoint::getSpeed(){
	if(m_follow_node != NULL) {
		if(withinDistance(1.0f)) return 0.0f;
		else if(m_follow_node_moving) return m_walk_speed;
		else if(withinDistance(3.0f)) return m_walk_speed * 0.3f;
		else if(withinDistance(6.0f)) return m_walk_speed * 0.8f;
		else if(withinDistance(10.0f)) return m_walk_speed;
		else if(withinDistance(30.0f)) return m_walk_speed * 1.5f;
		else return m_walk_speed * 2.0f;
	}
	return m_walk_speed;
}
Пример #3
0
void WayPoint::Update(float dt){
	//std::cout << "Tott pos: " << m_node->getPosition() << std::endl;

	if(m_follow_node != NULL) {
		m_destination = m_follow_node->getPosition();
		m_direction = m_destination - m_node->getPosition();

		m_follow_node_moving = (m_destination != m_old_destination);
		m_old_destination = m_destination;
	}
	else{
	}

	if (m_direction == Ogre::Vector3::ZERO) {
        if (NextLocation()) { }
    }
	else {
		UpdateGoal();
		//do naaathing
		//std::cout << "Deque empty: " << m_walk_list.empty() << std::endl;
	}

	if (withinDistance(1.0f)){
		if(m_follow_node != NULL) {
			//do nothing for now
		}
		else {
			m_direction = Ogre::Vector3::ZERO;
		}
	}
};