Beispiel #1
0
 private void deleteCurrent(View view) {
   CalibrationContext context = view.getCalibrationContext();
   if (context.currentSelection != -1) {
     context.modelVertices.remove(context.currentSelection);
     context.projectedVertices.remove(context.currentSelection);
     context.currentSelection = -1;
     calibrate(view);
   }
 }
Beispiel #2
0
  @Override
  public void mousePressed(MouseEvent e, View view) {
    button = e.getButton();
    if (selectedView != view) {
      selectedView = view;
      repaintAll();
    }
    if (mode == ControlMode.CALIBRATE) {
      CalibrationContext context = view.getCalibrationContext();

      // reset first
      context.currentSelection = -1;

      // first, try to hit calibration point
      for (int i = 0; i < context.projectedVertices.size(); ++i) {
        int x = view.deviceToScreenX(context.projectedVertices.get(i).getX());
        int y = view.deviceToScreenY(context.projectedVertices.get(i).getY());
        if (snap2D(e.getX(), view.getHeight() - e.getY(), x, y)) {
          // we got a point to move!
          context.currentSelection = i;
          view.repaint();
          return;
        }
      }

      // second, try to hit model point
      float[] mv = getModel().getCalibrationVertices();
      double[] vv = new double[3];
      for (int i = 0; i < mv.length; i += 3) {
        if (!view.projectToScreenCoordinates(mv[i], mv[i + 1], mv[i + 2], vv)) continue;
        if (snap2D(e.getX(), view.getHeight() - e.getY(), (int) vv[0], (int) vv[1])) {
          Vector3D a = new Vector3D(mv[i], mv[i + 1], mv[i + 2]);
          int index = context.modelVertices.indexOf(a);
          if (index != -1) {
            context.currentSelection = index;
          } else {
            context.currentSelection = context.modelVertices.size();
            context.modelVertices.add(a);
            context.projectedVertices.add(
                new Vector3D(
                    view.screenToDeviceX((int) vv[0]), view.screenToDeviceY((int) vv[1]), 0));
          }
          calibrate(view);
          view.repaint();
          return;
        }
      }
    }
  }
Beispiel #3
0
  private void calibrate(View view) {
    try {
      CalibrationContext context = view.getCalibrationContext();
      context.calibrated = false;

      double error =
          getCalibrator()
              .calibrate(context.modelVertices, context.projectedVertices, View.NEAR, View.FAR);
      if (error < MAX_CALIBRATION_ERROR) context.calibrated = true;

      view.setProjectionMatrix(getCalibrator().getProjectionMatrix());
      view.setModelviewMatrix(getCalibrator().getModelviewMatrix());
      view.repaint();
      // System.out.println("error: " + error);
    } catch (Throwable t) {
    }
  }