Example usage for javax.media.j3d Transform3D rotZ

List of usage examples for javax.media.j3d Transform3D rotZ

Introduction

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

Prototype

public void rotZ(double angle) 

Source Link

Document

Sets the value of this transform to a counter clockwise rotation about the z axis.

Usage

From source file:TexCoordTest.java

protected BranchGroup createSceneBranchGroup() {
    BranchGroup objRoot = super.createSceneBranchGroup();

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

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

    Transform3D axisTranslate = new Transform3D();
    axisTranslate.rotZ(Math.toRadians(90));

    Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 6000, 0, 0, 0, 0, 0);

    m_PositionInterpolator = new PositionInterpolator(rotationAlpha, objPosition, axisTranslate, 0, 70);

    m_PositionInterpolator.setSchedulingBounds(createApplicationBounds());
    objPosition.addChild(m_PositionInterpolator);
    m_PositionInterpolator.setEnable(false);

    m_RotationInterpolator = new RotationInterpolator(rotationAlpha, objRotate, new Transform3D(), 0.0f,
            (float) Math.PI * 2.0f);

    m_RotationInterpolator.setSchedulingBounds(getApplicationBounds());
    objRotate.addChild(m_RotationInterpolator);
    m_RotationInterpolator.setEnable(true);

    TransformGroup tgLand = new TransformGroup();
    Transform3D t3dLand = new Transform3D();
    t3dLand.setTranslation(new Vector3d(0, -30, 0));
    tgLand.setTransform(t3dLand);/*from  www  .  ja  v  a2  s. com*/

    tgLand.addChild(createDemLandscape());
    objRotate.addChild(tgLand);

    objPosition.addChild(objRotate);

    objRoot.addChild(objPosition);

    // create some lights for the scene
    Color3f lColor1 = new Color3f(0.3f, 0.3f, 0.3f);
    Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f);
    Color3f alColor = new Color3f(0.1f, 0.1f, 0.1f);

    AmbientLight aLgt = new AmbientLight(alColor);
    aLgt.setInfluencingBounds(getApplicationBounds());
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    lgt1.setInfluencingBounds(getApplicationBounds());

    // add the lights to the parent BranchGroup
    objRoot.addChild(aLgt);
    objRoot.addChild(lgt1);

    return objRoot;
}

From source file:HiResCoordTest.java

protected BranchGroup createSceneBranchGroupEarth() {
    BranchGroup objRoot = super.createSceneBranchGroup();

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

    Transform3D yAxis = new Transform3D();
    yAxis.rotZ(0.2);
    Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);

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

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), m_TranslateSunZ);
    rotator.setSchedulingBounds(bounds);
    objTrans.addChild(rotator);//from w ww  .  j ava2s  .  c o  m

    Transform3D t3d = new Transform3D();
    t3d.setScale(m_EarthRadius);

    objTrans.addChild(createPlanet("Earth", new Color3f(0, 0.1f, 1), t3d, "earth.jpg"));
    objRoot.addChild(objTrans);

    return objRoot;
}

From source file:KeyNavigateTest.java

protected void doRotateZ(double radians) {
    transformGroup.getTransform(transform3D);
    Transform3D toMove = new Transform3D();
    toMove.rotZ(radians);
    transform3D.mul(toMove);/*  w w w. j a  va2 s.  c  o m*/
    updateTransform();
}

From source file:AppearanceTest.java

public void onZ_30_degrees() {
    Transform3D t3d = new Transform3D();
    t3d.rotZ(Math.toRadians(30));
    getTextureAttributes().setTextureTransform(t3d);
}

From source file:ExTexture.java

