Exemplo n.º 1
0
void ViewPort::glDraw(const Rectangle3R &bbox) const {
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();

  // Background
  glBegin(GL_QUADS);
  glColor3ub(0x25, 0x30, 0x40);
  glVertex2f(-1, -1);
  glVertex2f(1, -1);
  glColor3ub(0x5, 0x5, 0x5);
  glVertex2f(1, 1);
  glVertex2f(-1, 1);
  glEnd();

  // Compute "radius"
  Vector3R dims = bbox.getDimensions();
  real radius = dims.x() < dims.y() ? dims.y() : dims.x();
  radius = dims.z() < radius ? radius : dims.z();

  // Perspective
  gluPerspective(45, (float)width / height, 1, 100000);

  // Translate
  glTranslatef(translation.x() * radius / zoom,
               translation.y() * radius / zoom, 0);

  // Scale
  gluLookAt(0, 0, radius / zoom, 0, 0, 0, 0, 1, 0);

  glMatrixMode(GL_MODELVIEW);

  // Rotate
  glRotated(rotation[0], rotation[1], rotation[2], rotation[3]);

  // Center
  Vector3R center = bbox.getCenter();
  glTranslatef(-center.x(), -center.y(), -center.z());

  // Axes
  if (axes) {
    double length = (bbox.getWidth() + bbox.getLength() + bbox.getHeight()) / 3;
    length *= 0.1;
    double radius = length / 20;

    setLighting(true);

    for (int axis = 0; axis < 3; axis++)
      for (int up = 0; up < 2; up++)
        drawAxis(axis, up, length, radius);

    setLighting(false);
  }
  
  // Bounds
  if (bounds) {
    glEnable(GL_LINE_STIPPLE);
    glLineStipple(1, 0x5555);
    glLineWidth(1);
    glColor4f(1, 1, 1, 0.5); // White

    BoundsView(bbox).draw();

    glDisable(GL_LINE_STIPPLE);
  }
}
Exemplo n.º 2
0
Workpiece::Workpiece(const Rectangle3R &r) :
  Rectangle3R(r), center(r.getCenter()) {
  Vector3R halfDim = r.getDimensions() / 2;
  halfDim2 = halfDim * halfDim;
}