-
Notifications
You must be signed in to change notification settings - Fork 0
Add local pointer field #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -60,8 +60,6 @@ export class BlobPhysics { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private mouseY = 50; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private mouseVelX = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private mouseVelY = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private lastMouseX = 50; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private lastMouseY = 50; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private gravity: GravityVector = { x: 0, y: 0 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -214,8 +212,6 @@ export class BlobPhysics { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const previousMouseY = this.mouseY; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.mouseVelX = x - previousMouseX; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.mouseVelY = y - previousMouseY; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.lastMouseX = previousMouseX; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.lastMouseY = previousMouseY; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.mouseX = x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.mouseY = y; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -457,6 +453,9 @@ export class BlobPhysics { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.applyAccelerometerForces(blob); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.applyPointerField(blob); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.updateMovementWithAccelerometer(blob, time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -494,6 +493,20 @@ export class BlobPhysics { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private applyPointerField(blob: ConvexBlob): void { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (this.mouseX === 50 && this.mouseY === 50) return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const dx = this.mouseX - blob.currentX; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const dy = this.mouseY - blob.currentY; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const distance = Math.sqrt(dx * dx + dy * dy); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (distance === 0 || distance >= 34) return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const normalized = 1 - distance / 34; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const scale = (normalized * normalized * 0.0014) / distance; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| blob.velocityX += dx * scale; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| blob.velocityY += dy * scale; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+496
to
+508
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The hardcoded
Suggested change
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private updateMovementWithAccelerometer(blob: ConvexBlob, time: number): void { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const neutralDriftX = (Math.random() - 0.5) * 0.001; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mouseX === 50 && mouseY === 50is the sentinel for "no pointer input yet / pointer reset to neutral." If the coordinate space is [0, 100] (whichmouseX = 50at init and themouseDistanceformula suggest), a user whose cursor legitimately lands at the exact center will get no pointer attraction. The sentinel conflates "uninitialized" with a valid position. A separate boolean flag (e.g.private pointerActive = false) would eliminate the ambiguity without a performance cost.