Oops, I missed the attachment; here it is!

The tutorial (not yet complete) is available for download one
chapter at a time from:
        http://sun.com/desktop/java3d/collateral


Vladimir Olenin wrote:
>
> Hey, Dennis, could u possibly attach the mentioned example
> AlphaApp.java? Is this tutorial available somewhere in Internet?
>
> vladimir
>              -=V=-
> >~~~~~~~<=============>~~~~~~~<
> Join in Java community now!
> http://javacafe.virtualave.net/
> >~~~~~~~<=============>~~~~~~~<
>
> PS: u could send the example directly to my email.
>
> Dennis J Bouvier wrote:
> >
> > The following is an excerpt from the next chapter (5) of the Java 3D
> > API Tutorial.  This particular section addresses the smoothing
> > of the alpha waveform only.
> >
> > Chapter 5, titled Animation, will explain the Alpha,
> > interpolator, BillboardBehavior, LOD, and Morph classes.
> >
> > Attached is an example of Alpha smoothing.
> >
> > Chapter 5 may be published before the end of July.
> >
> > I hope this helps,
> > Dennis
> >
> > Smoothing of the Alpha Waveform
> > In addition to the duration of the four phases, the programmer
> > can specify a ramp duration for the increasing alpha and decreasing
> > alpha phases.  During the ramp duration, the alpha value changes
> > gradually.  In the case of motion interpolators, it will appear
> > as though the visual object is accelerating and decelerating in
> > a more natural, real world, manner.
> >
> > The ramp duration value is used for both the beginning and ending
> > portions of the phase and therefore the ramp duration is limited
> > to half of the duration of the phase.  Figure 5-6 shows an Alpha
> > waveform with both IncreasingAlphaRampDuration and a
> > DecreasingAlphaRampDuration.  Note that the alpha value changes
> > linearly between the two ramp periods.
> >
> > An example program, AlphaApp.java, demonstrates the effect
> > of an IncreasingAlphaRampDuration on an Alpha waveform.  In
> > this program there are three car visual objects.  The three
> > cars start at the same time from the same x coordinate and
> > travel parallel.  The upper car has no ramp (ramp duration = 0),
> >  the bottom car has maximum ramp duration (half of the duration
> > of the increasing or decreasing alpha duration), and the middle
> > car has half the maximum ramp duration (one quarter of the
> > duration of the increasing or decreasing alpha duration).
> > Each car takes two seconds to cross the view.
> >
> > Vladimir Olenin wrote:
> > >
> > > Hi,
> > >
> > > Let say that ViewPlatfrom is a car and i want to move it in accordance
> > > with physics laws. This means that in the first place i need to specify
> > > "ease-in"/"ease-out" behavior for acceleration/deceleration. It is said
> > > in Java3D official documentation that for these purposes Interpolators
> > > can be used (in section 9.6.2 - Acceleration of Alpha). It is said there
> > > what Alpha parameters resposible for what, but, alas, no examples.
> > >
> > > This is quite a tough topic, so, please, if anyone out here has some
> > > examples of using Interpolators or knows the sequence in which they
> > > should be created/used/terminated, i would very appreciate any
> > > information. Thank u!
> > >
> > > vladimir
> > > --
> > >              -=V=-
> > > >~~~~~~~<=============>~~~~~~~<
> > > Join in Java community now!
> > > http://javacafe.virtualave.net/
> > > >~~~~~~~<=============>~~~~~~~<
> > >
> > > ===========================================================================
> > > To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> > > of the message "signoff JAVA3D-INTEREST".  For general help, send email to
> > > [EMAIL PROTECTED] and include in the body of the message "help".
> >
> > --
> > -----
> > Dennis J Bouvier
> >
> > Find the Java 3D Tutorial "Getting Started with the Java 3D API" at
> > http://sun.com/desktop/java3d/collateral
> >
> > ===========================================================================
> > To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> > of the message "signoff JAVA3D-INTEREST".  For general help, send email to
> > [EMAIL PROTECTED] and include in the body of the message "help".
>
> --
>              -=V=-
> >~~~~~~~<=============>~~~~~~~<
> Join in Java community now!
> http://javacafe.virtualave.net/
> >~~~~~~~<=============>~~~~~~~<
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff JAVA3D-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".

