MCPcopy Create free account
hub / github.com/esengine/esengine / _getShapeOffset

Method _getShapeOffset

packages/particle/src/ParticleEmitter.ts:313–379  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

311 }
312
313 private _getShapeOffset(): [number, number] {
314 const config = this.config;
315
316 switch (config.shape) {
317 case EmissionShape.Point:
318 return [0, 0];
319
320 case EmissionShape.Circle: {
321 // 填充圆形 | Filled circle
322 const angle = Math.random() * Math.PI * 2;
323 const radius = Math.random() * config.shapeRadius;
324 return [Math.cos(angle) * radius, Math.sin(angle) * radius];
325 }
326
327 case EmissionShape.Ring: {
328 // 圆环边缘 | Ring edge only
329 const angle = Math.random() * Math.PI * 2;
330 return [Math.cos(angle) * config.shapeRadius, Math.sin(angle) * config.shapeRadius];
331 }
332
333 case EmissionShape.Rectangle: {
334 // 填充矩形 | Filled rectangle
335 const x = randomRange(-config.shapeWidth / 2, config.shapeWidth / 2);
336 const y = randomRange(-config.shapeHeight / 2, config.shapeHeight / 2);
337 return [x, y];
338 }
339
340 case EmissionShape.Edge: {
341 // 矩形边缘 | Rectangle edge only
342 const perimeter = 2 * (config.shapeWidth + config.shapeHeight);
343 const t = Math.random() * perimeter;
344
345 const w = config.shapeWidth;
346 const h = config.shapeHeight;
347
348 if (t < w) {
349 // 上边 | Top edge
350 return [t - w / 2, h / 2];
351 } else if (t < w + h) {
352 // 右边 | Right edge
353 return [w / 2, h / 2 - (t - w)];
354 } else if (t < 2 * w + h) {
355 // 下边 | Bottom edge
356 return [w / 2 - (t - w - h), -h / 2];
357 } else {
358 // 左边 | Left edge
359 return [-w / 2, -h / 2 + (t - 2 * w - h)];
360 }
361 }
362
363 case EmissionShape.Line: {
364 const t = Math.random() - 0.5;
365 const cos = Math.cos(config.direction + Math.PI / 2);
366 const sin = Math.sin(config.direction + Math.PI / 2);
367 return [cos * config.shapeWidth * t, sin * config.shapeWidth * t];
368 }
369
370 case EmissionShape.Cone: {

Callers 1

_initParticleMethod · 0.95

Calls 2

randomMethod · 0.80
randomRangeFunction · 0.70

Tested by

no test coverage detected