Skip to content

Commit 20abaad

Browse files
committed
bug fixes and _eye in TrackballCamera
1 parent 61ca697 commit 20abaad

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/extras/cameras/TrackballCamera.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ THREE.TrackballCamera = function ( parameters ) {
6666
var _keyPressed = false,
6767
_state = this.STATE.NONE,
6868

69+
_eye = new THREE.Vector3(),
70+
6971
_rotateStart = new THREE.Vector3(),
7072
_rotateEnd = new THREE.Vector3(),
7173

@@ -117,9 +119,11 @@ THREE.TrackballCamera = function ( parameters ) {
117119

118120
}
119121

122+
_eye = this.position.clone().subSelf( this.target.position );
123+
120124
var projection = this.up.clone().setLength( mouseOnBall.y );
121-
projection.addSelf( this.up.clone().crossSelf( this.position ).setLength( mouseOnBall.x ) );
122-
projection.addSelf( this.position.clone().setLength( mouseOnBall.z ) );
125+
projection.addSelf( this.up.clone().crossSelf( _eye ).setLength( mouseOnBall.x ) );
126+
projection.addSelf( _eye.setLength( mouseOnBall.z ) );
123127

124128
return projection;
125129

@@ -138,7 +142,7 @@ THREE.TrackballCamera = function ( parameters ) {
138142

139143
quaternion.setFromAxisAngle( axis, -angle );
140144

141-
quaternion.multiplyVector3( this.position );
145+
quaternion.multiplyVector3( _eye );
142146
quaternion.multiplyVector3( this.up );
143147

144148
quaternion.multiplyVector3( _rotateEnd );
@@ -164,8 +168,7 @@ THREE.TrackballCamera = function ( parameters ) {
164168

165169
if ( factor !== 1.0 && factor > 0.0 ) {
166170

167-
var eye = this.position.clone().subSelf( this.target.position );
168-
this.position.add( this.target.position, eye.multiplyScalar( factor ) );
171+
_eye.multiplyScalar( factor );
169172

170173
if ( this.staticMoving ) {
171174

@@ -187,11 +190,9 @@ THREE.TrackballCamera = function ( parameters ) {
187190

188191
if ( mouseChange.lengthSq() ) {
189192

190-
var factor = this.position.distanceTo( this.target.position ) * this.panSpeed;
191-
192-
mouseChange.multiplyScalar( factor );
193+
mouseChange.multiplyScalar( _eye.length() * this.panSpeed );
193194

194-
var pan = this.position.clone().crossSelf( this.up ).setLength( mouseChange.x );
195+
var pan = _eye.clone().crossSelf( this.up ).setLength( mouseChange.x );
195196
pan.addSelf( this.up.clone().setLength( mouseChange.y ) );
196197

197198
this.position.addSelf( pan );
@@ -221,11 +222,9 @@ THREE.TrackballCamera = function ( parameters ) {
221222

222223
}
223224

224-
var eye = this.position.clone().subSelf( this.target.position );
225+
if ( _eye.lengthSq() < this.minDistance * this.minDistance ) {
225226

226-
if ( eye.lengthSq() < this.minDistance * this.minDistance ) {
227-
228-
this.position.add( this.target.position, eye.setLength( this.minDistance ) );
227+
this.position.add( this.target.position, _eye.setLength( this.minDistance ) );
229228

230229
}
231230

@@ -235,6 +234,8 @@ THREE.TrackballCamera = function ( parameters ) {
235234

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

237+
_eye = this.position.clone().subSelf( this.target.position ),
238+
238239
this.rotateCamera();
239240

240241
if ( !this.noZoom ) {
@@ -249,6 +250,8 @@ THREE.TrackballCamera = function ( parameters ) {
249250

250251
}
251252

253+
this.position.add( this.target.position, _eye );
254+
252255
this.checkDistances();
253256

254257
this.supr.update.call( this, parentMatrixWorld, forceUpdate, camera );

0 commit comments

Comments
 (0)