Placing Particles
27/07/09
Papervision is great but I sometimes feel that I would be a lot better off with a greater understanding of 3D Math. Therefore this post based upon an experiment I did a little while ago, with the aim of generating a sphere of particles and improving my 3D Math.
The following picture is close to what I intended to achieve, however due to the very high number of particles with the sphere Papervision struggles render it. In this case switching to Flint, and using their 3D particle system would probably be a better idea.

Time to get gritty! The block of code below creates a sphere of Particles. The for loops below increase in specified steps for latitude and longitude, unlike your normal for loop which counts from 0 to whatever in single increments this stepped process enables us to distribute the Particles at an even distance. The sine wave calculation Math.sin(lat*Math.PI/180) is important for placing the particles in a spherical shape. A positive sine wave multiplied by PI divided by 180 creates us a semi-circle, combined with a negative sine wave we get a full circle. With in the two for loops I’ve also added a random if statement so that Papervision doesn’t struggle to render a high number of Particles, but still keeps the shape of a high density particle sphere. It’s also worth noting that I’ve created a class which extends the Particle class in Paperivision called Dot, to which I’m passing the calculated x y z values, these are then stored so that the Particles can be tweened from a random x y z to form a sphere. I’ve done this only for visual reasons!
for (var lat:Number = -90; lat<90; lat+=(360/dens))
{
var radius:Number = Math.cos(lat * Math.PI / 180) * size;
var circumference:Number = (2*Math.PI*radius);
var numberOfDots:Number = Math.floor(dens*circumference)/size;
for (var long:Number = 0; long<360; long+=(360/numberOfDots))
{
if (Math.floor(Math.random()*8) == 1)
{
part = new Dot(Math.cos(long*Math.PI/180)*radius,
Math.sin(lat*Math.PI/180)*size,
Math.sin(long*Math.PI/180)*radius );
this.particleArray.push(part);
this.particleHolder.addParticle(part);
}
}
}
Click below in order to activate the Flash movie.
The following is a no flash image
In end the outcome above is close to what I intended to achieve, however the density of the dots around the latitude axis is exactly the same at the poles as the equator. I've tried to resolve the density problem but without success, mainly due to Papervision struggling to render such a high density of Particles. I'm realistically on the edge of Math skills and perhaps purchasing a 3D Math primer would be a good idea. Anyway this was an interesting experiment which I got very close to getting it right.
Tags: 3D, as3, flash, papervision, particles particles
No comments