Android OpenGL在触摸移动方向上旋转立方体

时间:2012-07-14 14:18:24

标签: android opengl-es rotation cube motion

  

可能重复:
  Visually correct rotation with OpenGl and touch screen capabilities

我有一个立方体,我想在同一个方向旋转我在触摸时移动我的手指。我知道如何获得当前的触摸移动并使用这些值来旋转立方体,但这不是我想要的。

这就是我目前使用的:

    case MotionEvent.ACTION_DOWN:
        mx = me.getX();
        my = me.getY();
        break;
    case MotionEvent.ACTION_MOVE:
        x_diff = mx - me.getX();
        y_diff = my - me.getY();
        mx = me.getX();
        my = me.getY();
        this.rot_x -= y_diff;
        this.rot_y -= x_diff;
        break;

旋转:

gl.glRotatef(rot_x, 1, 0, 0);
gl.glRotatef(rot_y, 0, 1, 0);
gl.glRotatef(rot_z, 0, 0, 1);

2 个答案:

答案 0 :(得分:3)

我找到了解决方案。正确的方法是实施ArcBall旋转。

NeHe OpenGL教程:http://nehe.gamedev.net/tutorial/arcball_rotation/19003/
Java端口:http://www.java-tips.org/other-api-tips/jogl/arcball-rotation-nehe-tutorial-jogl-port.html

答案 1 :(得分:0)

您没有指定您对当前实现不满意的内容,但有一个想法可能是使用VelocityTracker并根据触摸速度为您的立方体分配3维速度,然后当你停止移动手指时,让立方体缓慢减速回到静止状态。它会让互动更加自然。

相关问题