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

globalToLocal3D test

Get Adobe Flash player
by dizgid 27 May 2010
/**
 * Copyright dizgid ( http://wonderfl.net/user/dizgid )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/miq0
 */

package {
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.geom.Point;
    import flash.geom.Vector3D;
    public class FlashTest extends Sprite {
    	
    		private var rectSp:Rect;
        public function FlashTest() {
            // write as3 code here..
            rectSp = new Rect();
            this.addChild(rectSp);
            
            rectSp.x = stage.stageWidth / 2;
            rectSp.y = stage.stageHeight / 2;
            rectSp.rotationY = 45;
            rectSp.rotationX = 35;
             
            stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
            
        }
        
        private function mouseDownHandler(e:MouseEvent):void
        {
        		var p:Point = new Point(stage.mouseX, stage.mouseY);
        		var pos3d:Vector3D = rectSp.globalToLocal3D(p);
        		
        		var dot:Dot = new Dot();
        		/*
        		//
        		//var vec3d:Vector3D = rectSp.transform.matrix3D.decompose()[0];
        		var vec3d:Vector3D = pos3d;
        		var point:Point = new Point();
        		point = this.local3DToGlobal(vec3d);
        		
        		var t_d:Dot = new Dot(0x0000ff, 10);
        		point.x += stage.stageWidth / 2;
        		point.y += stage.stageHeight / 2;
        		t_d.x = point.x;
        		t_d.y = point.y;
        		this.addChild(t_d);
        		
        		vec3d = rectSp.globalToLocal3D(point);
        		
        		dot.x = vec3d.x + stage.stageWidth / 2;
        		dot.y = vec3d.y + stage.stageHeight / 2;
        		dot.z = vec3d.z;
        		
        		this.addChild(dot);
        		*/
        		/*
        		dot.x = pos3d.x ;
        		dot.y = pos3d.y ;
        		dot.z = pos3d.z;
        		rectSp.addChild(dot);
        		*/
        		
        		pos3d = Sprite(rectSp).transform.matrix3D.transformVector(pos3d);
        		
        		dot.x = pos3d.x;
        		dot.y = pos3d.y;
        		dot.z = pos3d.z;
        		
        		this.addChild(dot);
        		
        }
    }
}

import flash.display.Sprite;
import flash.display.Graphics;
internal class Dot extends Sprite
{
	public function Dot(color:int = 0xff0000, size:Number = 20){
		var g:Graphics = this.graphics;
		g.beginFill(color);
		g.drawCircle(0,0,size);
		g.endFill();
	}
}
internal class Rect extends Sprite
{
	public function Rect(){
		var g:Graphics = this.graphics;
		var size:Number = 200;
		g.beginFill(0x00ff00);
		g.drawRect(-size/2,-size/2,size, size);
		g.endFill();
	}
}