DirectX Media for Animation Programmer's Guide Previous
Previous
TOC
TOC
Index
Index
Next
Next

Displaying Behaviors

Overview , Models in Direct Animation

The above section discusses how Direct Animation behaviors are created, but doesn't discuss how they get viewed, or made available in a Java applet or application. This section describes the classes provided by Direct Animation for Java for displaying and controlling the execution of behaviors.


Overview

The basic sequence of events that allow an application to view behaviors in either an applet or a canvas is listed below:

  1. The application subclasses the Direct Animation Model class and implements the createModel() method to build up the image, sound, and geometry behaviors it wants to view. It optionally implements preference settings that apply specifically to this model.
  2. It then constructs an instance of a DXMApplet or DXMCanvas, providing an instance of the Model subclass built in the step above.
  3. It then uses that applet or canvas in any way it otherwise would use any applet or canvas. The model (and all of its component behaviors) is automatically sampled and displayed.

Additionally, if the application wants explicit control over the frame loop, it overrides certain methods provided by DXMApplet or DXMCanvas classes.

The following sections describe the steps listed above in more detail.


Models in Direct Animation

In Direct Animation, the model is the set of behaviors actually displayed and sampled on behalf of the application. A model typically consists of some combination of image behavior and sound behavior. It can also have certain per-model preferences bound up with it (such as rendering quality choices made on a per-model basis).

Direct Animation for Java provides a Model class to standardize the construction of Direct Animation models. An instance of this Model class must be provided as input when constructing a Direct Animation viewer inside either a Direct Animation subclass of either Applet or Canvas in order to actually view a behavior. This is the relevant portion of the Java definition:


public class Model extends Statics {
    // These are to be overridden by the application 
    public abstract void createModel(double startTime, BehaviorCtx ctx);
    public void          establishPreferences(Preferences p) {}
    // These are to be invoked by the application
    public void setImage(ImageBvr img);
    public void setSound(SoundBvr snd);
}

Applications will override this class and implement at least the createModel() method. This method will create the set of behaviors to be displayed and call setImage() and setSound() on the image and sound behaviors that are intended to be viewed. Any subset of these can be called, depending on what constitutes the model. Optionally, the application can implement establishPreferences to set up per-model preferences such as rendering quality. This method will be invoked by the Viewer that is going to display the model.

The following is an example model that simply constructs a red image. This model has no sound.


public class RedImg extends Model {
    public void createModel(double startTime, BehaviorCtx ctx) {
        ImageBvr im = solidColorImage(red);
        setImage(im);
    }
}

The next example adds a sound with a time-varying panning factor:


public class AllMediaTypes extends Model {
    public void createModel(double startTime, BehaviorCtx ctx) {
        ImageBvr im = solidColorImage(red);
        SoundBvr snd = importSound("foo.wav", null);
        SoundBvr panningSound = snd.pan(sin(localTime));
        setImage(im);
        setSound(panningSound);
    }
}


Top© 1997 Microsoft Corporation. All rights reserved. Legal Notices.