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() 

Source Link

Document

Constructs and initializes a BoundingSphere with radius = 1 at 0 0 0.

Usage

From source file:Rotation.java

/**
 * Erstellt den Szenegraphen//from   w w w .  jav a  2s.  c  o  m
 * 
 * @return BranchGroup
 */
public BranchGroup macheSzene() {
    BranchGroup objWurzel = new BranchGroup();
    // Transformation, 2 Rotationen:
    Transform3D drehung = new Transform3D();
    Transform3D drehung2 = new Transform3D();
    drehung.rotX(Math.PI / 4.0d);
    drehung2.rotY(Math.PI / 5.0d);
    drehung.mul(drehung2);
    TransformGroup objDreh = new TransformGroup(drehung);
    TransformGroup spin = new TransformGroup();
    spin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    spin.addChild(new ColorCube(0.4));
    objDreh.addChild(spin);
    objWurzel.addChild(objDreh);

    // Drehung
    Alpha spinAlpha = new Alpha(-1, 5000);
    RotationInterpolator dreher = new RotationInterpolator(spinAlpha, spin);
    BoundingSphere zone = new BoundingSphere();
    dreher.setSchedulingBounds(zone);
    spin.addChild(dreher);

    return objWurzel;
}

From source file:MousePickApp.java

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

    TransformGroup objRotate = null;//from  www . j  a  v  a2  s . com
    PickRotateBehavior pickRotate = null;
    Transform3D transform = new Transform3D();
    BoundingSphere behaveBounds = new BoundingSphere();

    // create ColorCube and PickRotateBehavior objects
    transform.setTranslation(new Vector3f(-0.6f, 0.0f, -0.6f));
    objRotate = new TransformGroup(transform);
    objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objRotate.setCapability(TransformGroup.ENABLE_PICK_REPORTING);

    objRoot.addChild(objRotate);
    objRotate.addChild(new ColorCube(0.4));

    pickRotate = new PickRotateBehavior(objRoot, canvas, behaveBounds);
    objRoot.addChild(pickRotate);

    // add a second ColorCube object to the scene graph
    transform.setTranslation(new Vector3f(0.6f, 0.0f, -0.6f));
    objRotate = new TransformGroup(transform);
    objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objRotate.setCapability(TransformGroup.ENABLE_PICK_REPORTING);

    objRoot.addChild(objRotate);
    objRotate.addChild(new ColorCube(0.4));

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

    return objRoot;
}

From source file:MouseBehaviorApp.java

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

    TransformGroup objTransform = new TransformGroup();
    objTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    objRoot.addChild(objTransform);/*from   www . j ava2  s.  c om*/
    objTransform.addChild(new ColorCube(0.4));
    objRoot.addChild(new Axis());

    MouseRotate myMouseRotate = new MouseRotate();
    myMouseRotate.setTransformGroup(objTransform);
    myMouseRotate.setSchedulingBounds(new BoundingSphere());
    objRoot.addChild(myMouseRotate);

    MouseTranslate myMouseTranslate = new MouseTranslate();
    myMouseTranslate.setTransformGroup(objTransform);
    myMouseTranslate.setSchedulingBounds(new BoundingSphere());
    objRoot.addChild(myMouseTranslate);

    MouseZoom myMouseZoom = new MouseZoom();
    myMouseZoom.setTransformGroup(objTransform);
    myMouseZoom.setSchedulingBounds(new BoundingSphere());
    objRoot.addChild(myMouseZoom);

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

    return objRoot;
}

From source file:PickCallbackApp.java

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

    TransformGroup objRotate = null;/*from   w  w w .j av a 2  s  .c o m*/
    PickRotateBehavior pickRotate = null;
    Transform3D transform = new Transform3D();
    BoundingSphere behaveBounds = new BoundingSphere();

    // create ColorCube and PickRotateBehavior objects
    transform.setTranslation(new Vector3f(-0.6f, 0.0f, -0.6f));
    objRotate = new TransformGroup(transform);
    objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objRotate.setCapability(TransformGroup.ENABLE_PICK_REPORTING);

    objRoot.addChild(objRotate);
    objRotate.addChild(new ColorCube(0.4));

    pickRotate = new PickRotateBehavior(objRoot, canvas, behaveBounds);
    objRoot.addChild(pickRotate);

    PickingCallback myCallback = new MyCallbackClass();
    // Register the class callback to be called 
    pickRotate.setupCallback(myCallback);

    // add a second ColorCube object to the scene graph
    transform.setTranslation(new Vector3f(0.6f, 0.0f, -0.6f));
    objRotate = new TransformGroup(transform);
    objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objRotate.setCapability(TransformGroup.ENABLE_PICK_REPORTING);

    objRoot.addChild(objRotate);
    objRotate.addChild(new ColorCube(0.4));

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

    return objRoot;
}

