import java.applet.Applet; import java.awt.*; import com.sun.j3d.utils.geometry.ColorCube; import com.sun.j3d.utils.universe.SimpleUniverse; import com.sun.j3d.utils.image.*; import javax.media.j3d.*; import javax.vecmath.*; public class Plaat3 extends Applet { public Plaat3() { setLayout(new BorderLayout()); Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); add(c, BorderLayout.CENTER); BranchGroup juur = new BranchGroup(); QuadArray nurgad=new QuadArray(4, GeometryArray.COORDINATES | GeometryArray.COLOR_3 | GeometryArray.TEXTURE_COORDINATE_2); nurgad.setCoordinate(0, new Point3f(-0.5f, 0, 0)); nurgad.setCoordinate(1, new Point3f( 0.5f, 0, 0)); nurgad.setCoordinate(2, new Point3f( 0.5f, 0.5f, 0)); nurgad.setCoordinate(3, new Point3f( -0.5f, 0.5f, 0)); Shape3D kujund=new Shape3D(); Appearance a=new Appearance(); TextureLoader mustrilugeja=new TextureLoader("taust1.gif", this); ImageComponent2D pilt=mustrilugeja.getImage(); Texture2D muster = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA, pilt.getWidth(), pilt.getHeight()); muster.setImage(0, pilt); a.setTexture(muster); nurgad.setTextureCoordinates(0,0 , new TexCoord2f[]{ //kuidas mustri koordinaadid plaadi omadega kokku langevad new TexCoord2f(0, 0), new TexCoord2f(1, 0), new TexCoord2f(1, 1), new TexCoord2f(0, 1) } ); kujund.setGeometry(nurgad); kujund.setAppearance(a); juur.addChild(kujund); juur.compile(); SimpleUniverse u = new SimpleUniverse(c); u.getViewingPlatform().setNominalViewingTransform(); u.addBranchGraph(juur); } public static void main(String[] args) { Frame f=new Frame("Plaat"); f.add(new Plaat3()); f.setSize(300, 300); f.setVisible(true); } }