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:
- import org.papervision3d.scenes.*;
- import org.papervision3d.cameras.*;
- import org.papervision3d.objects.*;
- import org.papervision3d.materials.*;
- import caurina.transitions.*;
-
- // Create the container sprite
- var con:Sprite = new Sprite();
- con.x = stage.stageWidth * 0.5 - 300;
- con.y = stage.stageHeight * 0.5 + 250;
- addChild(con);
-
- // Setup the scene
- var scene:Scene3D = new Scene3D(con);
- var cam:Camera3D = new Camera3D();
- cam.zoom = 11;
- cam.x = 250;
- cam.y = 250;
-
- // Create the planes
- var pa:Array = new Array();
- for(var i:uint=0; i<10; i++)
- {
- for(var j:uint=0; j<10; j++)
- {
- var cm:ColorMaterial = new ColorMaterial(Math.random()*0xFFFFFF);
- cm.oneSide = false;
- var p:Plane = new Plane(cm, 50, 50);
- p.x = j * 50 + 25;
- p.y = i * 50 + 25;
- scene.addChild(p);
- pa.push({pl:p, rotY:Math.random() * 360, rotZ:Math.random() * 360, z:Math.random() * 30000});
- p.rotationY = pa[i].rotY;
- p.rotationZ = pa[i].rotZ;
- p.z = pa[i].z;
- }
- }
-
- // Create the render loop
- addEventListener(Event.ENTER_FRAME, render);
-
- function render(e:Event):void
- {
- for(var i:uint; i<pa.length; i++)
- {
- if(checkDist(pa[i].pl))
- {
- Tweener.addTween(pa[i].pl, {rotationY:0, rotationZ:0, z:0, time:0.3});
- }
- else
- {
- Tweener.addTween(pa[i].pl, {rotationY:pa[i].rotY, rotationZ:pa[i].rotZ, z:pa[i].z, time:3});
- }
- }
- scene.renderCamera(cam);
- }
-
- function checkDist(p:Plane):Boolean
- {
- var p1:Point = new Point(p.x, p.y);
- var p2:Point = new Point(con.mouseX, -con.mouseY);
- if(Point.distance(p1, p2) <150)
- {
- return true;
- }
- else return false;
- }
