Example usage for javax.media.j3d BoundingSphere BoundingSphere

List of usage examples for javax.media.j3d BoundingSphere BoundingSphere

Introduction

In this page you can find the example usage for javax.media.j3d BoundingSphere BoundingSphere.

Prototype

public BoundingSphere(Point3d center, double radius) 

Source Link

Document

Constructs and initializes a BoundingSphere from a center and radius.

Usage

From source file:GeometryByReferenceTest.java

BranchGroup createSceneGraph() {
    BranchGroup objRoot = new BranchGroup();

    // Set up attributes to render lines
    app = new Appearance();

    transp = new TransparencyAttributes();
    transp.setTransparency(0.5f);/*from ww w  . jav a2 s  .c om*/
    transp.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE);
    transp.setTransparencyMode(TransparencyAttributes.NONE);
    app.setTransparencyAttributes(transp);

    tetraRegular = createGeometry(1);
    tetraStrip = createGeometry(2);
    tetraIndexed = createGeometry(3);
    tetraIndexedStrip = createGeometry(4);

    geoArrays[0] = tetraRegular;
    geoArrays[1] = tetraStrip;
    geoArrays[2] = tetraIndexed;
    geoArrays[3] = tetraIndexedStrip;

    shape = new Shape3D(tetraRegular, app);
    shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
    shape.setCapability(Shape3D.ALLOW_GEOMETRY_READ);

    Transform3D t = new Transform3D();
    // move the object upwards
    t.set(new Vector3f(0.0f, 0.3f, 0.0f));

    // rotate the shape
    Transform3D temp = new Transform3D();
    temp.rotX(Math.PI / 4.0d);
    t.mul(temp);
    temp.rotY(Math.PI / 4.0d);
    t.mul(temp);

    // Shrink the object
    t.setScale(0.6);

    TransformGroup trans = new TransformGroup(t);
    trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    objRoot.addChild(trans);
    trans.addChild(shape);

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    // Set up the global lights
    Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
    Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f);
    Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);

    AmbientLight aLgt = new AmbientLight(alColor);
    aLgt.setInfluencingBounds(bounds);
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    lgt1.setInfluencingBounds(bounds);
    objRoot.addChild(aLgt);
    objRoot.addChild(lgt1);

    // Let Java 3D perform optimizations on this scene graph.
    objRoot.compile();

    return objRoot;
}

From source file:AvatarTest.java

BoundingSphere getBoundingSphere() {
    return new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 400.0);
}

From source file:LineTypes.java

BranchGroup createSceneGraph() {
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    // Create a TransformGroup to scale the scene down by 3.5x
    // TODO: move view platform instead of scene using orbit behavior
    TransformGroup objScale = new TransformGroup();
    Transform3D scaleTrans = new Transform3D();
    //scaleTrans.set(1 / 3.5f); // scale down by 3.5x
    objScale.setTransform(scaleTrans);// w w  w .j av  a2  s .  c  om
    objRoot.addChild(objScale);

    // Create a TransformGroup and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // the mouse behaviors 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);
    objScale.addChild(objTrans);

    // Add the primitives to the scene
    objTrans.addChild(createLineTypes());

    BoundingSphere bounds = new BoundingSphere(new Point3d(), 100.0);

    Background bg = new Background(new Color3f(1.0f, 1.0f, 1.0f));
    bg.setApplicationBounds(bounds);
    objTrans.addChild(bg);

    // set up the mouse rotation behavior
    MouseRotate mr = new MouseRotate();
    mr.setTransformGroup(objTrans);
    mr.setSchedulingBounds(bounds);
    mr.setFactor(0.007);
    objTrans.addChild(mr);

    // 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, 1.0f);
    Vector3f light1Direction = new Vector3f(0.0f, -0.2f, -1.0f);

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

    return objRoot;
}

From source file:ConfigObjLoad.java

