void update() { Transformation transformation = rigidBody.getTransformation(); topGroup.setTransformation(transformation); double s = 1.5 * shaft.getSizeZ(); double[] vec = topGroup.toSpaceFrame(new double[] {0, 0, 1}); orientation.setSizeXYZ(s * vec[0], s * vec[1], s * vec[2]); orientationTrace.addPoint(s * vec[0], s * vec[1], s * vec[2]); frame.render(); }
public SpinningTopSpaceView(SpinningTop rigidBody) { this.rigidBody = rigidBody; frame.setSize(600, 600); // panel.setDisplayMode(VisualizationHints.DISPLAY_NO_PERSPECTIVE); double d = 4; frame.setPreferredMinMax(-d, d, -d, d, -d, d); frame.setDecorationType( org.opensourcephysics.display3d.core.VisualizationHints.DECORATION_AXES); orientation.getStyle().setFillColor(java.awt.Color.RED); orientationTrace.getStyle().setLineColor(java.awt.Color.BLACK); base.setSizeXYZ(2, 2, 0.15); base.getStyle().setResolution(new Resolution(4, 12, 1)); base.getStyle().setFillColor(java.awt.Color.RED); base.setZ(-3); post.setSizeXYZ(0.2, 0.2, 3); post.getStyle().setResolution(new Resolution(2, 10, 15)); post.setZ(-1.5); // shift by half the length post.getStyle().setFillColor(java.awt.Color.RED); shaft.setSizeXYZ(0.2, 0.2, 3); shaft.setXYZ(0, 0, 1.5); shaft.getStyle().setResolution(new Resolution(1, 10, 15)); disk.setSizeXYZ(1.75, 1.75, 0.25); disk.setXYZ(0, 0, 2.0); disk.getStyle().setResolution(new Resolution(4, 12, 1)); topGroup.addElement(shaft); topGroup.addElement(disk); topGroup.setTransformation(rigidBody.getTransformation()); frame.addElement(base); frame.addElement(post); frame.addElement(orientation); frame.addElement(orientationTrace); frame.addElement(topGroup); }