prependRotation
クリックするとポインタの位置に合わせて視点が切り替わる
♥0 |
Line 57 |
Modified 2010-07-21 22:19:30 |
MIT License
archived:2017-03-20 13:25:55
ActionScript3 source code
/**
* Copyright hacker_szoe51ih ( http://wonderfl.net/user/hacker_szoe51ih )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/kRLF
*/
/*クリックするとポインタの位置に合わせて視点が切り替わる*/
package {
import flash.events.MouseEvent;
import flash.events.Event;
import flash.geom.*;
import flash.display.Sprite;
[SWF(frameRate="60", width="465", height="465",backgroundColor=0x000000)]
public class FlashTest extends Sprite {
public var square1:Square;
public var W:Number=stage.stageWidth;
public var H:Number=stage.stageHeight;
public var nDeceleration:Number=0.05;
public var nX:Number;
public var myMatrix3D:Matrix3D;
public var atPerspectiveProjection:PerspectiveProjection;
public function FlashTest() {
init();
}
public function init():void{
atPerspectiveProjection = root.transform.perspectiveProjection;
square1=new Square(0xaaccff,100);
addChild(square1);
square1.x=W/2;
square1.y=H/2;
square1.z=0;
nX=square1.x;
myMatrix3D=new Matrix3D();
myMatrix3D=square1.transform.matrix3D;
stage.addEventListener(MouseEvent.CLICK,onClick);
addEventListener(Event.ENTER_FRAME,enterFramer);
}
public function enterFramer(e:Event):void{
var nRotationY:Number=(mouseX-nX)*nDeceleration;
myMatrix3D.prependRotation(nRotationY,Vector3D.Y_AXIS);
}
public function onClick(e:MouseEvent):void{
atPerspectiveProjection.projectionCenter = new Point(mouseX,mouseY);
}
}
}
import flash.geom.Matrix;
import flash.display.*;
class Square extends Sprite {
public var p:Sprite;
public function Square(col:uint,len:Number):void {
var myMatrix:Matrix=new Matrix();
myMatrix.createGradientBox(len,len,0,0,0);
var colors:Array=[0xffffff,0x356999,0x113388];
var ratios:Array=[0,127,255];
var alphas:Array=[1,1,1];
p=new Sprite();
p.graphics.lineStyle();
p.graphics.beginGradientFill(GradientType.LINEAR,colors,alphas,ratios,myMatrix,SpreadMethod.PAD);
p.graphics.drawRect(-len/2,-len/2,len,len);
p.graphics.endFill();
addChild(p);
}
}