Papervision3D Spiral Carousel Example

Here is another Papervision3D example. This time I am extending a 3D carousel on the Y axis to create a spiral. There are 100 planes and the spiral rotates around 5 times. The Y of your mouse controls the Y of the spiral and the X position of the mouse controls the rotation. This could probably be useful for some type of list and it is at least somewhat different than the typical carousel.

Actionscript:

  1. import org.papervision3d.scenes.*;
  2. import org.papervision3d.cameras.*;
  3. import org.papervision3d.objects.*;
  4. import org.papervision3d.materials.*;
  5.  
  6. // Create the container sprite
  7. var con:Sprite = new Sprite();
  8. con.x = stage.stageWidth * 0.5;
  9. con.y = stage.stageHeight * 0.5;
  10. addChild(con);
  11.  
  12. // Setup the scene
  13. var scene:Scene3D = new Scene3D(con);
  14. var cam:Camera3D = new Camera3D();
  15. cam.zoom = 4;
  16.  
  17. // Create camera center
  18. var pc:Plane = new Plane();
  19. pc.visible = false;
  20. cam.target = pc;
  21.  
  22. // Spiral properties
  23. var num:int = 100;
  24. var numOfRotations:Number = 5;
  25. var anglePer:Number = ((Math.PI*2) * numOfRotations) / num;
  26. var yPos:Number = 0;
  27.  
  28. // Create the planes
  29. var pa:Array = new Array();
  30. for(var i:uint=0; i<num ; i++)
  31. {
  32.     var cm:BitmapAssetMaterial = new BitmapAssetMaterial("air");
  33.     cm.oneSide = false;
  34.     var p:Plane = new Plane(cm, 100, 100);
  35.     p.x = Math.cos(i * anglePer) * 550;
  36.     p.z = Math.sin(i * anglePer) * 550;
  37.     p.y = yPos += 50;
  38.     p.rotationY = (-i*anglePer) * (180/Math.PI) + 270;
  39.     scene.addChild(p);
  40. }
  41.  
  42. // Create the render loop
  43. addEventListener(Event.ENTER_FRAME, render);
  44.  
  45. var angle:Number = 0;
  46.  
  47. function render(e:Event):void
  48. {
  49.     var dist:Number = ((stage.mouseY) - stage.stageHeight * 0.5) * -0.1;
  50.     var dist2:Number = ((stage.mouseX) - stage.stageWidth * 0.5) * 0.0005;
  51.     angle += dist2;
  52.     cam.x = Math.cos(angle) * 1000;
  53.     cam.z = Math.sin(angle) * 1000;
  54.     cam.y += dist;
  55.     if(cam.y <369) cam.y = 369;
  56.     if(cam.y> 4755) cam.y = 4755;
  57.     pc.y = cam.y;
  58.     scene.renderCamera(cam);
  59. }


Share

0 条评论

留下评论