public void init() {
    if (filename == null) {
        try {//from  w  w w  . jav  a  2 s.c o m
            filename = new URL("file:galleon.obj");
        } catch (MalformedURLException e) {
            System.err.println(e);
            System.exit(1);
        }
    }

    // Get the config file URL from the j3d.configURL property or use the
    // default config file "j3d1x1-window" in the current directory.
    URL configURL = ConfiguredUniverse.getConfigURL("file:j3d1x1-window");

    // Create a simple scene and attach it to the virtual universe
    BranchGroup scene = createSceneGraph();
    u = new ConfiguredUniverse(configURL);

    // Get the ViewingPlatform.
    ViewingPlatform viewingPlatform = u.getViewingPlatform();

    // This will move the ViewPlatform back a bit so the objects in the
    // scene can be viewed. This will only have an effect if the config
    // file sets the window eyepoint policy to something other than
    // RELATIVE_TO_COEXISTENCE, which is the default eyepoint policy
    // applied by ConfiguredUniverse.
    // 
    // The default view attach policy for ConfiguredUniverse applications
    // is NOMINAL_SCREEN. This sets the view platform origin in the
    // physical world to the center of coexistence, which allows eye
    // positions expressed relative to coexistence to see the appropriate
    // field of view automatically.
    viewingPlatform.setNominalViewingTransform();

    // Add a ViewPlatformBehavior if not specified in the config file.
    if (!spin && viewingPlatform.getViewPlatformBehavior() == null) {
        OrbitBehavior orbit = new OrbitBehavior(u.getCanvas(), OrbitBehavior.REVERSE_ALL);
        BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

        orbit.setSchedulingBounds(bounds);
        viewingPlatform.setViewPlatformBehavior(orbit);
    }

    // See if there's a 6 degree of freedom mouse in the environment.
    // We look for one named "mouse6d".
    Map sensorMap = null;
    sensorMap = u.getNamedSensors();
    if (sensorMap != null) {
        Sensor mouse6d = (Sensor) sensorMap.get("mouse6d");
        if (mouse6d != null) {
            Mouse6DPointerBehavior behavior = new Mouse6DPointerBehavior(mouse6d, 1.0, true);

            BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
            behavior.setSchedulingBounds(bounds);

            scene.addChild(behavior);
            scene.addChild(behavior.getEcho());
        }
    }

    // Listen for a typed "q", "Q", or "Escape" key on each canvas to
    // allow a convenient exit from full screen configurations.
    Canvas3D[] canvases;
    canvases = u.getViewer().getCanvas3Ds();

    class QuitListener extends KeyAdapter {
        public void keyTyped(KeyEvent e) {
            char c = e.getKeyChar();
            if (c == 'q' || c == 'Q' || c == 27)
                System.exit(0);
        }
    }

    QuitListener quitListener = new QuitListener();
    for (int i = 0; i < canvases.length; i++)
        canvases[i].addKeyListener(quitListener);

    // Make the scenegraph live.
    u.addBranchGraph(scene);
}

From source file:SplineInterpolatorTest.java

protected Bounds createApplicationBounds() {
    m_ApplicationBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 10.0);
    return m_ApplicationBounds;
}

From source file:Text3DLoad.java

public void init() {

    if (textString == null) {
        textString = "Java3D";
    }/*from ww  w .  j  a  v  a 2  s  .  c  om*/
    setLayout(new BorderLayout());

    button = new Button("remove behaviors");
    button.addActionListener(this);
    Panel p = new Panel();
    p.add(button);
    add("South", p);

    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

    Canvas3D c = new Canvas3D(config);
    add("Center", c);

    // Create a simple scene and attach it to the virtual universe
    BranchGroup scene = createSceneGraph();

    // create a SimpleUniverse with 4 TransformGroups for the mouse
    // behaviors
    u = new SimpleUniverse(c);

    // add the behaviors to the ViewingPlatform
    ViewingPlatform viewingPlatform = u.getViewingPlatform();

    viewingPlatform.setNominalViewingTransform();

    // add orbit behavior to ViewingPlatform
    orbit = new OrbitBehavior(c, OrbitBehavior.REVERSE_ALL | OrbitBehavior.STOP_ZOOM);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    orbit.setSchedulingBounds(bounds);
    viewingPlatform.setViewPlatformBehavior(orbit);

    behaviorsOn = true;

    u.addBranchGraph(scene);
}

From source file:MultiTextureTest.java

public void init() {
    if (stoneImage == null) {
        // the path to the image for an applet
        try {//from w  ww. j  a v  a  2s . c  o m
            stoneImage = new java.net.URL(getCodeBase().toString() + "/stone.jpg");
        } catch (java.net.MalformedURLException ex) {
            System.out.println(ex.getMessage());
            System.exit(1);
        }
    }

    if (skyImage == null) {
        // the path to the image for an applet
        try {
            skyImage = new java.net.URL(getCodeBase().toString() + "/bg.jpg");
        } catch (java.net.MalformedURLException ex) {
            System.out.println(ex.getMessage());
            System.exit(1);
        }
    }

    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

    Canvas3D c = new Canvas3D(config);
    add("Center", c);

    BranchGroup scene = createSceneGraph();
    u = new SimpleUniverse(c);

    ViewingPlatform viewingPlatform = u.getViewingPlatform();
    // This will move the ViewPlatform back a bit so the
    // objects in the scene can be viewed.
    viewingPlatform.setNominalViewingTransform();

    // add orbit behavior but disable translate
    OrbitBehavior orbit = new OrbitBehavior(c, OrbitBehavior.REVERSE_ALL | OrbitBehavior.DISABLE_TRANSLATE);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    orbit.setSchedulingBounds(bounds);
    viewingPlatform.setViewPlatformBehavior(orbit);

    u.addBranchGraph(scene);

    // create the gui
    choice = new Choice();
    choice.addItem("stone + light");
    choice.addItem("stone");
    choice.addItem("lightMap");
    choice.addItem("sky");
    choice.addItem("stone + sky");
    choice.addItemListener(this);
    add("North", choice);

}

From source file:GeometryByReferenceNIOBuffer.java

