babylon.sphereParticleEmitter.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435
  1. module BABYLON {
  2. export class SphereParticleEmitter implements IParticleEmitterType {
  3. constructor(private radius: number) {
  4. }
  5. startDirectionFunction(emitPower: number, worldMatrix: Matrix, directionToUpdate: Vector3, particle: Particle): void {
  6. // measure the direction Vector from the emitter to the particle.
  7. var direction = particle.position.subtract(worldMatrix.getTranslation());
  8. Vector3.TransformNormalFromFloatsToRef(direction.x * emitPower, direction.y * emitPower, direction.z * emitPower, worldMatrix, directionToUpdate);
  9. }
  10. startPositionFunction(worldMatrix: Matrix, positionToUpdate: Vector3, particle: Particle): void {
  11. var phi = ParticleSystem.randomNumber(0, 2 * Math.PI);
  12. var theta = ParticleSystem.randomNumber(0, Math.PI);
  13. var randX = this.radius * Math.cos(phi) * Math.sin(theta);
  14. var randY = this.radius * Math.cos(theta);
  15. var randZ = this.radius * Math.sin(phi) * Math.sin(theta);
  16. Vector3.TransformCoordinatesFromFloatsToRef(randX, randY, randZ, worldMatrix, positionToUpdate);
  17. }
  18. }
  19. export class SphereDirectedParticleEmitter extends SphereParticleEmitter {
  20. constructor(radius: number, private direction1: Vector3, private direction2: Vector3) {
  21. super(radius);
  22. }
  23. startDirectionFunction(emitPower: number, worldMatrix: Matrix, directionToUpdate: Vector3, particle: Particle): void {
  24. var randX = ParticleSystem.randomNumber(this.direction1.x, this.direction2.x);
  25. var randY = ParticleSystem.randomNumber(this.direction1.y, this.direction2.y);
  26. var randZ = ParticleSystem.randomNumber(this.direction1.z, this.direction2.z);
  27. Vector3.TransformNormalFromFloatsToRef(randX * emitPower, randY * emitPower, randZ * emitPower, worldMatrix, directionToUpdate);
  28. }
  29. }
  30. }