From source file:MouseRotateApp.java

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

    TransformGroup objRotate = new TransformGroup();
    objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    objRoot.addChild(objRotate);//from   w w  w.j a va  2 s .  c  o m
    objRotate.addChild(new ColorCube(0.4));
    objRoot.addChild(new Axis());

    MouseRotate myMouseRotate = new MouseRotate();
    myMouseRotate.setTransformGroup(objRotate);
    myMouseRotate.setSchedulingBounds(new BoundingSphere());
    objRoot.addChild(myMouseRotate);

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

    return objRoot;
}

From source file:MouseRotate2App.java

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

    TransformGroup objRotate = null;//from   w ww  .  j av a 2  s.c o  m
    MouseRotate myMouseRotate = null;
    Transform3D transform = new Transform3D();

    // create ColorCube and MouseRotate behvaior objects
    transform.setTranslation(new Vector3f(-0.6f, 0.0f, -0.6f));
    objRotate = new TransformGroup(transform);
    objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    objRoot.addChild(objRotate);
    objRotate.addChild(new ColorCube(0.4));

    myMouseRotate = new MouseRotate();
    myMouseRotate.setTransformGroup(objRotate);
    myMouseRotate.setSchedulingBounds(new BoundingSphere());
    objRoot.addChild(myMouseRotate);

    // create ColorCube and MouseRotate behvaior objects
    transform.setTranslation(new Vector3f(0.6f, 0.0f, -0.6f));
    objRotate = new TransformGroup(transform);
    objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    objRoot.addChild(objRotate);
    objRotate.addChild(new ColorCube(0.4));

    myMouseRotate = new MouseRotate();
    myMouseRotate.setTransformGroup(objRotate);
    myMouseRotate.setSchedulingBounds(new BoundingSphere());
    objRoot.addChild(myMouseRotate);

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

    return objRoot;
}

From source file:HelloJava3Dc.java

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

    // Create the transform group node and initialize it to the
    // identity. Add it to the root of the subgraph.
    TransformGroup objSpin = new TransformGroup();
    objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objRoot.addChild(objSpin);/*from   w w  w . j a v a 2s  .  c o  m*/

    // Create a simple shape leaf node, add it to the scene graph.
    // ColorCube is a Convenience Utility class
    objSpin.addChild(new ColorCube(0.4));

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

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objSpin);

    // a bounding sphere specifies a region a behavior is active
    // create a sphere centered at the origin with radius of 100
    BoundingSphere bounds = new BoundingSphere();
    rotator.setSchedulingBounds(bounds);
    objSpin.addChild(rotator);

    return objRoot;
}

From source file:BasicConstruct.java

/**
 * Adds a light source to the universe//from  w  w  w.  j  av  a 2s  .c om
 * 
 * @param direction
 *            The inverse direction of the light
 * @param color
 *            The color of the light
 */
public void addDirectionalLight(Vector3f direction, Color3f color) {
    // Creates a bounding sphere for the lights
    BoundingSphere bounds = new BoundingSphere();
    bounds.setRadius(1000d);

    // Then create a directional light with the given
    // direction and color
    DirectionalLight lightD = new DirectionalLight(color, direction);
    lightD.setInfluencingBounds(bounds);

    // Then add it to the root BranchGroup
    rootBranchGroup.addChild(lightD);
}

From source file:LitSphereApp.java

BranchGroup createScene() {
    BranchGroup scene = new BranchGroup();

    scene.addChild(new Sphere(0.9f, Sphere.GENERATE_NORMALS, createAppearance()));

    AmbientLight lightA = new AmbientLight();
    lightA.setInfluencingBounds(new BoundingSphere());
    scene.addChild(lightA);//  w  w  w.  ja v  a2 s  .com

    DirectionalLight lightD1 = new DirectionalLight();
    lightD1.setInfluencingBounds(new BoundingSphere());
    Vector3f direction1 = new Vector3f(-1.0f, -1.0f, -0.5f);
    direction1.normalize();
    lightD1.setDirection(direction1);
    lightD1.setColor(new Color3f(0.0f, 0.0f, 1.0f));
    scene.addChild(lightD1);

    DirectionalLight lightD2 = new DirectionalLight();
    lightD2.setInfluencingBounds(new BoundingSphere());
    Vector3f direction2 = new Vector3f(1.0f, -1.0f, -0.5f);
    direction2.normalize();
    lightD2.setDirection(direction2);
    lightD2.setColor(new Color3f(1.0f, 0.0f, 0.0f));
    scene.addChild(lightD2);

    Background bg = new Background();
    bg.setColor(1.0f, 1.0f, 1.0f);
    bg.setApplicationBounds(new BoundingSphere());
    scene.addChild(bg);

    return scene;
}

From source file:SimpleBehaviorApp.java

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

    TransformGroup objRotate = new TransformGroup();
    objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    objRoot.addChild(objRotate);/*from   ww  w  .  j a va2 s.  co m*/
    objRotate.addChild(new ColorCube(0.4));

    SimpleBehavior myRotationBehavior = new SimpleBehavior(objRotate);
    myRotationBehavior.setSchedulingBounds(new BoundingSphere());
    objRoot.addChild(myRotationBehavior);

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

    return objRoot;
}