Model/Display separation

Model/Display Separation

The Model
The animation model is the set of variables, such as position, velocity, etc, that store the state of the animation along with the algorithm that makes their values change. It is a mathematical model, consisting of numbers and calculations with them.

The animation model is really separate from what appears on screen, which is merely a visual representation of the model. They are often closely related so that they seem like the same thing. However, the model can function without ever showing a representation of it on screen.

Separating the model from the display means two things:

  • First, it means the model uses only its own variables (like x, xVelo, xAccel, etc) and doesn’t use display properties (like loch and locv, stage width/height, etc). If these properties are needed, variables are initialized to them and then the variables are used.
  • Second, it means writing code that renders the model. This is often done by simply setting sprite properties equal to the model variables, but there is much more that can be done at this step.

Creating a visual representation of a mathematical model is called rendering. The diagram below shows the usual way to render an animation in Director. As a logical step, rendering includes the calculations you make to set sprite and cast member properties, as well as Director’s drawing of the screen based on them:

In the first render step, sprite properties are set based on the variables of the animation model. Often this is just setting the sprite properties equal to the model variables. But with an algorithm at this step you can scale, rotate, apply perspective, distort, etc, the animation.

In the second render step, Director uses sprite and member properties to set the rgb value of each pixel of the stage.

This demo is a revisit of Inventing a Force, but separates the model from the display and gives the user control over the first rendering step.

Model/display separationsource movie

The important thing to note is that the animation model is not affected by adjusting the sliders. Only the rendering is affected.

Property lists are used as vectors in the demo. The method of rotating the vectors is covered in Incremental Rotation (coming).

Coordinate System
By separating the model, you can use whatever kind of coordinate system you’d like. If you prefer to have your animation model centered around the origin (0,0) you can do that, and part of the rendering will be to shift the coordinates to screen coordinates. Or you can use a 3D coordinate system or polar coordinate system, and render from those.

Other Ways to Render in Director
There is more than one way to render an animation model:

  • set sprite properties, as done in this demo
  • use imaging lingo to render to an image object
  • set Shockwave 3D properties
  • set vector cast member properties
  • text-based animation (hey, it would work!)

And there are probably others as well. If you wanted you could render the same animation model in all these ways in the same program.

Other Examples
Case Study: Space Viewport
Independent Model Rate
All of the 3D quad demos