public void checkboxChanged(CheckboxMenu menu, int check) {
    if (menu == imageMenu) {
        // Change the texture image
        currentImage = check;// w w w.  j  a v a  2s .co m
        Texture tex = textureComponents[currentImage];
        int mode = ((Integer) boundaries[currentBoundary].value).intValue();
        Color3f color = (Color3f) colors[currentColor].value;
        int filter = ((Integer) filters[currentFilter].value).intValue();

        shape.setAppearance(dummyApp);
        tex.setEnable(textureOnOff);
        tex.setBoundaryModeS(mode);
        tex.setBoundaryModeT(mode);
        tex.setBoundaryColor(color.x, color.y, color.z, 0.0f);
        tex.setMagFilter(filter);
        tex.setMinFilter(filter);
        app.setTexture(tex);
        shape.setAppearance(app);

        return;
    }

    if (menu == boundaryMenu) {
        // Change the texture boundary mode
        currentBoundary = check;
        Texture tex = textureComponents[currentImage];
        int mode = ((Integer) boundaries[currentBoundary].value).intValue();

        shape.setAppearance(dummyApp);
        tex.setBoundaryModeS(mode);
        tex.setBoundaryModeT(mode);
        app.setTexture(tex);
        shape.setAppearance(app);

        return;
    }

    if (menu == colorMenu) {
        // Change the boundary color
        currentColor = check;
        Color3f color = (Color3f) colors[currentColor].value;
        Texture tex = textureComponents[currentImage];

        shape.setAppearance(dummyApp);
        tex.setBoundaryColor(color.x, color.y, color.z, 0.0f);
        app.setTexture(tex);
        shape.setAppearance(app);

        return;
    }

    if (menu == filterMenu) {
        // Change the filter mode
        currentFilter = check;
        int filter = ((Integer) filters[currentFilter].value).intValue();
        Texture tex = textureComponents[currentImage];

        shape.setAppearance(dummyApp);
        tex.setMagFilter(filter);
        tex.setMinFilter(filter);
        app.setTexture(tex);
        shape.setAppearance(app);

        return;
    }

    if (menu == modeMenu) {
        // Change the texture mode
        currentMode = check;
        int mode = ((Integer) modes[currentMode].value).intValue();

        app.setTextureAttributes(dummyAtt);
        texatt.setTextureMode(mode);
        app.setTextureAttributes(texatt);

        return;
    }

    if (menu == blendColorMenu) {
        // Change the boundary color
        currentBlendColor = check;
        Color3f color = (Color3f) colors[currentBlendColor].value;

        app.setTextureAttributes(dummyAtt);
        texatt.setTextureBlendColor(color.x, color.y, color.z, 0.5f);
        app.setTextureAttributes(texatt);

        return;
    }

    if (menu == xformMenu) {
        // Change the texture transform
        currentXform = check;
        Transform3D tt = new Transform3D();
        switch (currentXform) {
        default:
        case 0:
            // Identity
            texatt.setTextureTransform(tt);
            return;

        case 1:
            // Scale by 2
            tt.setScale(2.0);
            texatt.setTextureTransform(tt);
            return;

        case 2:
            // Scale by 4
            tt.setScale(4.0);
            texatt.setTextureTransform(tt);
            return;

        case 3:
            // Z rotate by 45 degrees
            tt.rotZ(Math.PI / 4.0);
            texatt.setTextureTransform(tt);
            return;

        case 4:
            // Translate by 0.25
            tt.set(new Vector3f(0.25f, 0.0f, 0.0f));
            texatt.setTextureTransform(tt);
            return;
        }
    }

    // Handle all other checkboxes
    super.checkboxChanged(menu, check);
}

From source file:ExSound.java

