// 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; }