
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.*;
import java.awt.event.*;
import java.awt.GraphicsConfiguration;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.geometry.Box;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.net.URL;
import java.util.Enumeration;




public class pit extends Applet {

        gsTimer gt;     


        

   public BranchGroup createSceneGraph() {

                // Put a cube in the world
        BranchGroup objRoot = new BranchGroup();
        Transform3D tt = new Transform3D();
        Vector3d vv = new Vector3d(0.01, 0.2 ,0.01);
        TransformGroup objTrans = new TransformGroup();
        objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        objRoot.addChild(objTrans);
        objTrans.addChild(new ColorCube(0.5));
        tt.setTranslation(vv);
        objTrans.setTransform(tt);

        // Create a new gsTimer & pass it some data, i.e. the object we want to move
        gt = new gsTimer();
        gt.dataPort (objTrans, tt);

        // A bounding sphere to set the behaviour running
        BoundingSphere myBounds =
            new BoundingSphere(new Point3d(0.0,0.0,0.0), 200.0);
        gt.setSchedulingBounds(myBounds);

        // add the timer to the tree
        objTrans.addChild(gt);

   //add fixed object in the virtual universe                
   Group obstacle = createBox(0.5, new Vector3d(0, 0, -3));  
     TransformGroup objObstacleTrans = new TransformGroup(); 
     objObstacleTrans.addChild(obstacle);                    
     objRoot.addChild(objObstacleTrans);                     






        return objRoot;
   }


   public Group createBox(double scale, Vector3d pos) {     
                                                            
      Transform3D t3d = new Transform3D();                  
      t3d.set(scale, pos);                                  
                                                            
      TransformGroup objTrans = new TransformGroup(t3d);    
                                                            
                                                            
      Appearance app = new Appearance();                    
      ColoringAttributes ca = new ColoringAttributes();     
      ca.setColor(0.2f, 0.6f, 0.3f);                        
      app.setColoringAttributes(ca);                        
      //shape.setAppearance(app);                           
                                                            
      Box shape = new Box(0.5f, 1.0f, 1.0f, app);           
                                                            
      objTrans.addChild(shape);                             
                                                            
      return objTrans;                                      
   }
   



// ---------------------------------------------------
//      IGNORE THE CODE BELOW THIS LINE
// ---------------------------------------------------


    public pit() {

        setLayout(new FlowLayout());            // of AWT panel
        GraphicsConfiguration config =        // For H/W drawing
        SimpleUniverse.getPreferredConfiguration();


        BranchGroup scene = createSceneGraph();       // Build up the sceneGraph

        
        Canvas3D c1 = new Canvas3D(config);
        TransformGroup ot1 = new TransformGroup();
        ViewPlatform gbsvp1 = new ViewPlatform();
        ot1.addChild(gbsvp1);
        Transform3D loc1 = new Transform3D();
        
        loc1.setTranslation( new Vector3d( 0.0, 0.0, 2.0 ) );
        ot1.setTransform(loc1);
        scene.addChild(ot1);

        View gbsv1 = new View();
        gbsv1.attachViewPlatform(gbsvp1);
        gbsv1.setPhysicalBody(new PhysicalBody());
        gbsv1.setPhysicalEnvironment(new PhysicalEnvironment());



   scene.compile();     // optimise the scenegraph


   VirtualUniverse u = new VirtualUniverse();
   Locale l = new Locale (u);
   l.addBranchGraph(scene);

   gbsv1.addCanvas3D(c1);

   c1.setSize(400, 400);
   add (c1);

   

    }

    public static void main(String[] args) {
      
                new MainFrame(new pit(), 456, 456);
    }
}


