mrdoob/three.js — Issue #703: submitting patch: noRotate property for TrackballCamera
Author: huttarl
Created: 2011-10-29 22:03:07+00:00
State: open

I've tried to go through the proper git procedures to submit this as a pull request, and I can't get git to work. So, with apologies, here it is as a patch. If you can suggest a better way for me to do this, I would appreciate it.

TrackballCamera has a noZoom param/property, and also noPan. It would be useful to have a corresponding noRotate property, so that we could temporarily disable the rotation of the trackball. (In my case, I need to do this when the user is clicking the mouse for some other purpose, e.g. to select an object.) So I've implemented it, and tested it. When the user doesn't access the noRotate property (existing code), behavior is unaffected. Here is the patch:

```*** TrackballCamera.js.orig	Sat Oct 29 16:41:23 2011
--- TrackballCamera.js	Sat Oct 29 16:34:55 2011
***************
*** 15,20 ****
--- 15,21 ----
*	zoomSpeed: ,
*	panSpeed: ,

+ * noRotate: ,
*	noZoom: ,
*	noPan: ,

***************
*** 47,52 ****
--- 48,54 ----
this.zoomSpeed = parameters.zoomSpeed || 1.2;
this.panSpeed = parameters.panSpeed || 0.3;

+	this.noRotate = parameters.noRotate || false;
this.noZoom = parameters.noZoom || false;
this.noPan = parameters.noPan || false;

***************
*** 234,243 ****

this.update = function( parentMatrixWorld, forceUpdate, camera ) {

!	_eye = this.position.clone().subSelf( this.target.position ),

this.rotateCamera();

if ( !this.noZoom ) {

this.zoomCamera();
--- 236,249 ----

this.update = function( parentMatrixWorld, forceUpdate, camera ) {

!	_eye = this.position.clone().subSelf( this.target.position );
!
!	if ( !this.noRotate ) {

this.rotateCamera();

+	}
+
if ( !this.noZoom ) {

this.zoomCamera();
***************
*** 267,273 ****

return;

!	} else if ( event.keyCode === this.keys[ this.STATE.ROTATE ] ) {

_state = this.STATE.ROTATE;

--- 273,279 ----

return;

!	} else if ( event.keyCode === this.keys[ this.STATE.ROTATE ] && !this.noRotate ) {

_state = this.STATE.ROTATE;

***************
*** 308,314 ****

_state = event.button;

!	if ( _state === this.STATE.ROTATE ) {

_rotateStart = _rotateEnd = this.getMouseProjectionOnBall( event.clientX, event.clientY );

--- 314,320 ----

_state = event.button;

!	if ( _state === this.STATE.ROTATE && !this.noRotate ) {

_rotateStart = _rotateEnd = this.getMouseProjectionOnBall( event.clientX, event.clientY );

***************
*** 342,348 ****

return;

!	} else if ( _state === this.STATE.ROTATE ) {

_rotateEnd = this.getMouseProjectionOnBall( event.clientX, event.clientY );

--- 348,354 ----

return;

!	} else if ( _state === this.STATE.ROTATE && !this.noRotate ) {

_rotateEnd = this.getMouseProjectionOnBall( event.clientX, event.clientY );

```