use of maspack.matrix.RotationMatrix3d in project artisynth_core by artisynth.
the class AffineTransformWidget method updateInternalValue.
/**
* Updates the internal representation of the value, updates any result
* holders, and returns true if the new value differs from the old value.
*/
protected boolean updateInternalValue(Object value) {
if (!valuesEqual(value, getInternalValue())) {
maskValueChanges(true);
if (value == Property.VoidValue) {
for (LabeledTextField c : myFields) {
c.setValue(Property.VoidValue);
}
myValueIsVoid = true;
} else {
RotationMatrix3d R = new RotationMatrix3d();
Vector3d p = new Vector3d();
Vector3d scale = new Vector3d(1, 1, 1);
Vector3d shear = new Vector3d(0, 0, 0);
if (value instanceof RigidTransform3d) {
RigidTransform3d newX = (RigidTransform3d) value;
p.set(newX.p);
R.set(newX.R);
// System.out.println ("newT\n" + newX.toString("%10.6f"));
} else if (value instanceof AffineTransform3d) {
AffineTransform3d newX = (AffineTransform3d) value;
p.set(newX.p);
newX.factorA(R, scale, shear);
// System.out.println ("newX\n" + newX.toString("%10.6f"));
} else {
throw new InternalErrorException("Unknown value type " + value.getClass());
}
setTranslation(p);
setRotation(R.getAxisAngle());
setScale(scale);
setShear(shear);
myValueIsVoid = false;
}
maskValueChanges(false);
return true;
} else {
return false;
}
}
use of maspack.matrix.RotationMatrix3d in project artisynth_core by artisynth.
the class AxisAngleField method main.
public static void main(String[] args) {
JFrame frame = new JFrame("AxisAngleField Test");
LabeledComponentPanel panel = new LabeledComponentPanel();
AxisAngleField widget = new AxisAngleField();
frame.getContentPane().add(panel);
RotationMatrix3d R = new RotationMatrix3d(1, 0, 0, Math.toRadians(45));
widget.setValue(new AxisAngle(R));
panel.addWidget("axisAng", widget);
// panel.addWidget (widget);
frame.pack();
frame.setVisible(true);
}
use of maspack.matrix.RotationMatrix3d in project artisynth_core by artisynth.
the class GLViewer method computeInverseTranspose.
protected Matrix3d computeInverseTranspose(Matrix3dBase M) {
Matrix3d out = new Matrix3d(M);
if (!(M instanceof RotationMatrix3d)) {
boolean success = out.invert();
if (!success) {
SVDecomposition3d svd3 = new SVDecomposition3d(M);
svd3.pseudoInverse(out);
}
out.transpose();
}
return out;
}
use of maspack.matrix.RotationMatrix3d in project artisynth_core by artisynth.
the class GLViewer method rotateFixedUp.
/**
* Rotate the eye coordinate frame about the center point, while maintaining
* the default up vector.
*
* @param xang
* amount of horizontal rotation (in radians)
* @param yang
* amount of vertical rotation (in radians)
* @see #getUpVector
*/
protected void rotateFixedUp(double xang, double yang) {
Vector3d reye = new Vector3d();
reye.sub(getEye(), myViewState.myCenter);
if (yang != 0) {
// right-facing vector
Vector3d xCam = new Vector3d();
synchronized (viewMatrix) {
viewMatrix.R.getRow(0, xCam);
}
double oldAngle = Math.acos(reye.dot(myViewState.myUp) / reye.norm());
if (!((yang < 0 && (-yang) > oldAngle) || (yang > 0 && yang > (Math.PI - oldAngle)))) {
reye.transform(new RotationMatrix3d(new AxisAngle(xCam, yang)));
}
}
if (xang != 0) {
reye.transform(new RotationMatrix3d(new AxisAngle(myViewState.myUp, xang)));
}
Point3d eye = new Point3d();
eye.add(reye, myViewState.myCenter);
setEyeToWorld(eye, myViewState.myCenter, myViewState.myUp);
repaint();
}
use of maspack.matrix.RotationMatrix3d in project artisynth_core by artisynth.
the class Transrotator3d method updateRotation.
protected void updateRotation(RotationMatrix3d Rot, boolean constrained) {
RigidTransform3d Tinc = (RigidTransform3d) myIncrementalTransform;
RigidTransform3d T = (RigidTransform3d) myTransform;
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);
}
Tinc.R.mulInverseLeft(T.R, R);
if (myConstrainer != null) {
RotationMatrix3d Rnew = new RotationMatrix3d();
Rnew.mul(myXDraggerToWorld.R, Tinc.R);
RigidTransform3d Tnew = new RigidTransform3d(myXDraggerToWorld);
if (myConstrainer.updateRotation(Rnew, myXDraggerToWorld)) {
Tinc.R.mulInverseLeft(myXDraggerToWorld.R, Rnew);
myXDraggerToWorld.R.set(Rnew);
T.R.mul(Tinc.R);
myRotPnt.transform(T.R, myPnt0);
} else {
Tinc.R.setIdentity();
}
} else {
T.R.set(R);
myXDraggerToWorld.R.mul(Tinc.R);
}
}
Aggregations