16
16
* noZoom: <bool>,
17
17
* noPan: <bool>,
18
18
19
+ * keys: <Array>, // [ rotateKey, zoomKey, panKey ]
20
+
19
21
* domElement: <HTMLElement>,
20
22
* }
21
23
*/
@@ -33,7 +35,10 @@ THREE.TrackballCamera = function ( parameters ) {
33
35
34
36
this . noZoom = false ;
35
37
this . noPan = false ;
36
-
38
+
39
+ this . keys = [ 65 , 83 , 68 ] ;
40
+ this . keyPressed = false ;
41
+
37
42
this . domElement = document ;
38
43
39
44
if ( parameters ) {
@@ -46,6 +51,8 @@ THREE.TrackballCamera = function ( parameters ) {
46
51
if ( parameters . noZoom !== undefined ) this . noZoom = parameters . noZoom ;
47
52
if ( parameters . noPan !== undefined ) this . noPan = parameters . noPan ;
48
53
54
+ if ( parameters . keys !== undefined ) this . keys = parameters . keys ;
55
+
49
56
if ( parameters . domElement !== undefined ) this . domElement = parameters . domElement ;
50
57
51
58
}
@@ -103,14 +110,37 @@ THREE.TrackballCamera.prototype.handleEvent = function ( event ) {
103
110
} ;
104
111
105
112
THREE . TrackballCamera . prototype . keydown = function ( event ) {
113
+
114
+ if ( this . state !== this . STATE . NONE ) {
115
+
116
+ return ;
117
+
118
+ } else if ( event . keyCode === this . keys [ this . STATE . ROTATE ] ) {
119
+
120
+ this . state = this . STATE . ROTATE ;
121
+ this . keyPressed = true ;
122
+
123
+ } else if ( event . keyCode === this . keys [ this . STATE . ZOOM ] ) {
106
124
125
+ this . state = this . STATE . ZOOM ;
126
+ this . keyPressed = true ;
107
127
128
+ } else if ( event . keyCode === this . keys [ this . STATE . PAN ] ) {
129
+
130
+ this . state = this . STATE . PAN ;
131
+ this . keyPressed = true ;
132
+
133
+ }
108
134
109
135
} ;
110
136
111
137
THREE . TrackballCamera . prototype . keyup = function ( event ) {
112
138
139
+ if ( this . state !== this . STATE . NONE ) {
113
140
141
+ this . state = this . STATE . NONE ;
142
+
143
+ }
114
144
115
145
} ;
116
146
@@ -138,6 +168,15 @@ THREE.TrackballCamera.prototype.mousedown = function(event) {
138
168
} ;
139
169
140
170
THREE . TrackballCamera . prototype . mousemove = function ( event ) {
171
+
172
+ if ( this . keyPressed ) {
173
+
174
+ this . start = this . getMouseProjectionOnBall ( event . clientX , event . clientY ) ;
175
+ this . mouse = this . getMouseOnScreen ( event . clientX , event . clientY ) ;
176
+
177
+ this . keyPressed = false ;
178
+
179
+ }
141
180
142
181
if ( this . state === this . STATE . NONE ) {
143
182
@@ -171,7 +210,7 @@ THREE.TrackballCamera.prototype.mouseup = function( event ) {
171
210
THREE . TrackballCamera . prototype . getScreenDimensions = function ( ) {
172
211
173
212
if ( this . domElement != document ) {
174
-
213
+
175
214
return {
176
215
width : this . domElement . offsetWidth ,
177
216
height : this . domElement . offsetHeight ,
@@ -275,8 +314,8 @@ THREE.TrackballCamera.prototype.panCamera = function( clientX, clientY ) {
275
314
var pan = this . position . clone ( ) . crossSelf ( this . up ) . setLength ( mouseChange . x ) ;
276
315
pan . addSelf ( this . up . clone ( ) . setLength ( mouseChange . y ) ) ;
277
316
278
- this . position . addSelf ( pan ) ;
279
- this . target . position . addSelf ( pan ) ;
317
+ this . position . addSelf ( pan ) ;
318
+ this . target . position . addSelf ( pan ) ;
280
319
281
320
this . mouse = newMouse ;
282
321
0 commit comments