public void mouseEvent(MouseEvent e) {
    float maxSide = parent.max(parent.width, parent.height);

    float mx = e.getX() / maxSide - 1.0f;
    float my = 1.0f - e.getY() / maxSide;

    if (e.getAction() == MouseEvent.PRESS) {
      Mode mode = Mode.NONE;

      if (e.getButton() == PApplet.LEFT) mode = Mode.ROTATE;
      else if (e.getButton() == PApplet.RIGHT) mode = Mode.ZOOM;
      else if (e.getButton() == PApplet.CENTER) mode = Mode.PAN;

      begin(mode, mx, my);
      parent.redraw();
    } else if (e.getAction() == MouseEvent.DRAG) {
      move(mx, my);
      parent.redraw();
    } else if (e.getAction() == MouseEvent.RELEASE) end();
  }
Exemple #2
0
  public void mouseEvent(processing.event.MouseEvent e) {

    switch (e.getAction()) {
      case MouseEvent.PRESS:
        if (e.getButton() == mouseButton) {
          startX = e.getX();
          startY = e.getY();
          mousePressed = 1 + ctrlPressed;
        }
        if (extra > 0 && e.getButton() == extra) {
          startX = e.getX();
          startY = e.getY();
          mousePressed = 1 + ctrlPressed + extra;
        }
        break;
      case MouseEvent.RELEASE:
        if (e.getButton() == mouseButton) {
          panVector.x = 0;
          panVector.y = 0;
          rotVector.x = 0;
          rotVector.y = 0;
          mousePressed = 0;
        }
        break;
        //		case MouseEvent.CLICK:
        //			// do something for mouse clicked
        //			break;
      case MouseEvent.DRAG:
        if (mousePressed > 0) {
          if (mousePressed == 1 && extra == 0) {
            if (switchPanOrbit == 0) {
              panVector.x = panFactor * (startX - e.getX());
              panVector.y = -1 * panFactor * (startY - e.getY());
            } else {
              rotVector.x = rotFactor * (startX - e.getX());
              rotVector.y = pitchFactor * (startY - e.getY());
            }
          }
          if (mousePressed == 2) {
            if (switchPanOrbit == 0) {
              rotVector.x = rotFactor * (startX - e.getX());
              rotVector.y = pitchFactor * (startY - e.getY());
            } else {
              panVector.x = panFactor * (startX - e.getX());
              panVector.y = -1 * panFactor * (startY - e.getY());
            }
          }
          if (extra > 0 && mousePressed == 2 + extra) {
            if (switchPanOrbit == 0) {
              panVector.x = panFactor * (startX - e.getX());
              panVector.y = -1 * panFactor * (startY - e.getY());

            } else {
              rotVector.x = rotFactor * (startX - e.getX());
              rotVector.y = pitchFactor * (startY - e.getY());
            }
          }
          startX = e.getX();
          startY = e.getY();
        }
        break;
      case MouseEvent.MOVE:
        // umm... forgot
        break;
      case MouseEvent.WHEEL:
        System.out.println("the wheel works!");
        break;
    }
  }