使用OpenGL和触摸屏功能,在视觉上正确的旋转触摸屏、视觉、正确、功能

2023-09-04 05:10:16 作者:孤人

我一直在努力做的鲁比克魔方的为Android。我对轮换一个问题。我想旋转的数字视觉上是正确的。这意味着,如果用户的触摸屏和他的举动后,手指向右一个数字旋转到正确的观察点的一侧。但是,当我做一些旋转的身影开始朝着不正确的方向。据我所知,这取决于该轴是改变自己的处境。不过,我试图用逆模型矩阵以获取必要的坐标,但是我还没有结果。任何人可以给我的例子或3D图形的视觉正确的旋转连接鼠标或触摸屏的帮助?

  //取得联系的矢量3D
   Vector3f touchVector = getRubikSystemCoordinates(mTouchX,mTouchY,square.rubikRotationMatrix);
   //获取移动矢量3D
   Vector3f moveVector = getRubikSystemCoordinates(mMoveX,mMoveY,square.rubikRotationMatrix);
        //获取运动方向
        浮动方向= touchVector.substractFrom(moveVector);
        //获取轴旋转
        Vector3f轴= touchVector.vectorProductTo(moveVector);
        //规范化轴
        axis.normalize();
        //获取旋转角
        浮动角= direction.length;
        //使身份四
        四元数四=新四元数();
        //使旋转四
        quad.makeRotationKvaternion(角,轴);
        //从四免费获赠矩阵
        Matrix4f矩阵= quad.toMatrix();
        //乘以当前模型视图矩阵
        gl.glMultMatrixf(matrix.returnArray(),0);
        //保存旋转矩阵
        square.rotationMatrix = square.rotationMatrix.multiply(矩阵);
        //保存模型视图矩阵
        square.saveModelView(square.initMatrix.returnArray());


      //触摸COORDS当前的模型视图COORDS
      私人Vector3f getRubikSystemCoordinates(浮X,浮动Y,Matrix4f矩阵){
       //触摸COORDS屏幕的正常COORDS
       Vector2f normalCoords =(新Vector2f(X,Y))toNormalScreenCoordinates(Settings.viewPort [2],Settings.viewPort [3])。
        //为球体三维COORDS
        Vector3f sphereVector =新Vector3f(normalCoords.x,normalCoords.y,FloatMath.sqrt(2-normalCoords.x * normalCoords.x-normalCoords.y * normalCoords.y));
        //获取逆矩阵的模型视图矩阵
        Matrix4f米= matrix.inverseMatrix();
        //获取载体当前模型视图三维COORDS
        Vector3f矢量= m.multiplyToVector(向量);
        //使规范化矢量
        vector.normalize();
        返回向量;
        }
 

解决方案

您要查找的内容被命名为弧形球的旋转。你会发现很多资源在互联网上围绕Java这一点。

触摸屏的三个特性,视觉效果有影响关键点

I have been trying to do Cube of Rubik for android. I have one question about rotations. I want to rotate a figure visually correct. It means if user touch screen and after move his finger to right a figure rotate to right from side of observation point. But when I make some rotations the figure start move in not correct direction. I understand that it depends on that axis are change their situation. But I tried to use inverse model matrix to get necessary coordinates, but I haven't already result. Could anybody give me example or link of visually correct rotation of 3D figure with help of mouse or touch screen?

   //get vector 3D of touch
   Vector3f touchVector = getRubikSystemCoordinates(mTouchX,mTouchY,square.rubikRotationMatrix);
   //Get vector 3D of move     
   Vector3f moveVector = getRubikSystemCoordinates(mMoveX,mMoveY,square.rubikRotationMatrix);
        //get direction of motion
        float direction = touchVector.substractFrom(moveVector); 
        //get axis for rotation
        Vector3f axis = touchVector.vectorProductTo(moveVector);
        //normalize axis
        axis.normalize();
        //get angle of rotation
        float angle = direction.length;
        //make identity Quad
        Quaternion quad = new Quaternion();
        //make rotation quad
        quad.makeRotationKvaternion(angle,axis);
        //from quad recieve matrix
        Matrix4f matrix = quad.toMatrix();
        //multiply to current modelview matrix
        gl.glMultMatrixf(matrix.returnArray(),0);
        //save rotation matrix
        square.rotationMatrix = square.rotationMatrix.multiply(matrix);
        //save modelView matrix
        square.saveModelView(square.initMatrix.returnArray()); 


      // touch coords to current modelView coords
      private Vector3f getRubikSystemCoordinates(float x, float y, Matrix4f matrix){
       // touch coords to normal coords of screen 
       Vector2f normalCoords = (new Vector2f(x,y)).toNormalScreenCoordinates(Settings.viewPort[2],Settings.viewPort[3]);
        // to sphere coords in 3D
        Vector3f sphereVector = new Vector3f(normalCoords.x,normalCoords.y, FloatMath.sqrt(2-normalCoords.x*normalCoords.x-normalCoords.y*normalCoords.y));
        //Get inverse matrix from ModelView Matrix
        Matrix4f m = matrix.inverseMatrix();
        //Get vector for current modelView 3D coords
        Vector3f vector = m.multiplyToVector(vector);
        // make normalize vector
        vector.normalize();
        return vector;
        }

解决方案

What you're looking for is named arcball rotation. You'll find plenty of resources in java around the internet on this.

 
精彩推荐
图片推荐