fiore@3: #include "GraphicManager.h" fiore@3: fiore@3: void GraphicManager::init(void){ fiore@3: fiore@3: // Enable depth buffering for hidden surface removal. fiore@3: glDepthFunc(GL_LEQUAL); fiore@3: glEnable(GL_DEPTH_TEST); fiore@3: fiore@3: // Cull back faces. fiore@3: glCullFace(GL_BACK); fiore@3: glEnable(GL_CULL_FACE); fiore@3: fiore@3: // Setup other misc features. fiore@3: glEnable(GL_LIGHTING); fiore@3: glEnable(GL_NORMALIZE); fiore@3: glShadeModel(GL_SMOOTH); fiore@3: fiore@3: // Setup lighting model. fiore@3: glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE); fiore@3: glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); fiore@3: glLightModelfv(GL_LIGHT_MODEL_AMBIENT, light_model_ambient); fiore@3: glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse); fiore@3: glLightfv(GL_LIGHT0, GL_POSITION, light0_direction); fiore@3: glEnable(GL_LIGHT0); fiore@3: fiore@3: fiore@3: } fiore@3: fiore@3: void GraphicManager::draw(void){ fiore@3: glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); fiore@3: // Draw 3D cursor at haptic device position. fiore@3: drawCursor(); fiore@3: fiore@3: glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT); fiore@3: glEnable(GL_COLOR_MATERIAL); fiore@3: fiore@3: // Draw each of the nodes as lit sphere. fiore@3: int numNodes = collectionsManager->getNodesNum(); fiore@3: GLdouble dPointSize; fiore@3: fiore@3: for ( int i = 0; i < numNodes; i++){ fiore@3: dPointSize = nodeSize; fiore@3: glColor3dv(nodeColor); fiore@3: fiore@3: glPushMatrix(); fiore@3: CollectionsManager::NodeData & nd = collectionsManager->getNodeData(i); fiore@3: glTranslated(nd.x,nd.y, 0); fiore@3: double dPointScale = dPointSize * gWorldScale; fiore@3: glScaled(dPointScale, dPointScale, dPointScale); fiore@3: /* draw shpere */ fiore@3: glutSolidSphere(0.5, 10, 10); fiore@3: glPopMatrix(); fiore@3: } fiore@3: fiore@3: //draw edges fiore@3: glColor3f(1.0, 0.0, 0.0); fiore@3: glLineWidth(2.0); fiore@3: glPushAttrib(GL_ENABLE_BIT); fiore@3: glDisable(GL_LIGHTING); fiore@3: glEnable(GL_COLOR_MATERIAL); fiore@3: fiore@3: int numEdges = collectionsManager->getEdgesNum(); fiore@3: for(int i = 0; i < numEdges; i++){ fiore@3: CollectionsManager::EdgeData & ed = collectionsManager->getEdgeData(i); fiore@3: glPushAttrib(GL_ENABLE_BIT); fiore@3: glLineStipple(1, ed.stipplePattern); fiore@3: glEnable(GL_LINE_STIPPLE); fiore@3: glBegin(GL_LINES); fiore@3: for(unsigned int j = 0; j < ed.getSize(); j++){ fiore@3: for(unsigned int k = j; k < ed.getSize(); k++){ fiore@3: if(ed.adjMatrix[j][k]){ fiore@3: glVertex3d(ed.x[j],ed.y[j],0); fiore@3: glVertex3d(ed.x[k],ed.y[k],0); fiore@3: } fiore@3: } fiore@3: } fiore@3: glEnd(); fiore@3: glPopAttrib(); fiore@3: } fiore@3: glPopAttrib(); fiore@3: glPopMatrix(); fiore@3: fiore@3: } fiore@3: fiore@3: void GraphicManager::drawCursor(){ fiore@3: HLdouble proxyxform[16]; fiore@3: fiore@3: GLUquadricObj *qobj = 0; fiore@3: fiore@3: glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT); fiore@3: glPushMatrix(); fiore@3: if (!gCursorDisplayList){ fiore@3: gCursorDisplayList = glGenLists(1); fiore@3: glNewList(gCursorDisplayList, GL_COMPILE); fiore@3: qobj = gluNewQuadric(); fiore@3: fiore@3: gluCylinder(qobj, 0.0, kCursorRadius, kCursorHeight, fiore@3: kCursorTess, kCursorTess); fiore@3: glTranslated(0.0, 0.0, kCursorHeight); fiore@3: gluCylinder(qobj, kCursorRadius, 0.0, kCursorHeight / 5.0, fiore@3: kCursorTess, kCursorTess); fiore@3: fiore@3: gluDeleteQuadric(qobj); fiore@3: glEndList(); fiore@3: } fiore@3: fiore@3: // Get the proxy transform in world coordinates. fiore@3: hlGetDoublev(HL_PROXY_TRANSFORM, proxyxform); fiore@3: glMultMatrixd(proxyxform); fiore@3: fiore@3: // Apply the local cursor scale factor. fiore@3: glScaled(gCursorScale, gCursorScale, gCursorScale); fiore@3: fiore@3: glEnable(GL_COLOR_MATERIAL); fiore@3: fiore@3: if(hapticManager->isDraggingNode()){ fiore@3: glColor3dv(nodeColor); fiore@3: glutSolidSphere(0.25, 10, 10); fiore@3: }else if(hapticManager->isDraggingEdge()){ fiore@3: glColor3dv(edgeColor); fiore@3: glutSolidSphere(0.12,10,10); fiore@3: } fiore@3: glColor3f(0.0, 0.5, 1.0); fiore@3: glCallList(gCursorDisplayList); fiore@3: fiore@3: glPopMatrix(); fiore@3: glPopAttrib(); fiore@3: } fiore@3: fiore@3: const double GraphicManager::kCursorRadius = 0.5; fiore@3: const double GraphicManager::kCursorHeight = 1.5; fiore@3: const int GraphicManager::kCursorTess = 15; fiore@3: fiore@3: const GLfloat GraphicManager::light_model_ambient[] = {0.3f, 0.3f, 0.3f, 1.0f}; fiore@3: const GLfloat GraphicManager::light0_diffuse[] = {0.9f, 0.9f, 0.9f, 0.9f}; fiore@3: const GLfloat GraphicManager::light0_direction[] = {0.0f, -0.4f, 1.0f, 0.0f}; fiore@3: fiore@3: fiore@3: const double GraphicManager::nodeSize = 10; fiore@3: fiore@3: const hduVector3Dd GraphicManager::nodeColor(1.0, 1.0, 1.0); fiore@3: const hduVector3Dd GraphicManager::edgeColor(1.0,0.0,0.0); fiore@3: