Spiral
Papervision3D入門を参考。
黒いのをクリックすると等倍距離に移動します。
/**
* Copyright toshihiko_nii ( http://wonderfl.net/user/toshihiko_nii )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/esHO
*/
package
{
import caurina.transitions.Tweener;
import flash.events.Event;
import org.papervision3d.events.InteractiveScene3DEvent;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.view.BasicView;
public class Spiral extends BasicView
{
private var _angle:Number = 0;
private var _angle2:Number = 0;
private var _floor:Plane;
public function Spiral()
{
super(0, 0, true, true);
viewport.buttonMode = true;
_floor = new Plane(new ColorMaterial(0xCCCCCC, 1, true), 2000, 2000, 15, 15);
_floor.material.doubleSided = true;
_floor.rotationX = 90;
_floor.y = -stage.stageHeight;
scene.addChild(_floor);
var max:int = 100;
for (var i:int = 0; i < max; i++)
{
var obj:Plane = new Plane(new ColorMaterial(0x000000, 1, true), 100, 100);
obj.material.doubleSided = true;
var angle:Number = 360 * (i / 25);
var objX:Number = 600 * Math.sin(angle * Math.PI / 180);
var objZ:Number = 600 * Math.cos(angle * Math.PI / 180);
var objY:Number = (i * 10 - stage.stageHeight) + 130;
obj.extra = angle;
Tweener.addTween(obj, { x:objX, z:objZ, y:objY, rotationY:angle+720, time:2, transition:"easeOut" } );
obj.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, onClick);
scene.addChild(obj);
}
startRendering();
addEventListener(Event.ENTER_FRAME, onEnterframe);
}
private function onClick(e:InteractiveScene3DEvent):void
{
var moveZ:Number = e.target.z + camera.zoom * camera.focus * Math.cos(e.target.extra * Math.PI / 180);
var moveX:Number = e.target.x + camera.zoom * camera.focus * Math.sin(e.target.extra * Math.PI / 180);
Tweener.addTween(camera, { x:moveX, y:e.target.y, time:3, transition:"easeOutCubic" } );
Tweener.addTween(camera, { z:moveZ, time:4, transition:"easeOutCubic" } );
Tweener.addTween(camera.target, { z:e.target.z, x:e.target.x, y:e.target.y, time:3, transition:"easeOutQuint", onComplete:function():void
{
_floor.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, onBack);
} } );
removeEventListener(Event.ENTER_FRAME, onEnterframe);
}
private function onBack(e:InteractiveScene3DEvent):void
{
addEventListener(Event.ENTER_FRAME, onEnterframe);
Tweener.addTween(camera.target, { z:0, x:0, y:0, time:0.5, transition:"linear" } );
}
private function onEnterframe(e:Event):void
{
var moveX:Number = (stage.stageWidth / 2 - mouseX);
var moveY:Number = (stage.stageHeight / 2 - mouseY);
_angle = Math.atan2(camera.x, camera.z) * 180 / Math.PI + moveX * 0.02;
_angle2 += moveY * 0.002;
var cX:Number = 1000 * Math.sin(_angle * Math.PI / 180);
var cZ:Number = 1000 * Math.cos(_angle * Math.PI / 180);
var cY:Number = 1200 * Math.sin(_angle2 * Math.PI / 180);
Tweener.addTween(camera, { x:cX, y:cY, z:cZ, time:2, transition:"easeOut" } );
}
}
}