示例#1
0
  /** Translate specified camera view */
  public void translateView(vtkCamera c, vtkRenderer r, double dx, double dy) {
    // translation mode
    double FPoint[];
    double PPoint[];
    double APoint[] = new double[3];
    double RPoint[];
    double focalDepth;

    lock();
    try {
      // get the current focal point and position
      FPoint = c.GetFocalPoint();
      PPoint = c.GetPosition();

      // calculate the focal depth since we'll be using it a lot
      r.SetWorldPoint(FPoint[0], FPoint[1], FPoint[2], 1.0);
      r.WorldToDisplay();
      focalDepth = r.GetDisplayPoint()[2];

      final int[] size = rw.GetSize();
      APoint[0] = (size[0] / 2.0) + dx;
      APoint[1] = (size[1] / 2.0) + dy;
      APoint[2] = focalDepth;
      r.SetDisplayPoint(APoint);
      r.DisplayToWorld();
      RPoint = r.GetWorldPoint();
      if (RPoint[3] != 0.0) {
        RPoint[0] = RPoint[0] / RPoint[3];
        RPoint[1] = RPoint[1] / RPoint[3];
        RPoint[2] = RPoint[2] / RPoint[3];
      }

      /*
       * Compute a translation vector, moving everything 1/2 the distance
       * to the cursor. (Arbitrary scale factor)
       */
      c.SetFocalPoint(
          (FPoint[0] - RPoint[0]) / 2.0 + FPoint[0],
          (FPoint[1] - RPoint[1]) / 2.0 + FPoint[1],
          (FPoint[2] - RPoint[2]) / 2.0 + FPoint[2]);
      c.SetPosition(
          (FPoint[0] - RPoint[0]) / 2.0 + PPoint[0],
          (FPoint[1] - RPoint[1]) / 2.0 + PPoint[1],
          (FPoint[2] - RPoint[2]) / 2.0 + PPoint[2]);
      r.ResetCameraClippingRange();
    } finally {
      unlock();
    }
  }
示例#2
0
 /** Set the specified light at the same position than the specified camera */
 public static void setLightToCameraPosition(vtkLight l, vtkCamera c) {
   l.SetPosition(c.GetPosition());
   l.SetFocalPoint(c.GetFocalPoint());
 }