コード例 #1
0
void InputDevice::sendFullTouchEvent(QTouchEvent *event)
{
    if (!mouseFocus()) {
        qWarning("Cannot send touch event, no pointer focus, fix the compositor");
        return;
    }

    if (event->type() == QEvent::TouchCancel) {
        sendTouchCancelEvent();
        return;
    }

    TouchExtensionGlobal *ext = m_compositor->touchExtension();
    if (ext && ext->postTouchEvent(event, mouseFocus()))
        return;

    const QList<QTouchEvent::TouchPoint> points = event->touchPoints();
    if (points.isEmpty())
        return;

    const int pointCount = points.count();
    QPointF pos = mouseFocus()->pos();
    for (int i = 0; i < pointCount; ++i) {
        const QTouchEvent::TouchPoint &tp(points.at(i));
        // Convert the local pos in the compositor window to surface-relative.
        QPointF p = tp.pos() - pos;
        sendTouchPointEvent(tp.id(), p.x(), p.y(), tp.state());
    }
    sendTouchFrameEvent();
}
コード例 #2
0
ファイル: RigidControlet.cpp プロジェクト: JohnCrash/iRobot
void RaduisControlet::injectMouseMove(int _absx, int _absy, int _absz)
{
	if( mPick && 
		(_absx!=mMouseX ||
		_absy!=mMouseY) ){
		Game& game = Game::getSingleton();
		int sx = game.getScreenWidth();
		int sy = game.getScreenHeight();
		Ogre::Vector3 eye = game.getCamera()->getPosition();

		Ogre::Ray B = game.getCamera()->getCameraToViewportRay(
				(Ogre::Real)_absx/(Ogre::Real)sx,
				(Ogre::Real)_absy/(Ogre::Real)sy
			);
		Ogre::Matrix3 m3 = mNode->getLocalAxes();
		Ogre::Vector3 v3 = mNode->getPosition();
		Math3d::CalcResult result = Math3d::CalcRayPlanePoint( B,
			Ogre::Plane(m3.GetColumn(2),v3) );

		if( result.first ){
			Ogre::Real r = v3.distance( result.second );
			Ogre::Real R = r-2*mScale;
			if( R <= 1 )
				R = 1;
			
			setRaduis( v3,m3.GetColumn(2),R,mScale );
			mNotify( mName,R );
		}
		mMouseX = _absx;
		mMouseY = _absy;
	}
	mouseFocus( _absx,_absy );
}
コード例 #3
0
ファイル: RigidControlet.cpp プロジェクト: JohnCrash/iRobot
void RotateControlet::injectMouseMove(int _absx, int _absy, int _absz){
	if( mPick && 
		(_absx!=mMouseX ||
		_absy!=mMouseY) ){
		/*上一个鼠标位置和眼睛组成的射线A,新的鼠标位置和眼睛组成的射线B
		它们和旋转盘相交,交点和旋转盘中心组成的矢量的角度,既是旋转角
		*/
		Game& game = Game::getSingleton();
		int sx = game.getScreenWidth();
		int sy = game.getScreenHeight();
		Ogre::Vector3 eye = game.getCamera()->getPosition();
		Ogre::Ray A = game.getCamera()->getCameraToViewportRay(
				(Ogre::Real)mMouseX/(Ogre::Real)sx,
				(Ogre::Real)mMouseY/(Ogre::Real)sy
			);
		Ogre::Ray B = game.getCamera()->getCameraToViewportRay(
				(Ogre::Real)_absx/(Ogre::Real)sx,
				(Ogre::Real)_absy/(Ogre::Real)sy
			);
		//计算和旋转盘的交点,旋转盘是一个平面
		//平面的法向量是Local Z轴,平面通过Local原点
		Ogre::Matrix3 m3 = mNode->getLocalAxes();
		Ogre::Vector3 v3 = mNode->getPosition();
		Ogre::Vector3 axis(m3[0][2],m3[1][2],m3[2][2]);
		Ogre::Plane P(axis,v3 ); //旋转盘平面
		Math3d::CalcResult result1 = Math3d::CalcRayPlanePoint( A,P );
		Math3d::CalcResult result2 = Math3d::CalcRayPlanePoint( B,P );
		if( result1.first && result2.first ){
			//方程都有解
			Ogre::Vector3 a,b;
			a = result1.second;
			b = result2.second;
			a -= v3;b -= v3;
			a.normalise();
			b.normalise();
			Ogre::Vector3 c = b.crossProduct(a);
			Ogre::Real sinv = c.length();
			Ogre::Real ang = asinf(sinv);

			if( axis.dotProduct( c ) > 0 )
				ang = -ang;

			mNode->rotate( axis,Ogre::Radian(ang),Ogre::Node::TS_WORLD );

			mNotify( mName,axis,ang );
		}
		mMouseX = _absx;
		mMouseY = _absy;
	}

	mouseFocus( _absx,_absy );
}
コード例 #4
0
ファイル: RigidControlet.cpp プロジェクト: JohnCrash/iRobot
void OrientationControlet::injectMouseMove(int _absx, int _absy, int _absz){
	if( mPick && 
		(_absx!=mMouseX ||
		_absy!=mMouseY) ){
		/*计算和摇杆球面的交点
		*/
		Game& game = Game::getSingleton();
		int sx = game.getScreenWidth();
		int sy = game.getScreenHeight();
		Ogre::Vector3 eye = game.getCamera()->getPosition();
		Ogre::Ray A = game.getCamera()->getCameraToViewportRay(
				(Ogre::Real)mMouseX/(Ogre::Real)sx,
				(Ogre::Real)mMouseY/(Ogre::Real)sy
			);
		Ogre::Ray B = game.getCamera()->getCameraToViewportRay(
				(Ogre::Real)_absx/(Ogre::Real)sx,
				(Ogre::Real)_absy/(Ogre::Real)sy
			);
		//计算和旋转盘的交点,旋转盘是一个平面
		//平面的法向量是Local Z轴,平面通过Local原点
		Ogre::Matrix3 m3 = mNode->getLocalAxes();
		Ogre::Vector3 v3 = mNode->getPosition();
		Ogre::Vector3 axis = m3.GetColumn(2);

		Ogre::Sphere S(v3,mRaduis);

		Math3d::CalcResult result1 = Math3d::CalcRaySphereNearFarPoint(A,S,mNearFar);
		Math3d::CalcResult result2 = Math3d::CalcRaySphereNearFarPoint(B,S,mNearFar);
		if( result1.first && result2.first ){//都相交
			//然后使用直线的参数方程计算出具体的焦点
			Ogre::Vector3 a = result1.second;
			Ogre::Vector3 b = result2.second;
			a -= v3;b -= v3;
			a.normalise();
			b.normalise();
			Ogre::Vector3 c = b.crossProduct(a);
			Ogre::Real sinv = c.length();
			Ogre::Real ang = -asinf(sinv);
			c.normalise();

			mNode->rotate( c,Ogre::Radian(ang),Ogre::Node::TS_WORLD );
			mNotify( mName,c,ang );
		}
		mMouseX = _absx;
		mMouseY = _absy;
	}

	mouseFocus( _absx,_absy );
}
コード例 #5
0
ファイル: RigidControlet.cpp プロジェクト: JohnCrash/iRobot
void LinearControlet::injectMouseMove(int _absx, int _absy, int _absz){
	if( mPick && 
		(_absx!=mMouseX ||
		_absy!=mMouseY) ){
		/*鼠标按下点(mMouseX,mMouseY)连接眼睛的位置,在空间形成一条直线(直线A)。
		同样(_absx,_absy)与眼睛相连也形成一条直线(直线B)。这两条直线可以构成一个平面(叫V平面吧)。
		而LinearControlet的位置和方向在空间也形成一条直线(C)。该直线在V上的投影直线与直线A与B相交
		形成一个矢量,把该矢量投影回C,形成一个移动向量。
		简化点:这个问题等价与两个直线间的最短距离。A与C B与C
		*/
		Game& game = Game::getSingleton();
		int sx = game.getScreenWidth();
		int sy = game.getScreenHeight();
		Ogre::Vector3 eye = game.getCamera()->getPosition();
		Ogre::Ray A = game.getCamera()->getCameraToViewportRay(
				(Ogre::Real)mMouseX/(Ogre::Real)sx,
				(Ogre::Real)mMouseY/(Ogre::Real)sy
			);
		Ogre::Ray B = game.getCamera()->getCameraToViewportRay(
				(Ogre::Real)_absx/(Ogre::Real)sx,
				(Ogre::Real)_absy/(Ogre::Real)sy
			);
		Ogre::Matrix3 m3 = mNode->getLocalAxes();
		Ogre::Vector3 v3 = mNode->getPosition();
		//m3[0][2],m3[1][2],m3[2][2] 是Z坐标轴在世界坐标中的矢量
		Ogre::Ray C(v3,Ogre::Vector3(m3[0][2],m3[1][2],m3[2][2]));
		Math3d::CalcResult result1 = Math3d::CalcNearPoint( C,A );
		Math3d::CalcResult result2 = Math3d::CalcNearPoint( C,B );
		if( result1.first && result2.first ){
			Ogre::Vector3 a = result1.second;
			Ogre::Vector3 b = result2.second;
			/*将移动限制在mLimited之间,mLimited是两个直线参数
			*/
			Ogre::Ray ray(mPosition,-mDirection);
			Ogre::Real t = Math3d::RayParameter( ray,v3 + b-a );
			if( t < mLimited[0] )
				t = mLimited[0];
			if( t > mLimited[1] )
				t = mLimited[1];
			Ogre::Vector3 p = Math3d::RayPoint( ray,t );

			mNode->setPosition( p );
			mNotify( mName,p-v3 );
		}
		mMouseX = _absx;
		mMouseY = _absy;
	}
	mouseFocus( _absx,_absy );
}