Search in sources :

Example 6 with Dragger3d

use of maspack.render.Dragger3d in project artisynth_core by artisynth.

the class GLMouseAdapter method updateDraggerModeAndFlags.

private void updateDraggerModeAndFlags(int mods, Dragger3d dragger) {
    dragger.clearFlags();
    int draggerFlags = 0;
    Dragger3d.DragMode dragMode = Dragger3d.DragMode.OFF;
    if ((mods & draggerConstrainMask) == draggerConstrainMask) {
        draggerFlags |= Dragger3d.CONSTRAIN;
    }
    if ((mods & draggerRepositionMask) == draggerRepositionMask) {
        draggerFlags |= Dragger3d.REPOSITION;
        dragMode = Dragger3d.DragMode.REPOSITION;
    } else if ((mods & draggerDragMask) == draggerDragMask) {
        dragMode = Dragger3d.DragMode.DRAG;
    }
    dragger.setDragMode(dragMode);
    dragger.setFlags(draggerFlags);
}
Also used : DragMode(maspack.render.Dragger3d.DragMode) Point(java.awt.Point) Dragger3d(maspack.render.Dragger3d)

Example 7 with Dragger3d

use of maspack.render.Dragger3d in project artisynth_core by artisynth.

the class GLMouseAdapter method mouseClicked.

public void mouseClicked(MouseEvent e) {
    Dragger3d drawTool = viewer.myDrawTool;
    int mods = e.getModifiersEx() & ALL_MODIFIERS;
    boolean grabbed = false;
    if (viewer.myDraggers.size() > 0 || drawTool != null) {
        MouseRayEvent rayEvt = MouseRayEvent.create(e, viewer);
        for (Dragger3d d : viewer.myDraggers) {
            // pass event to any visible Dragger3dBase, or any other Dragger3d
            if (d.isVisible()) {
                updateDraggerModeAndFlags(mods, d);
                if (d.mouseClicked(rayEvt)) {
                    grabbed = true;
                    dragAction = DRAGGER_ACTION;
                    break;
                }
            }
        }
        if (drawTool != null && drawTool.isVisible()) {
            updateDraggerModeAndFlags(mods, drawTool);
            if (drawTool.mouseClicked(rayEvt)) {
                grabbed = true;
            }
        }
    }
    if (grabbed) {
        viewer.repaint();
    }
}
Also used : MouseRayEvent(maspack.render.MouseRayEvent) Point(java.awt.Point) Dragger3d(maspack.render.Dragger3d)

Example 8 with Dragger3d

use of maspack.render.Dragger3d in project artisynth_core by artisynth.

the class GLMouseAdapter method mouseMoved.

public void mouseMoved(MouseEvent e) {
    currentCursor = new Point(e.getX(), e.getY());
    if (viewer.getEllipticSelection()) {
        viewer.repaint();
    } else {
        int mods = e.getModifiersEx() & ALL_MODIFIERS;
        Dragger3d drawTool = viewer.myDrawTool;
        boolean grabbed = false;
        if (viewer.myDraggers.size() > 0 || drawTool != null) {
            MouseRayEvent rayEvt = MouseRayEvent.create(e, viewer);
            for (Dragger3d d : viewer.myDraggers) {
                // pass event to any visible Dragger3dBase, or any other Dragger3d
                if (d.isVisible()) {
                    updateDraggerFlags(mods, d);
                    if (d.mouseMoved(rayEvt)) {
                        grabbed = true;
                        break;
                    }
                }
            }
            if (drawTool != null && drawTool.isVisible()) {
                updateDraggerFlags(mods, drawTool);
                if (drawTool.mouseMoved(rayEvt)) {
                    grabbed = true;
                }
            }
        }
        if (grabbed) {
            viewer.repaint();
        }
    }
}
Also used : MouseRayEvent(maspack.render.MouseRayEvent) Point(java.awt.Point) Point(java.awt.Point) Dragger3d(maspack.render.Dragger3d)

Example 9 with Dragger3d

use of maspack.render.Dragger3d in project artisynth_core by artisynth.

the class GL3Viewer method doDisplay.

