Friday, June 18, 2010

[android-developers] Re: [openGL] how to rotate quad around its center?

I have to traslate into the z-axis a bit, otherwise I wouldn't see
anything on the screen.

Anyway, I'm doing this step by step as you said to me ;)
At first i traslate the quad to the origin and in fact i see it there.
Then I rotate of 45 degree around the z-axis and I see it rotated
right.

At last I traslate it again to the previous position, but the quad
goes to a different position from that which I expected.
Instead, if i do after the rotation:

glTraslete(1.0f, 0f,0f);

the quad moves of an unit along x-axis as if also this was rotated of
45 degrees, nord-east direction (in order to intend us) and not east-
direction as I expect. I hope you undestrand me now :(

Paolo

p.s. if you prefer I can post my code


On 18 Giu, 18:45, Leigh McRae <leigh.mc...@lonedwarfgames.com> wrote:
> I am not exactly sure what you're saying actually.  At any rate, I
> noticed that you're translating along the z-axis.  If you're rotating
> around the z-axis you don't need to translate along z.  Also it could be
> that you're translating the quad offscreen since you haven't mirrored
> the z translation.
>
> Anyway, what are you seeing?  Did you change the order?  I would do it
> step by step.  Start with getting the translation to the origin right.  
> Once that looks right then add the rotation. Finally add the translation
> back.
>
> Leigh
>
> On 6/18/2010 12:35 PM, Paolo wrote:
>
>
>
>
>
> > Thanks for your answer.
>
> > my matrix is GL_MODELVIEW.
> > I have noticed that once I have traslated and rotated the quad, also
> > the aces x,y,z seem to be rotated of 45 degree. If it is right, it's
> > normal that when i applied the second traslalte the quad goes in
> > another position.
>
> > is it normal? is there something wrong?
>
> > On 18 Giu, 18:21, Leigh McRae<leigh.mc...@lonedwarfgames.com>  wrote:
>
> >> OpenGL applies it's transforms in reverse so maybe swap the two
> >> translates.  Sounds lame but this is the sort of thing you get right
> >> once and don't look at again for sometime.    Also make sure your matrix
> >> mode is GL_MODELVIEW.
>
> >> Leigh
>
> >> On 6/18/2010 11:58 AM, Paolo wrote:
>
> >>> Hi leigh!
> >>> I've tried, but it doesn't work... the quad goes in a wrong position :
> >>> (
>
> >>> My quad has these coordinates
>
> >>>                   //vertex bottom left
> >>>             vertex[0] = 9.5f;
> >>>             vertex[1] = 10f;
> >>>             vertex[2] = 0.0f;
> >>>             //top left
> >>>             vertex[3] = 9.5f;
> >>>             vertex[4] = 11.0f;
> >>>             vertex[5] = 0.0f;
> >>>             //bottom right
> >>>             vertex[6] = 10.5f;
> >>>             vertex[7] = 10f;
> >>>             vertex[8] = 0.0f;
> >>>             //top right
> >>>             vertex[9] = 10.5;
> >>>             vertex[10] = 11f;
> >>>             vertex[11] = 0.0f;
>
> >>> and this is my draw function...
>
> >>> public void draw(GL10 gl){
> >>>             gl.glPushMatrix();
> >>>             gl.glTranslatef(-10, -10.5f, 0);  //to the origin
>
> >>>             gl.glRotatef(45, 0, 0, -1);   //rotate
>
> >>>             gl.glTranslatef(10, 10.5f, -2.0f);   //back to previous position
>
> >>>             // Enabled the vertices buffer for writing and to be used during
> >>>             // rendering.
> >>>             gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
> >>>             // Specifies the location and data format of an array of vertex
> >>>             // coordinates to use when rendering.
> >>>             gl.glVertexPointer(3, GL10.GL_FLOAT, 0, markerBuffer);
> >>>             gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, NUMERO_VERTICI);
> >>>             // Disable the vertices buffer.
> >>>             gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
> >>>             gl.glPopMatrix();
>
> >>>     }
>
> >>> On 18 Giu, 17:31, Leigh McRae<leigh.mc...@lonedwarfgames.com>    wrote:
>
> >>>> Translate the quad to the origin, rotate, translate back.
>
> >>>> Leigh
>
> >>>> On 6/18/2010 11:12 AM, Paolo wrote:
>
> >>>>> Hi guys!
> >>>>> I'm a newbie in OpenGL. :D
> >>>>> I'm trying to rotate a quad around its center.
>
> >>>>> This is my scenario: I've a quad, drawn with TRIANGLE_STRIP, at
> >>>>> specified coordinates. Now I want to rotate of 45 degrees around its
> >>>>> center, without move it from its position, not around the origin of
> >>>>> the aces.
> >>>>> I hope you are able to understand my english... :)
>
> >>>>> How can I do that?
>
> >>>>> Thanks
>
> >>>>> Paolo
>
> >>>> --
> >>>> Leigh McRaewww.lonedwarfgames.com
>
> >> --
> >> Leigh McRaewww.lonedwarfgames.com
>
> --
> Leigh McRaewww.lonedwarfgames.com

--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment