2010-04-20 | 10:27
マウスの動きに合わせて回転します。
package { import flash.display.*; import flash.events.*; import flash.geom.*; [SWF(width='500',height='500',backgroundColor='0xffffff',framerate='5')] public class Rotate3D_2 extends Sprite { private var m:Matrix3D = new Matrix3D(); private var pictures:Array = []; public function Rotate3D_2( ) { for(var i:int = 0 ; i < 10 ; i++){ var p:Picture = new Picture(200-i*30); pictures.push(p); addChild(p); } this.stage.addEventListener(MouseEvent.MOUSE_MOVE, func); } public function func(event:Event):void { trace(stage.mouseX); var rady:Number = (stage.mouseX - 250) / 250*90; var radx:Number = (250 - stage.mouseY ) / 250*90; for each(var p:Picture in pictures){ p.rotate(rady, radx); } } } } import flash.display.*; import flash.geom.*; internal class Picture extends Sprite{ [Embed(source="lena.jpg")] private var myImage:Class; private var container:Sprite = new Sprite(); private var bm:Bitmap = new myImage(); private var zz:int; public function Picture(i:int){ container.addChild(bm); addChild(container); var pos:Matrix3D = new Matrix3D(); pos.position = new Vector3D(100, 50, i); this.transform.matrix3D = pos; this.zz = i; } public function rotate(rady:Number, radx:Number):void{ var pos:Matrix3D = new Matrix3D(); pos.position = new Vector3D(100,50,0); // Y軸回転 { var my:Matrix3D = new Matrix3D(); my.position = new Vector3D(0, 0, zz); my.appendRotation(rady, Vector3D.Y_AXIS); my.append(pos); } // X軸回転 { var mx:Matrix3D = new Matrix3D(); mx.position = new Vector3D(0, 0, zz); mx.appendRotation(radx, Vector3D.X_AXIS); mx.append(pos); } // 合成 mx.prepend(my); container.transform.matrix3D = mx; } }
Comment
Post a comment