Search in sources :

Example 1 with AffineTransformWidget

use of maspack.widgets.AffineTransformWidget in project artisynth_core by artisynth.

the class RigidBodyAgent method createGeometryPanel.

protected void createGeometryPanel() {
    RigidBody protoBody = null;
    int numExistingBodies = myModel.rigidBodies().size();
    if (numExistingBodies > 0) {
        protoBody = myModel.rigidBodies().get(numExistingBodies - 1);
    }
    myGeometryPanel = new GeometryInertiaPanel(myGeometrySettings, protoBody, /* editing= */
    false);
    myGeometryPanel.setBorder(GuiUtils.createTitledPanelBorder("Geometry And Inertia"));
    if (myGeometrySettings == null) {
        GLViewer viewer = myMain.getMain().getViewer();
        double width = viewer.distancePerPixel(viewer.getCenter()) * viewer.getScreenWidth() / 6;
        double boxScale = 1;
        if (width > boxScale) {
            for (int i = -1; width > boxScale; i++) {
                boxScale *= (i % 3 == 0) ? 2.5 : 2.0;
            }
        } else {
            for (int i = -1; width < boxScale; i++) {
                boxScale /= (i % 3 == 0) ? 2.5 : 2.0;
            }
        }
        myGeometryPanel.myBoxWidthsField.setValue(new Vector3d(boxScale, boxScale, boxScale));
    }
    geometrySelector = myGeometryPanel.myGeometrySelector;
    geometrySelector.addValueChangeListener(this);
    myGeometryPanel.myBoxWidthsField.addValueChangeListener(this);
    myGeometryPanel.myPointRadiusField.addValueChangeListener(this);
    myGeometryPanel.myPointSlicesField.addValueChangeListener(this);
    myGeometryPanel.myMeshFileField.addValueChangeListener(this);
    AffineTransformWidget meshXformWidget = myGeometryPanel.myMeshXformWidget;
    meshXformWidget.getTranslationField().addValueChangeListener(this);
    myGeometryPanel.myDensityField.setValue(1.0);
    scaleField = meshXformWidget.getScaleField();
    autoScaleBtn = new JButton("Auto Scale");
    autoScaleBtn.addActionListener(this);
    scaleField.addMajorComponent(autoScaleBtn);
    addWidget(myGeometryPanel);
}
Also used : GLViewer(maspack.render.GL.GLViewer) Vector3d(maspack.matrix.Vector3d) AffineTransformWidget(maspack.widgets.AffineTransformWidget) JButton(javax.swing.JButton) RigidBody(artisynth.core.mechmodels.RigidBody)

Example 2 with AffineTransformWidget

use of maspack.widgets.AffineTransformWidget in project artisynth_core by artisynth.

the class GeometryInertiaPanel method createGeometryWidgets.

// Called once at panel creation time to create all the widgets
// that may be needed for the Geometry.
protected void createGeometryWidgets() {
    myBoxWidthsField = new VectorField("widths", new Vector3d(), "%.4g");
    myBoxWidthsField.setResultHolder(new Vector3d());
    initWidget(myBoxWidthsField);
    myPointRadiusField = new DoubleField("radius", 0, "%.4g");
    initWidget(myPointRadiusField);
    myPointSlicesField = new IntegerField("slices", 12);
    initWidget(myPointSlicesField);
    myMeshFileField = new FileNameField("file name", "", 20);
    initWidget(myMeshFileField);
    myMeshXformWidget = new AffineTransformWidget("", "TRS", new RigidTransform3d());
    initWidget(myMeshXformWidget);
    myMeshXformWidget.unpackFields();
    myMeshXformWidget.getTranslationField().setLabelText("offset");
    myMeshXformWidget.getScaleField().setLabelText("scale");
    myMeshXformWidget.getRotationField().setLabelText("rotation");
    myCOMButton = new JButton("COM");
    myCOMButton.addActionListener(this);
    myCOMButton.setToolTipText("puts mesh origin at its center of mass");
    GuiUtils.setFixedSize(myCOMButton, myMeshFileField.getBrowseButton().getPreferredSize());
    myMeshXformWidget.getTranslationField().addMajorComponent(myCOMButton);
}
Also used : VectorField(maspack.widgets.VectorField) AffineTransformWidget(maspack.widgets.AffineTransformWidget) IntegerField(maspack.widgets.IntegerField) DoubleField(maspack.widgets.DoubleField) FileNameField(maspack.widgets.FileNameField)

Aggregations

AffineTransformWidget (maspack.widgets.AffineTransformWidget)2 RigidBody (artisynth.core.mechmodels.RigidBody)1 JButton (javax.swing.JButton)1 Vector3d (maspack.matrix.Vector3d)1 GLViewer (maspack.render.GL.GLViewer)1 DoubleField (maspack.widgets.DoubleField)1 FileNameField (maspack.widgets.FileNameField)1 IntegerField (maspack.widgets.IntegerField)1 VectorField (maspack.widgets.VectorField)1