Skip to content

Commit a886da3

Browse files
committed
fix: improved roll angle calculation and logic
1 parent f4a985f commit a886da3

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

engine/src/Core/Particle.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ import {
1818
defaultRetryCount,
1919
defaultTransform,
2020
double,
21+
doublePI,
2122
half,
2223
identity,
2324
millisecondsToSeconds,
2425
minZ,
25-
none,
2626
randomColorValue,
27-
rollFactor,
2827
squareExp,
28+
triple,
2929
tryCountIncrement,
3030
zIndexFactorOffset,
3131
} from "./Utils/Constants.js";
@@ -727,10 +727,30 @@ export class Particle {
727727
return false;
728728
}
729729

730-
const backFactor = this.roll.horizontal && this.roll.vertical ? double * rollFactor : rollFactor,
731-
backSum = this.roll.horizontal ? Math.PI * half : none;
730+
const angle = this.roll.angle;
732731

733-
return !!(Math.floor((this.roll.angle + backSum) / (Math.PI / backFactor)) % double);
732+
if (this.roll.horizontal && this.roll.vertical) {
733+
const normalizedAngle = angle % doublePI,
734+
adjustedAngle = normalizedAngle < defaultAngle ? normalizedAngle + doublePI : normalizedAngle;
735+
736+
return adjustedAngle >= Math.PI * half && adjustedAngle < Math.PI * triple * half;
737+
}
738+
739+
if (this.roll.horizontal) {
740+
const normalizedAngle = (angle + Math.PI * half) % (Math.PI * double),
741+
adjustedAngle = normalizedAngle < defaultAngle ? normalizedAngle + Math.PI * double : normalizedAngle;
742+
743+
return adjustedAngle >= Math.PI && adjustedAngle < Math.PI * double;
744+
}
745+
746+
if (this.roll.vertical) {
747+
const normalizedAngle = angle % (Math.PI * double),
748+
adjustedAngle = normalizedAngle < defaultAngle ? normalizedAngle + Math.PI * double : normalizedAngle;
749+
750+
return adjustedAngle >= Math.PI && adjustedAngle < Math.PI * double;
751+
}
752+
753+
return false;
734754
}
735755

736756
isVisible(): boolean {

engine/src/Core/Utils/Constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ export const generatedAttribute = "generated",
6868
decayOffset = 1,
6969
tryCountIncrement = 1,
7070
minRetries = 0,
71-
rollFactor = 1,
7271
minZ = 0,
7372
defaultRadius = 0,
7473
posOffset = -quarter,

0 commit comments

Comments
 (0)