use of maspack.matrix.AffineTransform3d in project artisynth_core by artisynth.
the class AffineTransformWidget method getTransformValue.
public AffineTransform3d getTransformValue() {
RotationMatrix3d R = new RotationMatrix3d(getRotation());
Vector3d scale = getScale();
Vector3d shear = getShear();
// XXX Note: if you return a RigidTransform3d, results in
// an Illegal Argument Exception on "method.invoke(...)"
// if (scale.x == 1 && scale.y == 1 && scale.z == 1 &&
// shear.x == 0 && shear.y == 0 && shear.z == 0) {
// RigidTransform3d RT = new RigidTransform3d();
// RT.p.set (getTranslation());
// RT.R.set (R);
// return RT;
// }
// else {
AffineTransform3d XT = new AffineTransform3d();
XT.p.set(getTranslation());
XT.setA(R, scale, shear);
return XT;
// }
}
use of maspack.matrix.AffineTransform3d in project artisynth_core by artisynth.
the class AffineTransformWidget method main.
public static void main(String[] args) {
JFrame frame = new JFrame("AffineTransformWidget Test");
LabeledComponentPanel panel = new LabeledComponentPanel();
AffineTransformWidget widget = new AffineTransformWidget("affineX", "TR");
frame.getContentPane().add(panel);
widget.unpackFields();
AffineTransform3d X = new AffineTransform3d();
RotationMatrix3d R = new RotationMatrix3d(1, 0, 0, Math.toRadians(45));
Vector3d scale = new Vector3d(1, 2, 3);
Vector3d shear = new Vector3d(0.2, 0.4, 0.6);
// Vector3d scale = new Vector3d (1, 1, 1);
// Vector3d shear = new Vector3d (0, 0, 0);
X.setA(R, scale, shear);
widget.setValue(X);
widget.addValueChangeListener(new ValueChangeListener() {
public void valueChange(ValueChangeEvent e) {
AffineTransformWidget w = (AffineTransformWidget) e.getSource();
System.out.println("new value:\n" + w.getTransformValue().toString("%10.6f"));
}
});
panel.addWidget("translation", widget.getTranslationField());
panel.addWidget("orientation", widget.getRotationField());
panel.addWidget("scale", widget.getScaleField());
panel.addWidget("shear", widget.getShearField());
// panel.addWidget (widget);
frame.pack();
frame.setVisible(true);
}
use of maspack.matrix.AffineTransform3d in project artisynth_core by artisynth.
the class MFreeElement3d method renderWidget.
public void renderWidget(Renderer renderer, double size, RenderProps props, int flags) {
if (myBoundaryMesh != null && size > 0) {
if (!renderMeshValid) {
// for (Vertex3d vtx : myBoundaryMesh.getVertices()) {
// if (vtx instanceof MFreeVertex3d) {
// ((MFreeVertex3d)vtx).updatePosAndVelState();
// }
// }
renderMeshValid = true;
}
Point3d cntr = new Point3d();
AffineTransform3d trans = new AffineTransform3d();
myBoundaryMesh.computeCentroid(cntr);
cntr.scale(1 - size);
trans.setTranslation(cntr);
trans.applyScaling(size, size, size);
renderer.pushModelMatrix();
renderer.mulModelMatrix(trans);
if (isSelected()) {
flags |= Renderer.HIGHLIGHT;
}
myBoundaryMesh.render(renderer, props, flags);
renderer.popModelMatrix();
}
}
use of maspack.matrix.AffineTransform3d in project artisynth_core by artisynth.
the class RigidBody method createEllipsoid.
/**
* Creates an ellipsoidal RigidBody with a prescribed uniform density.
* The ellipsoid is centered on the origin.
*
* @param bodyName name of the RigidBody
* @param a semi-axis length in the x direction
* @param b semi-axis length in the y direction
* @param c semi-axis length in the z direction
* @param density density of the body
* @param nslices number of slices used in creating the mesh
* @return ellipsoidal rigid body
*/
public static RigidBody createEllipsoid(String bodyName, double a, double b, double c, double density, int nslices) {
RigidBody body = new RigidBody(bodyName);
PolygonalMesh mesh = MeshFactory.createSphere(1.0, nslices);
AffineTransform3d XScale = new AffineTransform3d();
XScale.applyScaling(a, b, c);
mesh.transform(XScale);
body.setMesh(mesh, null);
double mass = 4 / 3.0 * Math.PI * a * b * c * density;
body.setInertia(SpatialInertia.createEllipsoidInertia(mass, a, b, c));
return body;
}
use of maspack.matrix.AffineTransform3d in project artisynth_core by artisynth.
the class AffineNumericInputProbe method getTransform.
public AffineTransform3d getTransform() {
Matrix3d Ar = new Matrix3d();
R.getSubMatrix(0, 0, Ar);
// not very
Vector3d At = new Vector3d(t.get(0), t.get(1), t.get(2));
return new AffineTransform3d(Ar, At);
}
Aggregations