private Group buildTumblingBox(float width, float height, float depth, Appearance app, int xDur, int yDur,
        int zDur) {
    BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center
            1000.0); // Extent

    //  Build a box to tumble
    Shape3D box = buildBox(width, height, depth, app);

    //  Build a set of nested transform groups. Attach
    //  to each one a behavior that rotates around an X,
    //  Y, or Z axis. Use different rotation speeds for
    //  each axis to create a tumbling effect.
    TransformGroup outerGroup = new TransformGroup();
    outerGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    Transform3D yAxis = new Transform3D();
    Alpha alpha = new Alpha(-1, // loop count: -1 = forever
            Alpha.INCREASING_ENABLE, // increasing
            0, // trigger time: 0 = now
            0, // delay: 0 = none
            xDur, // increasing duration
            0, // increasing ramp duration
            0, // at one (sustain) duration
            0, // decreasing duration
            0, // decreasing ramp duration
            0); // at zero duration
    RotationInterpolator rot = new RotationInterpolator(alpha, // Alpha
            // control
            outerGroup, // Target transform group
            yAxis, // Y axis rotation
            0.0f, // Minimum angle
            2.0f * (float) Math.PI);// Maximum angle
    rot.setSchedulingBounds(worldBounds);
    outerGroup.addChild(rot);// w ww . java 2 s .co m

    TransformGroup middleGroup = new TransformGroup();
    middleGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    Transform3D xAxis = new Transform3D();
    xAxis.rotZ(-1.571f);
    alpha = new Alpha(-1, // loop count: -1 = forever
            Alpha.INCREASING_ENABLE, // increasing
            0, // trigger time: 0 = now
            0, // delay: 0 = none
            yDur, // increasing duration
            0, // increasing ramp duration
            0, // at one (sustain) duration
            0, // decreasing duration
            0, // decreasing ramp duration
            0); // at zero duration
    rot = new RotationInterpolator(alpha, // Alpha control
            middleGroup, // Target transform group
            xAxis, // Y axis rotation
            0.0f, // Minimum angle
            2.0f * (float) Math.PI);// Maximum angle
    rot.setSchedulingBounds(worldBounds);
    middleGroup.addChild(rot);
    outerGroup.addChild(middleGroup);

    TransformGroup innerGroup = new TransformGroup();
    innerGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    Transform3D zAxis = new Transform3D();
    zAxis.rotX(1.571f);
    alpha = new Alpha(-1, // loop count: -1 = forever
            Alpha.INCREASING_ENABLE, // increasing
            0, // trigger time: 0 = now
            0, // delay: 0 = none
            zDur, // increasing duration
            0, // increasing ramp duration
            0, // at one (sustain) duration
            0, // decreasing duration
            0, // decreasing ramp duration
            0); // at zero duration
    rot = new RotationInterpolator(alpha, // Alpha control
            innerGroup, // Target transform group
            zAxis, // Y axis rotation
            0.0f, // Minimum angle
            2.0f * (float) Math.PI);// Maximum angle
    rot.setSchedulingBounds(worldBounds);
    innerGroup.addChild(rot);
    middleGroup.addChild(innerGroup);

    innerGroup.addChild(box);
    return outerGroup;
}

From source file:ExBluePrint.java

private Group buildGadget() {
    if (debug)//ww  w.  j  a v a  2  s . c o m
        System.err.println("  gadget...");
    //
    //  Create two appearances:
    //    wireframeApp: draw as blue wireframe
    //    shadedApp: draw as metalic shaded polygons
    //

    //  Wireframe:
    //    no Material - defaults to coloring attributes color
    //    polygons as lines, with backfaces
    //    thick lines
    Appearance wireframeApp = new Appearance();

    ColoringAttributes wireframeCatt = new ColoringAttributes();
    wireframeCatt.setColor(0.0f, 0.2559f, 0.4213f);
    wireframeCatt.setShadeModel(ColoringAttributes.SHADE_FLAT);
    wireframeApp.setColoringAttributes(wireframeCatt);

    PolygonAttributes wireframePatt = new PolygonAttributes();
    wireframePatt.setPolygonMode(PolygonAttributes.POLYGON_LINE);
    wireframePatt.setCullFace(PolygonAttributes.CULL_NONE);
    wireframeApp.setPolygonAttributes(wireframePatt);

    LineAttributes wireframeLatt = new LineAttributes();
    wireframeLatt.setLineWidth(2.0f);
    wireframeApp.setLineAttributes(wireframeLatt);

    //  Shaded:
    //    silver material
    Appearance shadedApp = new Appearance();

    Material shadedMat = new Material();
    shadedMat.setAmbientColor(0.30f, 0.30f, 0.30f);
    shadedMat.setDiffuseColor(0.30f, 0.30f, 0.50f);
    shadedMat.setSpecularColor(0.60f, 0.60f, 0.80f);
    shadedMat.setShininess(0.10f);
    shadedApp.setMaterial(shadedMat);

    ColoringAttributes shadedCatt = new ColoringAttributes();
    shadedCatt.setShadeModel(ColoringAttributes.SHADE_GOURAUD);
    shadedApp.setColoringAttributes(shadedCatt);

    //
    //  Create a switch group to hold two versions of the
    //  shape: one wireframe, and one shaded
    //
    Transform3D tr = new Transform3D();
    tr.set(new Vector3f(-1.0f, 0.2f, 0.0f));
    TransformGroup gadget = new TransformGroup(tr);
    shadingSwitch = new Switch();
    shadingSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);
    Group wireframe = new Group();
    Group shaded = new Group();
    shadingSwitch.addChild(wireframe);
    shadingSwitch.addChild(shaded);
    shadingSwitch.setWhichChild(1); // shaded
    gadget.addChild(shadingSwitch);

    //
    //  Build a gear (wireframe and shaded)
    //
    tr = new Transform3D();
    tr.rotY(Math.PI / 2.0);
    TransformGroup tg = new TransformGroup(tr);
    SpurGear gear = new SpurGearThinBody(24, // tooth count
            1.6f, // pitch circle radius
            0.3f, // shaft radius
            0.08f, // addendum
            0.05f, // dedendum
            0.3f, // gear thickness
            0.28f, // tooth tip thickness
            wireframeApp);// appearance
    tg.addChild(gear);
    wireframe.addChild(tg);

    tg = new TransformGroup(tr);
    gear = new SpurGearThinBody(24, // tooth count
            1.6f, // pitch circle radius
            0.3f, // shaft radius
            0.08f, // addendum
            0.05f, // dedendum
            0.3f, // gear thickness
            0.28f, // tooth tip thickness
            shadedApp); // appearance
    tg.addChild(gear);
    shaded.addChild(tg);

    //
    //  Build another gear (wireframe and shaded)
    //
    tr.rotY(Math.PI / 2.0);
    Vector3f trans = new Vector3f(-0.5f, 0.0f, 0.0f);
    tr.setTranslation(trans);
    tg = new TransformGroup(tr);
    gear = new SpurGearThinBody(30, // tooth count
            2.0f, // pitch circle radius
            0.3f, // shaft radius
            0.08f, // addendum
            0.05f, // dedendum
            0.3f, // gear thickness
            0.28f, // tooth tip thickness
            wireframeApp);// appearance
    tg.addChild(gear);
    wireframe.addChild(tg);

    tg = new TransformGroup(tr);
    gear = new SpurGearThinBody(30, // tooth count
            2.0f, // pitch circle radius
            0.3f, // shaft radius
            0.08f, // addendum
            0.05f, // dedendum
            0.3f, // gear thickness
            0.28f, // tooth tip thickness
            shadedApp); // appearance
    tg.addChild(gear);
    shaded.addChild(tg);

    //
    //  Build a cylindrical shaft (wireframe and shaded)
    //
    tr.rotZ(-Math.PI / 2.0);
    trans = new Vector3f(1.0f, 0.0f, 0.0f);
    tr.setTranslation(trans);
    tg = new TransformGroup(tr);
    Cylinder cyl = new Cylinder(0.3f, // radius
            4.0f, // length
            Primitive.GENERATE_NORMALS, // format
            16, // radial resolution
            1, // length-wise resolution
            wireframeApp);// appearance
    tg.addChild(cyl);
    wireframe.addChild(tg);

    tg = new TransformGroup(tr);
    cyl = new Cylinder(0.3f, // radius
            4.0f, // length
            Primitive.GENERATE_NORMALS, // format
            16, // radial resolution
            1, // length-wise resolution
            shadedApp); // appearance
    tg.addChild(cyl);
    shaded.addChild(tg);

    //
    //  Build shaft teeth (wireframe and shaded)
    //
    tr.rotY(Math.PI / 2.0);
    trans = new Vector3f(2.05f, 0.0f, 0.0f);
    tr.setTranslation(trans);
    tg = new TransformGroup(tr);
    gear = new SpurGear(12, // tooth count
            0.5f, // pitch circle radius
            0.3f, // shaft radius
            0.05f, // addendum
            0.05f, // dedendum
            1.5f, // gear thickness
            0.8f, // tooth tip thickness
            wireframeApp);// appearance
    tg.addChild(gear);
    wireframe.addChild(tg);

    tg = new TransformGroup(tr);
    gear = new SpurGear(12, // tooth count
            0.5f, // pitch circle radius
            0.3f, // shaft radius
            0.05f, // addendum
            0.05f, // dedendum
            1.5f, // gear thickness
            0.8f, // tooth tip thickness
            shadedApp); // appearance
    tg.addChild(gear);
    shaded.addChild(tg);

    return gadget;
}

From source file:GearTest.java

public BranchGroup createGearBox(int toothCount) {
    Transform3D tempTransform = new Transform3D();

    // Create the root of the branch graph
    BranchGroup branchRoot = createBranchEnvironment();

    // Create a Transformgroup to scale all objects so they
    // appear in the scene.
    TransformGroup objScale = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setScale(0.4);/*from  w w  w.j ava  2 s  .co  m*/
    objScale.setTransform(t3d);
    branchRoot.addChild(objScale);

    // Create an Appearance.
    Appearance look = new Appearance();
    Color3f objColor = new Color3f(0.5f, 0.5f, 0.6f);
    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
    look.setMaterial(new Material(objColor, black, objColor, white, 100.0f));

    // 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 gearboxTrans = new TransformGroup();
    gearboxTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    gearboxTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objScale.addChild(gearboxTrans);

    // Create a bounds for the mouse behavior methods
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    // Define the shaft base information
    int shaftCount = 4;
    int secondsPerRevolution = 8000;

    // Create the Shaft(s)
    Shaft shafts[] = new Shaft[shaftCount];
    TransformGroup shaftTGs[] = new TransformGroup[shaftCount];
    Alpha shaftAlphas[] = new Alpha[shaftCount];
    RotationInterpolator shaftRotors[] = new RotationInterpolator[shaftCount];
    Transform3D shaftAxis[] = new Transform3D[shaftCount];

    // Note: the following arrays we're incorporated to make changing
    // the gearbox easier.
    float shaftRatios[] = new float[shaftCount];
    shaftRatios[0] = 1.0f;
    shaftRatios[1] = 0.5f;
    shaftRatios[2] = 0.75f;
    shaftRatios[3] = 5.0f;

    float shaftRadius[] = new float[shaftCount];
    shaftRadius[0] = 0.2f;
    shaftRadius[1] = 0.2f;
    shaftRadius[2] = 0.2f;
    shaftRadius[3] = 0.2f;

    float shaftLength[] = new float[shaftCount];
    shaftLength[0] = 1.8f;
    shaftLength[1] = 0.8f;
    shaftLength[2] = 0.8f;
    shaftLength[3] = 0.8f;

    float shaftDirection[] = new float[shaftCount];
    shaftDirection[0] = 1.0f;
    shaftDirection[1] = -1.0f;
    shaftDirection[2] = 1.0f;
    shaftDirection[3] = -1.0f;

    Vector3d shaftPlacement[] = new Vector3d[shaftCount];
    shaftPlacement[0] = new Vector3d(-0.75, -0.9, 0.0);
    shaftPlacement[1] = new Vector3d(0.75, -0.9, 0.0);
    shaftPlacement[2] = new Vector3d(0.75, 0.35, 0.0);
    shaftPlacement[3] = new Vector3d(-0.75, 0.60, -0.7);

    // Create the shafts.
    for (int i = 0; i < shaftCount; i++) {
        shafts[i] = new Shaft(shaftRadius[i], shaftLength[i], 25, look);
    }

    // Create a transform group node for placing each shaft
    for (int i = 0; i < shaftCount; i++) {
        shaftTGs[i] = new TransformGroup();
        gearboxTrans.addChild(shaftTGs[i]);
        shaftTGs[i].getTransform(tempTransform);
        tempTransform.setTranslation(shaftPlacement[i]);
        shaftTGs[i].setTransform(tempTransform);
        shaftTGs[i].addChild(shafts[i]);
    }

    // Add rotation interpolators to rotate the shaft in the appropriate
    // direction and at the appropriate rate
    for (int i = 0; i < shaftCount; i++) {
        shaftAlphas[i] = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0,
                (long) (secondsPerRevolution * shaftRatios[i]), 0, 0, 0, 0, 0);
        shaftAxis[i] = new Transform3D();
        shaftAxis[i].rotX(Math.PI / 2.0);
        shaftRotors[i] = new RotationInterpolator(shaftAlphas[i], shafts[i], shaftAxis[i], 0.0f,
                shaftDirection[i] * (float) Math.PI * 2.0f);
        shaftRotors[i].setSchedulingBounds(bounds);
        shaftTGs[i].addChild(shaftRotors[i]);
    }

    // Define the gear base information. Again, these arrays exist to
    // make the process of changing the GearBox via an editor faster
    int gearCount = 5;
    float valleyToCircularPitchRatio = .15f;
    float pitchCircleRadius = 1.0f;
    float addendum = 0.05f;
    float dedendum = 0.05f;
    float gearThickness = 0.3f;
    float toothTipThickness = 0.27f;

    // Create an array of gears and their associated information
    SpurGear gears[] = new SpurGear[gearCount];
    TransformGroup gearTGs[] = new TransformGroup[gearCount];

    int gearShaft[] = new int[gearCount];
    gearShaft[0] = 0;
    gearShaft[1] = 1;
    gearShaft[2] = 2;
    gearShaft[3] = 0;
    gearShaft[4] = 3;

    float ratio[] = new float[gearCount];
    ratio[0] = 1.0f;
    ratio[1] = 0.5f;
    ratio[2] = 0.75f;
    ratio[3] = 0.25f;
    ratio[4] = 1.25f;

    Vector3d placement[] = new Vector3d[gearCount];
    placement[0] = new Vector3d(0.0, 0.0, 0.0);
    placement[1] = new Vector3d(0.0, 0.0, 0.0);
    placement[2] = new Vector3d(0.0, 0.0, 0.0);
    placement[3] = new Vector3d(0.0, 0.0, -0.7);
    placement[4] = new Vector3d(0.0, 0.0, 0.0);

    // Create the gears.
    for (int i = 0; i < gearCount; i++) {
        gears[i] = new SpurGearThinBody(((int) ((float) toothCount * ratio[i])), pitchCircleRadius * ratio[i],
                shaftRadius[0], addendum, dedendum, gearThickness, toothTipThickness,
                valleyToCircularPitchRatio, look);
    }

    // Create a transform group node for arranging the gears on a shaft
    // and attach the gear to its associated shaft
    for (int i = 0; i < gearCount; i++) {
        gearTGs[i] = new TransformGroup();
        gearTGs[i].getTransform(tempTransform);
        tempTransform
                .rotZ((shaftDirection[gearShaft[i]] == -1.0) ? gears[i].getCircularPitchAngle() / -2.0f : 0.0f);
        tempTransform.setTranslation(placement[i]);
        gearTGs[i].setTransform(tempTransform);
        gearTGs[i].addChild(gears[i]);
        shafts[gearShaft[i]].addChild(gearTGs[i]);
    }

    // Have Java 3D perform optimizations on this scene graph.
    branchRoot.compile();

    return branchRoot;
}

From source file:pl.edu.icm.visnow.geometries.viewer3d.Display3DPanel.java

private void formKeyPressed(KeyEvent evt) {
    if (lockView) {
        return;//from   www . ja  v a  2 s  .c  om
    }

    double dAngle = Math.PI / 144;
    double dScale = 129. / 128.;
    if (storingFrames) {
        dAngle = Math.PI / 360;
        dScale = 513. / 512.;
    }
    if ((evt.getModifiers() & KeyEvent.CTRL_MASK) != 0) {
        dAngle = Math.PI / 2;
    }
    if ((evt.getModifiers() & KeyEvent.SHIFT_MASK) != 0) {
        dAngle = Math.PI / 6;
    }
    objRotate.getTransform(tempTransform);
    Transform3D rot = new Transform3D();
    switch (evt.getKeyCode()) {
    case KeyEvent.VK_NUMPAD5:
        reset();
        break;
    case KeyEvent.VK_DOWN:
    case KeyEvent.VK_KP_DOWN:
    case KeyEvent.VK_NUMPAD2:
        rot.rotX(dAngle);
        break;
    case KeyEvent.VK_UP:
    case KeyEvent.VK_KP_UP:
    case KeyEvent.VK_NUMPAD8:
        rot.rotX(-dAngle);
        break;
    case KeyEvent.VK_LEFT:
    case KeyEvent.VK_KP_LEFT:
    case KeyEvent.VK_NUMPAD4:
        rot.rotY(-dAngle);
        break;
    case KeyEvent.VK_RIGHT:
    case KeyEvent.VK_KP_RIGHT:
    case KeyEvent.VK_NUMPAD6:
        rot.rotY(dAngle);
        break;
    case KeyEvent.VK_PAGE_UP:
    case KeyEvent.VK_NUMPAD9:
        rot.rotZ(dAngle);
        break;
    case KeyEvent.VK_PAGE_DOWN:
    case KeyEvent.VK_NUMPAD3:
        rot.rotZ(-dAngle);
        break;
    }
    rot.mul(tempTransform);
    objRotate.setTransform(rot);

    switch (evt.getKeyCode()) {
    case KeyEvent.VK_HOME:
    case KeyEvent.VK_NUMPAD7:
        mouseScale *= dScale;
        break;
    case KeyEvent.VK_END:
    case KeyEvent.VK_NUMPAD1:
        mouseScale /= dScale;
        break;
    }
    tempTransform = new Transform3D(new Matrix3d(1., 0., 0., 0., 1., 0., 0., 0., 1.),
            //sceneCenter,
            new Vector3d(0.0, 0.0, 0.0), externScale * mouseScale);
    objScale.setTransform(tempTransform);
    switch (evt.getKeyCode()) {

    case CAMERA_UP_KEY:
        cameraUpKeyPressed = true;
        processCameraKeys(evt);
        break;
    case CAMERA_DOWN_KEY:
        cameraDownKeyPressed = true;
        processCameraKeys(evt);
        break;
    case CAMERA_LEFT_KEY:
        cameraLeftKeyPressed = true;
        processCameraKeys(evt);
        break;
    case CAMERA_RIGHT_KEY:
        cameraRightKeyPressed = true;
        processCameraKeys(evt);
        break;
    case CAMERA_FORWARD_KEY:
        cameraForwardKeyPressed = true;
        processCameraKeys(evt);
        break;
    case CAMERA_BACKWARD_KEY:
        cameraBackwardKeyPressed = true;
        processCameraKeys(evt);
        break;

    // TODO milimetr: delete the code below after testing
    case '8':
        pickObject.setPickModuleMode(1);
        break;
    case '9':
        pickObject.setPickModuleMode(2);
        break;
    case '0':
        pickObject.setPickModuleMode(3);
        break;

    default:
        break;
    }
}

From source file:pl.edu.icm.visnow.geometries.viewer3d.Display3DPanel.java

public void animate(double[] params) {
    if (lockView) {
        return;//from  w  w w .  j a v a  2 s .  c o m
    }

    objRotate.getTransform(tempTransform);
    Transform3D rot = new Transform3D();
    Transform3D tmp = new Transform3D();
    tmp.rotX(params[0]);
    rot.mul(tmp);
    tmp.rotY(params[1]);
    rot.mul(tmp);
    tmp.rotZ(params[2]);
    rot.mul(tmp);
    rot.mul(tempTransform);
    objRotate.setTransform(rot);
    objTranslate.getTransform(rot);
    Vector3d trans = new Vector3d(params[3], params[4], params[5]);
    tmp = new Transform3D();
    tmp.setTranslation(trans);
    rot.mul(tmp);
    objTranslate.setTransform(rot);
    mouseScale *= params[6];
    tempTransform = new Transform3D(new Matrix3d(1., 0., 0., 0., 1., 0., 0., 0., 1.),
            //sceneCenter,
            new Vector3d(0.0, 0.0, 0.0), externScale * mouseScale);
    objScale.setTransform(tempTransform);
}