flash on 2012-11-17

by xarple
♥0 | Line 62 | Modified 2012-11-17 20:10:56 | MIT License
play

ActionScript3 source code

/**
 * Copyright xarple ( http://wonderfl.net/user/xarple )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/vRdy
 */

package {
  import flash.display.*;
  import flash.events.Event;
  import flash.geom.*;
  import flash.net.URLRequest;
  import flash.system.LoaderContext;
  import flash.utils.getTimer;
  [SWF(backgroundColor="#000000")]
  public class ch40ex4 extends Sprite {

    protected var modelMatrix:Matrix3D;

    protected var texture:Bitmap;

    protected var s:Sprite;
    
    public function ch40ex4() {


     s = new Sprite();
     addChild(s);


      modelMatrix = new Matrix3D();

      var l:Loader = new Loader();
      l.load(new URLRequest("http://actionscriptbible.com/files/texture-approved.jpg"), new LoaderContext(true));
      l.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoad);
    }
    protected function onLoad(event:Event):void {
      texture = Bitmap(LoaderInfo(event.target).content);
      s.addChild(texture);
                 texture.x = -stage.stageWidth/4;
     texture.y = -stage.stageHeight/4;
           texture.scaleX = 0.5;
      texture.scaleY = 0.5;

      addEventListener(Event.ENTER_FRAME, onEnterFrame);
    }
    protected function onEnterFrame(event:Event):void {
      modelMatrix.identity();
      modelMatrix.appendRotation(10*Math.cos(getTimer()/2000), Vector3D.Y_AXIS);
      modelMatrix.appendRotation(10*Math.sin(getTimer()/2000), Vector3D.X_AXIS);

s.transform.matrix3D = modelMatrix;
    }
  }
}
import flash.geom.Rectangle;
import flash.geom.Vector3D;
class Plane3D {
  public var vertices:Vector.<Number> = new Vector.<Number>();
  public var uvt:Vector.<Number> = new Vector.<Number>();
  public var indices:Vector.<int> = new Vector.<int>();
  public function Plane3D(r:Rectangle):void {
    vertices.push(
      r.left, r.bottom, 0, //bottom left = 0
      r.left, r.top, 0,  //top left = 1
      r.right, r.top, 0, //top right = 2
      r.right, r.bottom, 0 //bottom right = 3
    );
    uvt.push(
      0, 1, 0, //bottom left
      0, 0, 0, //top left
      1, 0, 0, //top right
      1, 1, 0 //bottom right
    );
    indices.push(
      0, 2, 1, //left-side triangle BL->TR->TL
      0, 3, 2 //right-side triangle BL->BR->TR
    );
  }
}