Search in sources :

Example 6 with AxisAngle

use of maspack.matrix.AxisAngle in project artisynth_core by artisynth.

the class RotatableScaler3d method updateRotation.

protected void updateRotation(RotationMatrix3d Rot, boolean constrained, boolean repositioning) {
    RotationMatrix3d R = new RotationMatrix3d();
    R.mulInverseLeft(myRot0, Rot);
    if (constrained) {
        AxisAngle axisAng = new AxisAngle();
        R.getAxisAngle(axisAng);
        double deg = Math.toDegrees(axisAng.angle);
        axisAng.angle = Math.toRadians(5 * Math.round(deg / 5));
        R.setAxisAngle(axisAng);
        myRotPnt.transform(R, myPnt0);
    }
    RotationMatrix3d Rinc = new RotationMatrix3d();
    Rinc.mulInverseLeft(myLastR, R);
    myLastR.set(R);
    if (repositioning) {
        myXDraggerToWorld.R.mul(Rinc);
    }
}
Also used : AxisAngle(maspack.matrix.AxisAngle) RotationMatrix3d(maspack.matrix.RotationMatrix3d)

Example 7 with AxisAngle

use of maspack.matrix.AxisAngle in project artisynth_core by artisynth.

the class Rotator3d method mouseDragged.

public boolean mouseDragged(MouseRayEvent e) {
    if (mySelectedComponent != NONE) {
        // boolean constrained = dragIsConstrained (e);
        boolean constrained = dragIsConstrained();
        findRotation(myRot, myRotPnt, e.getRay());
        myRot.mulInverseLeft(myRot0, myRot);
        if (constrained) {
            AxisAngle axisAng = new AxisAngle();
            myRot.getAxisAngle(axisAng);
            double deg = Math.toDegrees(axisAng.angle);
            axisAng.angle = Math.toRadians(5 * Math.round(deg / 5));
            myRot.setAxisAngle(axisAng);
            myRotPnt.transform(myRot, myPnt0);
        }
        // myTransform.setIdentity();
        myIncrementalTransform.R.mulInverseLeft(myTransform.R, myRot);
        myTransform.R.set(myRot);
        // if (!dragIsRepositioning(e)) {
        if (!dragIsRepositioning()) {
            fireDraggerMoveListeners(myTransform, myIncrementalTransform, e.getModifiersEx());
        } else {
            myXDraggerToWorld.mul(myIncrementalTransform);
        }
        return true;
    }
    return false;
}
Also used : AxisAngle(maspack.matrix.AxisAngle)

Example 8 with AxisAngle

use of maspack.matrix.AxisAngle in project artisynth_core by artisynth.

the class MultiViewerTesterBase method loadStanfordBunny.

protected static PolygonalMesh loadStanfordBunny() {
    // read Standford bunny directly
    String bunnyURL = "http://graphics.stanford.edu/~mdfisher/Data/Meshes/bunny.obj";
    // bunny
    File bunnyFile = new File("tmp/data/stanford_bunny.obj");
    PolygonalMesh bunny = null;
    try {
        if (!bunnyFile.exists()) {
            bunnyFile.getParentFile().mkdirs();
            // read file directly from remote
            FileCacher cacher = new FileCacher();
            cacher.initialize();
            cacher.cache(new URIx(bunnyURL), bunnyFile);
            cacher.release();
        }
        WavefrontReader reader = new WavefrontReader(bunnyFile);
        bunny = new PolygonalMesh();
        reader.readMesh(bunny);
        // bunny.computeVertexNormals();
        // normalize bunny
        double r = bunny.computeRadius();
        Vector3d c = new Vector3d();
        bunny.computeCentroid(c);
        c.negate();
        bunny.scale(1.0 / r);
        c.z -= 0.5;
        bunny.transform(new RigidTransform3d(c, new AxisAngle(1, 0, 0, Math.PI / 2)));
        reader.close();
    } catch (IOException e1) {
        e1.printStackTrace();
        System.out.println("Unable to load stanford bunny... requires internet connection");
        bunny = null;
    }
    return bunny;
}
Also used : WavefrontReader(maspack.geometry.io.WavefrontReader) RigidTransform3d(maspack.matrix.RigidTransform3d) AxisAngle(maspack.matrix.AxisAngle) Vector3d(maspack.matrix.Vector3d) FileCacher(maspack.fileutil.FileCacher) URIx(maspack.fileutil.uri.URIx) IOException(java.io.IOException) File(java.io.File) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 9 with AxisAngle

use of maspack.matrix.AxisAngle in project artisynth_core by artisynth.

the class TextTester method addContent.

