#pragma once #include #include #include #include class Prim { public: float lx,ly,lz; float rx,ry,rz; float sx,sy,sz; float cx,cy,cz; int type; GLUquadricObj *quadObj; Prim() {} Prim(char* ttype) { if(strstr(ttype,"box")!=NULL) type=1; else type=2; quadObj = gluNewQuadric(); } void draw() { GLfloat*c = new GLfloat[3]; c[0]=cx; c[1]=cy; c[2]=cz; glMaterialfv(GL_FRONT, GL_DIFFUSE, c); glPushMatrix(); //glLoadIdentity(); glTranslatef(lx, ly, lz); glRotatef(rx, 1.0, 0.0, 0.0); glRotatef(ry, 0.0, 1.0, 0.0); glRotatef(rz, 0.0, 0.0, 1.0); glScalef(sx,sy,sz); if(type==1) { glBegin(GL_POLYGON); glNormal3f(0.0, 0.0, 2.0); glVertex3f(2.0, 2.0, 2.0); glVertex3f(-2.0, 2.0, 2.0); glVertex3f(-2.0, -2.0, 2.0); glVertex3f(2.0, -2.0, 2.0); glEnd(); glBegin(GL_POLYGON); glNormal3f(0.0, 0.0, -2.0); glVertex3f(2.0, 2.0, -2.0); glVertex3f(2.0, -2.0, -2.0); glVertex3f(-2.0, -2.0, -2.0); glVertex3f(-2.0, 2.0, -2.0); glEnd(); glBegin(GL_POLYGON); glNormal3f(-2.0, 0.0, 0.0); glVertex3f(-2.0, 2.0, 2.0); glVertex3f(-2.0, 2.0, -2.0); glVertex3f(-2.0, -2.0, -2.0); glVertex3f(-2.0, -2.0, 2.0); glEnd(); glBegin(GL_POLYGON); glNormal3f(2.0, 0.0, 0.0); glVertex3f(2.0, 2.0, 2.0); glVertex3f(2.0, -2.0, 2.0); glVertex3f(2.0, -2.0, -2.0); glVertex3f(2.0, 2.0, -2.0); glEnd(); glBegin(GL_POLYGON); glNormal3f(0.0, 2.0, 0.0); glVertex3f(-2.0, 2.0, -2.0); glVertex3f(-2.0, 2.0, 2.0); glVertex3f(2.0, 2.0, 2.0); glVertex3f(2.0, 2.0, -2.0); glEnd(); glBegin(GL_POLYGON); glNormal3f(0.0, -2.0, 0.0); glVertex3f(-2.0, -2.0, -2.0); glVertex3f(2.0, -2.0, -2.0); glVertex3f(2.0, -2.0, 2.0); glVertex3f(-2.0, -2.0, 2.0); glEnd(); } else { gluQuadricDrawStyle(quadObj, GLU_FILL); gluCylinder(quadObj, 2, 2, 2, 20, 20); } glPopMatrix(); delete c; } };