// Cubes.cpp: implementation of the CCubes class. // ////////////////////////////////////////////////////////////////////// #include "Cubes.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// GLfloat gCubeVertices[8][3] ={{-1.5,-1.0,-0.5},{1.5,-1.0,-0.5},{1.5,1.0,-0.5}, {-1.5,1.0,-0.5}, {-1.5,-1.0,0.5},{1.5,-1.0,0.5}, {1.5,1.0,0.5}, {-1.5,1.0,0.5}}; GLfloat gCubeColors[12][3] ={{1.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0}, {1.0,1.0,0.0},{1.0,0.0,1.0},{0.0,1.0,1.0}, {1.0,0.5,0.0},{1.0,0.0,0.5},{0.5,1.0,0.0}, {0.0,1.0,0.5},{0.5,0.0,1.0},{0.0,0.5,1.0}}; CCubes::CCubes(): CGeometry() { Type=CUBE; Name="cube"; setVertices(gCubeVertices); setColors(gCubeColors); Visible=true; } CCubes::~CCubes() { } void CCubes::setVertices(GLfloat Vertices[][3]) { int i, j; for (i=0;i<8;i++) for(j=0;j<3;j++) cubeVertices[i][j]=Vertices[i][j]; } void CCubes::setColors(GLfloat cols[12][3]) { int i, j; for (i=0;i<12;i++) for(j=0;j<3;j++) colors[i][j]=cols[i][j]; } // Draw ling in different colors void CCubes::drawLine(GLfloat Vertices[][3], int a, int b) { glBegin(GL_LINES); glVertex3fv(Vertices[a]); glVertex3fv(Vertices[b]); glEnd(); } // Draw cube's one plane in same color void CCubes::drawCubePlane(GLfloat Vertices[][3], int a, int b, int c, int d) { // Draw the sides of the cube glBegin(GL_QUADS); glVertex3fv(Vertices[a]); glVertex3fv(Vertices[b]); glVertex3fv(Vertices[c]); glVertex3fv(Vertices[d]); glEnd(); } // Draw cube's one plane in different color void CCubes::drawCubePlane(GLfloat Vertices[][3], int a, int b, int c, int d, int color) { glColor3fv(colors[color]); // Draw the sides of the cube glBegin(GL_QUADS); glVertex3fv(Vertices[a]); glVertex3fv(Vertices[b]); glVertex3fv(Vertices[c]); glVertex3fv(Vertices[d]); glEnd(); //drawCubePlane(Vertices[][3],a,b,c,d); } //Draw cube in different colors void CCubes::drawCube() { drawCubePlane(cubeVertices,0,1,2,3,0); drawCubePlane(cubeVertices,0,1,5,4,1); drawCubePlane(cubeVertices,1,2,6,5,2); drawCubePlane(cubeVertices,2,3,7,6,4); drawCubePlane(cubeVertices,3,0,4,7,3); drawCubePlane(cubeVertices,4,5,6,7,5); } //Draw cube in same colors void CCubes::drawCube(GLfloat color[]) { glColor3fv(color); drawCubePlane(cubeVertices,0,1,2,3); drawCubePlane(cubeVertices,0,1,5,4); drawCubePlane(cubeVertices,1,2,6,5); drawCubePlane(cubeVertices,2,3,7,6); drawCubePlane(cubeVertices,3,0,4,7); drawCubePlane(cubeVertices,4,5,6,7); } // Draw Cube in wire frame void CCubes::drawCubeInWireFrame() { glColor4f(0.0,0.0,0.0,1.0); drawLine(cubeVertices,0,1); drawLine(cubeVertices,0,3); drawLine(cubeVertices,0,4); drawLine(cubeVertices,1,2); drawLine(cubeVertices,1,5); drawLine(cubeVertices,2,3); drawLine(cubeVertices,2,6); drawLine(cubeVertices,3,7); drawLine(cubeVertices,4,5); drawLine(cubeVertices,4,7); drawLine(cubeVertices,5,6); drawLine(cubeVertices,6,7); } void CCubes::render() { if(isSelected()) glColor3fv(HighlightColor); else glColor3fv(NormalColor); glutWireCube(1.0); } void CCubes::renderSolid() { if(isSelected()) glColor3fv(HighlightColor); else glColor3fv(NormalColor); glutSolidCube(1.0); }