Beispiel #1
0
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);
}
Beispiel #2
0
// 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);
}
Beispiel #4
0
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;
}