提交 ab7c7251 编写于 作者: M Mr.doob

TrackballControls: Caching event.

上级 2856874d
...@@ -55,6 +55,10 @@ THREE.TrackballControls = function ( object, domElement ) { ...@@ -55,6 +55,10 @@ THREE.TrackballControls = function ( object, domElement ) {
_panStart = new THREE.Vector2(), _panStart = new THREE.Vector2(),
_panEnd = new THREE.Vector2(); _panEnd = new THREE.Vector2();
// events
var changeEvent = { type: 'change' };
// methods // methods
...@@ -68,7 +72,7 @@ THREE.TrackballControls = function ( object, domElement ) { ...@@ -68,7 +72,7 @@ THREE.TrackballControls = function ( object, domElement ) {
}; };
this.getMouseOnScreen = function( clientX, clientY ) { this.getMouseOnScreen = function ( clientX, clientY ) {
return new THREE.Vector2( return new THREE.Vector2(
( clientX - _this.screen.offsetLeft ) / _this.radius * 0.5, ( clientX - _this.screen.offsetLeft ) / _this.radius * 0.5,
...@@ -77,7 +81,7 @@ THREE.TrackballControls = function ( object, domElement ) { ...@@ -77,7 +81,7 @@ THREE.TrackballControls = function ( object, domElement ) {
}; };
this.getMouseProjectionOnBall = function( clientX, clientY ) { this.getMouseProjectionOnBall = function ( clientX, clientY ) {
var mouseOnBall = new THREE.Vector3( var mouseOnBall = new THREE.Vector3(
( clientX - _this.screen.width * 0.5 - _this.screen.offsetLeft ) / _this.radius, ( clientX - _this.screen.width * 0.5 - _this.screen.offsetLeft ) / _this.radius,
...@@ -107,7 +111,7 @@ THREE.TrackballControls = function ( object, domElement ) { ...@@ -107,7 +111,7 @@ THREE.TrackballControls = function ( object, domElement ) {
}; };
this.rotateCamera = function() { this.rotateCamera = function () {
var angle = Math.acos( _rotateStart.dot( _rotateEnd ) / _rotateStart.length() / _rotateEnd.length() ); var angle = Math.acos( _rotateStart.dot( _rotateEnd ) / _rotateStart.length() / _rotateEnd.length() );
...@@ -140,7 +144,7 @@ THREE.TrackballControls = function ( object, domElement ) { ...@@ -140,7 +144,7 @@ THREE.TrackballControls = function ( object, domElement ) {
}; };
this.zoomCamera = function() { this.zoomCamera = function () {
var factor = 1.0 + ( _zoomEnd.y - _zoomStart.y ) * _this.zoomSpeed; var factor = 1.0 + ( _zoomEnd.y - _zoomStart.y ) * _this.zoomSpeed;
...@@ -162,7 +166,7 @@ THREE.TrackballControls = function ( object, domElement ) { ...@@ -162,7 +166,7 @@ THREE.TrackballControls = function ( object, domElement ) {
}; };
this.panCamera = function() { this.panCamera = function () {
var mouseChange = _panEnd.clone().subSelf( _panStart ); var mouseChange = _panEnd.clone().subSelf( _panStart );
...@@ -190,7 +194,7 @@ THREE.TrackballControls = function ( object, domElement ) { ...@@ -190,7 +194,7 @@ THREE.TrackballControls = function ( object, domElement ) {
}; };
this.checkDistances = function() { this.checkDistances = function () {
if ( !_this.noZoom || !_this.noPan ) { if ( !_this.noZoom || !_this.noPan ) {
...@@ -210,7 +214,7 @@ THREE.TrackballControls = function ( object, domElement ) { ...@@ -210,7 +214,7 @@ THREE.TrackballControls = function ( object, domElement ) {
}; };
this.update = function() { this.update = function () {
_eye.copy( _this.object.position ).subSelf( _this.target ); _eye.copy( _this.object.position ).subSelf( _this.target );
...@@ -240,7 +244,7 @@ THREE.TrackballControls = function ( object, domElement ) { ...@@ -240,7 +244,7 @@ THREE.TrackballControls = function ( object, domElement ) {
if ( lastPosition.distanceTo( _this.object.position ) > 0 ) { if ( lastPosition.distanceTo( _this.object.position ) > 0 ) {
_this.dispatchEvent( { type: 'change' } ); _this.dispatchEvent( changeEvent );
lastPosition.copy( _this.object.position ); lastPosition.copy( _this.object.position );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册