void PtexViewer::goToFace(int i) { if (i>=0 && _displayFace<0) _mainCam = _cam; else if (i<0) _cam = _mainCam; _displayFace = i; if (_displayFace>=0 || (i<0&&_mainCam.getDistance()==0)) frameView(); }
void PtexViewer::pan(int x, int y) { double wsize[2]; getWindowSize(wsize[0], wsize[1]); wsize[0] /= 2.0; wsize[1] /= 2.0; float winasp = wsize[0]/wsize[1]; double panX, panY; double panscale = _cam.getDistance()*0.5; panX = panscale*((double)(x))/wsize[0]; panY = panscale*((double)(-y))/(wsize[1]*winasp); _cam.pan(panX,panY,(_mode3d&&_displayFace<0)); }
void PtexViewer::render(int selx, int sely) { if (!_shaderProgram) makeShader(); if (_options.bgColorLight) glClearColor(0.8,0.8,0.8,1); else glClearColor(0.0,0.0,0.0,1); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); GLint vp[4]; glGetIntegerv(GL_VIEWPORT, vp); float width = vp[2]; float height = vp[3]; float winasp = width/height; glMatrixMode(GL_PROJECTION); glLoadIdentity(); bool selectMode = selx>=0 && sely>=0; if (selectMode) gluPickMatrix((double)selx,(double)vp[3]-sely,3,3,vp); if (!_mode3d||_displayFace>=0) { float sc = _cam.getDistance()/2; glOrtho(-sc, sc, -sc/winasp, sc/winasp, -100, 100); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(-_cam.getLookAt()[0],-_cam.getLookAt()[1],-_cam.getLookAt()[2]); } else { _cam.applyProjectionTransform(winasp, _bounds); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); _cam.applyModelViewTransform(); } glEnable(GL_DEPTH_TEST); glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(1.0,1.0); glColor4f(1.0, 1.0, 1.0, 1.0); glUseProgramObjectARB(_shaderProgram); _geometry.draw(_displayFace); glUseProgramObjectARB(0); if (!selectMode && _options.showGridLines) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_LINE_SMOOTH); glColor4f(0.0, 0.0, 0.0, 0.25); _geometry.draw(_displayFace); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glDisable(GL_BLEND); glDisable(GL_LINE_SMOOTH); } glDisable(GL_POLYGON_OFFSET_FILL); glDisable(GL_DEPTH_TEST); if (selectMode) return; // Display text information char str[64]; if (_options.bgColorLight) glColor3f(0.0, 0.0, 0.0); else glColor3f(0.9, 0.9, 0.9); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); if (!_options.envMode) { if (_numFaces==1) strcpy(str, "1 face"); else sprintf(str,"%i faces",_numFaces); renderChars(-0.8,-0.92,GLUT_BITMAP_8_BY_13,str); if (_displayFace>=0 && _numFaces!=1) { sprintf(str,"Face ID: %i",_displayFace); renderChars(-0.8,0.92,GLUT_BITMAP_8_BY_13,str); } if (_numFaces==1) { int ures = _geometry.getFace(0)->ures; int vres = _geometry.getFace(0)->vres; sprintf(str,"Res: %i x %i",ures,vres); renderChars(-0.8,0.92,GLUT_BITMAP_8_BY_13,str); } else if (_displayFace>=0) { int ures = _geometry.getFace(_displayFace)->ures; int vres = _geometry.getFace(_displayFace)->vres; sprintf(str,"Face Res: %i x %i",ures,vres); renderChars(-0.2,0.92,GLUT_BITMAP_8_BY_13,str); } renderChars(0.25,-0.92,GLUT_BITMAP_8_BY_13,(char*)_typeStr.c_str()); } }