BranchGroup createSceneGraph() {
    BranchGroup objRoot = new BranchGroup();

    // Set up attributes to render lines
    app = new Appearance();

    transp = new TransparencyAttributes();
    transp.setTransparency(0.5f);//w ww.  j a  v  a2s.co  m
    transp.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE);
    transp.setTransparencyMode(TransparencyAttributes.NONE);
    app.setTransparencyAttributes(transp);

    //create the direct nio buffer
    createJ3DBuffers();

    tetraRegular = createGeometry(1);
    tetraStrip = createGeometry(2);
    tetraIndexed = createGeometry(3);
    tetraIndexedStrip = createGeometry(4);

    geoArrays[0] = tetraRegular;
    geoArrays[1] = tetraStrip;
    geoArrays[2] = tetraIndexed;
    geoArrays[3] = tetraIndexedStrip;

    shape = new Shape3D(tetraRegular, app);
    shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
    shape.setCapability(Shape3D.ALLOW_GEOMETRY_READ);

    Transform3D t = new Transform3D();
    // move the object upwards
    t.set(new Vector3f(0.0f, 0.3f, 0.0f));

    // rotate the shape
    Transform3D temp = new Transform3D();
    temp.rotX(Math.PI / 4.0d);
    t.mul(temp);
    temp.rotY(Math.PI / 4.0d);
    t.mul(temp);

    // Shrink the object
    t.setScale(0.6);

    TransformGroup trans = new TransformGroup(t);
    trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    objRoot.addChild(trans);
    trans.addChild(shape);

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    // Set up the global lights
    Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
    Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f);
    Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);

    AmbientLight aLgt = new AmbientLight(alColor);
    aLgt.setInfluencingBounds(bounds);
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    lgt1.setInfluencingBounds(bounds);
    objRoot.addChild(aLgt);
    objRoot.addChild(lgt1);

    // Let Java 3D perform optimizations on this scene graph.
    objRoot.compile();

    return objRoot;
}

From source file:cgview.java

public cgview(String args[]) {
    if (args.length < 1)
        usage();//  ww  w .ja v  a  2 s  .  c o m

    int index;
    if (args.length < 2)
        index = 0;
    else
        index = Integer.parseInt(args[1]);

    String filename = args[0];
    if (filename == null)
        usage();

    // Read the compressed geometry.
    CompressedGeometry cg = null;
    try {
        CompressedGeometryFile cgf;
        cgf = new CompressedGeometryFile(filename, false);

        if (cgf.getObjectCount() == 0) {
            System.out.println("no objects were found in " + filename);
            System.exit(0);
        }

        cg = cgf.read(index);
        cgf.close();

    } catch (IOException e) {
        System.out.println(e);
        System.exit(0);
    }

    setLayout(new BorderLayout());
    Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
    add("Center", c);

    // Create a simple scene and attach it to the virtual universe
    BranchGroup scene = createSceneGraph(cg);
    u = new SimpleUniverse(c);

    // add mouse behaviors to the ViewingPlatform
    ViewingPlatform viewingPlatform = u.getViewingPlatform();

    // This will move the ViewPlatform back a bit so the
    // objects in the scene can be viewed.
    viewingPlatform.setNominalViewingTransform();

    OrbitBehavior orbit = new OrbitBehavior(c, OrbitBehavior.REVERSE_ALL);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    orbit.setSchedulingBounds(bounds);
    viewingPlatform.setViewPlatformBehavior(orbit);

    u.addBranchGraph(scene);
}

From source file:ConicWorld.java

private Group createObject(int i, int j, Appearance app, double scale, double xpos, double ypos) {

    // Create a transform group node to scale and position the object.
    Transform3D t = new Transform3D();
    t.set(scale, new Vector3d(xpos, ypos, 0.0));
    TransformGroup objTrans = new TransformGroup(t);

    // Create a second transform group node and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime.
    TransformGroup spinTg = new TransformGroup();
    spinTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    spinTg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    Primitive obj = null;//from   w w w  .j  a va2 s .c  om

    if (i % 3 == 2) {
        obj = (Primitive) new Sphere(1.0f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_TEXTURE_COORDS, j * 8 + 4,
                app);
    } else if (i % 3 == 1) {
        obj = (Primitive) new Cylinder(1.0f, 2.0f, Cylinder.GENERATE_TEXTURE_COORDS | Cylinder.GENERATE_NORMALS,
                j * 8 + 4, j * 8 + 4, app);
    } else if (i % 3 == 0) {
        obj = (Primitive) new Cone(1.0f, 2.0f, Cone.GENERATE_NORMALS | Cone.GENERATE_TEXTURE_COORDS, j * 8 + 4,
                j * 8 + 4, app);
    }

    // add it to the scene graph.
    spinTg.addChild(obj);

    // Create a new Behavior object that will perform the desired
    // operation on the specified transform object and add it into
    // the scene graph.
    Transform3D yAxis = new Transform3D();
    Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 5000, 0, 0, 0, 0, 0);

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, spinTg, yAxis, 0.0f,
            (float) Math.PI * 2.0f);

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    rotator.setSchedulingBounds(bounds);

    // Add the behavior and the transform group to the object
    objTrans.addChild(rotator);
    objTrans.addChild(spinTg);

    return objTrans;
}