forked from ppfun/pixelplanet
make movement of 3d canvas conditional
This commit is contained in:
parent
994bd7b1cd
commit
0d9ac167c3
|
@ -122,9 +122,10 @@ class VoxelPainterControls {
|
||||||
storeViewInStateTime = Date.now();
|
storeViewInStateTime = Date.now();
|
||||||
prevTime = Date.now();
|
prevTime = Date.now();
|
||||||
offset = new Vector3();
|
offset = new Vector3();
|
||||||
direction = new Vector3();
|
|
||||||
velocity = new Vector3();
|
velocity = new Vector3();
|
||||||
vec = new Vector3();
|
vec = new Vector3();
|
||||||
|
// force full update next tick
|
||||||
|
forceNextUpdate = true;
|
||||||
|
|
||||||
constructor(renderer, camera, target, domElement, store) {
|
constructor(renderer, camera, target, domElement, store) {
|
||||||
this.renderer = renderer;
|
this.renderer = renderer;
|
||||||
|
@ -177,10 +178,12 @@ class VoxelPainterControls {
|
||||||
|
|
||||||
rotateLeft(angle) {
|
rotateLeft(angle) {
|
||||||
this.sphericalDelta.theta -= angle;
|
this.sphericalDelta.theta -= angle;
|
||||||
|
this.forceNextUpdate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
rotateUp(angle) {
|
rotateUp(angle) {
|
||||||
this.sphericalDelta.phi -= angle;
|
this.sphericalDelta.phi -= angle;
|
||||||
|
this.forceNextUpdate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// deltaX and deltaY are in pixels; right and down are positive
|
// deltaX and deltaY are in pixels; right and down are positive
|
||||||
|
@ -209,6 +212,7 @@ class VoxelPainterControls {
|
||||||
}
|
}
|
||||||
v.multiplyScalar(distance);
|
v.multiplyScalar(distance);
|
||||||
this.panOffset.add(v);
|
this.panOffset.add(v);
|
||||||
|
this.forceNextUpdate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -381,6 +385,7 @@ class VoxelPainterControls {
|
||||||
dollyDelta.set(0, (dollyEnd.y / dollyStart.y) ** zoomSpeed);
|
dollyDelta.set(0, (dollyEnd.y / dollyStart.y) ** zoomSpeed);
|
||||||
this.scale /= dollyDelta.y;
|
this.scale /= dollyDelta.y;
|
||||||
dollyStart.copy(dollyEnd);
|
dollyStart.copy(dollyEnd);
|
||||||
|
this.forceNextUpdate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
handleTouchMoveDollyPan(event) {
|
handleTouchMoveDollyPan(event) {
|
||||||
|
@ -601,44 +606,51 @@ class VoxelPainterControls {
|
||||||
const time = Date.now();
|
const time = Date.now();
|
||||||
const state = this.store.getState();
|
const state = this.store.getState();
|
||||||
const { moveU, moveV, moveW } = state.gui;
|
const { moveU, moveV, moveW } = state.gui;
|
||||||
|
const isMoving = (moveU || moveV || moveW);
|
||||||
|
|
||||||
if (!(force
|
if (!(force
|
||||||
|| this.state !== STATE.NONE
|
|| this.state !== STATE.NONE
|
||||||
|| this.forceNextUpdate
|
|| this.forceNextUpdate
|
||||||
|| moveU || moveV || moveW
|
|| isMoving
|
||||||
)) {
|
)) {
|
||||||
this.prevTime = time;
|
this.prevTime = time;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this.forceNextUpdate = false;
|
this.forceNextUpdate = false;
|
||||||
|
|
||||||
const delta = (time - this.prevTime) / 1000.0;
|
|
||||||
this.prevTime = time;
|
this.prevTime = time;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
camera,
|
camera,
|
||||||
target,
|
|
||||||
velocity,
|
|
||||||
direction,
|
|
||||||
offset,
|
|
||||||
vec,
|
|
||||||
spherical,
|
|
||||||
panOffset,
|
panOffset,
|
||||||
sphericalDelta,
|
|
||||||
} = this;
|
} = this;
|
||||||
|
|
||||||
velocity.set(-moveU, moveW, moveV)
|
if (isMoving) {
|
||||||
.normalize()
|
const {
|
||||||
.multiplyScalar(1000.0 * delta);
|
velocity,
|
||||||
|
vec,
|
||||||
|
} = this;
|
||||||
|
const delta = (time - this.prevTime) / 1000.0;
|
||||||
|
|
||||||
vec.setFromMatrixColumn(camera.matrix, 0);
|
velocity.set(-moveU, moveW, moveV)
|
||||||
vec.crossVectors(camera.up, vec);
|
.normalize()
|
||||||
vec.multiplyScalar(-velocity.z * delta);
|
.multiplyScalar(1000.0 * delta);
|
||||||
vec.y += -velocity.y * delta;
|
|
||||||
panOffset.add(vec);
|
vec.setFromMatrixColumn(camera.matrix, 0);
|
||||||
vec.setFromMatrixColumn(camera.matrix, 0);
|
vec.crossVectors(camera.up, vec);
|
||||||
vec.multiplyScalar(-velocity.x * delta);
|
vec.multiplyScalar(-velocity.z * delta);
|
||||||
panOffset.add(vec);
|
vec.y += -velocity.y * delta;
|
||||||
|
panOffset.add(vec);
|
||||||
|
vec.setFromMatrixColumn(camera.matrix, 0);
|
||||||
|
vec.multiplyScalar(-velocity.x * delta);
|
||||||
|
panOffset.add(vec);
|
||||||
|
}
|
||||||
|
|
||||||
|
const {
|
||||||
|
target,
|
||||||
|
offset,
|
||||||
|
spherical,
|
||||||
|
sphericalDelta,
|
||||||
|
} = this;
|
||||||
|
|
||||||
offset.copy(camera.position).sub(target);
|
offset.copy(camera.position).sub(target);
|
||||||
|
|
||||||
|
@ -677,23 +689,13 @@ class VoxelPainterControls {
|
||||||
panOffset.set(0, 0, 0);
|
panOffset.set(0, 0, 0);
|
||||||
}
|
}
|
||||||
target.add(panOffset);
|
target.add(panOffset);
|
||||||
/*
|
|
||||||
if (scope.target.y < 10.0) {
|
|
||||||
scope.target.y = 10.0;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// clamp to boundaries
|
// clamp to boundaries
|
||||||
const bound = state.canvas.canvasSize / 2;
|
const bound = state.canvas.canvasSize / 2;
|
||||||
target.clamp({
|
target.clamp(
|
||||||
x: -bound,
|
{ x: -bound, y: 0, z: -bound },
|
||||||
y: 0,
|
{ x: bound, y: THREE_CANVAS_HEIGHT, z: bound },
|
||||||
z: -bound,
|
);
|
||||||
}, {
|
|
||||||
x: bound,
|
|
||||||
y: THREE_CANVAS_HEIGHT,
|
|
||||||
z: bound,
|
|
||||||
});
|
|
||||||
|
|
||||||
offset.setFromSpherical(spherical);
|
offset.setFromSpherical(spherical);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user