private void doDisplay(GLAutoDrawable drawable, int flags) {
    // updates projection matrix
    if (resetViewVolume && autoResizeEnabled) {
        resetViewVolume(gl);
        resetViewVolume = false;
    }
    if (resetViewport && autoViewportEnabled) {
        setViewport(gl, 0, 0, width, height);
        resetViewport = false;
    }
    int nclips = Math.min(2 * myClipPlanes.size(), maxClipPlanes);
    myProgramInfo.setNumClipPlanes(nclips);
    myProgManager.reconfigure(gl, lightManager.numLights(), nclips);
    myProgManager.setLights(gl, lightManager.getLights(), 1.0f / lightManager.getMaxIntensity(), viewMatrix);
    // update matrices
    maybeUpdateState(gl);
    // clear background/depth
    gl.glClearColor(backgroundColor[0], backgroundColor[1], backgroundColor[2], backgroundColor[3]);
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    if (!isSelecting()) {
        if (gridVisible) {
            myGrid.render(this, flags);
        }
        if (axisLength > 0) {
            if (solidAxes) {
                drawSolidAxes(null, axisLength, axisLength / 50.0, false);
            } else {
                drawAxes(gl, axisLength);
            }
        }
        // not clipped by the clipping plane
        for (Dragger3d dragger : myDraggers) {
            dragger.render(this, 0);
        }
        if (myDrawTool != null) {
            myDrawTool.render(this, 0);
        }
        for (GLClipPlane cp : myClipPlanes) {
            cp.render(this, flags);
        }
    }
    for (int i = 0; i < myProgManager.numClipPlanes(); ++i) {
        boolean enabled = gl.glIsEnabled(GL3.GL_CLIP_DISTANCE0 + i);
        if (enabled) {
            Logger.getSystemLogger().debug("Why is this enabled?");
        }
    }
    // enable clip planes
    int iclips = 0;
    if (nclips > 0) {
        iclips = myProgManager.setClipPlanes(gl, myClipPlanes);
        for (int i = 0; i < iclips; ++i) {
            gl.glEnable(GL3.GL_CLIP_DISTANCE0 + i);
        }
    }
    if (!isSelecting()) {
        setFrontColor(DEFAULT_MATERIAL_COLOR);
    }
    int qid = 0;
    synchronized (myInternalRenderList) {
        qid = myInternalRenderList.renderOpaque(this, qid, flags);
    }
    RenderList elist = myExternalRenderList;
    if (elist != null) {
        synchronized (elist) {
            qid = elist.renderOpaque(this, qid, flags);
        }
    }
    if (hasTransparent3d()) {
        if (!isSelecting()) {
            enableTransparency();
        }
        synchronized (myInternalRenderList) {
            qid = myInternalRenderList.renderTransparent(this, qid, flags);
        }
        if (elist != null) {
            synchronized (elist) {
                qid = elist.renderTransparent(this, qid, flags);
            }
        }
        if (!isSelecting()) {
            disableTransparency();
        }
    }
    // disable clip planes
    for (int i = 0; i < nclips; ++i) {
        gl.glDisable(GL3.GL_CLIP_DISTANCE0 + i);
    }
    // Draw 2D objects
    if (has2d()) {
        begin2DRendering(width, height);
        try {
            synchronized (myInternalRenderList) {
                qid = myInternalRenderList.renderOpaque2d(this, qid, 0);
            }
            if (elist != null) {
                synchronized (elist) {
                    qid = elist.renderOpaque2d(this, qid, 0);
                }
            }
            if (hasTransparent2d()) {
                if (!isSelecting()) {
                    enableTransparency();
                }
                synchronized (myInternalRenderList) {
                    qid = myInternalRenderList.renderTransparent2d(this, qid, 0);
                }
                if (elist != null) {
                    synchronized (elist) {
                        qid = elist.renderTransparent2d(this, qid, 0);
                    }
                }
                if (!isSelecting()) {
                    disableTransparency();
                }
            }
        } finally {
            // methods throws and exception
            if (isTransparencyEnabled()) {
                disableTransparency();
            }
            end2DRendering();
        }
    }
    if (!isSelecting()) {
        if (myDragBox != null) {
            drawDragBox(gl);
        }
        if (myEllipticCursorActive) {
            Point cursor = myMouseHandler.getCurrentCursor();
            if (cursor != null) {
                drawEllipticCursor(gl, cursor);
            }
        }
    } else {
        // revert clear color
        gl.glClearColor(backgroundColor[0], backgroundColor[1], backgroundColor[2], backgroundColor[3]);
    }
    // trigger update of state (required for GLJPanel, which relies on
    // transparency to be off)
    maybeUpdateState(gl);
    gl.glFlush();
}
Also used : Point(java.awt.Point) GLClipPlane(maspack.render.GL.GLClipPlane) Point(java.awt.Point) RenderList(maspack.render.RenderList) Dragger3d(maspack.render.Dragger3d)

Example 10 with Dragger3d

use of maspack.render.Dragger3d in project artisynth_core by artisynth.

the class ViewerManager method resetViewer.

public void resetViewer(GLViewer viewer) {
    viewer.clearDraggers();
    for (Dragger3d d : myDraggers) {
        viewer.addDragger(d);
    }
    viewer.setExternalRenderList(getRenderList());
    if (myDefaultOrthographic) {
        viewer.autoFitOrtho();
    } else {
        viewer.autoFitPerspective();
    }
    if (myDefaultDrawAxes) {
        if (myDefaultAxisLength > 0) {
            viewer.setAxisLength(myDefaultAxisLength);
        } else {
            viewer.setAxisLength(GLViewer.AUTO_FIT);
        }
    }
    viewer.setGridVisible(myDefaultDrawGrid);
    viewer.setBackgroundColor(myBackgroundColor);
    viewer.setHighlightColor(mySelectionColor);
    viewer.setBlendDestFactor(GLViewer.DEFAULT_DST_BLENDING);
}
Also used : Dragger3d(maspack.render.Dragger3d)

Aggregations

Dragger3d (maspack.render.Dragger3d)11 Point (java.awt.Point)7 MouseRayEvent (maspack.render.MouseRayEvent)5 Vector2d (maspack.matrix.Vector2d)2 GLClipPlane (maspack.render.GL.GLClipPlane)2 RenderList (maspack.render.RenderList)2 SplineTool (maspack.widgets.SplineTool)2 GL2 (com.jogamp.opengl.GL2)1 Rectangle (java.awt.Rectangle)1 NURBSCurve2d (maspack.geometry.NURBSCurve2d)1 RigidTransform3d (maspack.matrix.RigidTransform3d)1 DragMode (maspack.render.Dragger3d.DragMode)1