Академический Документы
Профессиональный Документы
Культура Документы
Picking
Id tif Identifyauserdefinedobjectonthedisplay d fi d bj t th di l Inprinciple,itshouldbesimplebecausethemouse givesthepositionandweshouldbeableto h d h ld b bl determinetowhichobject(s)apositioncorresponds Practicaldifficulties
Pipelinearchitectureisfeedforward,hardtogofromscreen backtoworld b k ld Complicatedbyscreenbeing2D,worldis3D How close do we have to come to object to say we selected Howclosedowehavetocometoobjecttosayweselected it?
Easiertolookatmousepositionanddeterminewhich areaofscreenitisinthanusingselectionmodepicking
Inclientserverenvironment,displaylistis placedonserver
Can be redisplayed without sending primitives Canberedisplayedwithoutsendingprimitives overnetworkeachtime
Callacreatedlist
OpenGLvertexarrays
e5
Thereare8nodesand12edges 5interiorpolygons 6interior(shared)edges Each vertex has a location vi = (xi , yi , zi) Eachvertexhasalocationv
Inefficientandunstructured
Considermovingavertextoanewlocation Mustsearchforalloccurrences
Canstoremeshbyedgelist
x1 y1 z 1 x2 y2 z 2 x3 y3 z 3 x4 y4 z 4 x5 y5 z5. x6 y6 z 6 x7 y7 z 7 x8 y8 z 8
v6 e1 v1 e6
e8 v8 e11 e7 v2 v7 e12
e9 e10 v3
e4
e5
GLfloat vertices[][3] = { {-1.0,-1.0,-1.0}, {1.0,-1.0,-1.0}, {1.0,1.0,-1.0}, {-1.0,1.0,-1.0}, {-1.0,-1.0,1.0}, {1.0,-1.0,1.0}, {1.0,1.0,1.0}, {-1.0,1.0,1.0}}; GLfloat colors[][3] = {{0.0,0.0,0.0},{1.0,0.0,0.0}, {1.0,1.0,0.0}, {0.0,1.0,0.0}, {0.0,0.0,1.0}, {1.0,0.0,1.0}, {1.0,1.0,1.0}, {0.0,1.0,1.0}};
Drawingapolygonfromalistof indices
Drawaquadrilateralfromalistofindicesintothearray vertices andusecolorcorrespondingtofirstindex
void polygon(int a, int b, int c , int d) { glColor3fv(colors[a]); glBegin(GL_POLYGON); glVertex3fv(vertices[a]); glVertex3fv(vertices[b]); glVertex3fv(vertices[c]); glVertex3fv(vertices[d]); glEnd();
}
4 0
Note that vertices are ordered so that we obtain correct outward facing normals
Efficiency
Theweaknessofourapproachisthatweare h k f hi h buildingthemodelintheapplicationand mustdomanyfunctioncallstodrawthecube Drawingacubebyitsfacesinthemost g y straightforwardwayrequires
6 glBegin, 6 glEnd 6glBegin,6glEnd 6glColor 24 glVertex 24glVertex
Initialization
Usingthesamecolorandvertexdata,firstweenable
glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL COLOR ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
Formanarrayoffaceindices
GLubyte cubeIndices[24] = {0 3 2 1 2 3 7 6 {0,3,2,1, 2,3,7,6, 0,4,7,3, 1,2,6,5, 4,5,6,7, 0,1,5,4};
Method2:
glDrawElements(GL_QUADS, 24, _ GL_UNSIGNED_BYTE, cubeIndices);
Draws cube with 1 function call!!