FLARToolKit Bubble
from flartoolkit SimpleCube example
print this marker: http://saqoosha.net/lab/FLARToolKit/flarlogo-marker.pdf
/**
* Copyright maccyan ( http://wonderfl.net/user/maccyan )
* GNU General Public License, v3 ( http://www.gnu.org/licenses/quick-guide-gplv3.html )
* Downloaded from: http://wonderfl.net/c/hqjB
*/
// forked from mash's FLARToolKit SimpleCube sample
// from flartoolkit SimpleCube example
// print this marker: http://saqoosha.net/lab/FLARToolKit/flarlogo-marker.pdf
package {
import flash.display.*;
import flash.events.*;
import org.papervision3d.materials.*;
import org.papervision3d.lights.*;
import org.papervision3d.materials.shadematerials.*;
import org.papervision3d.objects.primitives.*;
import org.papervision3d.view.*;
import org.libspark.flartoolkit.example.PV3DARApp;
[SWF(width=640, height=480, backgroundColor=0x808080, frameRate=90)]
public class Bubble extends PV3DARApp {
private var _bubbles:Object = new Object();
private var id:Number = 0;
private var _bubbleInt:Number = 0;
private var light:PointLight3D;
private var material:GouraudMaterial;
private const _bubbleTime:Number = 1;
private var _bubble:Sphere;
public function Bubble() {
Wonderfl.capture_delay( 5 );
// Initalize application with the path of camera calibration file and patter definition file.
// カメラ補正ファイルとパターン定義ファイルのファイル名を渡して初期化。
addEventListener(Event.INIT, _onInit);
init('http://assets.wonderfl.net/static/flar/camera_para.dat', 'http://assets.wonderfl.net/static/flar/flarlogo.pat');
}
private function _onInit(e:Event):void {
// Place the light at upper front.
// ライトの設定。手前、上のほう。
light = new PointLight3D();
light.x = 0;
light.y = 1000;
light.z = -1000;
stage.addEventListener(Event.ENTER_FRAME, sub);
}
private function sub(e:Event = null):void {
// シャボン玉を動かす
for(var i:String in _bubbles) {
_bubbles[i].x += (-1 + Math.floor(Math.random() * 3));
_bubbles[i].x += Math.sin(100 * Math.PI / 360);
_bubbles[i].x -= Math.sin(100 * Math.PI / 360);
_bubbles[i].z += 10;
_bubbles[i].y += (-1 + Math.floor(Math.random() * 3));
_bubbles[i].y += Math.sin(100 * Math.PI / 360);
_bubbles[i].y -= Math.sin(100 * Math.PI / 360);
// シャボン玉ループ
if(_bubbles[i].z >= 2000){
_bubbles[i].x = Math.floor(Math.random() * 80) - 50;
_bubbles[i].z = 0;
_bubbles[i].y = Math.floor(Math.random() * 80) - 50;
}
}
_bubbleInt++;
// シャボン玉を発生させる
if(_bubbleInt > _bubbleTime) {
make_bubble();
_bubbleInt = 0;
}
}
// シャボン玉の設定
private function make_bubble():void {
material = new GouraudMaterial(light, 0xFFFFFF, Math.floor(Math.random() * 0xFFFFFF), 50);
_bubble = new Sphere(material, 18, 12, 12);
_bubbles["_bubbles"+id] = _bubble;
id++;
if(id < 100){
_bubble.x = Math.floor(Math.random() * 80) - 50;
_bubble.z = 0;
_bubble.y = Math.floor(Math.random() * 80) - 50;
_markerNode.addChild(_bubble);
} else {
stage.addEventListener(Event.ENTER_FRAME, sub);
}
}
}
}