-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathThreeHeadControls.js
executable file
·49 lines (43 loc) · 1.49 KB
/
ThreeHeadControls.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
if (typeof(JEEFACEFILTERAPI)==='undefined'){
throw new Error('Cannot found JEEFACEFILTERAPI. Was jeelizFaceFilter.js included before this script ?');
}
if (typeof(HeadControls)==='undefined'){
throw new Error('Cannot found HeadControls. helpers/HeadControls.js included before this script ?');
}
if (typeof(THREE)==='undefined'){
throw new Error('Cannot found THREE.JS');
}
THREE.HeadControls = function ( threeCamera, canvasId, NNCpath ) {
this.enableZoom=true;
this.sensibilityZ=1;
this.sensibilityRotateX=0.001;
this.sensibilityRotateY=0.001;
threeCamera.rotation.order='YXZ';
var that=this;
function callbackMove(mv){
if (that.enableZoom && mv.dZ!==0) { //move head forward/backward
threeCamera.translateZ(-mv.dZ*that.sensibilityZ);
}
var rotationNeedsUpdate=false;
if (mv.dRx!==0) { //turn head up-down
threeCamera.rotation.x+=-mv.dRx*that.sensibilityRotateX;
}
if (mv.dRy!==0) { //turn head left-right
threeCamera.rotation.y+=mv.dRy*that.sensibilityRotateY;
}
}
HeadControls.init({
canvasId: canvasId,
callbackMove: callbackMove, //will be explained later...
callbackReady: function(errCode){
if (errCode){
console.log('ERROR : THREE.HeadControls NOT READY. errCode =', errCode);
} else {
console.log('INFO : THREE.HeadControls ARE READY :)');
HeadControls.toggle(true);
}
},
NNCpath: NNCpath,
animateDelay: 2 //avoid DOM lags
}); //end HeadControls.init params
}