void Molecule::addPersistentForce(int theatom, const float *f) { // reset the force on this atom if any are stored // remove it completely if <f> is (0,0,0) float mag2 = f[0]*f[0] + f[1]*f[1] + f[2]*f[2]; int ind = persistent_force_indices.find(theatom); if (ind < 0) { if (mag2 > 0) { // only set if non-zero reset_disp_list(); persistent_force_indices.append(theatom); for (int i=0; i<3; i++) persistent_force_vectors.append(f[i]); } } else { if (mag2 > 0) { reset_disp_list(); for (int i=0; i<3; i++) persistent_force_vectors[3*ind+i] = f[i]; } else { // remove the persistent force (a zero will be sent automatically!) persistent_force_indices.remove(ind); // remove same index three times since this is a ResizeArray // and it will shift elements down as they are removed... persistent_force_vectors.remove(3*ind); persistent_force_vectors.remove(3*ind); persistent_force_vectors.remove(3*ind); } } }
void FPS::prepare() { if (!displayed()) return; ++loop_count; double curtime = time_of_day(); // force a redraw.... need_matrix_recalc(); // but don't redraw indicator more than twice per second if (curtime - last_update < 0.5) return; double rate = loop_count / (curtime - last_update); last_update = curtime; loop_count = 0; reset_disp_list(); append(DMATERIALOFF); float asp = disp->aspect(); float poscale = 1.2f; float pos[3]; pos[0] = asp * poscale; pos[1] = poscale; pos[2] = 0; DispCmdColorIndex cmdColor; cmdColor.putdata(usecolor, cmdList); DispCmdText cmdText; char buf[20]; sprintf(buf, "%5.2f", rate); cmdText.putdata(pos, buf, 1.0f, cmdList); }
// draw the geometry marker in the given Displayable's drawing list void GeometryBond::create_cmd_list() { char valbuf[32]; // get the transformed positions, and draw a line between them float pos1[3], pos2[3]; reset_disp_list(); if(!transformed_atom_coord(0, pos1)) return; if(!transformed_atom_coord(1, pos2)) return; append(DMATERIALOFF); DispCmdColorIndex cmdColor; cmdColor.putdata(my_color, cmdList); DispCmdLineType cmdLineType; DispCmdLineWidth cmdLineWidth; cmdLineType.putdata(DASHEDLINE, cmdList); cmdLineWidth.putdata(4, cmdList); // print value of distance at midpoint midpoint(valuePos, pos1, pos2); // left-align the value so that it doesn't appear to shift its position // when the label text size changes. Shift it to the right by a constant // amount so that it doesn't intersect the line. valuePos[0] += 0.05f; sprintf(valbuf, "%-7.2f", geomValue); display_string(valbuf, cmdList); // draw a line into the given Displayable display_line(pos1, pos2, cmdList); }
// draw the geometry marker in the given Displayable's drawing list void GeometryAtom::create_cmd_list() { reset_disp_list(); // get the molecule pointer and atom position Molecule *mol = transformed_atom_coord(0, valuePos); // do not draw if illegal molecule, or atom is not on if(!mol) return; append(DMATERIALOFF); DispCmdColorIndex cmdColor; cmdColor.putdata(my_color,cmdList); // everything is OK, draw text at atom position JString str; atom_formatted_name(str, mol, comIndex[0]); display_string((const char *)str, cmdList); }
// create the drawing command list void Stage::create_cmdlist(void) { int i, j, k, odd; float c[4][3], mycorner1[3]; mycorner1[0] = mycorner1[2] = -1.0; mycorner1[1] = 0.0; c[0][1] = c[1][1] = c[2][1] = c[3][1] = 0.0; // do reset first reset_disp_list(); // turn off material characteristics append(DMATERIALOFF); // draw odd/even squares separately for(k=0; k < 2; k++) { odd = (k == 1); // set color in checkerboard if (odd) cmdColor.putdata(usecolors[0],cmdList); else cmdColor.putdata(usecolors[1],cmdList); // start in lower-left corner c[0][0] = c[3][0] = mycorner1[0]; c[1][0] = c[2][0] = mycorner1[0] + inc; for(i=0; i < Panels; i++) { c[0][2] = c[1][2] = mycorner1[2]; c[2][2] = c[3][2] = mycorner1[2] + inc; for(j=0; j < Panels; j++) { if(!odd) cmdSquare.putdata(c[2], c[1], c[0], cmdList); odd = !odd; c[0][2] += inc; c[1][2] += inc; c[2][2] += inc; c[3][2] += inc; } c[0][0] += inc; c[1][0] += inc; c[2][0] += inc; c[3][0] += inc; if(Panels % 2 == 0) odd = !odd; } } }
void VMDTitle::redraw_list(void) { reset_disp_list(); float x; // offset to center VMD x = letter_V_width() + STROKE_WIDTH/2.0f + letter_M_width() + STROKE_WIDTH/2.0f + letter_V_width(); // same width as 'V' x=x/2; // center on the screen append(DMATERIALON); color.putdata(REGRED, cmdList); draw_letter_V(-x, -0.4f, cmdList); color.putdata(REGGREEN, cmdList); draw_letter_M(-x + STROKE_WIDTH/2.0f + letter_V_width(), -0.4f, cmdList); color.putdata(REGBLUE, cmdList); draw_letter_D(-x + STROKE_WIDTH/2.0f + letter_V_width() + STROKE_WIDTH/2.0f + letter_M_width(), -0.4f, cmdList); append(DMATERIALOFF); if (letterson) { color.putdata(REGWHITE, cmdList); float pos[3]; pos[0] = -x; pos[1] = -0.6f; pos[2] = 0.0f; DispCmdText txt; txt.putdata(pos, "Theoretical and Computational Biophysics Group", cmdList); pos[1] -= 0.1f; txt.putdata(pos, "NIH Resource for Macromolecular Modeling and Bioinformatics", cmdList); pos[1] -= 0.1f; txt.putdata(pos, "University of Illinois at Urbana-Champaign", cmdList); pos[1] -= 0.1f; txt.putdata(pos, VMD_AUTHORS_LINE1, cmdList); pos[1] -= 0.1f; txt.putdata(pos, VMD_AUTHORS_LINE2, cmdList); pos[1] -= 0.1f; txt.putdata(pos, VMD_AUTHORS_LINE3, cmdList); } }
// create the drawing command list void Axes::create_cmdlist(void) { char commentBuffer[128]; reset_disp_list(); // regenerate both data block and display commands sprintf(commentBuffer, "VMD: Starting axes output."); cmdCommentX.putdata(commentBuffer, cmdList); cmdBeginRepGeomGroup.putdata("vmd_axes", cmdList); #if defined(USELINEAXES) DispCmdLine cmdline; float arrow1[3], arrow2[3]; // turn on material characteristics append(DMATERIALOFF); // Draw axes as lines of width 2, faster for wimpy machines... DispCmdLineWidth cmdwidth; cmdwidth.putdata(2, cmdList); // x-axis xcol.putdata(usecolors[0], cmdList); cmdline.putdata(origin, xLineCap, cmdList); arrow1[0] = xLine[0]; arrow1[1] = xLine[1] - AXESCAPRAD/sqrt(2.0f); arrow1[2] = xLine[2] + AXESCAPRAD/sqrt(2.0f); arrow2[0] = xLine[0]; arrow2[1] = xLine[1] + AXESCAPRAD/sqrt(2.0f); arrow2[2] = xLine[2] - AXESCAPRAD/sqrt(2.0f); cmdline.putdata(xLineCap, arrow1, cmdList); cmdline.putdata(xLineCap, arrow2, cmdList); // y-axis xcol.putdata(usecolors[1], cmdList); cmdline.putdata(origin, yLineCap, cmdList); arrow1[0] = yLine[0] + AXESCAPRAD/sqrt(2.0f); arrow1[1] = yLine[1]; arrow1[2] = yLine[2] - AXESCAPRAD/sqrt(2.0f); arrow2[0] = yLine[0] - AXESCAPRAD/sqrt(2.0f); arrow2[1] = yLine[1]; arrow2[2] = yLine[2] + AXESCAPRAD/sqrt(2.0f); cmdline.putdata(yLineCap, arrow1, cmdList); cmdline.putdata(yLineCap, arrow2, cmdList); // z-axis xcol.putdata(usecolors[2], cmdList); cmdline.putdata(origin, zLineCap, cmdList); arrow1[0] = zLine[0] - AXESCAPRAD/sqrt(2.0f); arrow1[1] = zLine[1] + AXESCAPRAD/sqrt(2.0f); arrow1[2] = zLine[2]; arrow2[0] = zLine[0] + AXESCAPRAD/sqrt(2.0f); arrow2[1] = zLine[1] - AXESCAPRAD/sqrt(2.0f); arrow2[2] = zLine[2]; cmdline.putdata(zLineCap, arrow1, cmdList); cmdline.putdata(zLineCap, arrow2, cmdList); #else // Draw axes as solid cylinders/cones, for faster machines... // turn on material characteristics append(DMATERIALON); // set sphere type and resolution sphres.putdata(AXESSPHRES, cmdList); sphtype.putdata(SOLIDSPHERE, cmdList); // put in commands to draw lines // x-axis xcol.putdata(usecolors[0], cmdList); xcyl.putdata(origin, xLine, AXESRAD, AXESRES, 0, cmdList); xcap.putdata(xLine, xLineCap, AXESCAPRAD, 0, AXESRES, cmdList); // y-axis xcol.putdata(usecolors[1], cmdList); xcyl.putdata(origin, yLine, AXESRAD, AXESRES, 0, cmdList); xcap.putdata(yLine, yLineCap, AXESCAPRAD, 0, AXESRES, cmdList); // z-axis xcol.putdata(usecolors[2], cmdList); xcyl.putdata(origin, zLine, AXESRAD, AXESRES, 0, cmdList); xcap.putdata(zLine, zLineCap, AXESCAPRAD, 0, AXESRES, cmdList); // put in commands to draw sphere at origin xcol.putdata(usecolors[3], cmdList); sph.putdata(origin, AXESRAD, cmdList); // turn off material characteristics append(DMATERIALOFF); #endif // put in commands to label the axes xcol.putdata(usecolors[4], cmdList); txt.putdata(xText, "x", 1.0f, cmdList); txt.putdata(yText, "y", 1.0f, cmdList); txt.putdata(zText, "z", 1.0f, cmdList); // put in commands to draw pickpoints at axes endpoints pickPoint.putdata(origin, 0, cmdList); pickPoint.putdata(xLine, 1, cmdList); pickPoint.putdata(xLineCap, 2, cmdList); pickPoint.putdata(yLine, 3, cmdList); pickPoint.putdata(yLineCap, 4, cmdList); pickPoint.putdata(zLine, 5, cmdList); pickPoint.putdata(zLineCap, 6, cmdList); // done drawing axes sprintf(commentBuffer, "VMD: Done with axes."); cmdCommentX.putdata(commentBuffer, cmdList); need_create_cmdlist = FALSE; }
void MoleculeGraphics::create_cmdlist(void) { reset_disp_list(); // set the default values DispCmdTriangle triangle; DispCmdCylinder cylinder; DispCmdPoint point; DispCmdLine line; DispCmdCone cone; DispCmdColorIndex color; DispCmdLineType linetype; DispCmdLineWidth linewidth; DispCmdSphere sphere; DispCmdSphereRes sph_res; //DispCmdComment comment; DispCmdPickPoint cmdPickPoint; append(DMATERIALON); color.putdata(0, cmdList); // use the first color by default (blue) int last_res = -1; // default sphere resolution int last_line = ::SOLIDLINE; // default for lines linetype.putdata(last_line, cmdList); // solid and int last_width = 1; linewidth.putdata(last_width, cmdList); // of width 1 // go down the list and draw things int num = num_elements(); ShapeClass *shape; for (int i=0; i<num; i++) { shape = &(shapes[i]); switch (shape->shape) { case NONE: { break; } case POINT: { append(DMATERIALOFF); point.putdata(shape->data+0, cmdList); append(DMATERIALON); break; } case PICKPOINT: cmdPickPoint.putdata(shape->data, (int)shape->data[3], cmdList); break; case LINE: { append(DMATERIALOFF); int style = int(shape->data[6]); int width = int(shape->data[7]); if (style != last_line) { linetype.putdata(style, cmdList); last_line = style; } if (width != last_width) { linewidth.putdata(width, cmdList); last_width = width; } line.putdata(shape->data+0, shape->data+3, cmdList); append(DMATERIALON); break; } case TRIANGLE: { triangle.putdata(shape->data+0, shape->data+3, shape->data+6, cmdList); break; } case TRINORM: { triangle.putdata(shape->data+0, shape->data+3 , shape->data+6, shape->data+9, shape->data+12, shape->data+15, cmdList); break; } case TRICOLOR: { // compute rgb colors from indices float colors[9]; for (int i=0; i<3; i++) { int c = (int)shape->data[18+i]; c = clamp_int(c, 0, MAXCOLORS-1); vec_copy(colors+3*i, scene->color_value(c)); } const float *verts = shape->data+0; const float *norms = shape->data+9; int facets[3] = { 0,1,2 }; DispCmdTriMesh::putdata(verts, norms, colors, 3, facets, 1, 0, cmdList); } break; case CYLINDER: { cylinder.putdata(shape->data+0, shape->data+3, shape->data[6], int(shape->data[7]), (int (shape->data[8])) ? CYLINDER_TRAILINGCAP | CYLINDER_LEADINGCAP : 0, cmdList); break; } case CONE: { cone.putdata(shape->data+0, shape->data+3, shape->data[6], shape->data[8], int(shape->data[7]), cmdList); break; } case TEXT: { append(DMATERIALOFF); DispCmdText text; DispCmdTextSize textSize; textSize.putdata(shape->data[3], cmdList); text.putdata(shape->data, shapetext[(int)shape->data[5]], shape->data[4], cmdList); append(DMATERIALON); break; } #if 0 // these aren't supported yet case DBEGINREPGEOMGROUP: { char *s = (char *) (shape); beginrepgeomgroup.putdata(s,cmdList); break; } case DCOMMENT: { char *s = (char *) (shape); comment.putdata(s,cmdList); break; } #endif case SPHERE: { int res = int (shape->data[4]); if (res != last_res) { sph_res.putdata(res, cmdList); last_res = res; } sphere.putdata(shape->data+0, shape->data[3], cmdList); break; } case MATERIALS: { if (shape->data[0] == 0) append(DMATERIALOFF); else append(DMATERIALON); break; } case MATERIAL: { const float *data = shape->data; cmdList->ambient = data[0]; cmdList->specular = data[1]; cmdList->diffuse = data[2]; cmdList->shininess = data[3]; cmdList->mirror = data[4]; cmdList->opacity = data[5]; cmdList->outline = data[6]; cmdList->outlinewidth = data[7]; cmdList->transmode = data[8]; cmdList->materialtag = (int)data[9]; break; } case COLOR: { color.putdata(int(shape->data[0]), cmdList); break; } default: msgErr << "Sorry, can't draw that" << sendmsg; } } needRegenerate = 0; }