Er...it makes me headache:) (Let's simplify it, there is only one object, and we don't need to determine which object is touched.) So do you use Euler Angle to rotate your gube or do you use Axis Angle? (I learn it from internet, it seems Euler Angle means rotating objects around X, Y, Z axis, like this: glRotatef( ax, 1,0,0 ); glRotatef( ay, 0,1,0 ); glRotatef( az, 0,0,1);
and Axis Angle seems like this: axis = normalize( cross(v0, v1) ); angle = acosf( v0,v1); glRotatef(angle, axis.x, axis.y, axis.z);) I think my given idea is something like the Axis Angle method, I caculate the angle as follows: mAngle = ds * TOUCH_SCALE_FACTOR; Because this mAngle is not defined as total angle(total angle means defined like this: mAngle += ds * TOUCH_SCALE_FACTOR; in this case I can't use total angle, because the axis is changable), every time when I draw the GL world I need to get the previous state of the modelview, and then rotate. I use gl.glLoadMatrixf(mModelViewMatrix, 0) to reach the previous state, but it works not so good. If you use Axis Angle to rotate, how do you get the previous state? I hope you can understand my poor English :) On Jul 15, 10:00 pm, Streets Of Boston <[email protected]> wrote: > Aha... you mean 'how to rotate using the touchscreen'. > > You're on the right track :-) > > However, i found that gluUnProject in the api did not work for some > reason. I wrote my own (do a search on this forum). > > Handling swipes and translate them into rotations is not trivial. I > wrote the app "The Gube", a 3D rubix cube, and handling the user input > (touch screen, trackball) is what i spent most my time on. It can not > be explained in just a post here (without giving away my code). > > Some pointers: > -On ACTION_DOWN, determine which patch/object your finger is touching. > -On a swipe (onFling/onScroll on GestureDetector) and given the > earlier found patch/object, determine which direction the swipe is > happening in 3D space. > -Using the patch/object's normal determine the relation of the swipe > relative to the patch and rotate the patch/object accordingly. > > - To have a smooth interaction with swiping the screen and actually > rotating the objects; don't do all the 3D math and such in your main > GUI thread. Instead post user-action objects to a queue that is > handled by your opengl rendering-thread. The rendering-thread not only > renders your cube, but also reads the user-action objects from the > queue and does the appropriate 3D handling and instructs the rendering > engine how to modify the view/model accordingly. > > It took me a few months to get this right... > > On Jul 14, 11:25 pm, quill <[email protected]> wrote: > > > > > I have read the API Demo code. > > I have come up an idea to do it like this: > > 1)Map the touch point to 3D coordinates, and we can get a line when > > touch point moved, as Line1; > > 2)Also we can get another line which is vertical to the screen. Signed > > as Line2: gluunproject(x,y,0)-->gluunproject(x,y,1); > > 3)Line1 and Line2 can form a plane, and we can get the plane's normal > > line, it is just the rotation axis; > > 4)With a proper angle according to the touch point's moving distant, > > we can rotate the object. > > But this idea has come up a problem. how can I know the previous state > > of the object? I can't use the total angle to rotate because the axis > > is changable. I use gl.glLoadMatrixf(mModelViewMatrix, 0) to reach the > > previous state and then do glRotatef, it can work when I slip my > > finger quickly, but it works bad when I slip slowly. > > > On Jul 14, 11:34 pm, Streets Of Boston <[email protected]> > > wrote: > > > > Take a careful look at the API Demo code. > > > And then take a look at the OpenGL ES documentation > > > (http://www.khronos.org/opengles/) > > > Having the code that shows you how to rotate around the X or Y axis, > > > it should not be hard to figure out how to rotate along the Z axis > > > > On Jul 14, 11:23 am, quill <[email protected]> wrote: > > > > > In the api demo, there is an example for how to rotate a cube, but it > > > > can only rotate about X axis or Y axis, without Z-Axis Rotation. > > > > So how to perform 3D Rotation? Any advice is appreciated.- Hide quoted > > > > text - > > > > - Show quoted text -- Hide quoted text - > > > - Show quoted text -- Hide quoted text - > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

