topical media & game development

talk show tell print

#graphic-flex-image-effects-06-Flex-DecomposeRecomposeTest.ax

#graphic-flex-image-effects-06-Flex-DecomposeRecomposeTest.ax [swf] [flash] flex


  package {
  
          import flash.display.Shape;
          import flash.display.Sprite;
          import flash.geom.Matrix3D;
          import flash.geom.Vector3D;
  
          [SWF(width=700, height=400, backgroundColor=0xFFFFFF)]
  
          
Demonstrates how decompose/recompose can be used to affect one component of a 3D transform without being affected by transform's other components' values.

  
          public class @ax-graphic-flex-image-effects-06-Flex-DecomposeRecomposeTest extends Sprite {
  
                  
Constructor. Creates two shapes, then transforms both. For first shape, new scale is directly appended. For second shape, scale is just added to single scale vector after transform is decomposed.

  
                  public function @ax-graphic-flex-image-effects-06-Flex-DecomposeRecomposeTest() {
                          var shape0:Shape = createShape(0xFF0000);
                          var matrix0:Matrix3D = new Matrix3D();
                          matrix0.appendTranslation(250, 200, 100);
                          matrix0.appendRotation(45, Vector3D.Y_AXIS);
                          shape0.transform.matrix3D = matrix0;
  
                          var shape1:Shape = createShape(0x00FF00);
                          // dupe first shape's transform
                          shape1.transform.matrix3D = matrix0.clone();
  
                          // append scale to first shape
                          shape0.transform.matrix3D.appendScale(2, 1, 1);
  
                          // separate all of the transform's components
                          var vectors:Vector.<Vector3D> = shape1.transform.matrix3D.decompose();
                          // alter just the scale vector
                          vectors[2] = new Vector3D(2, 1, 1);
                          // recompose transform with new scale value
                          shape1.transform.matrix3D.recompose(vectors);
                  }
  
                  
Creates a shape of the specified color.
parameter: color The color for the shape.
returns: The shape created.

  
                  private function createShape(color:uint):Shape {
                          var shape:Shape = new Shape();
                          shape.graphics.beginFill(color);
                          shape.graphics.drawRect(-50, -50, 100, 100);
                          shape.graphics.endFill();
                          addChild(shape);
                          return shape;
                  }
  
          }
  
  }


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.