forked from ppfun/pixelplanet
set courser on touch devices to center of camera
This commit is contained in:
parent
1fdeecfdde
commit
2c2306f1a5
|
@ -643,7 +643,6 @@ class VoxelPainterControls extends EventDispatcher {
|
|||
if (scope.enabled === false) return;
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
switch (state) {
|
||||
case STATE.TOUCH_ROTATE:
|
||||
|
|
|
@ -163,10 +163,12 @@ class Renderer {
|
|||
|
||||
|
||||
this.onDocumentMouseMove = this.onDocumentMouseMove.bind(this);
|
||||
this.onDocumentTouchMove = this.onDocumentTouchMove.bind(this);
|
||||
this.onDocumentMouseDown = this.onDocumentMouseDown.bind(this);
|
||||
this.onDocumentMouseUp = this.onDocumentMouseUp.bind(this);
|
||||
this.onWindowResize = this.onWindowResize.bind(this);
|
||||
domElement.addEventListener('mousemove', this.onDocumentMouseMove, false);
|
||||
domElement.addEventListener('touchmove', this.onDocumentTouchMove, false);
|
||||
domElement.addEventListener('mousedown', this.onDocumentMouseDown, false);
|
||||
domElement.addEventListener('mouseup', this.onDocumentMouseUp, false);
|
||||
window.addEventListener('resize', this.onWindowResize, false);
|
||||
|
@ -380,6 +382,42 @@ class Renderer {
|
|||
this.mouseMoveStart = state.gui.hover;
|
||||
}
|
||||
|
||||
onDocumentTouchMove(event) {
|
||||
event.stopPropagation();
|
||||
|
||||
const {
|
||||
camera,
|
||||
objects,
|
||||
raycaster,
|
||||
mouse,
|
||||
rollOverMesh,
|
||||
store,
|
||||
} = this;
|
||||
const {
|
||||
placeAllowed,
|
||||
} = store.getState().user;
|
||||
|
||||
mouse.set(0, 0);
|
||||
raycaster.setFromCamera(mouse, camera);
|
||||
const intersects = raycaster.intersectObjects(objects);
|
||||
if (intersects.length > 0) {
|
||||
const intersect = intersects[0];
|
||||
const target = intersect.point.clone()
|
||||
.add(intersect.face.normal.multiplyScalar(0.5))
|
||||
.floor()
|
||||
.addScalar(0.5);
|
||||
if (!placeAllowed
|
||||
|| target.clone().sub(camera.position).length() > 120) {
|
||||
rollOverMesh.position.y = -10;
|
||||
} else {
|
||||
rollOverMesh.position.copy(target);
|
||||
}
|
||||
}
|
||||
const hover = rollOverMesh.position
|
||||
.toArray().map((u) => Math.floor(u));
|
||||
this.store.dispatch(setHover(hover));
|
||||
}
|
||||
|
||||
onDocumentTouchEnd() {
|
||||
// gets fired before onDocumentMouseUp
|
||||
// --
|
||||
|
|
Loading…
Reference in New Issue
Block a user