Skip to content

Commit

Permalink
add mobile pinch support
Browse files Browse the repository at this point in the history
  • Loading branch information
yanwsh committed Mar 6, 2017
1 parent 8fb1cd8 commit c97f43d
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 22 deletions.
51 changes: 45 additions & 6 deletions dist/videojs-panorama.v4.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/videojs-panorama.v4.min.js

Large diffs are not rendered by default.

51 changes: 45 additions & 6 deletions dist/videojs-panorama.v5.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/videojs-panorama.v5.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
});

player.on("VRModeOn", function(){
player.controlBar.fullscreenToggle.trigger("tap");
if(!player.isFullscreen())
player.controlBar.fullscreenToggle.trigger("tap");
});
}(window, window.videojs));
</script>
Expand Down
3 changes: 2 additions & 1 deletion index_3d.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@
});

player.on("VRModeOn", function(){
player.controlBar.fullscreenToggle.trigger("tap");
if(!player.isFullscreen())
player.controlBar.fullscreenToggle.trigger("tap");
});
}(window, window.videojs));
</script>
Expand Down
3 changes: 2 additions & 1 deletion index_v4.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
});

player.on("VRModeOn", function(){
player.controlBar.fullscreenToggle.trigger("tap");
if(!player.isFullscreen())
player.controlBar.fullscreenToggle.trigger("tap");
});
}(window, window.videojs));
</script>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "videojs-panorama",
"version": "0.1.4",
"version": "0.1.5",
"description": "a plugin for videojs run a full 360 degree panorama video. ",
"keywords": [
"videojs",
Expand Down
27 changes: 24 additions & 3 deletions src/scripts/lib/BaseCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import Detector from '../lib/Detector';
import MobileBuffering from '../lib/MobileBuffering';
import Util from '../lib/Util';

const HAVE_CURRENT_DATA = 2;

Expand Down Expand Up @@ -71,11 +72,11 @@ var BaseCanvas = function (baseComponent, THREE, settings = {}) {

attachControlEvents: function(){
this.on('mousemove', this.handleMouseMove.bind(this));
this.on('touchmove', this.handleMouseMove.bind(this));
this.on('touchmove', this.handleTouchMove.bind(this));
this.on('mousedown', this.handleMouseDown.bind(this));
this.on('touchstart',this.handleMouseDown.bind(this));
this.on('touchstart',this.handleTouchStart.bind(this));
this.on('mouseup', this.handleMouseUp.bind(this));
this.on('touchend', this.handleMouseUp.bind(this));
this.on('touchend', this.handleTouchEnd.bind(this));
if(this.settings.scrollable){
this.on('mousewheel', this.handleMouseWheel.bind(this));
this.on('MozMousePixelScroll', this.handleMouseWheel.bind(this));
Expand Down Expand Up @@ -114,6 +115,19 @@ var BaseCanvas = function (baseComponent, THREE, settings = {}) {
this.onPointerDownLat = this.lat;
},

handleTouchStart: function(event){
if(event.touches.length > 1){
this.isUserPinch = true;
this.multiTouchDistance = Util.getTouchesDistance(event.touches);
}
this.handleMouseDown(event);
},

handleTouchEnd: function(event){
this.isUserPinch = false;
this.handleMouseUp(event);
},

handleMouseMove: function(event){
var clientX = event.clientX || event.touches && event.touches[0].clientX;
var clientY = event.clientY || event.touches && event.touches[0].clientY;
Expand All @@ -131,6 +145,13 @@ var BaseCanvas = function (baseComponent, THREE, settings = {}) {
}
},

handleTouchMove: function(event){
//handle single touch event,
if(!this.isUserPinch || event.touches.length <= 1){
this.handleMouseMove(event);
}
},

handleMobileOrientation: function (event) {
if(typeof event.rotationRate === "undefined") return;
var x = event.rotationRate.alpha;
Expand Down
10 changes: 10 additions & 0 deletions src/scripts/lib/Canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ var Canvas = function (baseComponent, THREE, settings = {}) {
}
},

handleTouchMove: function (event) {
parent.handleTouchMove.call(this, event);
if(this.isUserPinch){
let currentDistance = Util.getTouchesDistance(event.touches);
event.wheelDeltaY = (currentDistance - this.multiTouchDistance) * 2;
this.handleMouseWheel.call(this, event);
this.multiTouchDistance = currentDistance;
}
},

render: function(){
parent.render.call(this);
this.camera.target.x = 500 * Math.sin( this.phi ) * Math.cos( this.theta );
Expand Down
9 changes: 8 additions & 1 deletion src/scripts/lib/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,19 @@ function deepCopy(obj) {
return to;
}

function getTouchesDistance(touches){
return Math.sqrt(
(touches[0].clientX-touches[1].clientX) * (touches[0].clientX-touches[1].clientX) +
(touches[0].clientY-touches[1].clientY) * (touches[0].clientY-touches[1].clientY));
}

export default {
whichTransitionEvent: whichTransitionEvent,
mobileAndTabletcheck: mobileAndTabletcheck,
isIos: isIos,
isRealIphone: isRealIphone,
fovToProjection: fovToProjection,
extend: extend,
deepCopy: deepCopy
deepCopy: deepCopy,
getTouchesDistance: getTouchesDistance
};

0 comments on commit c97f43d

Please sign in to comment.