I am writing a Java Applet sing Java3D and would like to reset the rotation of mouse in MouseRotate behavior when a button is clicked. The relevant codes are as follows:
BoundingSphere bound =
new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
MouseRotate mouseRotate = new MouseRotate();
TransformGroup modelGroup = new TransformGroup();
mouseRotate.setTransformGroup(modelGroup);
modelGroup.addChild(mouseRotate);
mouseRotate.setSchedulingBounds(bound);
Sorry, my mistake. It seems there is no way to reset MouseRotate
without rewriting it.
Second try: Include another TransformGroup
as parent of the modelGroup
into the scene graph and set its transform to the invert transform of the modelGroup
when resetting is denied.
TransformGroup modelGroupReset = new TransformGroup();
TransformGroup modelGroup = new TransformGroup();
modelGroupReset.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
modelGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
modelGroupReset.addChild(modelGroup);
JButton resetButton = new JButton();
resetButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Transform3D t3d = new Transform3D();
modelGroup.getTransform(t3d);
t3d.invert();
modelGroupReset.setTransform(t3d);
}
});
;