carousel

a circular flash animated 3D interface

carousel

src/nu/xero/gui/carousel.as


package nu.xero.gui {
	import caurina.transitions.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.text.*;
	
	import org.papervision3d.cameras.*;
	import org.papervision3d.core.math.*;
	import org.papervision3d.core.render.data.*;
	import org.papervision3d.events.*;
	import org.papervision3d.materials.*;
	import org.papervision3d.objects.*;
	import org.papervision3d.objects.primitives.*;
	import org.papervision3d.view.*;
	
	public class carousel extends BasicView {
		public  var stats			:RenderStatistics;
		private var theGallery		:Array = new Array();
		private var radius			:Number = 300;
		private var spinning		:Boolean = true;
		private var total			:Number;
		private var rootNode		:DisplayObject3D;
		private var theCarousel		:DisplayObject3D;
		
		public function carousel(gallery:XMLList, art:Array, lbl:TextField) {
			super(0, 0, true, true, CameraType.TARGET);
						
			camera.z = radius + 200;
			camera.y = 100; 
			camera.zoom = 6;
			camera.focus = 100;
			stats = renderer.renderScene(scene, camera, viewport);
						
			rootNode = new DisplayObject3D("rootNode");
			scene.addChild(rootNode);
			theCarousel = new DisplayObject3D("carousel");
			scene.addChild(theCarousel);
						
			total = gallery.length();
			radius = 18.75 * total;
			
			var i:Number = 0;
			while(i < total) {
				theGallery[i] = new Object();
				theGallery[i].img = new Plane(new BitmapMaterial(art[i].img), 100, 100, 2, 2);
				theGallery[i].img.material.doubleSided = true;
				theGallery[i].img.material.smooth = true;
				theGallery[i].img.material.interactive = true;
				theGallery[i].img.extra = false; //is zoomed
				theGallery[i].img.yaw(360/total*i);
				theGallery[i].img.moveForward(radius);
				theGallery[i].img.rotationY += 180;
				theCarousel.addChild(theGallery[i].img);
				theGallery[i].img.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS, stopSpin);
				i++;
			}
			theCarousel.y += 40;
			theCarousel.rotationY += 10;
			theCarousel.moveUp(20);
			
			startRendering();
			addEventListener(Event.ENTER_FRAME, loop3D);
		}
		
		private function stopSpin(e:InteractiveScene3DEvent = null):void {
			spinning = !spinning ? true : false;
			var do3d:DisplayObject3D = e.displayObject3D;
			var distance:Number = 80;
			var moveAxis:Number3D = new Number3D(0, 0, 0);
			moveAxis.z = (do3d.extra == false) ? -1 : 1;
			org.papervision3d.core.math.Matrix3D.rotateAxis(do3d.transform, moveAxis);
			var target:Number3D = new Number3D();
			target.x = distance * moveAxis.x + do3d.x;
			target.y = distance * moveAxis.y + do3d.y;
			target.z = distance * moveAxis.z + do3d.z;
			Tweener.addTween(e.target, {
				time: .8,
				x: target.x,
				y: target.y,
				z: target.z,
				transition: "easeOutExpo"
			});			
			do3d.extra = do3d.extra == true ? false : true;
		}
		
		private function loop3D(e:Event):void {
			if(spinning) {
				//mouse influence
				theCarousel.rotationY -= (mouseX-(stage.stageWidth*.5))/1000;
			}
			
		}
	}
}

Download

raw zip tar