コード例 #1
0
 /** Remove a given manipulator from a given window. The window must be registered. */
 public synchronized void removeManipFromWindow(Manip manip, AWTGLAutoDrawable window) {
   WindowInfo info = (WindowInfo) windowToInfoMap.get(window);
   if (info == null) {
     throw new RuntimeException("Window not registered");
   }
   if (!info.manips.remove(manip)) {
     throw new RuntimeException("Manip not registered in window");
   }
   Set windows = (Set) manipToWindowMap.get(manip);
   assert windows != null;
   windows.remove(window);
 }
コード例 #2
0
 /**
  * Make a given manipulator visible and active in a given window. The window must be registered.
  */
 public synchronized void showManipInWindow(Manip manip, AWTGLAutoDrawable window) {
   WindowInfo info = (WindowInfo) windowToInfoMap.get(window);
   if (info == null) {
     throw new RuntimeException("Window not registered");
   }
   info.manips.add(manip);
   Set windows = (Set) manipToWindowMap.get(manip);
   if (windows == null) {
     windows = new HashSet();
     manipToWindowMap.put(manip, windows);
   }
   windows.add(window);
 }
コード例 #3
0
 /** Remove all references to a given window, including removing all manipulators from it. */
 public synchronized void unregisterWindow(AWTGLAutoDrawable window) {
   if (window == null) {
     return;
   }
   WindowInfo info = (WindowInfo) windowToInfoMap.get(window);
   if (info != null) {
     Object[] manips = info.manips.toArray();
     for (int i = 0; i < manips.length; i++) {
       removeManipFromWindow((Manip) manips[i], window);
     }
     windowToInfoMap.remove(window);
     removeMouseListeners(window);
   }
 }
コード例 #4
0
 private void fireUpdate(Manip manip) {
   Set windows = (Set) manipToWindowMap.get(manip);
   assert windows != null;
   for (Iterator iter = windows.iterator(); iter.hasNext(); ) {
     windowListener.update((AWTGLAutoDrawable) iter.next());
   }
 }
コード例 #5
0
 /**
  * This must be called for a registered window every time the camera parameters of the window
  * change.
  */
 public synchronized void updateCameraParameters(
     AWTGLAutoDrawable window, CameraParameters params) {
   WindowInfo info = (WindowInfo) windowToInfoMap.get(window);
   if (info == null) {
     throw new RuntimeException("Window not registered");
   }
   info.params.set(params);
 }
コード例 #6
0
 /**
  * Cause the manipulators for a given window to be drawn. The drawing occurs immediately; this
  * routine must be called when an OpenGL context is valid, i.e., from within the display() method
  * of a GLEventListener.
  */
 public synchronized void render(AWTGLAutoDrawable window, GL2 gl) {
   WindowInfo info = (WindowInfo) windowToInfoMap.get(window);
   if (info == null) {
     throw new RuntimeException("Window not registered");
   }
   for (Iterator iter = info.manips.iterator(); iter.hasNext(); ) {
     ((Manip) iter.next()).render(gl);
   }
 }
コード例 #7
0
 private void motionMethod(AWTGLAutoDrawable window, int x, int y) {
   WindowInfo info = (WindowInfo) windowToInfoMap.get(window);
   if (info.dragging) {
     // Compute ray in 3D
     Vec3f rayStart = new Vec3f();
     Vec3f rayDirection = new Vec3f();
     computeRay(info.params, x, y, rayStart, rayDirection);
     info.curManip.drag(rayStart, rayDirection);
     fireUpdate(info.curManip);
   }
 }
コード例 #8
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);
        }
      }
    }
  }
コード例 #9
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;
   }
 }
コード例 #10
0
 /**
  * Make the ManipManager aware of the existence of a given window. This causes mouse and mouse
  * motion listeners to be installed on this window; see setupMouseListeners, below.
  */
 public synchronized void registerWindow(AWTGLAutoDrawable window) {
   windowToInfoMap.put(window, new WindowInfo());
   setupMouseListeners(window);
 }