#include #include #include "Stair.h" using namespace std; void disp(void); void idle(void); void reshape(int x,int y); void drawAxis(void); void handleErr(void); void keyb(unsigned char key, int x, int y); static Stair *stair; int main(int argc,char **argv){ glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); glutCreateWindow("Stair"); glClearColor(0.0,0.0,0.0,0.0); stair = new Stair(0.50,0.05,0,0,0,5,20.0); glutDisplayFunc(disp); glutIdleFunc(idle); glutReshapeFunc(reshape); glutKeyboardFunc(keyb); glutMainLoop(); } void disp(void){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f(1.0,1.0,1.0); glPushMatrix(); stair->draw(); drawAxis(); handleErr(); glutSwapBuffers(); glPopMatrix(); } void drawAxis(){ glBegin(GL_LINES); glColor3f(1.0,0.0,0.0); glVertex3f(0.0,0.0,0.0); glVertex3f(0.80,0.0,0.0); glColor3f(0.0,1.0,0.0); glVertex3f(0.0,0.0,0.0); glVertex3f(0.0,0.80,0.0); glColor3f(0.0,0.0,1.0); glVertex3f(0.0,0.0,0.0); glVertex3f(0.0,0.0,0.80); glEnd(); glPushMatrix(); glColor3f(1.0,0.0,0.0); glTranslatef(0.80,0.0,0.0); glRotatef(90,0.0,1.0,0.0); glutSolidCone(0.05,0.1,10,10); glPopMatrix(); glPushMatrix(); glColor3f(0.0,1.0,0.0); glTranslatef(0.0,0.80,0.0); glRotatef(-90,1.0,0.0,0.0); glutSolidCone(0.05,0.1,10,10); glPopMatrix(); glPushMatrix(); glColor3f(0.0,0.0,1.0); glTranslatef(0.0,0.0,0.80); glutSolidCone(0.05,0.1,10,10); glPopMatrix(); } void idle(void){ glutPostRedisplay(); } void keyb(unsigned char key, int x, int y){ stair->setAngle(stair->getAngle()+1.0); } void reshape(int x,int y){ glViewport(0,0,x,y); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(50,(x*1.0)/(y*1.0),1,6); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(2.0,0,0,0,0,0,0,1,0); } void handleErr(void){ static GLenum errCode; errCode = glGetError(); if(errCode != GL_NO_ERROR){ cout << gluErrorString(errCode) << endl;; } }