Clear principle:
First make sure that the coordinates in OpenGL are: The x-axis is in the right direction for the screen, the y-axis is the screen upward, the z-axis is in the direction of the screen from the inside out.
When the finger moves in the x-axis direction, the object in the picture should rotate around the y-axis, or GL.GLROTATEF (angle,0,1,0);
When the finger moves in the y-axis direction, the object in the picture should rotate around the x-axis, or GL.GLROTATEF (angle,1,0,0);
In addition, the function used by the screen response gesture movement in Android is: Ontouchevent.
The following shows the code:
private final float touch_scale_factor = 180.0f/320;
renderer = new Newrender ();
Public Booleanontouchevent (motionevent e) {Switch(E.getaction ()) { CaseMotionEvent.ACTION_DOWN:ypos=e.gety (); Xpos=E.getx (); return true; CaseMotionevent.action_move:floatDY = e.gety ()-ypos;//Calculate the Pen y offset floatDX = E.getx ()-xpos;//Calculate pen x offsetRenderer.center.mAngleX = dy * touch_scale_factor;//set the angle of rotation along the x axisRenderer.center.mAngleY = dx * TOUCH_SCALE_FACTOR;//set rotation angle along Y axisRequestrender ();//Redraw the screen return true; } return true; }
Newrender () is a class that I inherited from renderer.
Renderer.center.mAngleX = dy * touch_scale_factor; // set the angle of rotation along the x axis Renderer.center.mAngleY = dx * TOUCH_SCALE_FACTOR; // set rotation angle along y axis
Center.manglex and Center.mangley refer to the angle of rotation of my object (center).
In center, my rotation angle is set to:
Gl.glrotatef (Manglex, 1, 0, 0); // Rotate Gl.glrotatef (Mangley, 0, 1, 0);
Opengl es Android 3D finger Touch Rotate Object