Search in sources :

Example 91 with InternalErrorException

use of maspack.util.InternalErrorException in project artisynth_core by artisynth.

the class GL2Viewer method drawArrow.

public void drawArrow(RenderProps props, float[] pnt0, float[] pnt1, boolean capped, boolean highlight) {
    boolean savedHighlighting = getHighlighting();
    Shading savedShading = setLineShading(props);
    setLineColoring(props, highlight);
    GL2 gl = getGL2();
    maybeUpdateState(gl);
    utmp.set(pnt1[0] - pnt0[0], pnt1[1] - pnt0[1], pnt1[2] - pnt0[2]);
    double len = utmp.norm();
    utmp.normalize();
    vtmp.set(pnt0[0], pnt0[1], pnt0[2]);
    double arrowRad = 3 * props.getLineRadius();
    double arrowLen = 2 * arrowRad;
    vtmp.scaledAdd(len - arrowLen, utmp);
    ctmp[0] = (float) vtmp.x;
    ctmp[1] = (float) vtmp.y;
    ctmp[2] = (float) vtmp.z;
    if (len > arrowLen) {
        switch(props.getLineStyle()) {
            case LINE:
                {
                    setLineWidth(gl, props.getLineWidth());
                    gl.glBegin(GL2.GL_LINES);
                    gl.glVertex3fv(pnt0, 0);
                    gl.glVertex3fv(ctmp, 0);
                    gl.glEnd();
                    break;
                }
            case CYLINDER:
            case SOLID_ARROW:
                {
                    drawCylinder(pnt0, ctmp, props.getLineRadius(), capped);
                    break;
                }
            case SPINDLE:
                {
                    drawSpindle(pnt0, pnt1, props.getLineRadius());
                    break;
                }
            default:
                {
                    throw new InternalErrorException("Unimplemented line style " + props.getLineStyle());
                }
        }
    }
    if (props.getLineStyle() == LineStyle.LINE) {
        // reset shading from NONE to props value
        setShading(props.getShading());
    }
    if (len <= arrowLen) {
        doDrawCylinder(pnt0, pnt1, capped, len / 2, 0.0);
    } else {
        doDrawCylinder(ctmp, pnt1, capped, arrowRad, 0.0);
    }
    setShading(savedShading);
    setHighlighting(savedHighlighting);
}
Also used : InternalErrorException(maspack.util.InternalErrorException) GL2(com.jogamp.opengl.GL2)

Example 92 with InternalErrorException

use of maspack.util.InternalErrorException in project artisynth_core by artisynth.

the class GL2Viewer method drawLine.

public void drawLine(RenderProps props, float[] pnt0, float[] pnt1, float[] color, boolean capped, boolean highlight) {
    boolean savedHighlighting = getHighlighting();
    Shading savedShading = setLineShading(props);
    if (color == null) {
        color = props.getLineColorF();
    }
    setPropsColoring(props, color, highlight);
    GL2 gl = getGL2();
    maybeUpdateState(gl);
    if (color == null) {
        color = props.getLineColorF();
    }
    switch(props.getLineStyle()) {
        case LINE:
            {
                // setLightingEnabled (false);
                setLineWidth(gl, props.getLineWidth());
                // if (color.length == 3 && props.getAlpha () < 1) {
                // color = new float[]{color[0], color[1], color[2], (float)props.getAlpha ()};
                // }
                // setColor (color, selected);
                gl.glBegin(GL2.GL_LINES);
                gl.glVertex3fv(pnt0, 0);
                gl.glVertex3fv(pnt1, 0);
                gl.glEnd();
                // setLightingEnabled (true);
                break;
            }
        case CYLINDER:
            {
                // setShadeModel (props.getShading());
                // setPropsMaterial (props, color, selected);
                drawCylinder(pnt0, pnt1, props.getLineRadius(), capped);
                // restoreShading (props);
                break;
            }
        case SOLID_ARROW:
            {
                // setShadeModel (props.getShading());
                // setPropsMaterial (props, color, selected);
                drawArrow(pnt0, pnt1, props.getLineRadius(), capped);
                // restoreShading (props);
                break;
            }
        case SPINDLE:
            {
                // setShadeModel (props.getShading());
                // setPropsMaterial (props, color, selected);
                drawSpindle(pnt0, pnt1, props.getLineRadius());
                // restoreShading (props);
                break;
            }
        default:
            {
                throw new InternalErrorException("Unimplemented line style " + props.getLineStyle());
            }
    }
    setShading(savedShading);
    setHighlighting(savedHighlighting);
}
Also used : InternalErrorException(maspack.util.InternalErrorException) GL2(com.jogamp.opengl.GL2)

Aggregations

InternalErrorException (maspack.util.InternalErrorException)92 Vector3d (maspack.matrix.Vector3d)9 CompositeProperty (maspack.properties.CompositeProperty)8 Point3d (maspack.matrix.Point3d)7 Property (maspack.properties.Property)7 FemModel3d (artisynth.core.femmodels.FemModel3d)6 Point (artisynth.core.mechmodels.Point)6 ModelComponent (artisynth.core.modelbase.ModelComponent)5 PolygonalMesh (maspack.geometry.PolygonalMesh)5 Line (maspack.matrix.Line)5 RigidTransform3d (maspack.matrix.RigidTransform3d)5 EditingProperty (maspack.properties.EditingProperty)5 BadLocationException (javax.swing.text.BadLocationException)4 RotationMatrix3d (maspack.matrix.RotationMatrix3d)4 RigidBody (artisynth.core.mechmodels.RigidBody)3 RootModel (artisynth.core.workspace.RootModel)3 File (java.io.File)3 IOException (java.io.IOException)3 LinkedList (java.util.LinkedList)3 SelectionManager (artisynth.core.gui.selectionManager.SelectionManager)2