babylon.coneParticleEmitter.ts 1.4 KB

1234567891011121314151617181920212223242526272829
  1. module BABYLON {
  2. export class ConeParticleEmitter implements IParticleEmitterType {
  3. constructor(private redius: number, private angle: number) {
  4. }
  5. startDirectionFunction(emitPower: number, worldMatrix: Matrix, directionToUpdate: Vector3, particle: Particle): void {
  6. if (this.angle === 0) {
  7. Vector3.TransformNormalFromFloatsToRef(0, emitPower, 0, worldMatrix, directionToUpdate);
  8. }
  9. else {
  10. var phi = ParticleSystem.randomNumber(0, 2 * Math.PI);
  11. var theta = ParticleSystem.randomNumber(0, this.angle);
  12. var randX = Math.cos(phi) * Math.sin(theta);
  13. var randY = Math.cos(theta);
  14. var randZ = Math.sin(phi) * Math.sin(theta);
  15. Vector3.TransformNormalFromFloatsToRef(randX * emitPower, randY * emitPower, randZ * emitPower, worldMatrix, directionToUpdate);
  16. }
  17. }
  18. startPositionFunction(worldMatrix: Matrix, positionToUpdate: Vector3, particle: Particle): void {
  19. var s = ParticleSystem.randomNumber(0, Math.PI * 2);
  20. var redius = ParticleSystem.randomNumber(0, this.redius);
  21. var randX = redius * Math.sin(s);
  22. var randZ = redius * Math.cos(s);
  23. Vector3.TransformCoordinatesFromFloatsToRef(randX, 0, randZ, worldMatrix, positionToUpdate);
  24. }
  25. }
  26. }