Papervision3D Proximity Grid Example

Papervision3D Proximity Grid Example

Here is a little experiment that I created on the plane home from Switzerland. I am creating a grid of planes and then I'm using proximity to determine which planes align. If the mouse is a certain distance away it goes back into space at random positions and angles. I'm using Tweener to do the animation. Enjoy it!

Actionscript:

  1. import org.papervision3d.scenes.*;
  2. import org.papervision3d.cameras.*;
  3. import org.papervision3d.objects.*;
  4. import org.papervision3d.materials.*;
  5. import caurina.transitions.*;
  6.  
  7. // Create the container sprite
  8. var con:Sprite = new Sprite();
  9. con.x = stage.stageWidth * 0.5 - 300;
  10. con.y = stage.stageHeight * 0.5 + 250;
  11. addChild(con);
  12.  
  13. // Setup the scene
  14. var scene:Scene3D = new Scene3D(con);
  15. var cam:Camera3D = new Camera3D();
  16. cam.zoom = 11;
  17. cam.x = 250;
  18. cam.y = 250;
  19.  
  20. // Create the planes
  21. var pa:Array = new Array();
  22. for(var i:uint=0; i<10; i++)
  23. {
  24.     for(var j:uint=0; j<10; j++)
  25.     {
  26.         var cm:ColorMaterial = new ColorMaterial(Math.random()*0xFFFFFF);
  27.         cm.oneSide = false;
  28.         var p:Plane = new Plane(cm, 50, 50);
  29.         p.x = j * 50 + 25;
  30.         p.y = i * 50 + 25;
  31.         scene.addChild(p);
  32.         pa.push({pl:p, rotY:Math.random() * 360, rotZ:Math.random() * 360, z:Math.random() * 30000});
  33.         p.rotationY = pa[i].rotY;
  34.         p.rotationZ = pa[i].rotZ;
  35.         p.z = pa[i].z;
  36.     }
  37. }
  38.  
  39. // Create the render loop
  40. addEventListener(Event.ENTER_FRAME, render);
  41.  
  42. function render(e:Event):void
  43. {
  44.     for(var i:uint; i<pa.length; i++)
  45.     {
  46.         if(checkDist(pa[i].pl))
  47.         {
  48.             Tweener.addTween(pa[i].pl, {rotationY:0, rotationZ:0, z:0, time:0.3});
  49.         }
  50.         else
  51.         {
  52.             Tweener.addTween(pa[i].pl, {rotationY:pa[i].rotY, rotationZ:pa[i].rotZ, z:pa[i].z, time:3});
  53.         }
  54.     }
  55.     scene.renderCamera(cam);
  56. }
  57.  
  58. function checkDist(p:Plane):Boolean
  59. {
  60.     var p1:Point = new Point(p.x, p.y);
  61.     var p2:Point = new Point(con.mouseX, -con.mouseY);
  62.     if(Point.distance(p1, p2) <150)
  63.     {
  64.         return true;
  65.     }
  66.     else return false;
  67. }


Comments

Share

0 条评论

留下评论