package { //create the display sprite import flash.display.Sprite; //import papervision import org.papervision3d.scenes.*; import org.papervision3d.cameras.*; import org.papervision3d.objects.*; import org.papervision3d.materials.*; //Import genertal classes import flash.events.Event; import flash.display.BitmapData; import flash.filters.BlurFilter; import flash.text.TextField; //define general swf settings [SWF(width='800',height='600',backgroundColor='0x000000',frameRate='100')] public class YCarrousel extends Sprite { //Array to store created planes private var planes:Array; //Camera angle public var angle:Number //camera, scene, the center object and the output sprite private var cam:Camera3D private var s:Scene3D private var sp:Sprite private var center:Cube; //Circle radius, note that the camera radius is defined on the loop3d and should be a bit bigger private var radius:int = 1050; //constructor public function YCarrousel() { sp = new Sprite(); this.addChild(sp); //------------- Credit where credit is due :P var myTxt:TextField = new TextField() myTxt.text = 'Powered by Papervision3d'; myTxt.textColor = 0xffffff myTxt.autoSize = 'left'; myTxt.x = 600 myTxt.y = 570 addChild(myTxt) //--------------- //Position the sprite roughly on the center of the screen sp.x = 400; sp.y = 300; planes = new Array() s = new Scene3D(sp); cam = new Camera3D(); //these are just some default values for the camera cam.z = 50; cam.y = 50 //Instantiate the center object and position it in the center of the scene center = new Cube(); center.x = center.y = center.z = 0; //We are leaving the center visibility set to true so that we see it, you can of course set to false center.visible = true; //Add the planes //You can add as many planes as you like, although keep in mind that you should consider the radius //Eg.: if you add more planes you should make a larger circle, less and make it smaller addPlane('resources/1.jpg'); addPlane('resources/2.jpg'); addPlane('resources/3.jpg'); addPlane('resources/4.jpg'); addPlane('resources/5.jpg'); addPlane('resources/6.jpg'); addPlane('resources/7.jpg'); addPlane('resources/8.jpg'); //onEnterframe event used for loop3d this.addEventListener(Event.ENTER_FRAME, render); //Set the camera angle to 0 angle = 0; //And finally set the planes on their place calculatePlanes() } //This will handle the adding of planes private function addPlane(source:String):void { //Let's create the material to serve as texture, it scales automatically to fit the plane var mat:BitmapFileMaterial = new BitmapFileMaterial(source) mat.oneSide = false; var plane:Plane = new Plane(mat,320, 240, 5,5); //keep a reference and add it to the scene3d planes.push(plane); s.addChild(plane); } //Here we handle the position of the planes private function calculatePlanes():void { //Get the the step in Radians var step:Number = 2*Math.PI/planes.length //And in degrees var stepDeg:Number = 360/planes.length //Loop trough the planes and position them properly for(var i:int = 0; i < planes.length; i++){ var tmpPlane:Plane = planes[i] as Plane; //Set the x and z on the circle according to number and radius tmpPlane.x = Math.cos(i * step) * radius; tmpPlane.z = Math.sin(i * step ) * radius; //Now we rotate the planes inwards so they're facing the camera, when the camera passes by. tmpPlane.rotationY = 90-stepDeg*i//Math.cos(step * i) * stepDeg ; } } //Helper function private function convertToInterval(min:Number, max:Number, perc:Number):Number { var diff:Number = max - min; var factor:Number = diff/100; return (perc*factor)+min; } //Loop 3d event private function render(e:Event):void { //Calling calculate planes here is pointless in this example, however if you want to move the planes you should call the function. calculatePlanes() //This will give us the appropriate blur relating to the mouse position var blur:Number = convertToInterval(0,250,this.mouseX); //Create the blur filter and apply it to the sprite var myBlurry:BlurFilter = new BlurFilter(blur,0,4); sp.filters = [myBlurry] //Calculate the camera angle, note that this conversion ( -320 ª 0.001 ) is necessary to center the rotation // and use make the movement smooth, you can tinker with it. If you have any doubts, please ask!! angle += (this.mouseX - 320) * 0.001; //Position the camera on a larger radius than the planes cam.x = Math.cos(angle) * 1350; cam.z = Math.sin(angle) * 1350; //Apply the perspective relating to mouseY cam.y = mouseY - 320 * 0.001; //Set the target to the center object. cam.target = center; //And finally render the scene! s.renderCamera(cam); } } }