Bläddra i källkod

Brief:Switching to domElement coordinates
BUGZID:
Summary:
This switches the "screen" variable to use the domElement's dimensions & location rather
than the window.

It also removes the "radius" variable in favor of using each dimension's value (ie
width & height)

Kevin Schmidt 12 år sedan
förälder
incheckning
c497b86353
1 ändrade filer med 10 tillägg och 10 borttagningar
  1. 10 10
      examples/js/controls/TrackballControls.js

+ 10 - 10
examples/js/controls/TrackballControls.js

@@ -70,14 +70,14 @@ THREE.TrackballControls = function ( object, domElement ) {
 	// methods
 
 	this.handleResize = function () {
+		var rect = this.domElement.getBoundingClientRect();
+      
+		this.screen.width = rect.width;
+		this.screen.height = rect.height;
 
-		this.screen.width = window.innerWidth;
-		this.screen.height = window.innerHeight;
+		this.screen.offsetLeft = rect.left;
+		this.screen.offsetTop = rect.top;
 
-		this.screen.offsetLeft = 0;
-		this.screen.offsetTop = 0;
-
-		this.radius = ( this.screen.width + this.screen.height ) / 4;
 
 	};
 
@@ -94,8 +94,8 @@ THREE.TrackballControls = function ( object, domElement ) {
 	this.getMouseOnScreen = function ( clientX, clientY ) {
 
 		return new THREE.Vector2(
-			( clientX - _this.screen.offsetLeft ) / _this.radius * 0.5,
-			( clientY - _this.screen.offsetTop ) / _this.radius * 0.5
+			( clientX - _this.screen.offsetLeft ) / _this.screen.width,
+			( clientY - _this.screen.offsetTop ) / _this.screen.height
 		);
 
 	};
@@ -103,8 +103,8 @@ THREE.TrackballControls = function ( object, domElement ) {
 	this.getMouseProjectionOnBall = function ( clientX, clientY ) {
 
 		var mouseOnBall = new THREE.Vector3(
-			( clientX - _this.screen.width * 0.5 - _this.screen.offsetLeft ) / _this.radius,
-			( _this.screen.height * 0.5 + _this.screen.offsetTop - clientY ) / _this.radius,
+			( clientX - _this.screen.width * 0.5 - _this.screen.offsetLeft ) / (_this.screen.width*.5),
+			( _this.screen.height * 0.5 + _this.screen.offsetTop - clientY ) / (_this.screen.height*.5),
 			0.0
 		);