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

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

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

Hello,

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

#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(&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

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/