@Override
protected void addContent(MultiViewer mv) {
    final HashMap<String, Font> fontMap = new HashMap<>();
    for (Font font : GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts()) {
        fontMap.put(font.getName(), font);
    }
    mv.addRenderable(new SimpleSelectable() {

        JFrame debugframe = null;

        @Override
        public void updateBounds(Vector3d pmin, Vector3d pmax) {
            Point3d p1 = new Point3d(-3, -3, -3);
            Point3d p2 = new Point3d(3, 3, 3);
            p1.updateBounds(pmin, pmax);
            p2.updateBounds(pmin, pmax);
        }

        @Override
        public void render(Renderer renderer, int flags) {
            if (debugframe == null) {
                TextImageStore store = ((GLViewer) renderer).getTextRenderer().getImageStore();
                debugframe = TextImageStore.createDisplayFrame(store);
                debugframe.setVisible(true);
            }
            renderer.setShading(Shading.FLAT);
            renderer.setColor(Color.WHITE);
            renderer.setFaceStyle(FaceStyle.FRONT_AND_BACK);
            // renderer.drawSphere (Point3d.ZERO, 0.01);
            Font font = new Font(Font.SANS_SERIF, 0, 54);
            renderer.drawText(font, "Hello world! And goodnight to all.", new float[] { 0.4f, 0.3f, 0.3f }, 0.25);
            renderer.setColor(Color.ORANGE);
            String text = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
            renderer.drawText(font, text, new float[] { -2f, 0f, 0f }, 0.25);
            Font comic = fontMap.get("Comic Sans MS");
            if (comic == null) {
                comic = new Font(Font.MONOSPACED, Font.BOLD, 32);
            } else {
                comic = comic.deriveFont(Font.BOLD, 32);
            }
            renderer.setColor(Color.CYAN);
            text = "Cowabunga";
            Rectangle2D rect = renderer.getTextBounds(comic, text, 0.25);
            renderer.drawText(comic, text, new float[] { -(float) (rect.getWidth()), 0.5f, 0f }, 0.25);
            renderer.setColor(Color.MAGENTA);
            text = "Flip me!";
            font = new Font(Font.SERIF, Font.PLAIN, 64);
            rect = renderer.getTextBounds(font, text, 0.3);
            renderer.pushModelMatrix();
            RigidTransform3d trans = new RigidTransform3d(new Vector3d(0, -0.4, 0), new AxisAngle(0, 1, 0, Math.toRadians(30)));
            renderer.mulModelMatrix(trans);
            renderer.setFaceStyle(FaceStyle.FRONT);
            renderer.drawText(font, text, Point3d.ZERO, 0.3);
            trans = new RigidTransform3d(Vector3d.ZERO, new AxisAngle(0, 1, 0, Math.PI));
            renderer.mulModelMatrix(trans);
            renderer.drawText(font, text, new Point3d(-rect.getWidth(), 0, 0), 0.3);
            trans = new RigidTransform3d(Vector3d.ZERO, new AxisAngle(0.1, 1, 0, Math.PI * 1));
            renderer.mulModelMatrix(trans);
            renderer.setShading(Shading.NONE);
            renderer.setFaceStyle(FaceStyle.FRONT_AND_BACK);
            renderer.setColor(Color.GREEN);
            text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean sagittis hendrerit consequat. Duis id purus neque. Nulla luctus pretium lorem vel convallis. Praesent non ex eu risus porttitor scelerisque vel et lorem. Maecenas ultricies imperdiet tortor, ac varius enim. Integer sagittis dui lacus. Nulla vitae egestas orci. Phasellus vel metus vitae nibh imperdiet imperdiet ut a urna.";
            drawMultiline(renderer, font, text, new float[] { -1.75f, -0.2f, -0.5f }, 0.1, 2);
            renderer.popModelMatrix();
        }

        public void drawMultiline(Renderer renderer, Font font, String text, float[] loc, double size, double linelength) {
            float left = loc[0];
            float[] nloc = { loc[0], loc[1], loc[2] };
            Rectangle2D rect = renderer.getTextBounds(font, text, size);
            float lineheight = (float) (rect.getHeight());
            String[] words = text.split(" ");
            int w = 0;
            while (w < words.length) {
                String word = words[w];
                nloc[0] += renderer.drawText(font, word, nloc, size);
                ++w;
                while (w < words.length && nloc[0] < left + linelength) {
                    word = " " + words[w];
                    rect = renderer.getTextBounds(font, word, size);
                    double ll = nloc[0] + rect.getWidth();
                    if (ll < left + linelength) {
                        renderer.drawText(font, word, nloc, size);
                        ++w;
                    }
                    nloc[0] = (float) ll;
                }
                // newline
                nloc[0] = left;
                nloc[1] -= lineheight;
            }
        }

        @Override
        public void prerender(RenderList list) {
        }

        @Override
        public int getRenderHints() {
            return 0;
        }

        @Override
        public int numSelectionQueriesNeeded() {
            return 0;
        }

        @Override
        public boolean isSelectable() {
            return false;
        }

        @Override
        public void getSelection(LinkedList<Object> list, int qid) {
        }

        @Override
        public void setSelected(boolean set) {
        }

        @Override
        public boolean isSelected() {
            return false;
        }
    });
    mv.setAxialView(AxisAlignedRotation.X_Y);
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) HashMap(java.util.HashMap) Rectangle2D(java.awt.geom.Rectangle2D) Font(java.awt.Font) RenderList(maspack.render.RenderList) GLViewer(maspack.render.GL.GLViewer) AxisAngle(maspack.matrix.AxisAngle) SimpleSelectable(maspack.test.GL.MultiViewer.SimpleSelectable) JFrame(javax.swing.JFrame) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) Renderer(maspack.render.Renderer) TextImageStore(maspack.render.TextImageStore)

