#ifndef CUBE_H #define CUBE_H #include #include class Cube { private: Point3 pos; Point3 size; Point3 rot; public: Cube(Point3 pos, float size) : pos(pos), size(size,size,size), rot(0,0,0) { } Cube(Point3 pos, Point3 size, Point3 rot) : pos(pos), size(size), rot(rot) { } void paintGL() { float s = 1; glPushMatrix(); // 3) move to destination glTranslatef(pos.x, pos.z, pos.y); // swap yz // 2) rotate glRotatef(rot.x, 1, 0, 0); glRotatef(rot.y, 0, 0, 1); // swap yz glRotatef(rot.z, 0, 1, 0); // 1) scale glScalef(size.x, size.z, size.y); // swap yz glBegin(GL_QUADS); // bottom glNormal3f(0,-1,0); glVertex3f(+s, -s, -s); glVertex3f(+s, -s, +s); glVertex3f(-s, -s, +s); glVertex3f(-s, -s, -s); // top glNormal3f(0,+1,0); glVertex3f(-s, +s, -s); glVertex3f(-s, +s, +s); glVertex3f(+s, +s, +s); glVertex3f(+s, +s, -s); // left glNormal3f(-1,0,0); glVertex3f(-s, -s, -s); glVertex3f(-s, -s, +s); glVertex3f(-s, +s, +s); glVertex3f(-s, +s, -s); // right glNormal3f(+1,0,0); glVertex3f(+s, +s, -s); glVertex3f(+s, +s, +s); glVertex3f(+s, -s, +s); glVertex3f(+s, -s, -s); // front glNormal3f(0,0,+1); glVertex3f(+s, +s, +s); glVertex3f(-s, +s, +s); glVertex3f(-s, -s, +s); glVertex3f(+s, -s, +s); // rear glNormal3f(0,0,-1); glVertex3f(+s, -s, -s); glVertex3f(-s, -s, -s); glVertex3f(-s, +s, -s); glVertex3f(+s, +s, -s); glEnd(); glPopMatrix(); } }; #endif // CUBE_H