void ShapesUI::draw() { // Sets up the viewport and background color setup3DDrawing( Color( 0,0,0 ), width, height, true ); // Changes the way triangles are drawn switch ( shapesUI->getDisplayType() ) { case DISPLAY_WIREFRAME: { glDisable(GL_LIGHTING); glPolygonMode(GL_FRONT, GL_LINE); glColor3f(1.0f, 1.0f, 1.0f); } break; case DISPLAY_FLAT_SHADING: { glEnable(GL_LIGHTING); glPolygonMode(GL_FRONT, GL_FILL); glColor3f(1.0f, 1.0f, 1.0f); glShadeModel(GL_FLAT); } break; case DISPLAY_SMOOTH_SHADING: { glEnable(GL_LIGHTING); glPolygonMode(GL_FRONT, GL_FILL); glColor3f(1.0f, 1.0f, 1.0f); glShadeModel(GL_SMOOTH); } break; default: break; } // Setup the camera gluLookAt( 3.5 * cos( shapesUI->getYRot() ) * cos( shapesUI->getXRot() ), 3.5 * sin( shapesUI->getYRot() ), 3.5 * cos( shapesUI->getYRot() ) * sin( shapesUI->getXRot() ), 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); // ToDo: draw your shape here // DO NOT put the actual draw OpenGL code here - put it in the shape class and call the draw method if (current != 0){ if(shapesUI->getShapeType() != SHAPE_TORUS) { current->draw(); } else Torus(5,5); } endDrawing(); }
void InteractiveUI::draw() { setup3DDrawing( scene.getBackground(), scene.getCamera().getWidth(), scene.getCamera().getHeight(), false ); // Sets up the camera and model view matrices glMatrixMode(GL_PROJECTION); glLoadMatrixd( &ibar.getCamera().getProjection()(0,0) ); glMatrixMode(GL_MODELVIEW); glLoadMatrixd( &ibar.getCamera().getWorldToCamera()(0,0) ); glPushAttrib( GL_ALL_ATTRIB_BITS ); // Start drawing at the top of the tree scene.draw(); glPopAttrib(); if ( interactiveUI->m_bWidget->value() ) { glEnable( GL_LIGHT0 ); widget.DrawWidget(); } if ( interactiveUI->m_bIBar->value() ) ibar.Draw( bIsMouseOverIBar, interactiveUI->m_bIBarHelp->value() ? true : false ); endDrawing(); }
void IntersectionUI::draw() { setup3DDrawing( Color(1,1,1), width, height, true ); glMatrixMode(GL_MODELVIEW); gluLookAt( 3.5 * cos( intersectionUI->getYRot() ) * cos( intersectionUI->getXRot() ), 3.5 * sin( intersectionUI->getYRot() ), 3.5 * cos( intersectionUI->getYRot() ) * sin( intersectionUI->getXRot() ), 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); glDisable(GL_LIGHTING); if ( intersectionUI->m_bGrid->value() ) { glBegin(GL_LINES); // draw grid glColor3f(0.0f, 0.0f, 0.0f); for (int i = 0; i <= 10; i++) { float s = -2.0f + i / 2.5f; glVertex3f(s, 0.0f, -2.0f); glVertex3f(s, 0.0f, 2.0f); glVertex3f(-2.0f, 0.0f, s); glVertex3f( 2.0f, 0.0f, s); } glEnd(); // draw (X,Y,Z) axes glLineWidth(3.0f); glBegin(GL_LINES); glColor3f(1.0f, 0.0f, 0.0f); glVertex3f(-2.0f, 0.0f, 0.0f); glVertex3f( 2.0f, 0.0f, 0.0f); glColor3f(0.0f, 1.0f, 0.0f); glVertex3f(0.0f, -2.0f, 0.0f); glVertex3f(0.0f, 2.0f, 0.0f); glColor3f(0.0f, 0.0f, 1.0f); glVertex3f(0.0f, 0.0f, -2.0f); glVertex3f(0.0f, 0.0f, 2.0f); glEnd(); glLineWidth(1.0f); } // compute ray origin from parameters Point3 pAt( intersectionUI->m_dXAt->value(), intersectionUI->m_dYAt->value(), intersectionUI->m_dZAt->value() ); // compute ray direction from parameters Vector3 dir; dir[0] = cos(intersectionUI->getPhi()) * cos(intersectionUI->getTheta()); dir[1] = sin(intersectionUI->getPhi()); dir[2] = cos(intersectionUI->getPhi()) * sin(intersectionUI->getTheta()); const Point3 pE1 = pAt - dir * 2.0; const Point3 pE2 = pAt + dir * 2.0; if (intersectionUI->m_bRay->value()) { glPointSize(6.0f); glLineWidth(3.0f); glColor3f(0.5f, 0.5f, 0.0f); glBegin(GL_POINTS); glVertex3dv( &pE1[0]); glEnd(); glColor3f(0.5f, 0.0f, 0.5f); glBegin(GL_LINES); glVertex3dv( &pE1[0]); glVertex3dv( &pE2[0]); glEnd(); glLineWidth(1.0f); glPointSize(1.0f); } if (intersectionUI->m_bRayShadow->value()) { glPointSize(6.0f); glLineWidth(2.0f); glColor3f(0.1f, 0.1f, 0.0f); glBegin(GL_POINTS); glVertex3d( pE1[0], 0.0, pE1[2] ); glEnd(); glColor3f(0.0f, 0.0f, 0.0f); glEnable(GL_LINE_STIPPLE); glLineStipple(1, 0xF0F0); glBegin(GL_LINES); glVertex3d( pE1[0], 0.0, pE1[2] ); glVertex3d( pE2[0], 0.0, pE2[2] ); glVertex3d( pE1[0], 0.0, pE1[2] ); glVertex3dv( &pE1[0]); glVertex3d( pE2[0], 0.0, pE2[2] ); glVertex3dv( &pE2[0]); glEnd(); glLineWidth(1.0f); glPointSize(1.0f); glDisable(GL_LINE_STIPPLE); } glEnable(GL_LIGHTING); glEnable( GL_BLEND ); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); const float colPlane[4] = {0.5, 0.5, 0.75, 0.5}; const float colObj[4] = {0.5, 0.25, 0.25, 0.5}; glColor4fv( colPlane ); glMaterialfv(GL_FRONT, GL_DIFFUSE , colPlane); glBegin( GL_POLYGON ); glVertex3f( -2.0, 0.0, -2.0 ); glVertex3f( 2.0, 0.0, -2.0 ); glVertex3f( 2.0, 0.0, 2.0 ); glVertex3f( -2.0, 0.0, 2.0 ); glEnd(); glBegin( GL_POLYGON ); glVertex3f( -2.0, 0.0001f, -2.0 ); glVertex3f( -2.0, 0.0001f, 2.0 ); glVertex3f( 2.0, 0.0001f, 2.0 ); glVertex3f( 2.0, 0.0001f, -2.0 ); glEnd(); glColor4fv( colObj ); glMaterialfv(GL_FRONT, GL_DIFFUSE , colObj); glMaterialfv(GL_FRONT, GL_SPECULAR, colObj); // ToDo: draw your shape here and perform the intersection // then call drawHits so you can see where the ray has hit the shape // the origin is in variable 'p' and direction in variable 'dir' shape->DrawTriangles(); //Call HitRecord hr = intersect(pE1, dir); HitRecord *hr = shape->intersect(pE1, dir); drawHits(*hr); endDrawing(); }