--
-----
Dennis J Bouvier

Find the Java 3D Tutorial "Getting Started with the Java 3D API" at
http://sun.com/desktop/java3d/collateral
/*
 *      @(#)AlphaApp.java 1.0 99/07/02 16:06:00
 *
 * Copyright (c) 1996-1999 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
 * modify and redistribute this software in source and binary code form,
 * provided that i) this copyright notice and license appear on all copies of
 * the software; and ii) Licensee does not utilize the software in a manner
 * which is disparaging to Sun.
 *
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
 * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
 * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
 * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
 * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
 * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 *
 * This software is not designed or intended for use in on-line control of
 * aircraft, air traffic, aircraft navigation or aircraft communications; or in
 * the design, construction, operation or maintenance of any nuclear
 * facility. Licensee represents and warrants that it will not use or
 * redistribute the Software for such purposes.
 */

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Frame;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;


//   AlphaApp renders an

public class AlphaApp extends Applet {

    Shape3D createCar(float xScale, float yScale) {
        Shape3D car = new Shape3D();

        QuadArray carGeom = new QuadArray(16, GeometryArray.COORDINATES);

        carGeom.setCoordinate( 0, new Point3f(xScale*-0.25f, yScale*0.22f, 0.0f));
        carGeom.setCoordinate( 1, new Point3f(xScale* 0.20f, yScale*0.22f, 0.0f));
        carGeom.setCoordinate( 2, new Point3f(xScale* 0.10f, yScale*0.35f, 0.0f));
        carGeom.setCoordinate( 3, new Point3f(xScale*-0.20f, yScale*0.35f, 0.0f));
        carGeom.setCoordinate( 4, new Point3f(xScale*-0.50f, yScale*0.10f, 0.0f));
        carGeom.setCoordinate( 5, new Point3f(xScale* 0.50f, yScale*0.10f, 0.0f));
        carGeom.setCoordinate( 6, new Point3f(xScale* 0.45f, yScale*0.20f, 0.0f));
        carGeom.setCoordinate( 7, new Point3f(xScale*-0.48f, yScale*0.20f, 0.0f));
        carGeom.setCoordinate( 8, new Point3f(xScale*-0.26f, yScale*0.00f, 0.0f));
        carGeom.setCoordinate( 9, new Point3f(xScale*-0.18f, yScale*0.00f, 0.0f));
        carGeom.setCoordinate(10, new Point3f(xScale*-0.16f, yScale*0.12f, 0.0f));
        carGeom.setCoordinate(11, new Point3f(xScale*-0.28f, yScale*0.12f, 0.0f));
        carGeom.setCoordinate(12, new Point3f(xScale* 0.25f, yScale*0.00f, 0.0f));
        carGeom.setCoordinate(13, new Point3f(xScale* 0.33f, yScale*0.00f, 0.0f));
        carGeom.setCoordinate(14, new Point3f(xScale* 0.35f, yScale*0.12f, 0.0f));
        carGeom.setCoordinate(15, new Point3f(xScale* 0.23f, yScale*0.12f, 0.0f));

        car.setGeometry(carGeom);

        ColoringAttributes colorAttrib =
              new ColoringAttributes(0.0f, 0.0f, 1.0f, ColoringAttributes.NICEST);
        Appearance carAppear = new Appearance();
        carAppear.setColoringAttributes(colorAttrib);
        car.setAppearance(carAppear);

        return car;
    }

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

        // create target TransformGroup with Capabilities
        TransformGroup objMove1 = new TransformGroup();
        objMove1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

        Transform3D t3d = new Transform3D();
        t3d.setTranslation(new Vector3f(0.0f, 0.8f, 0.0f));
        TransformGroup objPos1 = new TransformGroup(t3d);

