the 3 coordinates axes

Hi all,

How can i draw the three coordinate axes in opengl and show the rotations of these axes simultaneous if i have the rotation angles with respect to each axes(euler angles)?

Pls help i wan use for some application development or tell me the best tutorial site with descriptions and sample codes.

cheers,

Best take the columns (or rows), depends on what matrix convention you use out of your viewing matrix. This will get you 3 line directions. Select endpoints for the 3 lines you’re going to draw and then draw them.

thx for your repley.

but i don’t understand may be can you put a code sample please since i am completely new to Opengl.

I have put my Opengl code below. My intention is to call start_Opengl ()from main, then start showing the rotation of the three coordinate axes based on rotation matrix RotMat[] which is updated for every call of start_Opengl() until i am done with the loop i have in my main program. Every call to start_Opengl() has different RotMat[] and i suppose should also show different rotation. I want show the rotation of the 3 axes for every iteration.

Pls help me

int start_Opengl(int argc,char** argv) {//Start opengl

glutInitWindowSize(250,250);
glutInitWindowPosition(40,40);
glutInit(&argc, argv);//argc=count of argmts supplied to progrm, array pts to the strngs w/c 'r those argmts
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE);
glutCreateWindow("head pose");//window to show Pose direction using coordiante axes

initGL();//initialize GL

glutReshapeFunc(resize);
glutDisplayFunc(display);
//glutKeyboardFunc(key);

glutIdleFunc(idle);

glutMainLoop();

return 1;

}

void initGL() {
glutSetOption ( GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION ) ;

glClearColor(1,1,1,1);
glShadeModel(GL_SMOOTH);

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);

glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial ( GL_FRONT, GL_AMBIENT_AND_DIFFUSE );

glLightfv(GL_LIGHT0, GL_AMBIENT,  light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE,  light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);

glMaterialfv(GL_FRONT, GL_AMBIENT,   mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE,   mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR,  mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);

glEnable(GL_LIGHTING);

glGenTextures(1, &textureID);

}

void resize(int width, int height)
{
const float ar = (float) width / (float) height;

glViewport(0, 0, width, height);//sets the viewPort

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluPerspective(40,1.0,0.01,1000.0);//specify the perspective projection matrix

glMatrixMode(GL_MODELVIEW);
glLoadIdentity() ;

}

void display(void)
{
glClearColor(1.0f, 1.0f, 1.0f, 0.5f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

gluLookAt(0,0,0,0,0,1,0,1,0);

//----------Axes
glPushMatrix();

glTranslated(0,0,5);

glPushMatrix();
float  Rot[16] = {	RotMat[0],RotMat[1],RotMat[2],0,
					RotMat[3],RotMat[4],RotMat[5],0,
					RotMat[6],RotMat[7],RotMat[8],0,
					0,	   0,	  0		,1};//Rotation Matrix from slovePnP
glMultMatrixf(Rot);//multiply the current matrix with the specified matrix
glRotated(180,1,0,0);// rotate around to face camera

/********************************/
/*			draw picture		*/

glEnable(GL_TEXTURE_2D);//(NEW) Enable 2D texturing
glBindTexture(GL_TEXTURE_2D, textureID);// (NEW) used to select the texture you wanted to use

glPushMatrix();

glBegin(GL_QUADS);// Just create a simple square
glTexCoord2f(0,1);//(NEW) This is the coordinate position on the texture we want to draw at this vertex (This is the upper left corner)
glVertex2f(-1,1);//This is the upper left corner of the square
glTexCoord2f(1,1);//This is the upper right corner of the bitmap
glVertex2f(1,1);
glTexCoord2f(1,0);//This is the lower right corner of the bitmap
glVertex2f(1,-1);
glTexCoord2f(0,0);//The lower left corner
glVertex2f(-1,-1);
glEnd();

glPopMatrix();

glDisable(GL_TEXTURE_2D);//(NEW) Disable 2D texturing
/*			end draw picture		*/
/************************************/


//Z = red
glPushMatrix();
glRotated(180,0,1,0);
glColor3d(1,0,0);
glutSolidCylinder(0.05,1,15,20);
glTranslated(0,0,1);//multiply the current matrix by translation matrix
glScaled(.1,.1,.1);
glutSolidTetrahedron();
glPopMatrix();

//Y = green
glPushMatrix();
glRotated(-90,1,0,0);
glColor3d(0,1,0);
glutSolidCylinder(0.05,1,15,20);
glTranslated(0,0,1);
glScaled(.1,.1,.1);
glutSolidTetrahedron();
glPopMatrix();

//X = blue
glPushMatrix();
glRotated(-90,0,1,0);
glColor3d(0,0,1);
glutSolidCylinder(0.05,1,15,20);
glTranslated(0,0,1);
glScaled(.1,.1,.1);
glutSolidTetrahedron();
glPopMatrix();

glPopMatrix();
glPopMatrix();
//----------End axes

glutSwapBuffers();

}

void idle(void)
{
glutPostRedisplay();
}

Hi,
Is this code for window based system? Because I am not able to run this on windows.
Any ways .
You can create axes by creating coordinate functions for e.g at 0,0,0.
with the help of lines and use it for your reference purpose

void drawAxes()
{
glBegin( GL_LINES );
glColor3f( 1., 0., 0. );
glVertex3f( -50., 0., 0. );
glVertex3f( 50., 0., 0. );
glEnd();

glBegin( GL_LINES );
	glColor3f( 0., 0., 1. );
	glVertex3f( 0., -50., 0. );
	glVertex3f( 0., 50., 0. );
glEnd();

glBegin( GL_LINES );
	glColor3f( 0., 1., 0. );
	glVertex3f( 0., 0., -50. );
	glVertex3f( 0., 0., 50. );
glEnd();

}

You need the first 3 columns of the matrix that:

gluLookAt(0,0,0,0,0,1,0,1,0);

generates.

no it is for linux, further more there are some headers that u have to include and some variable declarations. What i want is not only draw the axes, but i wan show the rotation for every iteration of the axis right. I have rotation matrix RotMat[] as u can see from the code.

regards,

i don’t understand wat u mean by the matrix generated by glLookAt()? and how can i use in my code?