Package javax.media.j3d

Examples of javax.media.j3d.TransformGroup


//*** The sphere and its transformation group ***
    Sphere s = new Sphere(r,Sphere.GENERATE_NORMALS,100,shadedApp);
    Transform3D tfSphere = new Transform3D();
    tfSphere.setTranslation(new Vector3f(-0.95f+r,0.0f,0.0f));
    TransformGroup tgSphere = new TransformGroup(tfSphere);
    tgSphere.addChild(s);
    theScene.addChild(tgSphere);




//*** The cube and its transformation group ***
    Box b2 = new Box(boxHL,boxHL,boxHL,shadedApp);
    Transform3D tfBox2 = new Transform3D();
    tfBox2.setTranslation(new Vector3f(-0.95f+r+shift,0.0f,0.0f));
    Transform3D rotation = new Transform3D();
    rotation.rotY(Math.PI/4);
    Transform3D rotationX = new Transform3D();
    rotationX.rotX(Math.PI/6);
    rotation.mul(rotationX);
    tfBox2.mul(rotation);
    TransformGroup tgBox2 = new TransformGroup(tfBox2);
    tgBox2.addChild(b2);
    theScene.addChild(tgBox2);




View Full Code Here





    //The transformation group for the spotlight and its rotation.
    TransformGroup tfmLight = new TransformGroup();
    tfmLight.addChild(lightSpot);

    //The Alpha for the rotation.
    Alpha alphaLight = new Alpha(-1,4000);
    //The rotation
    RotationInterpolator rot = new RotationInterpolator(alphaLight,tfmLight,
                                                        new Transform3D(),
                                                         0.0f,(float) Math.PI*2);
    rot.setSchedulingBounds(bounds);

    tfmLight.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    tfmLight.addChild(rot);

    bgLight.addChild(tfmLight);



View Full Code Here

        a.setMaterial(m);

        Shape3D sh = new Shape3D();
        sh.setGeometry(text);
        sh.setAppearance(a);
        TransformGroup tg = new TransformGroup();
        Transform3D t3d = new Transform3D();
        Transform3D tDown = new Transform3D();
        Transform3D rot = new Transform3D();
        Vector3f v3f = new Vector3f(-1.6f, -1.35f, -6.5f);
        t3d.setTranslation(v3f);
        rot.rotX(Math.PI / 5);
        t3d.mul(rot);
        v3f = new Vector3f(0, -1.4f, 0f);
        tDown.setTranslation(v3f);
        t3d.mul(tDown);
        tg.setTransform(t3d);
        tg.addChild(sh);
        group.addChild(tg);
    }
View Full Code Here

    for (int i=0; i<n; i++)
    {
      spheres[i] = new Sphere(r,Sphere.GENERATE_NORMALS,4+i*i*i,sphereApp);
      tf[i] = new Transform3D();
      tf[i].setTranslation(new Vector3f(-0.95f+r+shift*i,0.0f,0.0f));
      tg[i] = new TransformGroup(tf[i]);
      tg[i].addChild(spheres[i]);
      theScene.addChild(tg[i]);
    }


View Full Code Here

//*** The sphere and its transformation group ***
    Sphere s = new Sphere(r,Sphere.GENERATE_NORMALS,100,shadedApp);
    Transform3D tfSphere = new Transform3D();
    tfSphere.setTranslation(new Vector3f(-0.95f+r,0.0f,0.0f));
    TransformGroup tgSphere = new TransformGroup(tfSphere);
    tgSphere.addChild(s);
    theScene.addChild(tgSphere);




//*** The cube and its transformation group ***
    Box b2 = new Box(boxHL,boxHL,boxHL,shadedApp);
    Transform3D tfBox2 = new Transform3D();
    tfBox2.setTranslation(new Vector3f(-0.95f+r+shift,0.0f,0.0f));
    Transform3D rotation = new Transform3D();
    rotation.rotY(Math.PI/4);
    Transform3D rotationX = new Transform3D();
    rotationX.rotX(Math.PI/6);
    rotation.mul(rotationX);
    tfBox2.mul(rotation);
    TransformGroup tgBox2 = new TransformGroup(tfBox2);
    tgBox2.addChild(b2);
    theScene.addChild(tgBox2);




