refactor: extend PhysicsBody with cached dims and add dirtyElements
This commit is contained in:
@@ -4,6 +4,10 @@ interface PhysicsBody {
|
|||||||
y: number;
|
y: number;
|
||||||
vx: number;
|
vx: number;
|
||||||
vy: number;
|
vy: number;
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
|
originX: number;
|
||||||
|
originY: number;
|
||||||
isDragging: boolean;
|
isDragging: boolean;
|
||||||
startX: number;
|
startX: number;
|
||||||
startY: number;
|
startY: number;
|
||||||
@@ -11,6 +15,7 @@ interface PhysicsBody {
|
|||||||
|
|
||||||
export class GravityEngine {
|
export class GravityEngine {
|
||||||
private bodies: PhysicsBody[] = [];
|
private bodies: PhysicsBody[] = [];
|
||||||
|
private dirtyElements: HTMLElement[] = [];
|
||||||
private animationFrameId: number | null = null;
|
private animationFrameId: number | null = null;
|
||||||
private isRunning = false;
|
private isRunning = false;
|
||||||
|
|
||||||
@@ -83,6 +88,10 @@ export class GravityEngine {
|
|||||||
y: rect.top,
|
y: rect.top,
|
||||||
vx: (Math.random() - 0.5) * 8, // slight explosion outward
|
vx: (Math.random() - 0.5) * 8, // slight explosion outward
|
||||||
vy: (Math.random() - 0.5) * 5, // slight pop upward
|
vy: (Math.random() - 0.5) * 5, // slight pop upward
|
||||||
|
width: rect.width,
|
||||||
|
height: rect.height,
|
||||||
|
originX: rect.left,
|
||||||
|
originY: rect.top,
|
||||||
isDragging: false,
|
isDragging: false,
|
||||||
startX: 0,
|
startX: 0,
|
||||||
startY: 0,
|
startY: 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user