import java.applet.Applet; import java.awt.*; import java.util.*; import java.awt.geom.*; import com.sun.j3d.utils.geometry.ColorCube; import com.sun.j3d.utils.universe.SimpleUniverse; import com.sun.j3d.utils.behaviors.keyboard.*; import com.sun.j3d.utils.image.*; import javax.media.j3d.*; import javax.vecmath.*; public class Seinad extends Applet { LinkedList seinad=new LinkedList(); public Seinad() { setLayout(new BorderLayout()); Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); add(c, BorderLayout.CENTER); BranchGroup juur = new BranchGroup(); juur.addChild(looSein(2, -10, -2, -10, "taust.gif")); //x1, z1, x2, z2 juur.addChild(looSein(3, -7, 3, -12)); juur.addChild(looSein(-5, 0, -5, -8, Color.blue)); AmbientLight taustavalgus=new AmbientLight(); taustavalgus.setInfluencingBounds(new BoundingSphere(new Point3d(), 100)); juur.addChild(taustavalgus); SimpleUniverse u = new SimpleUniverse(c); u.getViewingPlatform().setNominalViewingTransform(); TransformGroup tg=u.getViewingPlatform().getViewPlatformTransform(); Klahviliikur k=new Klahviliikur(tg); k.setSchedulingBounds(new BoundingSphere(new Point3d(), 1000)); juur.addChild(k); u.addBranchGraph(juur); } Shape3D looSein(double x1, double z1, double x2, double z2){ return looSein(x1, z1, x2, z2, null, Color.green); } Shape3D looSein(double x1, double z1, double x2, double z2, String pilt){ return looSein(x1, z1, x2, z2, pilt, null); } Shape3D looSein(double x1, double z1, double x2, double z2, Color varv){ return looSein(x1, z1, x2, z2, null, varv); } Shape3D looSein(double x1, double z1, double x2, double z2, String pilt, Color varv){ QuadArray nurgad=new QuadArray(4, GeometryArray.COORDINATES | GeometryArray.COLOR_3 | GeometryArray.NORMALS | GeometryArray.TEXTURE_COORDINATE_2); nurgad.setCoordinate(0, new Point3d( x1, 0, z1)); nurgad.setCoordinate(1, new Point3d( x1, 5, z1)); nurgad.setCoordinate(2, new Point3d( x2, 5, z2)); nurgad.setCoordinate(3, new Point3d( x2, 0, z2)); seinad.add(new Line2D.Float((float)x1, (float)z1, (float)x2, (float)z2)); Appearance a=new Appearance(); if(pilt!=null){ try{ nurgad.setTextureCoordinate(0, 0, new TexCoord2f(1, 0)); nurgad.setTextureCoordinate(0, 1, new TexCoord2f(1, 1)); nurgad.setTextureCoordinate(0, 2, new TexCoord2f(0, 1)); nurgad.setTextureCoordinate(0, 3, new TexCoord2f(0, 0)); TextureLoader mustrilugeja=new TextureLoader("taust1.gif", this); ImageComponent2D mustripilt=mustrilugeja.getImage(); Texture2D muster = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA, mustripilt.getWidth(), mustripilt.getHeight()); muster.setImage(0, mustripilt); a.setTexture(muster); }catch(Exception viga){ System.out.println("Probleem mustriga: "+viga); } } else { if(varv==null){varv=Color.green;} Material materjal=new Material( new Color3f(Color.black), //hajuvalgus new Color3f(varv), //eralduv new Color3f(varv), //peegelduv valgus new Color3f(Color.black), 1 //läige ); a.setMaterial(materjal); } PolygonAttributes pind=new PolygonAttributes(); pind.setCullFace(PolygonAttributes.CULL_NONE); //et ka teine pool näha oleks a.setPolygonAttributes(pind); Shape3D kujund=new Shape3D(); kujund.setGeometry(nurgad); kujund.setAppearance(a); return kujund; } class Klahviliikur extends KeyNavigatorBehavior{ TransformGroup siht; Transform3D t=new Transform3D(); Matrix3f m=new Matrix3f(); Vector3f v=new Vector3f(); Transform3D vanatr=new Transform3D(); Vector3f vana=new Vector3f(); Transform3D uustr=new Transform3D(); Vector3f uus=new Vector3f(); double kaugus=1; public Klahviliikur(TransformGroup tg1){ super(tg1); siht=tg1; } public void processStimulus(Enumeration e){ siht.getTransform(vanatr); vanatr.get(vana); super.processStimulus(e); siht.getTransform(uustr); uustr.get(uus); if(!vana.equals(uus)){ //System.out.println("Kohad: "+vana.x+" "+vana.z+" "+uus.x+" "+uus.z); boolean teeVaba=true; for(int i=0;i