View Full Code Here

    Vector3f lightDir  = new Vector3f(0.0f, 0.0f, -1.0f);
    DirectionalLight light = new DirectionalLight(lightColour, lightDir);
    light.setInfluencingBounds(bounds);

    //The transformation group for the directional light and its rotation.
    TransformGroup tfmLight = new TransformGroup();
    tfmLight.addChild(light);

    //The Alpha for the rotation.
    Alpha alphaLight = new Alpha(-1,4000);
    //The rotation
    RotationInterpolator rot = new RotationInterpolator(alphaLight,tfmLight,
                                                        new Transform3D(),
                                                         0.0f,(float) Math.PI*2);
    rot.setSchedulingBounds(bounds);

    tfmLight.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    tfmLight.addChild(rot);

    bgLight.addChild(tfmLight);



View Full Code Here

      //A transformation rotating the platform a little bit.
      Transform3D tfPlatform = new Transform3D();
      tfPlatform.rotY(Math.PI/6);

      //The transformation group of the platform.
      TransformGroup tgPlatform = new TransformGroup(tfPlatform);
      tgPlatform.addChild(platform);


//*** The cockpit of the helicopter. ****

      //An Appearance to make the cockpit green.
      Appearance greenApp = new Appearance();
      setToMyDefaultAppearance(greenApp,new Color3f(0.0f,0.7f,0.0f));

      //Radius of the cockpit.
      float cabinRadius = 0.1f;

      //Generate the cockpit in the form of a sphere.
      Sphere cabin = new Sphere(cabinRadius,greenApp);

      //The transformation group for the cockpit.
      //The cockpit first remains in the origin. Later on, the whole
      //helicopter is shifted onto the platform.
      TransformGroup tgCabin = new TransformGroup();
      tgCabin.addChild(cabin);




//*** The rotor blade of the helicopter with its rotation ***

    //An Appearance to make the rotor blade blue.
    Appearance blueApp = new Appearance();
    setToMyDefaultAppearance(blueApp,new Color3f(0.0f,0.0f,1.0f));

    //Generate the rotor blade in the form of a (very thin and long) box.
    Box rotor = new Box(0.4f,0.0001f,0.01f,blueApp);

    //The transformation group for then rotor blade in which also the
    //animated rotation is implemented.
    TransformGroup tgmRotor = new TransformGroup();
    tgmRotor.addChild(rotor);

    //The slow rotation at the beginning.
    Transform3D bladeRotationAxis = new Transform3D();
    int timeStartRotor = 2000; //The rotor blade should start to turn after 2 seconds.
    int noStartRotations = 2//First, two slow rotations are carried out.
    int timeSlowRotation = 1500;//A slow rotation takes 1.5 seconds.

    //The Alpha for the slow rotation.
    Alpha bladeRotationStartAlpha = new Alpha(noStartRotations,
                                              Alpha.INCREASING_ENABLE,
                                              timeStartRotor,
                                              0,timeSlowRotation,0,0,0,0,0);



    //The slow rotation.
    RotationInterpolator bladeRotationStart = new RotationInterpolator(
                                             bladeRotationStartAlpha,tgmRotor,
                                             bladeRotationAxis,0.0f,(float) Math.PI*2);

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),Double.MAX_VALUE);
    bladeRotationStart.setSchedulingBounds(bounds);



    int timeFastRotation = 500; //A fast rotation takes 0.5 seconds.
    int timeOneWayFlight = 2000;//The helicopter rises within 2 seconds.
    int timeHovering = 1000;//It shall hover for one second.
    int timeStartWait = 1000;//The helicopter should start its flight when the rotor
                             //blade has been rotating fast for one second.

    //The overall time when the helicopter should start its flight.
    int timeFlightStart = timeStartRotor+timeSlowRotation*noStartRotations+timeStartWait;
    //Number of fast rotations.
    int noFastRotations = 1+ ((timeStartWait+2*timeOneWayFlight+timeHovering)/timeFastRotation);

    //The Alpha for the fast rotations.
    Alpha bladeRotationAlpha = new Alpha(noFastRotations,Alpha.INCREASING_ENABLE,
                                         timeStartRotor+timeSlowRotation*noStartRotations,
                                         0,timeFastRotation,0,0,0,0,0);


    //The fast rotation.
    RotationInterpolator bladeRotation = new RotationInterpolator(
                                             bladeRotationAlpha,tgmRotor,
                                             bladeRotationAxis,0.0f,(float) Math.PI*2);
    bladeRotation.setSchedulingBounds(bounds);


    //The slow and the fast rotation are assigned to the transformation group
    //of the rotor blade. These rotations are carried out in the origin so far.
    //The later transformations will place everything correctly.
    tgmRotor.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    tgmRotor.addChild(bladeRotationStart);
    tgmRotor.addChild(bladeRotation);


