19,468
社区成员
发帖
与我相关
我的任务
分享
void DrawKoordSystem (GLfloat xmin, GLfloat xmax, GLfloat ymin, GLfloat ymax,
GLfloat zmin, GLfloat zmax)
{
GLfloat w;
w = 2.0;
glLineWidth(w);
//
glBegin(GL_LINES);
// 坐标系x轴
glColor3f ( 1.0, 0.0, 0.0 );// red
glVertex3f (xmin,0,0);
glVertex3f (xmax,0,0);
// 坐标系Y轴
glColor3f ( 0.0, 1.0, 0.0 );// green
glVertex3f (0,ymin,0);
glVertex3f (0,ymax,0);
// 坐标系Z轴
glColor3f ( 0.0, 0.5, 1.0 );// blue
glVertex3f (0,0,zmin);
glVertex3f (0,0,zmax);
glEnd();
//
glMatrixMode(GL_MODELVIEW);
}
void DrawKoordSystem (GLfloat xmin, GLfloat xmax, GLfloat ymin, GLfloat ymax,
GLfloat zmin, GLfloat zmax)
{
GLfloat i;
GLfloat akt_color[4];
GLint akt_mode;
// spitze // arrow
GLUquadricObj *spitze = gluNewQuadric();
if (!spitze) return;
glPushAttrib(GL_ALL_ATTRIB_BITS);
glGetFloatv(GL_CURRENT_COLOR, akt_color);
glDisable (GL_LIGHTING);
// X segemnts
glBegin(GL_LINES);
glColor3f ( 1.0, 0.0, 0.0 );
glVertex3f (xmin,0,0);
glVertex3f (xmax,0,0);
for (i = xmin; i <= xmax; i++)
{
glVertex3f(i, -0.15, 0.0);
glVertex3f(i, 0.15, 0.0);
}
// Y segments
glColor3f ( 0.0, 1.0, 0.0 );
glVertex3f (0,ymin,0);
glVertex3f (0,ymax,0);
for (i = ymin; i <= ymax; i++)
{
glVertex3f (-0.15, i, 0.0);
glVertex3f (0.15, i, 0.0);
}
// Z segments
glColor3f ( 0.0, 0.0, 1.0 );
glVertex3f (0,0,zmin);
glVertex3f (0,0,zmax);
for (i = zmin; i <= zmax; i++)
{
glVertex3f(-0.15, 0.0, i);
glVertex3f(0.15, 0.0, i);
}
glEnd();
// Ende Linienpaare // end scale segments
glGetIntegerv(GL_MATRIX_MODE, &akt_mode);
glMatrixMode(GL_MODELVIEW);
// zuerst die X-Achse // arrow first X-axis
glPushMatrix();
glTranslatef(xmax, 0., 0.);
glRotatef(90., 0., 1., 0.);
glColor3f( 1.0, 0.0, 0.0 );// red
gluCylinder(spitze, 0.12, 0., 1., 10, 10);
glPopMatrix();
// dann die Y-Achse // then Y-axis
glPushMatrix();
glTranslatef(0., ymax, 0.);
glRotatef(-90., 1., 0., 0.);
glColor3f( 0.0, 1.0, 0.0 );// green
gluCylinder(spitze, 0.12, 0., 1., 10, 10);
glPopMatrix();
// zum Schluss die Z-Achse // at last Z-axis
glPushMatrix();
glTranslatef(0., 0., zmax);
glColor3f( 0.0, 0.0, 1.0 );// blue
gluCylinder(spitze, 0.12, 0., 1., 10, 10);
glPopMatrix();
//
glMatrixMode(akt_mode);
glColor4fv(akt_color);
glPopAttrib();
gluDeleteQuadric(spitze);
}
DrawKoordSystem (-5, 5, -5, 5, -5, 5);