PDA

View Full Version : Rotation and Translation in openGL



padre
01-16-2010, 04:13 AM
Iím rally new in openGL and already have some problems 
Iím loading meshes, extracted from 3D images, and the meshes have always different orientations. My task at the university is to transform the meshes in two defined orientations. Here is the orientations axis:

1. x = (1,0,0), y=(0,1,0) and z=(0,0,1) //axial view
2. x = (1,0,0), y=(0,0,1) and z=(0,-1,0) // sagital view

For the loaded mesh I can compute the orientation and the origin. So I defined a transformation matrix which is build from the inverse orientation of the mesh and the negative origin. In other words I transform first the mesh into its origin:

transMat(0,0) = ax[0]; transMat (0,1) = ax[1]; transMat (0,2) = ax[2]; transMat (0,3) = -org[0];
transMat (1,0) = ay[0]; transMat (1,1) = ay[1]; transMat (1,2) = ay[2]; transMat (0,3) = -org [1];
transMat (2,0) = az[0]; transMat (2,1) = az[1]; transMat (2,2) = az[2]; transMat (0,3) = -org [2];
transMat (2,0) = 0; transMat (2,1) =0 ; transMat (2,2) =0; transMat (0,3) = 1;

mesh->ApplyTransformation(transMat) ;

and then I apply the new orientation, e.g for case number 1:

ax = (1,0,0);
ay =(0,1,0);
az=(0,0,1) ;

transMat(0,0) = ax[0]; transMat (0,1) = ax[1]; transMat (0,2) = ax[2]; transMat (0,3) = org[0];
transMat (1,0) = ay[0]; transMat (1,1) = ay[1]; transMat (1,2) = ay[2]; transMat (0,3) = org [1];
transMat (2,0) = az[0]; transMat (2,1) = az[1]; transMat (2,2) = az[2]; transMat (0,3) = org [2];
transMat (2,0) = 0; transMat (2,1) =0 ; transMat (2,2) =0; transMat (0,3) = 1;

mesh->ApplyTransformation(transMat) ;

with this two operation I have the mesh in the required orientation. However, my supervisor at the university said I should not transform the mesh itself, but to use the MODEL_VIEW matrin in openGL in order to get the same required orientation. And here start my problem 

Here is how the openGL is initialized:

VVector3Dd eyeVector = VVector3Dd(0.0, 0.0, 150.0);
upVector = VVector3Dd(0.0, 1.0, 0.0);

void init()
{
glShadeModel(GL_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
}

void display()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glPushMatrix();
glLoadIdentity();
gluLookAt(eyeVector[0], eyeVector[1], eyeVector[2], 0.0, 0.0, 0.0, upVector[0], upVector[1], upVector[2]);

renderMesh();
glPopMatrix();
glutSwapBuffers();
}

void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glOrtho(-0.1 * w/2, 0.1 * w/2, -0.1 * h/2, 0.1 * h/2, 0.0, 1000.0);

glMatrixMode(GL_MODELVIEW);
}

can someone help me how to define the same orientations in openGL with probably glRotatef(..) and glTranslatef(..)

thank you very much
padre