せっかくFP10で3Dの概念が追加されたんだから3Dやってみようってことで
FP10で追加された3Dの機能
・flash.display.DisplayObject クラス
z プロパティやscaleZ
rotationX,rotationY,rotationZなどの各軸の回転角
3次元座標を2次元に変換するlocal3DToGlobal() メソッド が追加された
・flash.geom.Vector3D クラス
3次元座標を格納するクラス
回転角も入れたりできる
※Vectorクラスとは違います Vectorクラスはすべてのエレメントが同じデータ型を持つ配列で、Vector3Dクラスは3次元空間のベクトルを表すクラスです
・flash.geom.Matrix3D クラス
回転、拡大、縮小、平行移動などの3Dの変換を行うクラス
・flash.geom.PerspectiveProjection クラス
遠近法に基づく変形を行うクラス
とりあえずくるくる回転するだけの物を作ってみた
package {
import flash.display.Sprite;
import flash.events.Event;
public class Study3d1 extends Sprite {
private const SIZE:int = 100;
private const W:int = stage.stageWidth;
private const H:int = stage.stageHeight;
private var mc:Sprite;
public function Study3d1():void {
mc = new Sprite();
mc.graphics.beginFill(0x0077ff);
mc.graphics.drawRect(-SIZE/2, -SIZE/2, SIZE, SIZE);
mc.graphics.endFill();
mc.x = W / 2;
mc.y = H / 2;
addChild(mc);
addEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
}
private function onEnterFrameHandler(e:Event):void {
mc.rotationX = H / 2 - mouseY;
mc.rotationY = W / 2 - mouseX;
}
}
}
おー回ってる回ってる
次はもちっと複雑な動きをする物を作ってみたいと思います