Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 10 of 12

Thread: trouble with arcball rotation and translation

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2007
    Posts
    8

    trouble with arcball rotation and translation

    Hi everybody. I'm struggling pretty hard with this, and I need some help here. OK, I'm actually totally stuck. I'm trying to teach myself OpenGL to enhance some graphics in some applications we have here at the office, and I just can't find any help with this problem.

    Anyway, I'm trying to create a basic model viewer. I decided to go with the ArcBall type of interface because of how nicely it ends up working. I actually got the arcball interface working great. The problem I have is with translation.

    What I would like to try to do is to translate my model in a plane parallel to the screen, regardless of it's rotation, all while keeping the center of rotation in the center of the screen.

    This seems like it should be rudimentary at best, but no combination of translations and rotations seems to do the trick. I can get center-screen rotation or screen-plane translation to be mutually exclusive, but putting it together is driving me crazy. I never took a math modeling course, or a graphics course when I was in school, so all of this is totally beyond me...even if I knew where to start, I'd still be out of luck.

    Anyway, I've gotten the arcball working using code samples from the internet. If I posted some code, would somebody be willing to take a look and help me work through it, or at least tell me what I need to do?

    Thanks,
    -Langecrew-

  2. #2
    Junior Member Newbie
    Join Date
    Jul 2006
    Posts
    11

    Re: trouble with arcball rotation and translation

    you can try

    Code :
    float current_matrix[16];
    glGetFloatv(GL_MODELVIEW_MATRIX, current_matrix);
    glLoadIdentity();
    glTranslatef(x_translate_amount, y_translate_amount, 0);
    glMultMatrixf(current_matrix);

    whenever you have to translate the model. As for rotations, just keep using your unchanged arcball code.

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2007
    Posts
    8

    Re: trouble with arcball rotation and translation

    Thanks a lot for the reply!!

    Hmm...
    I think I tried something like this before. It works great to get the shapes translating parallel to the screen plane, but I still get the center of rotation translating with the shapes. I'd like to keep the center of rotation in the center of the screen. Maybe I'm just approaching it incorrectly??

    Check this out:

    Code :
    procedure DrawScreen;
    var
      CurrentMatrix: array [0..15] of GLFloat;
    begin
      glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
     
      glMatrixMode(GL_MODELVIEW);
      glLoadIdentity;
     
      //adjust the camera view
      gluLookAt( CamX, CamY, CamZ,
        SubjectX, SubjectY, SubjectZ,
        0, 1 ,0);
     
      glPushMatrix();
     
        //apply the arcball rotation
        glMultMatrixf(@ArcballRotationMatrix);
     
        glGetFloatV(GL_MODELVIEW_MATRIX, @CurrentMatrix);
        glLoadIdentity();
     
        glTranslatef(TransX, TransY, 0);
     
        glMultMatrixf(@CurrentMatrix);
     
        glPushMatrix();
     
          //draw the scene
          DrawModel;
     
        glPopMatrix();
      glPopMatrix();
     
      SwapBuffers(TheWindowHandle);
    end;

    Do I have to do something weird, like applying the reverse translation only to the arcball?

    Thanks again,
    -Langecrew-

  4. #4
    Intern Contributor
    Join Date
    Jul 2004
    Location
    Toronto
    Posts
    97

    Re: trouble with arcball rotation and translation

    In that case you apply the translation first, followed by rotation. Then it will rotate about the center of the screen.

  5. #5
    Junior Member Newbie
    Join Date
    Dec 2007
    Posts
    8

    Re: trouble with arcball rotation and translation

    Hey, thanks for the reply!!

    I've tried this also. But then, the problem is that my model will no longer translate left/right/up/down parallel to the screen plane.

    I'm starting to get an idea of what I think I need to do, and it scares me. Right now, I'm only using a translation value for X and Y. What I *think* I need to do, is to add a third translation value for Z. Next, I think I need to base all three translation factors (X, Y, Z) off of the current ArcBall rotation matrix that I have, thus allowing me to translate the model parallel to the screen plane. Problem being that I have absolutely NO idea how to do something like that. I only got ArcBall working using code samples online...I have no clue how the math works (yeah, I'm embarrassed to say it)

    Anyway, I think I'll turn this over to the opengl math forum and see what those guys say.

    Keep those suggestions coming, please!!! I'm totally lost (and feeling dumb about it too)!

    Thanks again,
    -Langecrew-

  6. #6
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,580

    Re: trouble with arcball rotation and translation


    If I am not mistaken, something like this should do the trick :

    Code :
                glPushMatrix ();
    	// view pos:
              glTranslated (0.1,1.0,0.3);
    	// view rotate (add arcball here) :
              glRotatef (theta, 0.0f, 0.0f, 1.0f);
    // fixed grid
                glBegin (GL_LINE_LOOP);
                glColor3f (1.0f, 0.0f, 0.0f);   glVertex2f (0.0f, 0.80f);
                glColor3f (1.0f, 0.0f, 0.0f);   glVertex2f (0.87f, -0.7f);
                glColor3f (1.0f, 0.0f, 0.0f);   glVertex2f (-0.87f, -0.7f);
                glEnd ();
     
    // moved object :
    	// object pos:
              glTranslated (0.1,0.5,0.3);
        // object rotate:
    //          glRotatef (theta, 0.0f, 0.0f, 1.0f);
     
                glBegin (GL_TRIANGLES);
                glColor3f (1.0f, 0.0f, 0.0f);   glVertex2f (0.0f, 1.0f);
                glColor3f (0.0f, 1.0f, 0.0f);   glVertex2f (0.87f, -0.5f);
                glColor3f (0.0f, 0.0f, 1.0f);   glVertex2f (-0.87f, -0.5f);
                glEnd ();
                glPopMatrix ();

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •