Results 1 to 5 of 5

Thread: 3ds translations and rotations

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2001
    Location
    Orange, CA
    Posts
    7

    3ds translations and rotations

    i guess this would be considered another 3ds parsing question, although i have no problem parsing the file but rather displaying it.
    what i have so far:
    a 3x3 rotation matrix
    xyz translation vector
    for all key frames a translation, xyz
    for all key frames a rotation angle and vector
    and object data

    i built a bone structure in 3ds. Now the problem comes in displaying with all these rotations and translations. The process ive done so far is this: first translate negitive direction, then rotate using the rotation matrix. This moves all the objects to the origin and rotates them the same way. then i do frame translation and negitive rotation. This method works for the first frame. I have found that you need to multiply the current matrix by every frame rotation up to the frame you want. This kind of works. the object stay in the right positions, ie the hand does not detatch from the forarm. however it appears the rotation is incorrect. for example when i rotated the waste in 3ds around the y, in my program the character bent around the z. Ive tried switching the y and z, that causes hell. I think i have a basic lack of rotation basics. please help

    thanks,
    the_sausager

  2. #2
    Junior Member Newbie
    Join Date
    Oct 2000
    Location
    Barcelona
    Posts
    18

    Re: 3ds translations and rotations

    Hi!
    Well... note, that opengl makes the transformation in inverse order.
    That's for example: if you have a cube which center is at (3,3,3)... and you wants to rotate that cube, using the center cube as a pivot of rotation... the logical thing to do is:
    first: translate the cube (-3,-3,-3)
    second: rotate the cube
    third: translate the cube (3,3,3)

    well in opengl, that must be at inverse order... something like that:

    glPushMatrix();
    glTranslatef(3,3,3);
    glRotated(...);
    gltranslatef(-3,-3,-3);
    //draw cube
    glPopMatrix();

    Try it, I think it will works...
    Shoot

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2001
    Location
    Orange, CA
    Posts
    7

    Re: 3ds translations and rotations

    I believe that i do have the translation and rotation order correct. Does my rotation order matter?? is

    glRotate( a1, v1, v2, v3 );
    glRotate( a2, b1, b2, b3 );

    the same rotation as

    glRotate( a2, b1, b2, b3 );
    glRotate( a1, v1, v2, v3 );


    ???

    i may have that mixed up

  4. #4
    Junior Member Newbie
    Join Date
    Jul 2001
    Location
    The Netherlands
    Posts
    24

    Re: 3ds translations and rotations

    Hello,

    Yes, the order of rotation is important. The following code will demonstrate:

    Code :
    #include <GL/glut.h>
    #include <stdlib.h>
     
    void init (void)
    {
      glClearColor(0.0, 0.0, 0.0, 0.0);
      glShadeModel(GL_FLAT);
      glEnable (GL_DEPTH_TEST);
    }
     
    void reshape (int w, int h)
    {
      if (h == 0)
          h = 1;
      glViewport(0.0, 0.0, (GLsizei) w, (GLsizei) h);
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      gluPerspective(60.0, (GLfloat) w / (GLfloat) h, 2.0, 20);
      glMatrixMode(GL_MODELVIEW);
    }
     
    void display (void)
    {
      GLfloat angle1 = 30.0, angle2 = 60.0;
     
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      glLoadIdentity();
      gluLookAt(0.0, 0.0, 7.0, 
                0.0, 0.0, 0.0,
                0.0, 1.0, 0.0);
      glPushMatrix();
     
      // First cube  
      glTranslatef(3.0, 1.0, 1.0);
      glRotatef(angle1, 1.0, 0.0, 0.0);  // First rotate along x
      glRotatef(angle2, 0.0, 1.0, 0.0);  // Then rotate along y
      glColor3f(1.0, 0.0, 0.0);
      glutWireCube(1.0);
      glPopMatrix();
     
      // Second cube
      glTranslatef(3.0, 1.0, 1.0);
      glRotatef(angle2, 0.0, 1.0, 0.0); // First rotate along y 
      glRotatef(angle1, 1.0, 0.0, 0.0); // Then rotate along x
      glColor3f(0.0, 1.0, 0.0);
      glutWireCube(1.0);
     
      glFlush();
    }
     
    int main(int argc, char** argv)
    {
      glutInit(&amp;argc, argv);
      glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
      glutInitWindowPosition (100, 100);
      glutInitWindowSize(500, 500);
      glutCreateWindow("Rotation Tests");
      init();
      glutDisplayFunc(display);
      glutReshapeFunc(reshape);
      glutMainLoop();
      return 0; 
    }
    Note that if the order of rotations does not matter, the two cubes should be overlapping each other, and they don't.

    Ritchie

  5. #5
    Senior Member Regular Contributor
    Join Date
    Feb 2001
    Location
    Montréal, QC, Canada
    Posts
    304

    Re: 3ds translations and rotations

    Have a look at CLAX : it is a free 3ds loader with full spline keyframer. Seems to work with every .3ds I feed it.
    Free, full source, not big so easy to understand.
    http://www.geocities.com/SiliconValley/Bay/6525/

Similar Threads

  1. order of translations/rotations
    By mikethebike in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 02-07-2012, 12:37 AM
  2. extract rotations and translations from matrix4x4
    By deshan in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 06-01-2011, 06:40 AM
  3. Collapsing a Seq of Translations/Quatern Rotations
    By Zed Gimbal in forum OpenGL: General
    Replies: 2
    Last Post: 03-29-2009, 09:01 AM
  4. Translations and rotations?!
    By esuvs in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-18-2003, 06:10 PM
  5. Problems with translations/rotations...
    By Evil-Dog in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 07-29-2001, 11:49 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