Datasheet

Chapter 1: Understanding Flash3D
25
plane.rotationY = -360 / numOfParticles * i + 90;
plane.alpha=1;
particles_ary.push(plane);
numVar++;
//Start Looping
if(numVar==numOfParticles)
{
addEventListener(Event.ENTER_FRAME, myonEnterFrame);
addChild(myDisplayObject);
myDisplayObject.rotationX=0;
myDisplayObject.x=CenterX;
myDisplayObject.y=CenterY;
}
}
//Sorting
function sortParticles():void
{
particles_ary.sort(particleZSort);
for(var i:int = 0; i < particles_ary.length; i++)
{
myDisplayObject.addChildAt(particles_ary[i] as Sprite, i);
}
}
function particleZSort(particle1:DisplayObject, particle2:DisplayObject):int
{
var zpos1:Vector3D = particle1.transform.matrix3D.position;
zpos1 = myDisplayObject.transform.matrix3D.deltaTransformVector(zpos1);
var zpos2:Vector3D = particle2.transform.matrix3D.position;
zpos2 = myDisplayObject.transform.matrix3D.deltaTransformVector(zpos2);
return zpos2.z - zpos1.z;
}
//Looping function
function myonEnterFrame(event:Event):void
{
myDisplayObject.rotationY += (CenterX - mouseX) * .01;
sortParticles();
}
Image Ball
An image ball is just a bunch of images equally distributed around a sphere. The trick to distributing the
images correctly is to use the parametric equation for a sphere, which can be found from
WolframMathWorld. Iterating through the different rows and columns of the parametric equations
distributes the planes to their correct positions. But they won t be oriented correctly.
plane.x = radius*Math.sin(i*pStep)*Math.sin(j*tStep);
plane.z = -radius*Math.sin(i*pStep)*Math.cos(j*tStep);
plane.y =-radius*Math.cos(i*pStep);
c01.indd 25c01.indd 25 12/14/09 3:03:32 PM12/14/09 3:03:32 PM