QVector<Eigen::AlignedBox3d> splitBox( const Eigen::AlignedBox3d & box, Vector3 axis ) { Eigen::AlignedBox3d b1 = box, b2 = box; Vector3 delta = axis.array() * ((box.sizes() * 0.5).array()); return QVector<Eigen::AlignedBox3d>() << box.intersection(b1.translate(-delta)) << box.intersection(b2.translate(delta)); }
void Viewer::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if(false) { // Default camera: glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-2, 2, -1.5, 1.5, 1, 40); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0, 0, -3); glRotatef(50, 1, 0, 0); glRotatef(70, 0, 1, 0); // Draw a white grid "floor" for the tetrahedron to sit on. glColor3d(0.8, 0.8, 0.7); glBegin(GL_LINES); for (GLfloat i = -2.5; i <= 2.5; i += 0.25) { glVertex3f(i, 2.5, 0); glVertex3f(i, -2.5, 0); glVertex3f(2.5, i, 0); glVertex3f(-2.5, i, 0); } glEnd(); // Draw the tetrahedron. if(false) { glBegin(GL_TRIANGLE_STRIP); glColor3f(1, 1, 1); glVertex3f(0, 0, 2); glColor3f(1, 0, 0); glVertex3f(-1, 1, 0); glColor3f(0, 1, 0); glVertex3f(1, 1, 0); glColor3f(0, 0, 1); glVertex3f(0, -1.4f, 0); glColor3f(1, 1, 1); glVertex3f(0, 0, 2); glColor3f(1, 0, 0); glVertex3f(-1, 1, 0); glEnd(); } } if( !isReady ) return; // Setup camera Eigen::Vector3d center, eye; { // Bounding volume { Eigen::Vector3d dir( cos(t), sin(t), 0.25); Eigen::AlignedBox3d bbox; for(auto v : vertices) bbox.extend(v); double radius = bbox.sizes().norm() * 2.75; center = bbox.center(); eye = center + (dir.normalized() * radius); } auto projectionMatrix = perspective<double>(20, 1.0, 0.01, 1000); auto cameraMatrix = lookAt< Eigen::Vector3d >(eye, center, Eigen::Vector3d(0,0,1)); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glLoadMatrixd( projectionMatrix.data() ); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glLoadMatrixd( cameraMatrix.data() ); } // Added user rotation { glRotatef(xRot / 16.0, 1.0, 0.0, 0.0); glRotatef(yRot / 16.0, 0.0, 1.0, 0.0); glRotatef(zRot / 16.0, 0.0, 0.0, 1.0); } glColor3d(1,0,0); // Render geometry { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glColor3d(0,0,0); glDisable(GL_LIGHTING); glLineWidth(6); //RenderMesh(); glClear(GL_DEPTH_BUFFER_BIT); //glEnable(GL_LIGHTING); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glColor3d(0,0,0); RenderMesh(); } }