fiore@3
|
1 #include "GraphicManager.h"
|
fiore@3
|
2
|
fiore@3
|
3 void GraphicManager::init(void){
|
fiore@3
|
4
|
fiore@3
|
5 // Enable depth buffering for hidden surface removal.
|
fiore@3
|
6 glDepthFunc(GL_LEQUAL);
|
fiore@3
|
7 glEnable(GL_DEPTH_TEST);
|
fiore@3
|
8
|
fiore@3
|
9 // Cull back faces.
|
fiore@3
|
10 glCullFace(GL_BACK);
|
fiore@3
|
11 glEnable(GL_CULL_FACE);
|
fiore@3
|
12
|
fiore@3
|
13 // Setup other misc features.
|
fiore@3
|
14 glEnable(GL_LIGHTING);
|
fiore@3
|
15 glEnable(GL_NORMALIZE);
|
fiore@3
|
16 glShadeModel(GL_SMOOTH);
|
fiore@3
|
17
|
fiore@3
|
18 // Setup lighting model.
|
fiore@3
|
19 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE);
|
fiore@3
|
20 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
|
fiore@3
|
21 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, light_model_ambient);
|
fiore@3
|
22 glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
|
fiore@3
|
23 glLightfv(GL_LIGHT0, GL_POSITION, light0_direction);
|
fiore@3
|
24 glEnable(GL_LIGHT0);
|
fiore@3
|
25
|
fiore@3
|
26
|
fiore@3
|
27 }
|
fiore@3
|
28
|
fiore@3
|
29 void GraphicManager::draw(void){
|
fiore@3
|
30 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
fiore@3
|
31 // Draw 3D cursor at haptic device position.
|
fiore@3
|
32 drawCursor();
|
fiore@3
|
33
|
fiore@3
|
34 glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT);
|
fiore@3
|
35 glEnable(GL_COLOR_MATERIAL);
|
fiore@3
|
36
|
fiore@3
|
37 // Draw each of the nodes as lit sphere.
|
fiore@3
|
38 int numNodes = collectionsManager->getNodesNum();
|
fiore@3
|
39 GLdouble dPointSize;
|
fiore@3
|
40
|
fiore@3
|
41 for ( int i = 0; i < numNodes; i++){
|
fiore@3
|
42 dPointSize = nodeSize;
|
fiore@3
|
43 glColor3dv(nodeColor);
|
fiore@3
|
44
|
fiore@3
|
45 glPushMatrix();
|
fiore@3
|
46 CollectionsManager::NodeData & nd = collectionsManager->getNodeData(i);
|
fiore@3
|
47 glTranslated(nd.x,nd.y, 0);
|
fiore@3
|
48 double dPointScale = dPointSize * gWorldScale;
|
fiore@3
|
49 glScaled(dPointScale, dPointScale, dPointScale);
|
fiore@3
|
50 /* draw shpere */
|
fiore@3
|
51 glutSolidSphere(0.5, 10, 10);
|
fiore@3
|
52 glPopMatrix();
|
fiore@3
|
53 }
|
fiore@3
|
54
|
fiore@3
|
55 //draw edges
|
fiore@3
|
56 glColor3f(1.0, 0.0, 0.0);
|
fiore@3
|
57 glLineWidth(2.0);
|
fiore@3
|
58 glPushAttrib(GL_ENABLE_BIT);
|
fiore@3
|
59 glDisable(GL_LIGHTING);
|
fiore@3
|
60 glEnable(GL_COLOR_MATERIAL);
|
fiore@3
|
61
|
fiore@3
|
62 int numEdges = collectionsManager->getEdgesNum();
|
fiore@3
|
63 for(int i = 0; i < numEdges; i++){
|
fiore@3
|
64 CollectionsManager::EdgeData & ed = collectionsManager->getEdgeData(i);
|
fiore@3
|
65 glPushAttrib(GL_ENABLE_BIT);
|
fiore@3
|
66 glLineStipple(1, ed.stipplePattern);
|
fiore@3
|
67 glEnable(GL_LINE_STIPPLE);
|
fiore@3
|
68 glBegin(GL_LINES);
|
fiore@3
|
69 for(unsigned int j = 0; j < ed.getSize(); j++){
|
fiore@3
|
70 for(unsigned int k = j; k < ed.getSize(); k++){
|
fiore@3
|
71 if(ed.adjMatrix[j][k]){
|
fiore@3
|
72 glVertex3d(ed.x[j],ed.y[j],0);
|
fiore@3
|
73 glVertex3d(ed.x[k],ed.y[k],0);
|
fiore@3
|
74 }
|
fiore@3
|
75 }
|
fiore@3
|
76 }
|
fiore@3
|
77 glEnd();
|
fiore@3
|
78 glPopAttrib();
|
fiore@3
|
79 }
|
fiore@3
|
80 glPopAttrib();
|
fiore@3
|
81 glPopMatrix();
|
fiore@3
|
82
|
fiore@3
|
83 }
|
fiore@3
|
84
|
fiore@3
|
85 void GraphicManager::drawCursor(){
|
fiore@3
|
86 HLdouble proxyxform[16];
|
fiore@3
|
87
|
fiore@3
|
88 GLUquadricObj *qobj = 0;
|
fiore@3
|
89
|
fiore@3
|
90 glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT);
|
fiore@3
|
91 glPushMatrix();
|
fiore@3
|
92 if (!gCursorDisplayList){
|
fiore@3
|
93 gCursorDisplayList = glGenLists(1);
|
fiore@3
|
94 glNewList(gCursorDisplayList, GL_COMPILE);
|
fiore@3
|
95 qobj = gluNewQuadric();
|
fiore@3
|
96
|
fiore@3
|
97 gluCylinder(qobj, 0.0, kCursorRadius, kCursorHeight,
|
fiore@3
|
98 kCursorTess, kCursorTess);
|
fiore@3
|
99 glTranslated(0.0, 0.0, kCursorHeight);
|
fiore@3
|
100 gluCylinder(qobj, kCursorRadius, 0.0, kCursorHeight / 5.0,
|
fiore@3
|
101 kCursorTess, kCursorTess);
|
fiore@3
|
102
|
fiore@3
|
103 gluDeleteQuadric(qobj);
|
fiore@3
|
104 glEndList();
|
fiore@3
|
105 }
|
fiore@3
|
106
|
fiore@3
|
107 // Get the proxy transform in world coordinates.
|
fiore@3
|
108 hlGetDoublev(HL_PROXY_TRANSFORM, proxyxform);
|
fiore@3
|
109 glMultMatrixd(proxyxform);
|
fiore@3
|
110
|
fiore@3
|
111 // Apply the local cursor scale factor.
|
fiore@3
|
112 glScaled(gCursorScale, gCursorScale, gCursorScale);
|
fiore@3
|
113
|
fiore@3
|
114 glEnable(GL_COLOR_MATERIAL);
|
fiore@3
|
115
|
fiore@3
|
116 if(hapticManager->isDraggingNode()){
|
fiore@3
|
117 glColor3dv(nodeColor);
|
fiore@3
|
118 glutSolidSphere(0.25, 10, 10);
|
fiore@3
|
119 }else if(hapticManager->isDraggingEdge()){
|
fiore@3
|
120 glColor3dv(edgeColor);
|
fiore@3
|
121 glutSolidSphere(0.12,10,10);
|
fiore@3
|
122 }
|
fiore@3
|
123 glColor3f(0.0, 0.5, 1.0);
|
fiore@3
|
124 glCallList(gCursorDisplayList);
|
fiore@3
|
125
|
fiore@3
|
126 glPopMatrix();
|
fiore@3
|
127 glPopAttrib();
|
fiore@3
|
128 }
|
fiore@3
|
129
|
fiore@3
|
130 const double GraphicManager::kCursorRadius = 0.5;
|
fiore@3
|
131 const double GraphicManager::kCursorHeight = 1.5;
|
fiore@3
|
132 const int GraphicManager::kCursorTess = 15;
|
fiore@3
|
133
|
fiore@3
|
134 const GLfloat GraphicManager::light_model_ambient[] = {0.3f, 0.3f, 0.3f, 1.0f};
|
fiore@3
|
135 const GLfloat GraphicManager::light0_diffuse[] = {0.9f, 0.9f, 0.9f, 0.9f};
|
fiore@3
|
136 const GLfloat GraphicManager::light0_direction[] = {0.0f, -0.4f, 1.0f, 0.0f};
|
fiore@3
|
137
|
fiore@3
|
138
|
fiore@3
|
139 const double GraphicManager::nodeSize = 10;
|
fiore@3
|
140
|
fiore@3
|
141 const hduVector3Dd GraphicManager::nodeColor(1.0, 1.0, 1.0);
|
fiore@3
|
142 const hduVector3Dd GraphicManager::edgeColor(1.0,0.0,0.0);
|
fiore@3
|
143
|