I'm creating a 3d particle engine and am trying to implement a cone spread. My emitter has a direction associated with it using a custom spherical coordinate class I wrote:
Code:class PVectorSphere {
public float radius;
public float inclination;
public float azimuth;
PVectorSphere(float r, float i, float a) {
radius = r;
inclination = i;
azimuth = a;
}
public PVector toCartesian() {
return new PVector(radius*sin(inclination - PI/2)*cos(azimuth), radius*cos(inclination - PI/2), radius*sin(inclination - PI/2)*sin(azimuth)); // A radius, inclination, and azimuth of (1, PI/2, 0) will return the positive y-axis.
}
}
When the emitter emits its particles, it modifies its own direction as so:
Code:directionRandomized = direction.get();
directionRandomized.inclination += radians(random(-spread, spread));
directionRandomized.azimuth += radians(random(-spread, spread));
directionRandomized.normalize();
This works all well and fine except for the consequence of using spherical coordinates, which is that the point density increases towards the poles. This means that if the inclination is 90 degrees, the azimuth doesn't affect anything, and I don't get a cone. Does anyone have any insight on this? Thanks!