below is a program i am working on. it has a keynavigator and a switch
for LOD. but the assignment I need to do requires me to populate teh
scene with many of my Avatars. Once I put the switch in, I do not know
how to get other avatars in the scene. Also, I need to populate the
scene depending on a value passed in through the command line. I know
how pass in the value, how do I add avatars randomly like that, anyone?

Jerry




import com.sun.j3d.loaders.objectfile.ObjectFile;
import com.sun.j3d.loaders.ParsingErrorException;
import com.sun.j3d.loaders.IncorrectFormatException;
import com.sun.j3d.loaders.Scene;
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.io.*;
import com.sun.j3d.utils.behaviors.mouse.*;
import com.sun.j3d.utils.behaviors.keyboard.*;
import com.sun.j3d.utils.image.TextureLoader;
import com.sun.j3d.utils.geometry.*;
import Avatar;

public class AvatarClass extends Applet {

    private boolean spin = false;
    private boolean noTriangulate = false;
    private boolean noStripify = false;
    private double creaseAngle = 60.0;
    private String filename = null;

    public BranchGroup createSceneGraph(SimpleUniverse theUniv, String[]
args) {
        // Create the root of the branch graph
        BranchGroup objRoot = new BranchGroup();

        // Create the transform group node and initialize it to the
        // identity.  Enable the TRANSFORM_WRITE capability so that
        // our behavior code can modify it at runtime.  Add it to the
        // root of the subgraph.
        TransformGroup objTrans = new TransformGroup();
        objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
        objRoot.addChild(objTrans);

        BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),
3000.0);
        TransformGroup vpTrans =
theUniv.getViewingPlatform().getViewPlatformTransform();

        KeyNavigatorBehavior keyNavigate = new
KeyNavigatorBehavior(vpTrans);
        keyNavigate.setSchedulingBounds(new BoundingSphere(new
Point3d(),1000.0));
        objTrans.addChild(keyNavigate);

      //create a switch for the lod
        Switch theSW = new Switch();
        theSW.setCapability(javax.media.j3d.Switch.ALLOW_SWITCH_WRITE);

      //create the different levels
      theSW.addChild(new Avatar(objRoot,100));
      theSW.addChild(new Avatar(objRoot,20));
      theSW.addChild(new Avatar(objRoot,2));

        objTrans.addChild(theSW);

      //add distance lod
        float[] distance = new float[2];
        distance[0] = Float.parseFloat( args[0]);
        distance[1] = Float.parseFloat(args[1]);
        DistanceLOD theLOD = new DistanceLOD(distance);
        theLOD.addSwitch(theSW);
        theLOD.setSchedulingBounds(bounds);
        objTrans.addChild(theLOD);

//test populate
        Transform3D t3d = new Transform3D();
        t3d.set(new Vector3f(0.6f, 0.0f, 0.0f));
        TransformGroup tga = new TransformGroup(t3d);
        objRoot.addChild(tga);
        tga.addChild(new Sphere(.40f));


        // Set up the background
        //Color3f bgColor = new Color3f(0.05f, 0.05f, 0.5f);
        Color3f bgColor = new Color3f(1f, 1f, 1f);
        Background bgNode = new Background(bgColor);
        bgNode.setApplicationBounds(bounds);
        objRoot.addChild(bgNode);

        // Set up the ambient light
        Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f);
        AmbientLight ambientLightNode = new AmbientLight(ambientColor);
        ambientLightNode.setInfluencingBounds(bounds);
        objRoot.addChild(ambientLightNode);

        // Set up the directional lights
        Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
        Vector3f light1Direction  = new Vector3f(4.0f, -7.0f, -12.0f);
        Color3f light2Color = new Color3f(0.3f, 0.3f, 0.4f);
        Vector3f light2Direction  = new Vector3f(-6.0f, -2.0f, -1.0f);

        DirectionalLight light1
            = new DirectionalLight(light1Color, light1Direction);
        light1.setInfluencingBounds(bounds);
        objRoot.addChild(light1);

        DirectionalLight light2
            = new DirectionalLight(light2Color, light2Direction);
        light2.setInfluencingBounds(bounds);
        objRoot.addChild(light2);

        objRoot.compile();
        return objRoot;
    }

    private void usage()
    {
      System.out.println(
        "Usage: java ObjLoad [-s] [-n] [-t] [-c degrees] <.obj file>");
      System.out.println("  -s Spin (no user interaction)");
      System.out.println("  -n No triangulation");
      System.out.println("  -t No stripification");
      System.out.println(
        "  -c Set crease angle for normal generation (default is 60 without");
      System.out.println(
        "     smoothing group info, otherwise 180 within smoothing groups)");
      System.exit(0);
    } // End of usage

    public AvatarClass(String args[]) {

      setLayout(new BorderLayout());
      Canvas3D c = new Canvas3D(null);
        add("Center", c);

        // Create a simple scene and attach it to the virtual universe
        SimpleUniverse u = new SimpleUniverse(c);
        BranchGroup scene = createSceneGraph(u, args);
        // This will move the ViewPlatform back a bit so the
        // objects in the scene can be viewed.
        u.getViewingPlatform().setNominalViewingTransform();
        u.addBranchGraph(scene);
    }



    //
    // The following allows ObjLoad to be run as an application
    // as well as an applet
    //
    public static void main(String[] args) {
        new MainFrame(new AvatarClass(args), 400, 400);
    }
}

--
J. Stone
[EMAIL PROTECTED]
http://www.DevilInBlue.org

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to