home > sandy Ver1

sandy Ver1

June 08, 2007

Flashで3D処理を扱うためのライブラリsandyを使ってデモをつくってみました!




まずは、ビットマップでそれぞれの面に画像を配置する。

import flash.display.BitmapData;
import sandy.util.DistortImage;
import com.mosesSupposes.fuse.*;
ZigoEngine.register(Fuse, PennerEasing, FuseFMP);

var sp:Number = 0;

//角配列
var fakes:Array = new Array();

//角を設定
for(var i=1; i<=8; i++){
 fakes.push(this.createEmptyMovieClip("f"+i , i+10));
}

//ビットマップ設定
var bmd1:BitmapData = new BitmapData(photo1._width, photo1._height);
var clip1:MovieClip = this.createEmptyMovieClip("holder1", 100);
var di1:DistortImage = new DistortImage(clip1, bmd1, 5, 5);

var bmd2:BitmapData = new BitmapData(photo2._width, photo2._height);
var clip2:MovieClip = this.createEmptyMovieClip("holder2", 110);
var di2:DistortImage = new DistortImage(clip2, bmd2, 5, 5);

var bmd3:BitmapData = new BitmapData(photo3._width, photo3._height);
var clip3:MovieClip = this.createEmptyMovieClip("holder3", 120);
var di3:DistortImage = new DistortImage(clip3, bmd3, 5, 5);

var bmd4:BitmapData = new BitmapData(photo4._width, photo4._height);
var clip4:MovieClip = this.createEmptyMovieClip("holder4", 160);
var di4:DistortImage = new DistortImage(clip4, bmd4, 5, 5);

//関数
function moveFakes():Void{
 for(n=1;n<=8;n++){
  this["f"+n]._x = p[n]._x;
  this["f"+n]._y = p[n]._y;
 }
}

this.onEnterFrame = function()
{
 di1.setTransform(f1._x, f1._y, f2._x, f2._y, f3._x, f3._y, f4._x, f4._y);
 di1.texture.draw(photo1);

 di2.setTransform(f5._x, f5._y, f6._x, f6._y, f7._x, f7._y, f8._x, f8._y);
 di2.texture.draw(photo2);

 di3.setTransform(f5._x, f5._y, f1._x, f1._y, f4._x, f4._y, f8._x, f8._y);
 di3.texture.draw(photo3);

 di4.setTransform(f6._x, f6._y, f2._x, f2._y, f3._x, f3._y, f7._x, f7._y);
 di4.texture.draw(photo4);
}

それから、ActionScriptで3Dの物体を回転さす。

初期設定

var Plane:Number =300;
var Rotx:Number = 0;
var Roty:Number = 0.04;

var maxc:Number = 8;
var one_circle:Number = 45;

p = new Array(maxc+1);
px = new Array(maxc+1);
py = new Array(maxc+1);
pz = new Array(maxc+1);

for( n=1 ;n<=maxc; n++){
 this.attachMovie("ball","point"+n, n);
 p[n] = this["point"+n];
}

px[1] = one_circle;
py[1] = one_circle;
pz[1] = one_circle;
 ~省力~
px[8] = -one_circle;
py[8] = -one_circle;
pz[8] = one_circle;

this.dragger.startDrag(true);


~省略~
for (n=1; n<=maxc; n++) {
 //X軸回りにY、Z軸を回転させる
 var qz = pz[n];
 var qy = py[n];
 pz[n] = qz*Math.cos(Rotx)-qy*Math.sin(Rotx);
 py[n] = qy*Math.cos(Rotx)+qz*Math.sin(Rotx);

 //Y軸回りにX、Z軸を回転させる
 var qx = px[n];
 var qz = pz[n];
 px[n] = qx*Math.cos(Roty)-qz*Math.sin(Roty);
 pz[n] = qz*Math.cos(Roty)+qx*Math.sin(Roty);

 with (p[n]) {
  var k = Plane/(Plane-pz[n]);
  _x += ((125+px[n]*k) - _x)/0.8;
  _y += ((90-py[n]*k) - _y)/0.8;
  _xscale = 100*k;
  _yscale = 100*k;
 }
}

for (n=1; n<=maxc; n++) {
 this["point"+n]._x = p[n]._x;
 this["point"+n]._y = p[n]._y;
}
~省略~



ブックマークする hatena del.ico.us


Comments

Post a Comment






Remember personal info