        // create Alpha that continuously cycles with a period of 1 sec
        Alpha alpha1 = new Alpha();

        alpha1.setIncreasingAlphaDuration(2000);
        alpha1.setAlphaAtOneDuration(1000);
        alpha1.setDecreasingAlphaDuration(2000);
        alpha1.setAlphaAtZeroDuration(1000);

        // create position interpolator
        PositionInterpolator posInt1 = new PositionInterpolator (alpha1, objMove1);
        posInt1.setSchedulingBounds(new BoundingSphere());

        posInt1.setStartPosition(-1.0f);

        objRoot.addChild(objPos1);
        objPos1.addChild(objMove1);
        objMove1.addChild(createCar(0.4f, 0.4f));
        objRoot.addChild(posInt1);

        // create target TransformGroup with Capabilities
        TransformGroup objMove2 = new TransformGroup();
        objMove2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

        t3d.setTranslation(new Vector3f(0.0f, 0.3f, 0.0f));
        TransformGroup objPos2 = new TransformGroup(t3d);

        Alpha alpha2 = new Alpha();

        alpha2.setIncreasingAlphaDuration(2000);
        alpha2.setAlphaAtOneDuration(1000);
        alpha2.setIncreasingAlphaRampDuration(500);

        // create position interpolator
        PositionInterpolator posInt2 = new PositionInterpolator (alpha2, objMove2);
        posInt2.setSchedulingBounds(new BoundingSphere());

        posInt2.setStartPosition(-1.0f);

        objRoot.addChild(objPos2);
        objPos2.addChild(objMove2);
        objMove2.addChild(createCar(0.4f, 0.4f));
        objRoot.addChild(posInt2);

        // create target TransformGroup with Capabilities
        TransformGroup objMove3 = new TransformGroup();
        objMove3.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

        t3d.setTranslation(new Vector3f(0.0f, -0.3f, 0.0f));
        TransformGroup objPos3 = new TransformGroup(t3d);

        Alpha alpha3 = new Alpha();

        alpha3.setIncreasingAlphaDuration(2000);
        alpha3.setAlphaAtOneDuration(1000);
        alpha3.setIncreasingAlphaRampDuration(1000);

        // create position interpolator
        PositionInterpolator posInt3 = new PositionInterpolator (alpha3, objMove3);
        posInt3.setSchedulingBounds(new BoundingSphere());

        posInt3.setStartPosition(-1.0f);

        objRoot.addChild(objPos3);
        objPos3.addChild(objMove3);
        objMove3.addChild(createCar(0.4f, 0.4f));
        objRoot.addChild(posInt3);

        Background background = new Background();
        background.setColor(1.0f, 1.0f, 1.0f);
        background.setApplicationBounds(new BoundingSphere());
        objRoot.addChild(background);

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

        return objRoot;
    } // end of CreateSceneGraph method of alpha1App

    // Create a simple scene and attach it to the virtual universe

    public AlphaApp() {
        setLayout(new BorderLayout());
        Canvas3D canvas3D = new Canvas3D(null);
        add("Center", canvas3D);

        BranchGroup scene = createSceneGraph();

        // SimpleUniverse is a Convenience Utility class
        SimpleUniverse simpleU = new SimpleUniverse(canvas3D);

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

        simpleU.addBranchGraph(scene);
    } // end of AlphaApp (constructor)

    //  The following allows this to be run as an application
    //  as well as an applet

    public static void main(String[] args) {
        System.out.print("AlphaApp.java \n- a demonstration of using alpha to control 
");
        System.out.println("Interpolators to provide animation in a Java 3D scene.");
        System.out.println("This is a simple example progam from The Java 3D API 
Tutorial.");
        System.out.println("The Java 3D Tutorial is available on the web at:");
        System.out.println("http://www.sun.com/desktop/java3d/collateral");
        Frame frame = new MainFrame(new AlphaApp(), 256, 256);
    } // end of main (method of AlphaApp)

} // end of class AlphaApp

Reply via email to