1

私は、指をスワイプするだけで 3D マトリックス (3D オブジェクト) を回転させる必要がある ios アプリケーションに取り組んでいます。回転に使用する方法は

setRotationMatrix(float angle, float x, float y, float z, float *matrix);

ただし、3D マトリックスを正しく回転させるために、タッチの x および y 位置の値を使用する方法がわかりません。これが私が使用しているコードです

-(IBAction)handlePan:(UIPanGestureRecognizer *)認識機能 {

    if(recognizer.state == UIGestureRecognizerStateBegan)
    {
        panStartPoint = [recognizer locationInView:self];
        previousPoint.x = 0;
        previousPoint.y = 0;
        currentPoint.x = panStartPoint.x;
        currentPoint.y = panStartPoint.y;
    }
    else if(recognizer.state == UIGestureRecognizerStateEnded)
    {
        panEndPoint = [recognizer locationInView:self];
    }
    else if (recognizer.state == UIGestureRecognizerStateChanged)
    {
        previousPoint.x = currentPoint.x;
        previousPoint.y = currentPoint.y;
        CGPoint instanteneousPoint = [recognizer locationInView:self];
        currentPoint.x = instanteneousPoint.x;
        currentPoint.y = instanteneousPoint.y;

        int xdifference = currentPoint.x - previousPoint.x;
        int ydifference = currentPoint.y - previousPoint.y;



        if((xdifference <= rotationThreshold *-1) || xdifference >= rotationThreshold)  //rotationThreshold = 3;
        {
            if(xdifference <= rotationThreshold *-1)
            {
                rotationY = -1.0;
            }
            else
            {
                rotationY = 1.0;
            }

            if( (ydifference >= rotationThreshold *-1) && ydifference <= rotationThreshold )
            {
                rotationX = 0.0;
            }
        }

        if((ydifference <= rotationThreshold *-1) || ydifference >= rotationThreshold)
        {
          if((ydifference <= rotationThreshold *-1))
          {
            rotationX = -1.0;
          }
          else
          {
              rotationX = 1.0;
          }
            if( (xdifference >= rotationThreshold *-1) && xdifference <= rotationThreshold )
            {
                rotationY = 0.0;
            }

        }
        if(rotationX != 0.0 || rotationY != 0.0)
        {
            rotationDegree += 5.0f;
            if(rotationDegree >= 360.0f)
            {
                rotationDegree = 0.0f;
            }
            ShaderUtils::rotatePoseMatrix(rotationDegree, rotationX, rotationY, rotationZ, &modelViewMatrix.data[0]); //rotationZ = 0;
        }}}

これにより、3D オブジェクトの回転が得られますが、本来あるべきほど自然ではありません。どんな助けでも大歓迎です。ありがとう。

4

2 に答える 2

0

これはあなたを助けるはずだと思います。正しい方法で作るためのいくつかの方法を含むチュートリアルです

于 2013-06-01T05:33:17.770 に答える
0

まあ..私は使用されたUIPanGestureRecognizerを使用したことがないので、どのように、なぜ機能しないのかわかりませんが、UITouchを使用して3Dオブジェクトを移動しました(より簡単だと思います)

わかりました..これが私がしたことです(私はもうコードを持っていないので、あなたにそれを与えることはできません...申し訳ありません):

あなたは touchesBegan ( UITouchPhaseBegan)で最初のタッチを取得します

次に、 touchesMoved の場合、タッチが y に移動した場合は x 軸上でオブジェクトを回転させ、タッチが x に移動した場合は y 軸上で回転させます..および 2 つの任意の組み合わせ (感度を自分で設定する必要があります)

また、次のようにビュー内のオブジェクトを移動するオプションもあります。2 回タップしてから指を動かします (ラップトップのトラック パッドのように)。

z軸上で移動するには、使用するだけですUIPinchGestureRecognizer

2Dサーフェスを使用して3Dオブジェクトをすべての3次元で移動できないことは明らかです

詳細については、UITouch クラス リファレンスを参照してください

うまく説明できていないかもしれませんが、基本的な考え方は理解できました

于 2012-03-30T15:40:14.430 に答える