Example 10 with AxisAngle

use of maspack.matrix.AxisAngle in project artisynth_core by artisynth.

the class AffineTransformWidget method initialize.

private void initialize(String compSpec, String fmtStr) {
    myPanel = new LabeledComponentPanel();
    for (int i = 0; i < compSpec.length(); i++) {
        switch(compSpec.charAt(i)) {
            case 'T':
                {
                    if (myTranslationField == null) {
                        myTranslationField = new VectorField("Pos:", 3);
                        myTranslationField.setResultHolder(new Vector3d());
                        myTranslationField.setFormat(fmtStr);
                        myFields.add(myTranslationField);
                    }
                    break;
                }
            case 'R':
                {
                    if (myRotationField == null) {
                        myRotationField = new AxisAngleField("Rot:");
                        myFields.add(myRotationField);
                    }
                    break;
                }
            case 'S':
                {
                    if (myScaleField == null) {
                        myScaleField = new ScaleField("Scale:");
                        myScaleField.setFormat(fmtStr);
                        myFields.add(myScaleField);
                    }
                    break;
                }
            case 'X':
                {
                    if (myShearField == null) {
                        myShearField = new VectorField("Shear:", 3);
                        myShearField.setResultHolder(new Vector3d());
                        myShearField.setFormat(fmtStr);
                        myFields.add(myShearField);
                    }
                    break;
                }
            default:
                {
                // unknown letters are ignored
                }
        }
    }
    int maxColumns = 0;
    for (LabeledTextField c : myFields) {
        c.addValueChangeListener(this);
        c.setVoidValueEnabled(true);
        c.setStretchable(false);
        if (c.getColumns() > maxColumns) {
            maxColumns = c.getColumns();
        }
        myPanel.addWidget(c);
    }
    // adjust columns to match
    for (LabeledTextField c : myFields) {
        c.setColumns(maxColumns);
    }
    // packFields();
    addMajorComponent(myPanel);
    // allocate places to store values for widgets that are null
    if (myTranslationField == null) {
        myTranslation = new Vector3d();
    }
    if (myRotationField == null) {
        myRotation = new AxisAngle();
    }
    if (myScaleField == null) {
        myScale = new Vector3d();
    }
    if (myShearField == null) {
        myShear = new Vector3d();
    }
}
Also used : AxisAngle(maspack.matrix.AxisAngle) Vector3d(maspack.matrix.Vector3d)

Aggregations

AxisAngle (maspack.matrix.AxisAngle)38 Vector3d (maspack.matrix.Vector3d)19 RigidTransform3d (maspack.matrix.RigidTransform3d)18 PolygonalMesh (maspack.geometry.PolygonalMesh)8 Point3d (maspack.matrix.Point3d)7 RotationMatrix3d (maspack.matrix.RotationMatrix3d)7 AffineTransform3d (maspack.matrix.AffineTransform3d)5 RigidBody (artisynth.core.mechmodels.RigidBody)4 MechModel (artisynth.core.mechmodels.MechModel)3 Font (java.awt.Font)3 File (java.io.File)3 IOException (java.io.IOException)3 GLViewer (maspack.render.GL.GLViewer)3 FemNode3d (artisynth.core.femmodels.FemNode3d)2 CollisionManager (artisynth.core.mechmodels.CollisionManager)2 HashMap (java.util.HashMap)2 JFrame (javax.swing.JFrame)2 RenderProps (maspack.render.RenderProps)2 ReaderTokenizer (maspack.util.ReaderTokenizer)2 AxisAngleField (maspack.widgets.AxisAngleField)2