// given the front surface coordinates(4) in counter clockwise direction // draw the solid box that goes around the box with that // surface, and a depth of 0.25 deep // The optional field requests that the ends also be covered static void draw_outsides(float c[8][3], VMDDisplayList *disp, int draw_ends=TRUE) { float zoffset[3] = { 0, 0, 0.25}; // make the other 4 coords for (int i=0; i<4; i++) vec_sub(c[i+4], c[i], zoffset); DispCmdTriangle tri; // draw the front parallegram tri.putdata(c[0], c[1], c[2], disp); tri.putdata(c[2], c[3], c[0], disp); // draw the rear parallegram tri.putdata(c[5], c[4], c[6], disp); tri.putdata(c[6], c[4], c[7], disp); // draw the left face tri.putdata(c[0], c[3], c[7], disp); tri.putdata(c[7], c[4], c[0], disp); // draw the right face tri.putdata(c[1], c[5], c[6], disp); tri.putdata(c[6], c[2], c[1], disp); if (!draw_ends) return; // draw the top face tri.putdata(c[0], c[5], c[4], disp); tri.putdata(c[5], c[0], c[1], disp); // draw the bottom face tri.putdata(c[2], c[7], c[3], disp); tri.putdata(c[7], c[2], c[6], disp); }
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; }