2009年 04月 07日
Spriteで作成した円を Matrix3D で擬似3D表現してみました。
Sphereより軽いでしょ。
Main.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="600" height="400"
applicationComplete="this._init();">
<mx:Text text="Belcro.net
Papervision3D Matrix3D" x="10" y="167" width="579" height="100" textAlign="center" fontSize="33"/>
<mx:Script>
<![CDATA[
import mx.effects.Glow;
import org.papervision3d.core.math.Matrix3D;
import image.Circle;
private var _circle_list:Array;
private var _speed:Number = 0;
private var _xspeed:Number = 1;
/*-------------------------------------------------
* _init
-------------------------------------------------*/
private function _init():void
{
this.stage.scaleMode = StageScaleMode.NO_SCALE;
this.stage.align = StageAlign.TOP_LEFT;
this._circle_list = new Array();
for(var i:uint=0; i<30; i++)
{
var circle:Circle = new Circle();
this._circle_list.push(circle);
this.stage.addChild(circle);
}
this.addEventListener(Event.ENTER_FRAME , this._enter_Frme_Event);
this.stage.addEventListener(MouseEvent.MOUSE_DOWN , this._mouseDown);
this.stage.addEventListener(MouseEvent.MOUSE_UP , this._mouseUp);
}
/*-------------------------------------------------
* _mouseDown
-------------------------------------------------*/
private function _mouseDown(evn:Event):void
{
this._xspeed = 2;
}
/*-------------------------------------------------
* _mouseUp
-------------------------------------------------*/
private function _mouseUp(evn:Event):void
{
this._xspeed = 1;
}
/*-------------------------------------------------
* _enter_Frme_Event
-------------------------------------------------*/
private function _enter_Frme_Event(evn:Event):void
{
this._speed += (this._xspeed - this._speed) * 0.1;
for(var i:uint=0; i<this._circle_list.length; i++)
{
var circle:Circle = this._circle_list[i] as Circle;
circle.add(this._speed);
var mat:Matrix3D = new Matrix3D(
[
1,1,1,
1,0,0,
0,0,0,
0,0,0
]
);
mat = Matrix3D.multiply(mat,Matrix3D.rotationX(circle.rot_x /180*Math.PI));
mat = Matrix3D.multiply(mat,Matrix3D.rotationY(circle.rot_y /180*Math.PI));
mat = Matrix3D.multiply(mat,Matrix3D.rotationZ(circle.rot_z /180*Math.PI));
circle.x = mat.n11*100 + 280;
circle.y = mat.n12*100 + 200;
circle.scaleX = circle.scaleY = ((2+mat.n13) /4);
circle.setPosZ(circle.scaleX * 20);
}
}
]]>
</mx:Script>
</mx:Application>
Circle.as
package image
{
import flash.display.BlendMode;
import flash.display.Sprite;
import flash.filters.GlowFilter;
public class Circle extends Sprite
{
public var rot_x:Number = 0;
public var rot_y:Number = 0;
public var rot_z:Number = 0;
private var _rot_x:Number = 0;
private var _rot_y:Number = 0;
private var _rot_z:Number = 0;
public var pos_z:Number = 0;
private var _glow:GlowFilter;
public function Circle()
{
super();
this.graphics.beginFill(0xffffff , 0.5);
this.graphics.drawCircle(0,0,10);
this.graphics.endFill();
this.rot_x = Math.random() * 360;
this.rot_y = Math.random() * 360;
this.rot_z = Math.random() * 360;
this._rot_x = 1 + Math.random() * 2;
this._rot_y = 1 + Math.random() * 2;
this._rot_z = 1 + Math.random() * 2;
this.pos_z = 1000//1 + Math.random() * 2;
this._glow = new GlowFilter(0xffffff,1,30,30);
this.blendMode = BlendMode.OVERLAY;
}
public function setPosZ(value:Number):void{
this._glow.blurX = this._glow.blurY = value;
this.filters = [this._glow];
}
public function add(speed:Number):void{
this.rot_x += this._rot_x * speed;
this.rot_y += this._rot_y * speed;
this.rot_z += this._rot_z * speed;
if(this.rot_x > 360) this.rot_x = this.rot_x - 360;
if(this.rot_y > 360) this.rot_y = this.rot_y - 360;
if(this.rot_z > 360) this.rot_z = this.rot_z - 360;
}
}
}
投稿者: d5 13 : 04
更新日:2009-04-07 13:27:32
|
|
|
| |