The cube project has been around for nearly a month. The last important function module is gesture recognition, this will add a winning weight for the "2010 Google Android app development China College Student Challenge. Gesture Recognition is simple, just reload the method. The trouble is that glrotatef (float angle, float X, float y, float Z) in OpenGL ES ). This function is different from the glrotatef (float angle, float X, float y, float Z) function in OpenGL.
I checked glrotatef () under OpenGL (). Angle indicates the angle of rotation, and the rotation direction satisfies the right-hand spiral setting. The (x, y, z) vectors that combine the following three parameters represent the axis. On the screen, the top and bottom are the Y axis, which is positive. The left and right are the X axis, the right is the positive, the outer is the Z axis, and the outer is the positive. This is because OpenGL ES is scarce at present, and ES is a simplified version of OpenGL. So I think the glrotatef () in ES is also used.
However, my big mistake!
Glrotatef () in ES is different from glrotatef () in OpenGL.
My development machine is mailstone, at least in mailstone, and the bottom is Y-axis positive, which is different. Another point is that the rotation direction of the angle does not meet the right-hand spiral setting. It has the following features: in the positive direction of X, the right direction is satisfied, and in the negative direction of the Y axis, the right direction is satisfied. Because it was tested on the two-dimensional screen of the mobile phone, the Z axis was not tested.
The test code is as follows:
Public class mygesture extends activity <br/>{< br/> private gesturedetector mgesturedetector; <br/> private ontouchlistener mgesturelistener; <br/> private Boolean misscrolling = false; <br/> private linearlayout alayout; </P> <p> @ override <br/> Public void oncreate (bundle savedinstancestate) <br/>{< br/> super. oncreate (savedinstancestate); <br/> setcontentview (R. layout. main); <br/> alayout = (linearlayout) findviewbyid (R. id. alinerlayout); <br/> mgesturedetector = new gesturedetector (New simpleongesturelistener () <br/>{< br/> @ override <br/> Public Boolean onscroll (motionevent E1, motionevent E2, float distancex, float distancey) <br/>{< br/> misscrolling = true; <br/> If (math. ABS (e2.gety ()-e1.gety () <0.1) <br/>{< br/> If (e2.getx ()-e1.getx ()> 0) <br/>{< br/> log. I ("direction", "right"); <br/>}< br/> else if (e2.getx ()-e1.getx () <0) <br/>{< br/> log. I ("direction", "Left"); <br/>}< br/> else if (math. ABS (e2.getx ()-e1.getx () <0.1) <br/>{< br/> If (e2.gety ()-e1.gety ()> 0) <br/>{< br/> log. I ("direction", "down"); <br/> log. I ("sdfsdf", String. valueof (e2.gety ()-e1.gety (); </P> <p >}< br/> else if (e2.gety ()-e1.gety () <0) <br/>{< br/> log. I ("direction", "up"); <br/> log. I ("sdfsdf", String. valueof (e2.gety ()-e1.gety (); <br/>}< br/> else if (e2.getx ()-e1.getx ()> 0) & (e2.gety ()-e1.gety () <0) <br/>{< br/> log. I ("direction", "right-up"); <br/>}< br/> else if (e2.getx ()-e1.getx () <0) & (e2.gety ()-e1.gety () <0) <br/>{< br/> log. I ("direction", "left-up"); <br/>}< br/> else if (e2.getx ()-e1.getx () <0) & (e2.gety ()-e1.gety ()> 0) <br/>{< br/> log. I ("direction", "left-down"); <br/>}< br/> else if (e2.getx ()-e1.getx ()> 0) & (e2.gety ()-e1.gety ()> 0) <br/>{< br/> log. I ("direction", "right-down"); <br/>}< br/> return true; <br/>}</P> <p> @ override <br/> Public Boolean ondown (motionevent e) <br/>{< br/> log. D ("123", "gesturedetector --> ondown"); <br/> return true; <br/>}< br/> }); </P> <p> mgesturelistener = new view. ontouchlistener () <br/>{< br/> Public Boolean ontouch (view V, motionevent event) <br/>{</P> <p> If (mgesturedetector. ontouchevent (event) <br/>{< br/> return true; <br/>}</P> <p> If (event. getaction () = motionevent. action_up) <br/>{< br/> If (misscrolling) <br/>{< br/> log. D ("end", "ontouchlistener --> ontouch action_up"); <br/> misscrolling = false; <br/>}</P> <p >}< br/> return false; <br/>}< br/>}; <br/> alayout. setontouchlistener (mgesturelistener); <br/>}< br/>
As you can see, when the finger slides to the right on the screen, the X coordinate difference between the two motionevents is positive. When the finger slides down on the screen, the Y coordinate difference between two motionevents is positive. This can be seen through logcat.
Reference: http://hi.baidu.com/zqw19891001/blog/item/79a6a4ef3bcc0d1ffcfa3c25.html/cmtid/d8aa78cb78903b12bf09e620