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: Matrix3D.pointAt()

http://help.adobe.com/ja_JP/AS3LCR/Flash_10.0/flash/geom/Matrix3D.html#pointAt()
/**
 * Copyright nutsu ( http://wonderfl.net/user/nutsu )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/rump
 */

// forked from dizgid's forked from: forked from: Matrix3D.pointAt()	
// forked from dizgid's forked from: Matrix3D.pointAt()	
// forked from dizgid's Matrix3D.pointAt()	
/**
http://help.adobe.com/ja_JP/AS3LCR/Flash_10.0/flash/geom/Matrix3D.html#pointAt()
*/
package {
	import flash.display.Sprite;
    import flash.display.MovieClip;
    import flash.display.Shape;
    import flash.display.Graphics;
    import flash.geom.*;
    import flash.events.Event;
    import caurina.transitions.Tweener;
    import net.hires.debug.Stats;

	[SWF(frameRate=60)]
    public class PointAtExample extends MovieClip {
        private var ellipse:Sprite = new Sprite();
        private var triangle:Clip;
        
        private var centerX:Number = stage.stageWidth / 2;
        private var centerY:Number = stage.stageHeight / 2;

        public function PointAtExample():void {
        		
        		this.graphics.beginFill(0x000000);
        		this.graphics.drawRect(0,0,stage.stageWidth, stage.stageHeight);
        		this.graphics.endFill();
        	
        		var ellipseShape:Shape = new Shape();
        		var size:Number = 80;
        		ellipse.addChild(ellipseShape);
            ellipseShape.graphics.beginFill(0xffffff, 0.3);
            ellipseShape.graphics.lineStyle(0, 0xffffff);
            ellipseShape.graphics.drawRect(-size*0.5,-size*0.5,size, size);
            ellipseShape.graphics.endFill();
            ellipseShape.rotationY = 90;
            ellipse.x = centerX;
            ellipse.y = centerY;
            ellipse.z = 1;
            
            triangle = new Clip(ellipse);
            triangle.x = centerX;
            triangle.y = centerY;
            triangle.z = 1;
            
            addChild(triangle);
            addChild(ellipse);
            
            for(var i:int=0; i < 60; i++){
            		var clip:Clip = new Clip(ellipse);
            		this.addChild(clip);
            		clip.x = (Math.random()*2-1) * 200 + centerX;
            		clip.y = (Math.random()*2-1) * 200 + centerY;
            		clip.z = (Math.random()*2-1) * 200;
            }

            ellipse.addEventListener(Event.ENTER_FRAME, ellipseEnterFrameHandler);
            
            randomMove();
            
        		this.addChild(new Stats({ bg: 0x202020, fps: 0xC0C0C0, ms: 0x505050, mem: 0x707070, memmax: 0xA0A0A0 }));
        }
        private function randomMove():void
        {
      	  	Tweener.addTween(ellipse, { 
				x:Math.random()*400-200 + centerX,
				y:Math.random()*400-200 + centerY,
				z:Math.random()*600-300,
				time:1.5, 
				transition:"linear",
				onComplete:function():void {
					randomMove();
				}
			} );
        }

        private function ellipseEnterFrameHandler(e:Event):void {
            ellipse.transform.matrix3D.pointAt(triangle.transform.matrix3D.position, Vector3D.X_AXIS, Vector3D.Y_AXIS);
        }
    }
}

import flash.display.Sprite;
import flash.events.Event;
import flash.geom.*;

class Clip extends Sprite{
	private var _target:Sprite;
	public function Clip(target:Sprite){
		_target = target;
		this.graphics.lineStyle(0, 0xffffff);
		this.graphics.moveTo(0, 4);
		this.graphics.lineTo(70, 0);
		this.graphics.lineTo(0, -4);
		this.graphics.lineTo(0, 4);
		this.graphics.endFill();
		
		this.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
	}
	
	//自前でやってみるテスト、、、あれ、まちごうとるかな、、あとで考える
	private var uu:Vector3D = new Vector3D(0,1,0);
	private var ux:Vector3D;
	private var uy:Vector3D;
	private var uz:Vector3D;
	private function enterFrameHandler(e:Event):void
	{
		var tx:Number = x;
		var ty:Number = y;
		var tz:Number = z;
		ux = new Vector3D( _target.x - tx, _target.y - ty, _target.z - tz );
		if ( ux.length > 0 ) {
			ux.normalize();
			uz = uu.crossProduct( ux ), uz.normalize();
			uy = uz.crossProduct( ux ), uy.normalize();
			transform.matrix3D.identity();
			transform.matrix3D.rawData = Vector.<Number>( [ux.x, ux.y, ux.z, 0, uy.x, uy.y, uy.z, 0, uz.x, uz.y, uz.z, 0,  0, 0, 0, 1 ] );
			transform.matrix3D.appendTranslation( tx, ty, tz );
		}
	}
}