📄 opengl_renderer.cpp
字号:
glNormal3d(dQt.x, dQt.y, dQt.z); for (j = 0; j < wormSides; ++j) { k = j + offset; if (k >= wormSides) k -= wormSides; glVertex3d(Cx[k], Cy[k], Cz[k]); } glEnd(); } /* store this circle as previous for next round; instead of copying all values, just swap pointers */#define SWAPPTR(p1,p2) tmp=(p1); (p1)=(p2); (p2)=tmp SWAPPTR(Nx, pNx); SWAPPTR(Ny, pNy); SWAPPTR(Nz, pNz); SWAPPTR(Cx, pCx); SWAPPTR(Cy, pCy); SWAPPTR(Cz, pCz); } } if (fblock) delete[] fblock;}static void DoCylinderPlacementTransform(const Vector& a, const Vector& b, double length){ /* to translate into place */ glTranslated(a.x, a.y, a.z); /* to rotate from initial position, so bond points right direction; handle special case where both ends share ~same x,y */ if (fabs(a.y - b.y) < 0.000001 && fabs(a.x - b.x) < 0.000001) { if (b.z - a.z < 0.0) glRotated(180.0, 1.0, 0.0, 0.0); } else { glRotated(RadToDegrees(acos((b.z - a.z) / length)), a.y - b.y, b.x - a.x, 0.0); }}static void DrawHalfBond(const Vector& site1, const Vector& midpoint, StyleManager::eDisplayStyle style, double radius, bool cap1, bool cap2){ // straight line bond if (style == StyleManager::eLineBond || (style == StyleManager::eCylinderBond && radius <= 0.0)) { glBegin(GL_LINES); glVertex3d(site1.x, site1.y, site1.z); glVertex3d(midpoint.x, midpoint.y, midpoint.z); glEnd(); } // cylinder bond else if (style == StyleManager::eCylinderBond) { double length = (site1 - midpoint).length(); if (length <= 0.000001 || bondSides <= 1) return; glPushMatrix(); DoCylinderPlacementTransform(site1, midpoint, length); gluCylinder(qobj, radius, radius, length, bondSides, 1); if (cap1) { glPushMatrix(); glRotated(180.0, 0.0, 1.0, 0.0); gluDisk(qobj, 0.0, radius, bondSides, 1); glPopMatrix(); } if (cap2) { glPushMatrix(); glTranslated(0.0, 0.0, length); gluDisk(qobj, 0.0, radius, bondSides, 1); glPopMatrix(); } glPopMatrix(); }}void OpenGLRenderer::DrawBond(const Vector& site1, const Vector& site2, const BondStyle& style, const Vector *site0, const Vector* site3){ GLenum colorType; Vector midpoint = (site1 + site2) / 2; if (style.end1.style != StyleManager::eNotDisplayed) { colorType = (style.end1.style == StyleManager::eLineBond || style.end1.style == StyleManager::eLineWormBond || style.end1.radius <= 0.0) ? GL_AMBIENT : GL_DIFFUSE; SetColor(colorType, style.end1.color[0], style.end1.color[1], style.end1.color[2]); glLoadName(static_cast<GLuint>(style.end1.name)); if (style.end1.style == StyleManager::eLineWormBond || style.end1.style == StyleManager::eThickWormBond) DrawHalfWorm(site0, site1, site2, site3, (style.end1.style == StyleManager::eThickWormBond) ? style.end1.radius : 0.0, style.end1.atomCap, style.midCap, style.tension); else DrawHalfBond(site1, midpoint, style.end1.style, style.end1.radius, style.end1.atomCap, style.midCap); displayListEmpty[currentDisplayList] = false; } if (style.end2.style != StyleManager::eNotDisplayed) { colorType = (style.end2.style == StyleManager::eLineBond || style.end2.style == StyleManager::eLineWormBond || style.end2.radius <= 0.0) ? GL_AMBIENT : GL_DIFFUSE; SetColor(colorType, style.end2.color[0], style.end2.color[1], style.end2.color[2]); glLoadName(static_cast<GLuint>(style.end2.name)); if (style.end2.style == StyleManager::eLineWormBond || style.end2.style == StyleManager::eThickWormBond) DrawHalfWorm(site3, site2, site1, site0, (style.end2.style == StyleManager::eThickWormBond) ? style.end2.radius : 0.0, style.end2.atomCap, style.midCap, style.tension); else DrawHalfBond(midpoint, site2, style.end2.style, style.end2.radius, style.midCap, style.end2.atomCap); displayListEmpty[currentDisplayList] = false; }}void OpenGLRenderer::DrawHelix(const Vector& Nterm, const Vector& Cterm, const HelixStyle& style){ SetColor(GL_DIFFUSE, style.color[0], style.color[1], style.color[2]); glLoadName(static_cast<GLuint>(NO_NAME)); double wholeLength = (Nterm - Cterm).length(); if (wholeLength <= 0.000001) return; // transformation for whole helix glPushMatrix(); DoCylinderPlacementTransform(Nterm, Cterm, wholeLength); // helix body double shaftLength = (style.style == StyleManager::eObjectWithArrow && style.arrowLength < wholeLength) ? wholeLength - style.arrowLength : wholeLength; gluCylinder(qobj, style.radius, style.radius, shaftLength, helixSides, 1); // Nterm cap glPushMatrix(); glRotated(180.0, 0.0, 1.0, 0.0); gluDisk(qobj, 0.0, style.radius, helixSides, 1); glPopMatrix(); // Cterm Arrow if (style.style == StyleManager::eObjectWithArrow && style.arrowLength < wholeLength) { // arrow base if (style.arrowBaseWidthProportion > 1.0) { glPushMatrix(); glTranslated(0.0, 0.0, shaftLength); glRotated(180.0, 0.0, 1.0, 0.0); gluDisk(qobj, style.radius, style.radius * style.arrowBaseWidthProportion, helixSides, 1); glPopMatrix(); } // arrow body glPushMatrix(); glTranslated(0.0, 0.0, shaftLength); gluCylinder(qobj, style.radius * style.arrowBaseWidthProportion, style.radius * style.arrowTipWidthProportion, style.arrowLength, helixSides, 10); glPopMatrix(); // arrow tip if (style.arrowTipWidthProportion > 0.0) { glPushMatrix(); glTranslated(0.0, 0.0, wholeLength); gluDisk(qobj, 0.0, style.radius * style.arrowTipWidthProportion, helixSides, 1); glPopMatrix(); } } // Cterm cap else { glPushMatrix(); glTranslated(0.0, 0.0, wholeLength); gluDisk(qobj, 0.0, style.radius, helixSides, 1); glPopMatrix(); } glPopMatrix(); displayListEmpty[currentDisplayList] = false;}void OpenGLRenderer::DrawStrand(const Vector& Nterm, const Vector& Cterm, const Vector& unitNormal, const StrandStyle& style){ GLdouble c000[3], c001[3], c010[3], c011[3], c100[3], c101[3], c110[3], c111[3], n[3]; Vector a, h; int i; SetColor(GL_DIFFUSE, style.color[0], style.color[1], style.color[2]); glLoadName(static_cast<GLuint>(NO_NAME)); /* in this brick's world coordinates, the long axis (N-C direction) is along +Z, with N terminus at Z=0; width is in the X direction, and thickness in Y. Arrowhead at C-terminus, of course. */ a = Cterm - Nterm; a.normalize(); h = vector_cross(unitNormal, a); Vector lCterm(Cterm); if (style.style == StyleManager::eObjectWithArrow) lCterm -= a * style.arrowLength; for (i=0; i<3; ++i) { c000[i] = Nterm[i] - h[i]*style.width/2 - unitNormal[i]*style.thickness/2; c001[i] = lCterm[i] - h[i]*style.width/2 - unitNormal[i]*style.thickness/2; c010[i] = Nterm[i] - h[i]*style.width/2 + unitNormal[i]*style.thickness/2; c011[i] = lCterm[i] - h[i]*style.width/2 + unitNormal[i]*style.thickness/2; c100[i] = Nterm[i] + h[i]*style.width/2 - unitNormal[i]*style.thickness/2; c101[i] = lCterm[i] + h[i]*style.width/2 - unitNormal[i]*style.thickness/2; c110[i] = Nterm[i] + h[i]*style.width/2 + unitNormal[i]*style.thickness/2; c111[i] = lCterm[i] + h[i]*style.width/2 + unitNormal[i]*style.thickness/2; } glBegin(GL_QUADS); for (i=0; i<3; ++i) n[i] = unitNormal[i]; glNormal3dv(n); glVertex3dv(c010); glVertex3dv(c011); glVertex3dv(c111); glVertex3dv(c110); for (i=0; i<3; ++i) n[i] = -unitNormal[i]; glNormal3dv(n); glVertex3dv(c000); glVertex3dv(c100); glVertex3dv(c101); glVertex3dv(c001); for (i=0; i<3; ++i) n[i] = h[i]; glNormal3dv(n); glVertex3dv(c100); glVertex3dv(c110); glVertex3dv(c111); glVertex3dv(c101); for (i=0; i<3; ++i) n[i] = -h[i]; glNormal3dv(n); glVertex3dv(c000); glVertex3dv(c001); glVertex3dv(c011); glVertex3dv(c010); for (i=0; i<3; ++i) n[i] = -a[i]; glNormal3dv(n); glVertex3dv(c000); glVertex3dv(c010); glVertex3dv(c110); glVertex3dv(c100); if (style.style == StyleManager::eObjectWithoutArrow) { for (i=0; i<3; ++i) n[i] = a[i]; glNormal3dv(n); glVertex3dv(c001); glVertex3dv(c101); glVertex3dv(c111); glVertex3dv(c011); } else { GLdouble FT[3], LT[3], RT[3], FB[3], LB[3], RB[3]; for (i=0; i<3; ++i) { FT[i] = lCterm[i] + unitNormal[i]*style.thickness/2 + a[i]*style.arrowLength; LT[i] = lCterm[i] + unitNormal[i]*style.thickness/2 + h[i]*style.arrowBaseWidthProportion*style.width/2; RT[i] = lCterm[i] + unitNormal[i]*style.thickness/2 - h[i]*style.arrowBaseWidthProportion*style.width/2; FB[i] = lCterm[i] - unitNormal[i]*style.thickness/2 + a[i]*style.arrowLength; LB[i] = lCterm[i] - unitNormal[i]*style.thickness/2 + h[i]*style.arrowBaseWidthProportion*style.width/2; RB[i] = lCterm[i] - unitNormal[i]*style.thickness/2 - h[i]*style.arrowBaseWidthProportion*style.width/2; } // the back-facing rectangles on the base of the arrow for (i=0; i<3; ++i) n[i] = -a[i]; glNormal3dv(n); glVertex3dv(c111); glVertex3dv(LT); glVertex3dv(LB); glVertex3dv(c101); glVertex3dv(c011); glVertex3dv(c001); glVertex3dv(RB); glVertex3dv(RT); // the left side of the arrow for (i=0; i<3; ++i) h[i] = FT[i] - LT[i]; Vector nL = vector_cross(unitNormal, h); nL.normalize(); for (i=0; i<3; ++i) n[i] = nL[i]; glNormal3dv(n); glVertex3dv(FT); glVertex3dv(FB); glVertex3dv(LB); glVertex3dv(LT); // the right side of the arrow for (i=0; i<3; ++i) h[i] = FT[i] - RT[i]; Vector nR = vector_cross(h, unitNormal); nR.normalize(); for (i=0; i<3; ++i) n[i] = nR[i]; glNormal3dv(n); glVertex3dv(FT); glVertex3dv(RT); glVertex3dv(RB); glVertex3dv(FB); glEnd(); glBegin(GL_TRIANGLES); // the top and bottom arrow triangles for (i=0; i<3; ++i) n[i] = unitNormal[i]; glNormal3dv(n); glVertex3dv(FT); glVertex3dv(LT); glVertex3dv(RT); for (i=0; i<3; ++i) n[i] = -unitNormal[i]; glNormal3dv(n); glVertex3dv(FB); glVertex3dv(RB); glVertex3dv(LB); } glEnd(); displayListEmpty[currentDisplayList] = false;}void OpenGLRenderer::DrawLabel(const string& text, const Vector& center, const Vector& color){ int width, height, textCenterX = 0, textCenterY = 0; if (text.empty()) return; if (!glCanvas->MeasureText(text, &width, &height, &textCenterX, &textCenterY)) WARNINGMSG("MeasureText() failed"); SetColor(GL_AMBIENT, color[0], color[1], color[2]); glListBase(FONT_BASE); glRasterPos3d(center.x, center.y, center.z); glBitmap(0, 0, 0.0, 0.0, -textCenterX, -textCenterY, NULL); glCallLists(text.size(), GL_UNSIGNED_BYTE, text.data()); glListBase(0); displayListEmpty[currentDisplayList] = false;}bool OpenGLRenderer::SaveToASNViewSettings(ncbi::objects::CCn3d_user_annotations *annotations){ // save current camera settings initialViewFromASN.Reset(new CCn3d_view_settings()); initialViewFromASN->SetCamera_distance(cameraDistance); initialViewFromASN->SetCamera_angle_rad(cameraAngleRad); initialViewFromASN->SetCamera_look_at_X(cameraLookAtX); initialViewFromASN->SetCamera_look_at_Y(cameraLookAtY); initialViewFromASN->SetCamera_clip_near(cameraClipNear); initialViewFromASN->SetCamera_clip_far(cameraClipFar); initialViewFromASN->SetMatrix().SetM0(viewMatrix[0]); initialViewFromASN->SetMatrix().SetM1(viewMatrix[1]); initialViewFromASN->SetMatrix().SetM2(viewMatrix[2]); initialViewFromASN->SetMatrix().SetM3(viewMatrix[3]); initialViewFromASN->SetMatrix().SetM4(viewMatrix[4]); initialViewFromASN->SetMatrix().SetM5(viewMatrix[5]); initialViewFromASN->SetMatrix().SetM6(viewMatrix[6]); initialViewFromASN->SetMatrix().SetM7(viewMatrix[7]); initialViewFromASN->SetMatrix().SetM8(viewMatrix[8]); initialViewFromASN->SetMatrix().SetM9(viewMatrix[9]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -