智慧 + 毅力 = 无所不能

正确性、健壮性、可靠性、效率、易用性、可读性、可复用性、兼容性、可移植性...

导航

Papervision3D Proximity Grid Example

Posted on 2010-06-10 14:05  Bill Yuan  阅读(778)  评论(0编辑  收藏  举报

转自:http://www.duzengqiang.com/blog/post/548.html

效果:

代码
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.5300;
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
{
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;
}