示例#1
0
/**
 * 
 * @param localPosition 
 */
void TriangleGeom::setLocalOrientation(const Quaternion &localOrientation) {

	for(int i = 0; i < mPoints.size(); i++) {
		mPoints.replace(i, (mPoints.at(i) - mLocalPosition));
	}

	Vector3D newPoint;
	Quaternion back(mLocalOrientation);
	back.setW(-back.getW());
	Quaternion inv = back.getInverse();
	Quaternion old(0, 0, 0, 0);
	for(int i = 0; i < mPoints.size(); i++) {
		old.set(0, mPoints.at(i).getX(), mPoints.at(i).getY(), mPoints.at(i).getZ());
		Quaternion newPointQ = back * old *inv;
		newPoint.set(newPointQ.getX(), newPointQ.getY(), newPointQ.getZ());
		mPoints.replace(i, newPoint);
	}	

	Quaternion inverse = localOrientation.getInverse();
	Quaternion oldPoint(0, 0, 0, 0);
	for(int i = 0; i < mPoints.size(); i++) {
		oldPoint.set(0,mPoints.at(i).getX(), mPoints.at(i).getY(), mPoints.at(i).getZ());
		Quaternion newPointQ = localOrientation * oldPoint *inverse;
		newPoint.set(newPointQ.getX(), newPointQ.getY(), newPointQ.getZ());
		mPoints.replace(i, newPoint);
	}

	for(int i = 0; i < mPoints.size(); i++) {
		mPoints.replace(i, (mPoints.at(i) + mLocalPosition));
	}

	SimGeom::setLocalOrientation(localOrientation);
}
示例#2
0
void MapTilesFrame::setViewportCoordinate(const QPoint &requestedPos)
{
    QPoint adjustedPoint;
    QPoint oldPoint(m_viewportCoordinate);

    adjustedPoint.rx() = qBound(0, requestedPos.x(), scaleMaps[getScaleLevel()].width - getViewportWidth());
    adjustedPoint.ry() = qBound(getViewportHeight(), requestedPos.y(), scaleMaps[getScaleLevel()].height);

    m_viewportCoordinate = adjustedPoint;

    qDebug() << "Requested viewportPoint: " << requestedPos << ", adjustedPoint" << adjustedPoint;
    emit viewportCoordinateChanged(adjustedPoint, oldPoint);

}
示例#3
0
	void Scene::GetGestures()
	{
		TouchManager& manager = TouchManager::GetInstance();
		
		const TouchList& touches = manager.Touches();
		
		//Single touch
		if (touches.size() == 1)
		{
			TouchRef touch = touches[0];
			
			// gets touches for blueprint button
			float touchConvX = touch->x /32;
			float touchConvY = touch->y /32;
			
			if ((!m_touchedDown && (touch->state == kTouchBegan)) ||
				(m_touchedDown && (touch->state == kTouchEnded || touch->state == kTouchCancelled)))
			{
				bool pressed = mr_missionBrief->touchHit( Vect2(touchConvX, touchConvY), mp_bluePrintButton, mr_camera);
				if (pressed) 
				{
					if(m_touchedDown)
					{
						// activate blueprint
						if(!mr_missionBrief->IsVisible())
						{
							mr_missionBrief->Show();
						}
						else 
						{
							mr_missionBrief->Hide();
						}
					
						m_infoButtonTimer = 0;
					}
					else 
					{
						m_touchedDown = true;
					}

				}
				else 
				{
					m_touchedDown = false;
				}
			}
			else
			{
				//Figure out vector
				b2Vec2 curPoint(touch->x, touch->y);
				b2Vec2 oldPoint(touch->prevX, touch->prevY);
			
				m_Avatar->MoveAvatar(.15f * (curPoint-oldPoint));
			}			
		}
		
		// PINCH
		if (manager.CurrentPinch().isValid())
		{
			static bool debounce = true;
			float scale = manager.CurrentPinch().getScale();
			if (debounce)
			{
				if (scale < PINCH_CONSTRAINT || scale > PINCH_HIGH)
				{
					debounce = false;
					if (!m_Avatar->IsMagnetOn())
					{
						m_Avatar->ActivateMagnet();
					}
                    else
					{
						m_Avatar->DeactivateMagnet();
					}
				}
			}
			else if(scale >PINCH_CONSTRAINT && scale < PINCH_HIGH)
			{
				debounce = true;
			}
		}
	}