Graphics Previous page   Next Page

Example -- Transforming a Hierarchy of Objects

This example creates a hierarchy of hgtransform objects, which are then transformed in sequence to create a cube from six squares. The example illustrates how you can parent hgtransform objects to other hgtransform objects to create a hierarchy and how transforming members of a hierarchy affects subordinate members.

The following picture illustrates the hierarchy.

  1. Set up the figure and the view. Use double buffering to prevent flashing during the loop. Set the Renderer property to zbuffer.
  2. Define a hierarchy of hgtransform objects.
  3. Create the patch and text objects and parent each pair to the respective hgtransform object.
  1. Note that the data defining each patch object and the locations of all text objects are the same and are assigned by a single call to set. The objects are then translated to the desired positions on screen.

  1. Translate the squares (patch objects) to the desired locations. Note that as hgtransform object 2 is translated, all its children (including hgtransform objects 3 through 6) are also translated. Therefore, each translation requires moving the square by only one unit in either the x or y direction. Hgtransform object 1 is left at its original position.

Previous page  Transforming Objects Object Properties Next page

© 1994-2005 The MathWorks, Inc.