/** Rotate random slices of the Rubik's cube */ void randomRotations(int numRotations) { for (int i=0; i<numRotations; i++) { int r = rand() % NUM_PLANES; rotateSlice(positions,r/3,r%3,rand()%2); rotationProgress = 1.0f; updateRotationProgress(); } }
void GameCamera::update( const glm::vec3 & position, const glm::vec3 & direction, float seconds, float normalizedCaveDistance) { updateRotationProgress(seconds); updateLookAt(position, direction, normalizedCaveDistance); }
void display() { glClearColor(0.5, 0.5, 0.5, 1.0); glClearDepth(1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glBindVertexArray(vao); // Pass info about the rotation/scale of the entire Rubik's cube glUniformMatrix4fv(uRotationMat, 1, 0, rotationMat); glUniform1f(uScale,scale); updateRotationProgress(); // Let the vertex shader handle all the angle calculations glUniform1f(uRotationProgress,rotationProgress); // Draw 27 cubes based on initial cube glClearStencil(0); glStencilMask(0xFF); glEnable(GL_STENCIL_TEST); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); for (int i=0; i<NUM_CUBES; i++) { // Stencil buffer: // http://en.wikibooks.org/wiki/OpenGL_Programming/Object_selection glStencilFunc(GL_ALWAYS, i+1, 0xFF); // i+1 because 0 is used for background glUniform1i(uCubeId,i); glUniform1i(uPositions,positions[i]); glUniform1iv(uColors,FACES_PER_CUBE,colors[i]); glUniform1i(uRotationAxes,rotationAxes[i]); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glDrawElements(GL_TRIANGLES, VERT_PER_CUBE, GL_UNSIGNED_SHORT, 0); } glBindVertexArray(0); glutSwapBuffers(); }