I’m an opengl beginner.I’m sorry my english is very poor,I am just puzzled by my program,because i think it show me that z axis
is point to the inner of the screen.Shouldn’t it point out?
the follow is my program;
#include <gl/glut.h>
static float angle_x = 0, angle_y=-10,angle_z=0;
void axis() //draw the axis
{
glBegin(GL_LINES);
glColor3f(1.0,0.0,0.0);
glVertex3f(-0.25f,0.0f,0.0f); //x red
glVertex3f(0.8f,0.0f,0.0f);
glColor3f(0.8f,0.5f,0.9f);
glVertex3f(0.0f,-0.25f,0.0f); //y
glVertex3f(0.0f,0.8f,0.0f);
glColor3f(1.0,1.0,1.0);
glVertex3f(0.0f,0.0f,-0.5f); //z white
glVertex3f(0.0f,0.0f,0.8f);
glEnd();
glBegin(GL_TRIANGLES);
glVertex3f(-0.1,-0.1,0.8);//z
glVertex3f(0.1,0.1,0.8);
glVertex3f(0.0,0.0,1.0);
glColor3f(1.0,0.0,0.0);//x
glVertex3f(0.8,0.1,0.1);
glVertex3f(0.8,-0.1,-0.1);
glVertex3f(1.0,0.0,0.0);
glColor3f(0.8f,0.5f,0.9f);//y
glVertex3f(-0.1,0.8,0.1);
glVertex3f(0.1,0.8,-0.1);
glVertex3f(0.0,1.0,0.0);
glEnd();
}
void myplay()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
/* gluPerspective(60.0f,1,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0,0,-2);
*/
glRotatef(-30,0,1,0);
glRotatef(-30,1,0,0);
axis();
glBegin(GL_POLYGON);
glColor3f(1.0,0.0,0.0);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(0.0f,0.5f,0.0f);
glVertex3f(0.5f,0.5f,0.0f);
glVertex3f(0.5f,0.0f,0.0f);
glEnd();
glBegin(GL_POLYGON);
glColor3f(1.0f,1.0,0.0);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(0.0f,0.5f,0.0f);
glVertex3f(0.0f,0.5f,0.5f);
glVertex3f(0.0f,0.0f,0.5f);
glEnd();
glBegin(GL_POLYGON);
glColor3f(1.0,0.0,1.0);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(0.0f,0.0f,0.5f);
glColor3f(1.0,0.0,0.0);
glVertex3f(0.5f,0.0f,0.5f);
glColor3f(0.0,1.0,0.0);
glVertex3f(0.5f,0.0f,0.0f);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.0,1.0,0.0);
glVertex3f(0.0f,0.5f,0.0f);
glVertex3f(0.5f,0.5f,0.0f);
glVertex3f(0.5f,0.5f,0.5f);
glVertex3f(0.0f,0.5f,0.5f);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.0,1.0,1.0);
glVertex3f(0.5f,0.5f,0.0f);
glVertex3f(0.5f,0.5f,0.5f);
glVertex3f(0.5f,0.0f,0.5f);
glVertex3f(0.5f,0.0f,0.0f);
glEnd();
glBegin(GL_POLYGON);
glColor3f(0.4,1.0,0.6);
glVertex3f(0.5f,0.5f,0.5f);
glVertex3f(0.5f,0.0f,0.5f);
glVertex3f(0.0f,0.0f,0.5f);
glVertex3f(0.0f,0.5f,0.5f);
glEnd();
glFlush();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(300,200);
glutInitWindowSize(400,400);
glutCreateWindow(“cube”);
glutDisplayFunc(&myplay);
glutMainLoop();
return 0;
}
I think the result tell me that the Z axis is point to the innner of the screen.why?
and i found that if i add the remarked code in the founction myplay(),the Z axis direction
will point out,it will be ok,but at this time the rotate angle will be not right .why?
Thank you very much .Now is the spring festival in china ,I wish
you happy new year,have a good luck!恭喜发财!