Пример #1
0
  private void mouseMethod(AWTGLAutoDrawable window, int modifiers, boolean isPress, int x, int y) {
    if ((modifiers & InputEvent.BUTTON1_MASK) != 0) {
      WindowInfo info = (WindowInfo) windowToInfoMap.get(window);

      if (isPress) {
        // Compute ray in 3D
        Vec3f rayStart = new Vec3f();
        Vec3f rayDirection = new Vec3f();
        computeRay(info.params, x, y, rayStart, rayDirection);
        // Compute all hits
        List hits = new ArrayList();
        for (Iterator iter = info.manips.iterator(); iter.hasNext(); ) {
          ((Manip) iter.next()).intersectRay(rayStart, rayDirection, hits);
        }
        // Find closest one
        HitPoint hp = null;
        for (Iterator iter = hits.iterator(); iter.hasNext(); ) {
          HitPoint cur = (HitPoint) iter.next();
          if ((hp == null) || (cur.intPt.getT() < hp.intPt.getT())) {
            hp = cur;
          }
        }
        if (hp != null) {
          if (info.curHighlightedManip != null) {
            info.curHighlightedManip.clearHighlight();
            fireUpdate(info.curHighlightedManip);
            info.curHighlightedManip = null;
          }

          if ((modifiers & InputEvent.SHIFT_MASK) != 0) {
            hp.shiftDown = true;
          }

          hp.manipulator.makeActive(hp);
          info.curManip = hp.manipulator;
          info.dragging = true;
          fireUpdate(info.curManip);
        }
      } else {
        if (info.curManip != null) {
          info.curManip.makeInactive();
          info.dragging = false;
          fireUpdate(info.curManip);
          info.curManip = null;
          // Check to see where mouse is
          passiveMotionMethod(window, x, y);
        }
      }
    }
  }
Пример #2
0
 private void passiveMotionMethod(AWTGLAutoDrawable window, int x, int y) {
   WindowInfo info = (WindowInfo) windowToInfoMap.get(window);
   // Compute ray in 3D
   Vec3f rayStart = new Vec3f();
   Vec3f rayDirection = new Vec3f();
   computeRay(info.params, x, y, rayStart, rayDirection);
   // Compute all hits
   List hits = new ArrayList();
   for (Iterator iter = info.manips.iterator(); iter.hasNext(); ) {
     ((Manip) iter.next()).intersectRay(rayStart, rayDirection, hits);
   }
   // Find closest one
   HitPoint hp = null;
   for (Iterator iter = hits.iterator(); iter.hasNext(); ) {
     HitPoint cur = (HitPoint) iter.next();
     if ((hp == null) || (cur.intPt.getT() < hp.intPt.getT())) {
       hp = cur;
     }
   }
   if (info.curHighlightedManip != null
       && (hp == null
           || hp.manipulator != info.curHighlightedManip
           || hp.manipPart != info.curHighlightedManipPart)) {
     info.curHighlightedManip.clearHighlight();
     fireUpdate(info.curHighlightedManip);
   }
   if (hp != null) {
     if (hp.manipulator != info.curHighlightedManip
         || hp.manipPart != info.curHighlightedManipPart) {
       // Highlight manip
       info.curHighlightedManip = hp.manipulator;
       info.curHighlightedManipPart = hp.manipPart;
       info.curHighlightedManip.highlight(hp);
       fireUpdate(info.curHighlightedManip);
     }
   } else {
     info.curHighlightedManip = null;
   }
 }