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); } } } }
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()); } }
/** * 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); } }
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; } }