comparison native/PhantomOmni/GraphicManager.cpp @ 3:9e67171477bc

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