//*** The transformation group to position the rotor blade on top of the cockpit. ***
    //The rotation of the rotor blade will therefore also take place om top
    //of the cockpit.
    Transform3D tfRotor = new Transform3D();
    tfRotor.setTranslation(new Vector3f(0.0f,cabinRadius,0.0f));
    TransformGroup tgRotor = new TransformGroup(tfRotor);
    tgRotor.addChild(tgmRotor);



//*** The tail of the helicopter. ***

    //Length of the tail.
    float halfTailLength = 0.2f;

    //Generate the tail in form of a green box.
    Box tail = new Box(halfTailLength,0.02f,0.02f,greenApp);

    //A transformation placing the tail at the end of the cockpit.
    Transform3D tfTail = new Transform3D();
    tfTail.setTranslation(new Vector3f(cabinRadius+halfTailLength,0.0f,0.0f));

    //The transformation group for the tail.
    TransformGroup tgTail = new TransformGroup(tfTail);
    tgTail.addChild(tail);



//*** The transformation group for the flight of the helicopter. ***
    //The flight is carried out with respect to the origin. Later on, the helicopter
    //including its movement will be placed onto the platform.
    TransformGroup tgmHelicopter = new TransformGroup();

    //Add all parts of the helicopter.
    tgmHelicopter.addChild(tgCabin);
    tgmHelicopter.addChild(tgRotor);
    tgmHelicopter.addChild(tgTail);

    //Define the movement for the flight.
    int timeAcc = 300; //The acceleration and breaking phase should last 0.3 seconds.
    //The helicopter fly slightly of from the vertical axis.
    Transform3D helicopterFlightAxis = new Transform3D();
    helicopterFlightAxis.rotZ(0.4*Math.PI);

    //The Alpha for the flight of the helicopter.
    Alpha helicopterAlpha = new Alpha(1,Alpha.INCREASING_ENABLE+Alpha.DECREASING_ENABLE,
                                      timeFlightStart,0,timeOneWayFlight,timeAcc,
                                      timeHovering,timeOneWayFlight,timeAcc,0);



    //The movement for the flight.
    PositionInterpolator posIPHelicopter = new PositionInterpolator(helicopterAlpha,
                                                   tgmHelicopter,helicopterFlightAxis,
                                                   0.0f,0.5f);

    posIPHelicopter.setSchedulingBounds(bounds);

    //Add the movement for the flight to the transformation group of the helicopter.
    tgmHelicopter.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    tgmHelicopter.addChild(posIPHelicopter);


//*** The transformation group for placing the helicopter on top of the platform.
    Transform3D tfHelicopter = new Transform3D();
    tfHelicopter.setTranslation(new Vector3f(0.0f,platformSize+cabinRadius,0.0f));
    TransformGroup tgHelicopter = new TransformGroup(tfHelicopter);
    tgHelicopter.addChild(tgmHelicopter);





