forked from: forked from: Matrix3D.pointAt()
http://help.adobe.com/ja_JP/AS3LCR/Flash_10.0/flash/geom/Matrix3D.html#pointAt()
/**
* Copyright dizgid ( http://wonderfl.net/user/dizgid )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/1dRH
*/
// 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 function enterFrameHandler(e:Event):void
{
this.transform.matrix3D.pointAt(_target.transform.matrix3D.position, Vector3D.X_AXIS, Vector3D.Y_AXIS);
}
}