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 <quill...@163.com> 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 <flyingdutc...@gmail.com>
> 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 <quill...@163.com> 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 -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to