import java.applet.Applet; import java.awt.*; import com.sun.j3d.utils.universe.SimpleUniverse; import javax.media.j3d.*; import javax.vecmath.*; import java.util.Enumeration; public class SuurL3 extends Applet { public class MorphBehavior extends Behavior{ private Morph targetMorph; private Alpha alpha; private double[] weights = {0, 0}; private WakeupCondition trigger = new WakeupOnElapsedFrames(10); MorphBehavior(Morph targetMorph, Alpha alpha){ this.targetMorph = targetMorph; this.alpha = alpha; } public void initialize(){ this.wakeupOn(trigger); } public void processStimulus(Enumeration e){ double x=alpha.value(); //esimesest kujundist võetakse osa, mida näitab alpha weights[0] = x; weights[1] = 1-x; // teisest võetakse ülejäänu targetMorph.setWeights(weights); this.wakeupOn(trigger); } } public SuurL3() { setLayout(new BorderLayout()); Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); add(c, BorderLayout.CENTER); BranchGroup juur = new BranchGroup(); Point3d p1=new Point3d(0, 0, 0), p2=new Point3d(0, 1, 0), p3=new Point3d(0.5, 0, 0), p3a=new Point3d(0.5, 0.5, 0); Point3d[] jooned={ p1, p2, p1, p3 }; Point3d[] jooned2={ p1, p2, p1, p3a }; LineArray joonemassiiv1=new LineArray(4, LineArray.COORDINATES | LineArray.COLOR_3); joonemassiiv1.setCoordinates(0, jooned); LineArray joonemassiiv2=new LineArray(4, LineArray.COORDINATES | LineArray.COLOR_3); joonemassiiv2.setCoordinates(0, jooned2); GeometryArray ga[]={joonemassiiv2, joonemassiiv1}; Morph m1=new Morph(ga); m1.setCapability(Morph.ALLOW_WEIGHTS_WRITE); Background background = new Background(); background.setColor(1f, 1f, 1f); background.setApplicationBounds(new BoundingSphere()); juur.addChild(background); Transform3D t3=new Transform3D(); t3.setTranslation(new Vector3f(0, -0.5f, 0)); TransformGroup tg=new TransformGroup(t3); juur.addChild(tg); tg.addChild(m1); Alpha alpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 10, 10, 2000, 1000, 1000, 1000, 1000, 1000); MorphBehavior morphBehav = new MorphBehavior(m1, alpha); morphBehav.setSchedulingBounds(new BoundingSphere()); juur.addChild(morphBehav); juur.compile(); SimpleUniverse u = new SimpleUniverse(c); u.getViewingPlatform().setNominalViewingTransform(); u.addBranchGraph(juur); } public static void main(String[] args) { Frame f=new Frame("Vahepealsed kujundid"); f.add(new SuurL3()); f.setSize(300, 300); f.setVisible(true); } }