In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: forked from: forked from: forked from: PerspectiveProjectionTest

Get Adobe Flash player
by hiro_loveness 16 Feb 2010
/**
 * Copyright hiro_loveness ( http://wonderfl.net/user/hiro_loveness )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/tTwM
 */

// forked from hiro_loveness's forked from: forked from: forked from: PerspectiveProjectionTest
// forked from hiro_loveness's forked from: forked from: PerspectiveProjectionTest
// forked from hiro_loveness's forked from: PerspectiveProjectionTest
// forked from ukkr's PerspectiveProjectionTest
package  {
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.display.Graphics;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.PerspectiveProjection;
	import flash.geom.Point;
	import flash.geom.Matrix3D;
	
	public class PerspectiveProjectionTest extends Sprite {
		private var _pro:PerspectiveProjection;			//PerspectiveProjetionクラス
		private var _centerPoint:Point = new Point(0,0);	//消失点用のPointクラス
		private var _panelNum:uint =18;					//プレートの数
		private var _panelSize:uint = 100;				//プレートのサイズ
		private var _ang:int = 90;						//プレート角度
		private var box:Sprite = new Sprite();			//プレート親ボックス
		private var _cx:Number =0.04;
		private var _cy:Number =0.05;
		private var sp:Sprite;
		
		public function PerspectiveProjectionTest() {
						
			//アクセスするperspectiveProjectionオブジェクト
			_pro = root.transform.perspectiveProjection;
			//視野角の遠近感の強さ
			_pro.fieldOfView = 140;
			//視点からオブジェクトまでの距離
			//_pro.focalLength =200;
			
			initStage();
		}
		
		private function initStage():void {
			for ( var i:int = 0; i < _panelNum; i++ ) {
				sp= new Sprite();
				var g:Graphics = sp.graphics;
				var col:uint = Math.floor(Math.random()*0Xdddddd)
				g.beginFill(col, 0.8 );
				g.drawRect( -_panelSize / 2, -_panelSize / 2, _panelSize,_panelSize );
				g.endFill();
				sp.x = Math.floor(Math.round( stage.stageWidth / _panelNum * i ));
				//sp.y = Math.floor(Math.round( stage.stageHeight / _panelNum * i ));
				sp.y = stage.stageHeight / 2+(5*i);
				//sp.z = (stage.stageHeight / 5)*(i*0.2);
				sp.rotationY = _ang;
				box.addChild( sp );
			}
			addChild(box);
			//box.rotationY =_ang;
			addEventListener( Event.ENTER_FRAME, enterFrameHandler );
		}
		
		//ここでマウスに消失点を追従
		private function enterFrameHandler( e:Event ):void {
			_centerPoint.x += (mouseX-_centerPoint.x)*_cx;
			_centerPoint.y += (mouseY-_centerPoint.y)*_cy;
			z =_centerPoint.y/8;
			_pro.projectionCenter = _centerPoint;
		}
}

}