Results 1 to 9 of 9

Thread: Screen Rotation

  1. #1
    Guest

    Screen Rotation

    I am trying to do rotation but I need the model to always rotate about the screen horizontal, vertical axes. Can someone please give me any pointers

    Many thanks

  2. #2
    Junior Member Newbie
    Join Date
    Oct 2002
    Location
    malaysia
    Posts
    2

    Re: Screen Rotation

    Originally posted by Dave Smith:
    I am trying to do rotation but I need the model to always rotate about the screen horizontal, vertical axes. Can someone please give me any pointers

    Many thanks
    use gluOrtho to set the view to the origin or use translate

  3. #3
    Guest

    Re: Screen Rotation

    Can you expand on this please


    Thank you

    Originally posted by harsher:
    use gluOrtho to set the view to the origin or use translate


  4. #4
    Member Newbie
    Join Date
    Jul 2002
    Location
    NY, US
    Posts
    36

    Re: Screen Rotation

    I am trying to do the same thing as we speak. I think you have to keep track of the "up" and "right" vectors throughout all your rotations. This way you can do a dot product calculation to back out the new up and right vector.

    I will reply back when I get it working..

    Anyone post some help if you have done this..

    Now that i think of it you may be trying something different.. If you use glookat and move the eye coords wouldnt that rotate about the screen hor and vert? The screen hor and vert are you perspective vectors. you want to rotate the perspective view around the model.

    [This message has been edited by delic (edited 10-26-2002).]

    [This message has been edited by delic (edited 10-26-2002).]

  5. #5
    Guest

    Re: Screen Rotation

    I think this might be the solution. I will try to implement this

    Thank you for the info. Will kep you posted.


    Originally posted by delic:
    I am trying to do the same thing as we speak. I think you have to keep track of the "up" and "right" vectors throughout all your rotations. This way you can do a dot product calculation to back out the new up and right vector.

    I will reply back when I get it working..

    Anyone post some help if you have done this..

    Now that i think of it you may be trying something different.. If you use glookat and move the eye coords wouldnt that rotate about the screen hor and vert? The screen hor and vert are you perspective vectors. you want to rotate the perspective view around the model.

    [This message has been edited by delic (edited 10-26-2002).]

    [This message has been edited by delic (edited 10-26-2002).]

  6. #6
    Guest

    Re: Screen Rotation

    I have tried to use the GluLookat but it still does not work.

    I have thought of using the GluUnproject to determine where the screenX and ScreenY transforms into the object 3D coordinates. But this requires that the transformation be done using incremental mode rather than absolute mode.


    Originally posted by delic:
    I am trying to do the same thing as we speak. I think you have to keep track of the "up" and "right" vectors throughout all your rotations. This way you can do a dot product calculation to back out the new up and right vector.

    I will reply back when I get it working..

    Anyone post some help if you have done this..

    Now that i think of it you may be trying something different.. If you use glookat and move the eye coords wouldnt that rotate about the screen hor and vert? The screen hor and vert are you perspective vectors. you want to rotate the perspective view around the model.

    [This message has been edited by delic (edited 10-26-2002).]

    [This message has been edited by delic (edited 10-26-2002).]

  7. #7
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: Screen Rotation

    The order in which you translate/rotate make a big diffrence.


    example 1:

    glTranslatef( 0.0, 0.0, -1.0);
    glRotatef( 15, 0.0, 1.0, 0.0);
    Draw_sphere(); // effect on sphere is first rotated 15 degrees and then move to -1 on the y-axis.

    example 2:
    glRotatef(15, 0.0, 1.0, 0.0);
    glTranslatef(0.0, 0.0, 1.0);
    Draw_sphere(); // effect on sphere is first translated out to the -1 y-axis, then rotated 15 degrees. But now since all rotations take place from the openGL origin, the sphere is rotated as if it was in orbit around the origin. Which would be translated out -1, then moved in a arc 15 degrees.

    Originally posted by Dave Smith:
    I am trying to do rotation but I need the model to always rotate about the screen horizontal, vertical axes. Can someone please give me any pointers

    Many thanks

  8. #8
    Member Newbie
    Join Date
    Jul 2002
    Location
    NY, US
    Posts
    36

    Re: Screen Rotation

    Dave Im not exactly sure if we were doing the same thing but I asccomplished what I was after.. In a nut shell you have to continually update your current screen upvector (y) and rgightvector (x)as you rotate around. I post the orientation code below:

    void getAxes(GLfloat upvect[3],GLfloat rgtvect[3],GLfloat outvect[3] )
    {
    GLfloat curModmatrix[4][4],curProjmatrix[4][4];
    glGetFloatv(GL_MODELVIEW_MATRIX,&curModmatrix[0][0]);
    glGetFloatv(GL_PROJECTION_MATRIX,&curProjmatrix[0][0]);
    GLfloat tempvect[3];

    tempvect[0] = rgtvect[0];
    tempvect[1] = rgtvect[1];
    tempvect[2] = rgtvect[2];
    rgtvect[0] = curModmatrix[0][0]*rgtvect[0] + curModmatrix[0][1]*rgtvect[1] + curModmatrix[0][2]*rgtvect[2];
    rgtvect[1] = curModmatrix[1][0]*tempvect[0] + curModmatrix[1][1]*rgtvect[1] + curModmatrix[1][2]*rgtvect[2];
    rgtvect[2] = curModmatrix[2][0]*tempvect[0] + curModmatrix[2][1]*tempvect[1] + curModmatrix[2][2]*rgtvect[2];
    tempvect[0] = rgtvect[0];
    tempvect[1] = rgtvect[1];
    tempvect[2] = rgtvect[2];
    rgtvect[0] = curProjmatrix[0][0]*rgtvect[0] + curProjmatrix[0][1]*rgtvect[1] + curProjmatrix[0][2]*rgtvect[2];
    rgtvect[1] = curProjmatrix[1][0]*tempvect[0] + curProjmatrix[1][1]*rgtvect[1] + curProjmatrix[1][2]*rgtvect[2];
    rgtvect[2] = curProjmatrix[2][0]*tempvect[0] + curProjmatrix[2][1]*tempvect[1] + curProjmatrix[2][2]*rgtvect[2];


    tempvect[0] = upvect[0];
    tempvect[1] = upvect[1];
    tempvect[2] = upvect[2];
    upvect[0] = curModmatrix[0][0]*upvect[0] + curModmatrix[0][1]*upvect[1] + curModmatrix[0][2]*upvect[2];
    upvect[1] = curModmatrix[1][0]*tempvect[0] + curModmatrix[1][1]*upvect[1] + curModmatrix[1][2]*upvect[2];
    upvect[2] = curModmatrix[2][0]*tempvect[0] + curModmatrix[2][1]*tempvect[1] + curModmatrix[2][2]*upvect[2];
    tempvect[0] = upvect[0];
    tempvect[1] = upvect[1];
    tempvect[2] = upvect[2];
    upvect[0] = curProjmatrix[0][0]*upvect[0] + curProjmatrix[0][1]*upvect[1] + curProjmatrix[0][2]*upvect[2];
    upvect[1] = curProjmatrix[1][0]*tempvect[0] + curProjmatrix[1][1]*upvect[1] + curProjmatrix[1][2]*upvect[2];
    upvect[2] = curProjmatrix[2][0]*tempvect[0] + curProjmatrix[2][1]*tempvect[1] + curProjmatrix[2][2]*upvect[2];


    tempvect[0] = outvect[0];
    tempvect[1] = outvect[1];
    tempvect[2] = outvect[2];
    outvect[0] = curModmatrix[0][0]*outvect[0] + curModmatrix[0][1]*outvect[1] + curModmatrix[0][2]*outvect[2];
    outvect[1] = curModmatrix[1][0]*tempvect[0] + curModmatrix[1][1]*outvect[1] + curModmatrix[1][2]*outvect[2];
    outvect[2] = curModmatrix[2][0]*tempvect[0] + curModmatrix[2][1]*tempvect[1] + curModmatrix[2][2]*outvect[2];
    tempvect[0] = outvect[0];
    tempvect[1] = outvect[1];
    tempvect[2] = outvect[2];
    outvect[0] = curProjmatrix[0][0]*outvect[0] + curProjmatrix[0][1]*outvect[1] + curProjmatrix[0][2]*outvect[2];
    outvect[1] = curProjmatrix[1][0]*tempvect[0] + curProjmatrix[1][1]*outvect[1] + curProjmatrix[1][2]*outvect[2];
    outvect[2] = curProjmatrix[2][0]*tempvect[0] + curProjmatrix[2][1]*tempvect[1] + curProjmatrix[2][2]*outvect[2];
    }

    [This message has been edited by delic (edited 10-29-2002).]

  9. #9
    Guest

    Re: Screen Rotation

    Many thanks for your help

    Originally posted by delic:
    Dave Im not exactly sure if we were doing the same thing but I asccomplished what I was after.. In a nut shell you have to continually update your current screen upvector (y) and rgightvector (x)as you rotate around. I post the orientation code below:

    void getAxes(GLfloat upvect[3],GLfloat rgtvect[3],GLfloat outvect[3] )
    {
    GLfloat curModmatrix[4][4],curProjmatrix[4][4];
    glGetFloatv(GL_MODELVIEW_MATRIX,&curModmatrix[0][0]);
    glGetFloatv(GL_PROJECTION_MATRIX,&curProjmatrix[0][0]);
    GLfloat tempvect[3];

    tempvect[0] = rgtvect[0];
    tempvect[1] = rgtvect[1];
    tempvect[2] = rgtvect[2];
    rgtvect[0] = curModmatrix[0][0]*rgtvect[0] + curModmatrix[0][1]*rgtvect[1] + curModmatrix[0][2]*rgtvect[2];
    rgtvect[1] = curModmatrix[1][0]*tempvect[0] + curModmatrix[1][1]*rgtvect[1] + curModmatrix[1][2]*rgtvect[2];
    rgtvect[2] = curModmatrix[2][0]*tempvect[0] + curModmatrix[2][1]*tempvect[1] + curModmatrix[2][2]*rgtvect[2];
    tempvect[0] = rgtvect[0];
    tempvect[1] = rgtvect[1];
    tempvect[2] = rgtvect[2];
    rgtvect[0] = curProjmatrix[0][0]*rgtvect[0] + curProjmatrix[0][1]*rgtvect[1] + curProjmatrix[0][2]*rgtvect[2];
    rgtvect[1] = curProjmatrix[1][0]*tempvect[0] + curProjmatrix[1][1]*rgtvect[1] + curProjmatrix[1][2]*rgtvect[2];
    rgtvect[2] = curProjmatrix[2][0]*tempvect[0] + curProjmatrix[2][1]*tempvect[1] + curProjmatrix[2][2]*rgtvect[2];


    tempvect[0] = upvect[0];
    tempvect[1] = upvect[1];
    tempvect[2] = upvect[2];
    upvect[0] = curModmatrix[0][0]*upvect[0] + curModmatrix[0][1]*upvect[1] + curModmatrix[0][2]*upvect[2];
    upvect[1] = curModmatrix[1][0]*tempvect[0] + curModmatrix[1][1]*upvect[1] + curModmatrix[1][2]*upvect[2];
    upvect[2] = curModmatrix[2][0]*tempvect[0] + curModmatrix[2][1]*tempvect[1] + curModmatrix[2][2]*upvect[2];
    tempvect[0] = upvect[0];
    tempvect[1] = upvect[1];
    tempvect[2] = upvect[2];
    upvect[0] = curProjmatrix[0][0]*upvect[0] + curProjmatrix[0][1]*upvect[1] + curProjmatrix[0][2]*upvect[2];
    upvect[1] = curProjmatrix[1][0]*tempvect[0] + curProjmatrix[1][1]*upvect[1] + curProjmatrix[1][2]*upvect[2];
    upvect[2] = curProjmatrix[2][0]*tempvect[0] + curProjmatrix[2][1]*tempvect[1] + curProjmatrix[2][2]*upvect[2];


    tempvect[0] = outvect[0];
    tempvect[1] = outvect[1];
    tempvect[2] = outvect[2];
    outvect[0] = curModmatrix[0][0]*outvect[0] + curModmatrix[0][1]*outvect[1] + curModmatrix[0][2]*outvect[2];
    outvect[1] = curModmatrix[1][0]*tempvect[0] + curModmatrix[1][1]*outvect[1] + curModmatrix[1][2]*outvect[2];
    outvect[2] = curModmatrix[2][0]*tempvect[0] + curModmatrix[2][1]*tempvect[1] + curModmatrix[2][2]*outvect[2];
    tempvect[0] = outvect[0];
    tempvect[1] = outvect[1];
    tempvect[2] = outvect[2];
    outvect[0] = curProjmatrix[0][0]*outvect[0] + curProjmatrix[0][1]*outvect[1] + curProjmatrix[0][2]*outvect[2];
    outvect[1] = curProjmatrix[1][0]*tempvect[0] + curProjmatrix[1][1]*outvect[1] + curProjmatrix[1][2]*outvect[2];
    outvect[2] = curProjmatrix[2][0]*tempvect[0] + curProjmatrix[2][1]*tempvect[1] + curProjmatrix[2][2]*outvect[2];
    }

    [This message has been edited by delic (edited 10-29-2002).]

Similar Threads

  1. Code in the post Object and Screen Space Rotation Demo by MaxH
    By xxk89xx in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 03-14-2013, 01:42 PM
  2. Rotation around screen center
    By admirandis in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 12-27-2012, 12:56 AM
  3. Object and Screen Space Rotation Demo
    By MaxH in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 06-03-2009, 06:04 PM
  4. 3D Model Rotation abt Screen Coords based on mouse movement
    By dan81 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 10-11-2005, 06:43 AM
  5. Rotation around the center of the screen...How???
    By mohsin in forum OpenGL: Basic Coding
    Replies: 9
    Last Post: 09-13-2001, 05:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean