Example usage for javax.media.j3d Alpha DECREASING_ENABLE

List of usage examples for javax.media.j3d Alpha DECREASING_ENABLE

Introduction

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

Prototype

int DECREASING_ENABLE

To view the source code for javax.media.j3d Alpha DECREASING_ENABLE.

Click Source Link

Document

Specifies that the decreasing component of the alpha is used

Usage

From source file:Morphing.java

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

    // 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);//w  w  w . j  a va 2s  .  c o  m
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    // Create a bounds for the background and lights
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    // Set up the background
    Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f);
    Background bg = new Background(bgColor);
    bg.setApplicationBounds(bounds);
    objScale.addChild(bg);

    // 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);
    objScale.addChild(aLgt);
    objScale.addChild(lgt1);

    //
    // Create the transform group nodes for the 3 original objects
    // and the morphed object. Add them to the root of the
    // branch graph.
    //
    TransformGroup objTrans[] = new TransformGroup[4];

    for (int i = 0; i < 4; i++) {
        objTrans[i] = new TransformGroup();
        objScale.addChild(objTrans[i]);
    }

    Transform3D tr = new Transform3D();
    Transform3D rotX90 = new Transform3D();
    rotX90.rotX(90.0 * Math.PI / 180.0);

    objTrans[0].getTransform(tr);
    tr.setTranslation(new Vector3d(-2.0, 1.5, -2.0));
    tr.mul(rotX90);
    objTrans[0].setTransform(tr);

    objTrans[1].getTransform(tr);
    tr.setTranslation(new Vector3d(0.0, 1.5, -2.0));
    tr.mul(rotX90);
    objTrans[1].setTransform(tr);

    objTrans[2].getTransform(tr);
    tr.setTranslation(new Vector3d(2.0, 1.5, -2.0));
    tr.mul(rotX90);
    objTrans[2].setTransform(tr);

    objTrans[3].getTransform(tr);
    tr.setTranslation(new Vector3d(0.0, -2.0, -2.0));
    tr.mul(rotX90);
    objTrans[3].setTransform(tr);

    // Now load the object files
    Scene s[] = new Scene[3];
    GeometryArray g[] = new GeometryArray[3];
    Shape3D shape[] = new Shape3D[3];
    ObjectFile loader = new ObjectFile(ObjectFile.RESIZE);
    for (int i = 0; i < 3; i++) {
        s[i] = null;
        g[i] = null;
        shape[i] = null;
    }

    for (int i = 0; i < 3; i++) {
        try {
            s[i] = loader.load(objFiles[i]);
        } catch (FileNotFoundException e) {
            System.err.println(e);
            System.exit(1);
        } catch (ParsingErrorException e) {
            System.err.println(e);
            System.exit(1);
        } catch (IncorrectFormatException e) {
            System.err.println(e);
            System.exit(1);
        }

        BranchGroup b = s[i].getSceneGroup();
        shape[i] = (Shape3D) b.getChild(0);
        g[i] = (GeometryArray) shape[i].getGeometry();

        shape[i].setGeometry(g[i]);
        objTrans[i].addChild(b);
    }

    //
    // Create a Morph node, and set the appearance and input geometry
    // arrays. Set the Morph node's capability bits to allow the weights
    // to be modified at runtime.
    //
    Appearance app = new Appearance();
    Color3f objColor = new Color3f(1.0f, 0.7f, 0.8f);
    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    app.setMaterial(new Material(objColor, black, objColor, black, 80.0f));
    Morph morph = new Morph(g, app);
    morph.setCapability(Morph.ALLOW_WEIGHTS_READ);
    morph.setCapability(Morph.ALLOW_WEIGHTS_WRITE);

    objTrans[3].addChild(morph);

    // Now create the Alpha object that controls the speed of the
    // morphing operation.
    Alpha morphAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 0, 0, 2000, 1000, 200,
            2000, 1000, 200);

    // Finally, create the morphing behavior
    MorphingBehavior mBeh = new MorphingBehavior(morphAlpha, morph);
    mBeh.setSchedulingBounds(bounds);
    objScale.addChild(mBeh);

    return objRoot;
}

From source file:SplineInterpolatorTest.java

public TransformGroup[] getViewTransformGroupArray() {
    TransformGroup[] tgArray = new TransformGroup[2];
    tgArray[0] = new TransformGroup();
    tgArray[1] = new TransformGroup();

    Transform3D t3d = new Transform3D();
    t3d.setScale(getScale());/* w w w  . j a va2s .c om*/
    t3d.invert();
    tgArray[0].setTransform(t3d);

    // create an Alpha object for the Interpolator
    Alpha alpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 0, 0, 25000, 4000, 100,
            20000, 5000, 50);

    // ensure the Interpolator can access the TG
    tgArray[1].setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    try {
        // create the Interpolator and load the keyframes from disk
        RotPosScaleTCBSplinePathInterpolator splineInterpolator = Utils.createSplinePathInterpolator(
                new UiAlpha(alpha), tgArray[1], new Transform3D(),
                new URL(getWorkingDirectory(), "rotate_viewer_spline.xls"));

        // set the scheduling bounds and attach to the scenegraph
        splineInterpolator.setSchedulingBounds(getApplicationBounds());
        tgArray[1].addChild(splineInterpolator);
    } catch (Exception e) {
        System.err.println(e.toString());
    }

    return tgArray;
}

From source file:AlphaTest.java

/**
 * Draws vertical lines and labels to denote the various phases of the Alpha
 * function./*from  w w  w . j  av a2 s.  c om*/
 */
protected void drawPhases(Graphics g, long lMaxTime) {
    int nLoop = 1;

    if (m_Alpha.getLoopCount() > 0)
        nLoop = m_Alpha.getLoopCount();

    double curTime = 0;

    g.setColor(Color.darkGray);

    curTime += m_Alpha.getTriggerTime();
    drawGraphLine(g, curTime * m_ScaleX, 0, curTime * m_ScaleX, m_nGraphMaxHeight);

    curTime += m_Alpha.getPhaseDelayDuration();
    drawGraphLine(g, curTime * m_ScaleX, 0, curTime * m_ScaleX, m_nGraphMaxHeight);

    double startPhaseTime = 0;

    for (int nIteration = 0; nIteration < nLoop; nIteration++) {
        startPhaseTime = curTime;

        g.setColor(Color.black);
        drawGraphString(g, -1, "" + curTime, curTime * m_ScaleX, -20);
        g.setColor(Color.darkGray);

        if ((m_Alpha.getMode() & Alpha.INCREASING_ENABLE) != 0) {
            curTime += m_Alpha.getIncreasingAlphaRampDuration();
            drawGraphLine(g, curTime * m_ScaleX, 0, curTime * m_ScaleX, m_nGraphMaxHeight);

            curTime = startPhaseTime + m_Alpha.getIncreasingAlphaDuration()
                    - m_Alpha.getIncreasingAlphaRampDuration();
            drawGraphLine(g, curTime * m_ScaleX, 0, curTime * m_ScaleX, m_nGraphMaxHeight);

            curTime = startPhaseTime + m_Alpha.getIncreasingAlphaDuration();
            drawGraphLine(g, curTime * m_ScaleX, 0, curTime * m_ScaleX, m_nGraphMaxHeight);

            curTime += m_Alpha.getAlphaAtOneDuration();
            drawGraphLine(g, curTime * m_ScaleX, 0, curTime * m_ScaleX, m_nGraphMaxHeight);
        }

        startPhaseTime = curTime;

        if ((m_Alpha.getMode() & Alpha.DECREASING_ENABLE) != 0) {
            curTime += m_Alpha.getDecreasingAlphaRampDuration();
            drawGraphLine(g, curTime * m_ScaleX, 0, curTime * m_ScaleX, m_nGraphMaxHeight);

            curTime = startPhaseTime + m_Alpha.getDecreasingAlphaDuration()
                    - m_Alpha.getDecreasingAlphaRampDuration();
            drawGraphLine(g, curTime * m_ScaleX, 0, curTime * m_ScaleX, m_nGraphMaxHeight);

            curTime = startPhaseTime + m_Alpha.getDecreasingAlphaDuration();
            drawGraphLine(g, curTime * m_ScaleX, 0, curTime * m_ScaleX, m_nGraphMaxHeight);

            curTime += m_Alpha.getAlphaAtZeroDuration();
            drawGraphLine(g, curTime * m_ScaleX, 0, curTime * m_ScaleX, m_nGraphMaxHeight);
        }
    }

    g.setColor(Color.black);
}

From source file:AlphaTest.java

/**
 * AWT paint method that can handle dynamic scale recomputation and graph
 * redraw./*from w  ww  .ja  v  a 2s  . com*/
 */
public void paint(Graphics g) {
    super.paint(g);

    long lMaxTime = 0;

    if ((m_Alpha.getMode() & Alpha.INCREASING_ENABLE) != 0) {
        lMaxTime += m_Alpha.getIncreasingAlphaDuration() + m_Alpha.getAlphaAtOneDuration();
    }

    if ((m_Alpha.getMode() & Alpha.DECREASING_ENABLE) != 0) {
        lMaxTime += m_Alpha.getDecreasingAlphaDuration() + m_Alpha.getAlphaAtZeroDuration();
    }

    if (m_Alpha.getLoopCount() > 0)
        lMaxTime *= m_Alpha.getLoopCount();

    lMaxTime += m_Alpha.getTriggerTime();
    lMaxTime += m_Alpha.getPhaseDelayDuration();
    computeDrawScale(lMaxTime);

    drawAxes(g, lMaxTime);
    drawPhases(g, lMaxTime);

    drawAlpha(g, lMaxTime);
}

From source file:SplineInterpolatorTest.java

protected Group createGeometryGroup(Appearance app, Vector3d position, Vector3d scale, String szTextureFile,
        String szSoundFile) {/*from w  w w .  ja v a  2 s .c  o m*/
    TransformGroup tg = new TransformGroup();

    // we need to flip the helicopter model
    // 90 degrees about the X axis
    Transform3D t3d = new Transform3D();
    t3d.rotX(Math.toRadians(-90));
    tg.setTransform(t3d);

    try {
        tg.addChild(loadGeometryGroup("heli.obj", app));

        // create an Alpha object for the Interpolator
        Alpha alpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE,
                (long) Utils.getRandomNumber(0, 500), (long) Utils.getRandomNumber(0, 500),
                (long) Utils.getRandomNumber(20000, 5000), 4000, 100, (long) Utils.getRandomNumber(20000, 5000),
                5000, 50);

        attachSplinePathInterpolator(alpha, new Transform3D(),
                new URL(((Java3dApplet) m_Component).getWorkingDirectory(), "heli_spline.xls"));
    } catch (Exception e) {
        System.err.println(e.toString());
    }

    return tg;
}

From source file:Demo3D.java

/**
 * Constructor that allows to specify the reference of the SceneBuilder32's
 * instance.//from   w w w.j  a va 2 s  .c o m
 * 
 * @param sceneBuilder32 -
 *            the SceneBuilder32 instance
 */
public SwitchBehavior(SceneBuilder32 sceneBuilder32) {
    super();

    // Create the alpha(t) function to automaticaly switch between the
    // five different earth's representations.
    switchAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 0, 0, 10000, 0, 0, 10000, 0,
            0);

    // Get the SceneBuilder32 reference
    this.sceneBuilder32 = sceneBuilder32;
}