wonderfl中

現在wonderfl中。
皆さんの凄いソースが上がっていますが、自分は地味に3Dについて研究中。


↑でとりあえずrotationX,rotationY,rotationZで回るのは分かった、がソースが汚い・・・。



↑も回転&無駄にズームさせてみただけですが、こちらは以下のようにして回転&Zソート。
でも、もっといい方法がありそう・・・。

//this.rotateXとthis.rotateY分回転させるMatrix3D
var mat:Matrix3D = new Matrix3D();
mat.appendRotation(this.rotateX, Vector3D.X_AXIS);
mat.appendRotation(this.rotateY, Vector3D.Y_AXIS);

//画面の中心へ
this.x = this.stage.stageWidth / 2;
this.y = this.stage.stageHeight / 2;
this.z = 0;

var i:int;
for (i = 0; i < POINT_NUM; i++)
{
  var point:Ball = this.points[i]; //配列から1つだけ取り出す
  
  //回転後の座標を取得する
  var vectorPoint:Vector3D
   = mat.transformVector(point as Vector3D);

  //取得した座標を反映する
  point.x = vectorPoint.x;
  point.y = vectorPoint.y;
  point.z = vectorPoint.z;
}
//Zソートする
//pointsはVector.<Ball>
//sortメソッドの引数はFunction型
this.points = this.points.sort(compare);

 ・
 ・ 省略
 ・
 
/**
 * Zソート
 */
private function compare( x:Ball, y:Ball ):Number
{
  return y.z - x.z;
}