Utils3D.pointTowards()
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/2k71
*/
// 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 field:Sprite = new Sprite();
field.x = centerX;
field.y = centerY;
field.z = 0;
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 = 0;
ellipse.y = 0;
ellipse.z = 1;
triangle = new Clip(ellipse);
triangle.x = 0;
triangle.y = 0;
triangle.z = 0;
field.addChild(triangle);
field.addChild(ellipse);
addChild(field);
for(var i:int=0; i < 80; i++){
var clip:Clip = new Clip(ellipse);
field.addChild(clip);
var vec:Vector3D = new Vector3D(Math.random()*2-1,Math.random()*2-1,Math.random()*2-1);
vec.normalize();
clip.x = vec.x * 230;
clip.y = vec.y * 230;
clip.z = vec.z * 230;
}
ellipse.addEventListener(Event.ENTER_FRAME, ellipseEnterFrameHandler);
field.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
randomMove();
this.addChild(new Stats({ bg: 0x202020, fps: 0xC0C0C0, ms: 0x505050, mem: 0x707070, memmax: 0xA0A0A0 }));
}
private function enterFrameHandler(e:Event):void
{
e.target.rotationY += 0.3;
}
private function randomMove():void
{
var vec:Vector3D = new Vector3D(Math.random()*2-1,Math.random()*2-1,Math.random()*2-1);
vec.normalize();
var r:Number = Math.random() * 250;
Tweener.addTween(ellipse, {
x:vec.x * r,
y:vec.y * r,
z:vec.z * r,
time:2.0,
transition:"easeOutSine",
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.display.Shape;
import flash.display.Graphics;
import flash.events.Event;
import flash.geom.*;
class Clip extends Sprite{
private var _target:Sprite;
private var _p:Number;
public function Clip(target:Sprite){
_target = target;
var shape0:Shape = new Shape();
drawGraphics(shape0.graphics);
/*
var shape1:Shape = new Shape();
drawGraphics(shape1.graphics);
shape1.rotationX = 90;
*/
_p = Math.random() * 0.05 + 0.005;
this.addChild(shape0);
//this.addChild(shape1);
this.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
private function drawGraphics(g:Graphics):void
{
g.lineStyle(0, 0xffffff);
g.beginFill(0xffffff, 0.3);
g.moveTo(0, 2);
g.lineTo(70, 0);
g.lineTo(0, -2);
g.lineTo(0, 2);
g.endFill();
}
private function enterFrameHandler(e:Event):void
{
var pos:Vector3D = _target.transform.matrix3D.position;
var newMtx3D:Matrix3D = Utils3D.pointTowards(_p, this.transform.matrix3D, pos,Vector3D.X_AXIS, Vector3D.Y_AXIS);
this.transform.matrix3D = newMtx3D;
//this.transform.matrix3D.pointAt(_target.transform.matrix3D.position, Vector3D.X_AXIS, Vector3D.Y_AXIS);
}
}