raijinken

06-03-2004, 10:11 AM

Hi. I need to plot a 3D graphic using OpenGL. Y display labels with the numbers of the axis using GL_QUADS. The axis and the graphic can be rotated but i need the labels to face always front so they'll be readable by user.

This is my code, comented to explain what i do in each line:

//Get the modelview matrix with rotations and translations

glGetFloatv(GL_MODELVIEW_MATRIX, &mv[0][0]);

//Store the matrix

glPushMatrix();

//Load identity matrix

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

//Store the position into an array

//I'm sure the coordinates are right cause i use them

//to draw the axis

position[0] = width+2;

position[1] = YAxisCut;

position[2] = ZAxisCut;

position[3] = 1.0f;

//This function multiplies mv x position and stores

//the resulting vector into position2

transformarVector(position, mv, position2);

//Translate to position2 coordinates. That's where i might

//be wrong; I'm supposing that being working with the

//identity matrix and multiplying my coordinates by

//the modelview matrix, i will get the correct coordinates

//to work with the identity matrix

glTranslatef(position2[0], position2[1], position2[2]);

//Once i'm translated to the point, i can draw the label

//I need to be working with the identity matrix to

//draw it always facing front the screen

point.x = 0; point.y = 0; point.z = 0;

//This function draws the label with point as center.

//It works well and draws the label facing front. What have

//to be wrong is the point which i translated to.

drawLabel(label[0], point);

//Restore the matrix for future drawing

glPopMatrix();

---------------------

I don't know if the entire idea is wrong or if i'm doing someting wrong.

If you have another idea or see something wrong in my code, please tell me.

Sorry about my poor English; hope you can understand it.

Thanks in advance.

This is my code, comented to explain what i do in each line:

//Get the modelview matrix with rotations and translations

glGetFloatv(GL_MODELVIEW_MATRIX, &mv[0][0]);

//Store the matrix

glPushMatrix();

//Load identity matrix

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

//Store the position into an array

//I'm sure the coordinates are right cause i use them

//to draw the axis

position[0] = width+2;

position[1] = YAxisCut;

position[2] = ZAxisCut;

position[3] = 1.0f;

//This function multiplies mv x position and stores

//the resulting vector into position2

transformarVector(position, mv, position2);

//Translate to position2 coordinates. That's where i might

//be wrong; I'm supposing that being working with the

//identity matrix and multiplying my coordinates by

//the modelview matrix, i will get the correct coordinates

//to work with the identity matrix

glTranslatef(position2[0], position2[1], position2[2]);

//Once i'm translated to the point, i can draw the label

//I need to be working with the identity matrix to

//draw it always facing front the screen

point.x = 0; point.y = 0; point.z = 0;

//This function draws the label with point as center.

//It works well and draws the label facing front. What have

//to be wrong is the point which i translated to.

drawLabel(label[0], point);

//Restore the matrix for future drawing

glPopMatrix();

---------------------

I don't know if the entire idea is wrong or if i'm doing someting wrong.

If you have another idea or see something wrong in my code, please tell me.

Sorry about my poor English; hope you can understand it.

Thanks in advance.