Mouse Wheel controlling Target Repulsion Force
This commit is contained in:
1 parent
b72d20fe0f
commit
0468cd05f0
3 files changed
+38
-5
No files matched your search
Binary file not shown.
@@ -365,8 +365,18 @@ function newCanvas() {
|
||||
var event = window.event || event; // old IE support
|
||||
let delta = Math.max(-1, Math.min(1, event.wheelDelta || -event.detail));
|
||||
|
||||
viewPort.applyZoom(delta);
|
||||
let floatingObjectIndex = canvas.floatingSpace.floatingLayer.isInside(event.pageX, event.pageY);
|
||||
|
||||
if (floatingObjectIndex > 0) {
|
||||
|
||||
canvas.floatingSpace.floatingLayer.changeTargetRepulsion(event.wheelDelta);
|
||||
|
||||
} else {
|
||||
|
||||
viewPort.applyZoom(delta);
|
||||
|
||||
}
|
||||
|
||||
return false; // This instructs the browser not to take the event and scroll the page.
|
||||
}
|
||||
|
||||
|
||||
@@ -15,10 +15,13 @@ function newFloatingLayer() {
|
||||
physicsLoop: physicsLoop,
|
||||
isInside: isInside,
|
||||
isInsideFloatingObject: isInsideFloatingObject,
|
||||
changeTargetRepulsion: changeTargetRepulsion,
|
||||
initialize: initialize
|
||||
};
|
||||
|
||||
innactiveFloatingObjects = [];
|
||||
let innactiveFloatingObjects = [];
|
||||
|
||||
let maxTargetRepulsionForce = 0.0005;
|
||||
|
||||
return thisObject;
|
||||
|
||||
@@ -502,10 +505,10 @@ function newFloatingLayer() {
|
||||
|
||||
/* We need to put a hard limit to this force, in order to to eject very little floatingObjects to the infinite and beyond. */
|
||||
|
||||
if (force > 0.0005) {
|
||||
force = 0.0005;
|
||||
if (force > maxTargetRepulsionForce) {
|
||||
force = maxTargetRepulsionForce;
|
||||
}
|
||||
|
||||
|
||||
var pos1 = {
|
||||
x: floatingObject1.currentPosition.x,
|
||||
y: floatingObject1.currentPosition.y
|
||||
@@ -540,6 +543,26 @@ function newFloatingLayer() {
|
||||
|
||||
}
|
||||
|
||||
function changeTargetRepulsion(pDelta) {
|
||||
|
||||
if (pDelta > 0) {
|
||||
|
||||
pDelta = 1;
|
||||
|
||||
} else {
|
||||
|
||||
pDelta = -1;
|
||||
|
||||
}
|
||||
|
||||
maxTargetRepulsionForce = maxTargetRepulsionForce + pDelta / 10000;
|
||||
|
||||
if (maxTargetRepulsionForce < 0.0001) {
|
||||
|
||||
maxTargetRepulsionForce = 0.0001
|
||||
}
|
||||
}
|
||||
|
||||
function colliding(floatingObject1, floatingObject2) {
|
||||
/* This function detects weather 2 floatingObjects collide with each other. */
|
||||
|
||||
|
||||
Reference in new issue
Block a user