//*** The helicopter and the platform are joint together in one    ***
//*** transformation group in order to place them together         ***
//*** in the scene.                                                ***
    Transform3D tfHeliPlat = new Transform3D();
    tfHeliPlat.setTranslation(new Vector3f(0.0f,0.1f,0.0f));
    TransformGroup tgHeliPlat = new TransformGroup(tfHeliPlat);
    tgHeliPlat.addChild(tgHelicopter);
    tgHeliPlat.addChild(tgPlatform);


//*** The tree trunk. ***

    //An Appearance to make the tree trunk brown.
    Appearance brownApp = new Appearance();
    setToMyDefaultAppearance(brownApp,new Color3f(0.5f,0.2f,0.2f));

    //Height of the tree trunk.
    float trunkHeight = 0.4f;

    //Generate the tree trunk as a cylinder.
    Cylinder trunk = new Cylinder(0.05f,trunkHeight,brownApp);

    //The transformation group of the tree trunk. The tree trunk first
    //remains in the origin and is placed in the scene together with the
    //leaves.
    TransformGroup tgTrunk = new TransformGroup();
    tgTrunk.addChild(trunk);


//*** The treetop. ***

    //Height of the treetop.
    float leavesHeight = 0.4f;

    //Generate the treetop in the form of a green cone.
    Cone leaves = new Cone(0.3f,leavesHeight,greenApp);

    //A transformation to place the treetop on top of the tree trunk.
    Transform3D tfLeaves = new Transform3D();
    tfLeaves.setTranslation(new Vector3f(0.0f,(trunkHeight+leavesHeight)/2,0.0f));

    //The transformation group of the treetop.
    TransformGroup tgLeaves = new TransformGroup(tfLeaves);
    tgLeaves.addChild(leaves);


//*** The tree assembled from the transformation groups for     ***
//*** the tree trunk and the treetop.                           ***

    //A transformation for positioning the tree in the scene.
    Transform3D tfTree = new Transform3D();
    tfTree.setTranslation(new Vector3f(-0.6f,0.0f,0.0f));

    //The transformation group of the tree.
    TransformGroup tgTree = new TransformGroup(tfTree);
    tgTree.addChild(tgTrunk);
    tgTree.addChild(tgLeaves);





View Full Code Here

    for (int i=0; i<n; i++)
    {
      spheres[i] = new Sphere(r,Sphere.GENERATE_NORMALS,4+i*i*i,sphereApp);
      tf[i] = new Transform3D();
      tf[i].setTranslation(new Vector3f(-0.95f+r+shift*i,0.0f,0.0f));
      tg[i] = new TransformGroup(tf[i]);
      tg[i].addChild(spheres[i]);
      theScene.addChild(tg[i]);
    }


View Full Code Here

        _containedNode = new Sphere((float) scale, primitiveFlags,
                divisionsValue, _appearance);

        if (_changesAllowedNow) {
            TransformGroup scaler = new TransformGroup();
            scaler.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
            _scaleTransform = new Transform3D();
            _scaleTransform.setScale(new Vector3d(radiusValue, radiusValue,
                    radiusValue));
            scaler.setTransform(_scaleTransform);
            scaler.addChild(_containedNode);
            _containedNode = scaler;
        } else {
            _scaleTransform = null;
        }
    }
View Full Code Here

        _initialYTranslation = ((DoubleToken) initialYTranslation.getToken())
                .doubleValue();
        _initialZTranslation = ((DoubleToken) initialZTranslation.getToken())
                .doubleValue();

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

        Transform3D transform = new Transform3D();
        transform.setTranslation(new Vector3d(_initialXTranslation,
                _initialYTranslation, _initialZTranslation));
View Full Code Here

TOP

Related Classes of javax.media.j3d.TransformGroup

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.