Browse Source

CanvasRenderer: Simplified setViewport implementation.

Mr.doob 11 years ago
parent
commit
1ef5c71a75
1 changed files with 3 additions and 15 deletions
  1. 3 15
      src/renderers/CanvasRenderer.js

+ 3 - 15
src/renderers/CanvasRenderer.js

@@ -20,13 +20,8 @@ THREE.CanvasRenderer = function ( parameters ) {
 
 	_canvasWidth = _canvas.width,
 	_canvasHeight = _canvas.height,
-	_canvasWidthHalf = Math.floor( _viewportWidth / 2 ),
-	_canvasHeightHalf = Math.floor( _viewportHeight / 2 ),
-
-	_viewportX = 0,
-	_viewportY = 0,
-	_viewportWidth = _canvasWidth,
-	_viewportHeight = _canvasHeight,
+	_canvasWidthHalf = Math.floor( _canvasWidth / 2 ),
+	_canvasHeightHalf = Math.floor( _canvasHeight / 2 ),
 	
 	_context = _canvas.getContext( '2d', {
 		alpha: parameters.alpha === true
@@ -192,14 +187,7 @@ THREE.CanvasRenderer = function ( parameters ) {
 
 	this.setViewport = function ( x, y, width, height ) {
 
-		_viewportX = x;
-		_viewportY = y;
-		_viewportWidth = width;
-		_viewportHeight = height;
-
-		_context.setTransform( 1, 0, 0, 1, 0, 0 );
-		_context.translate( _viewportX, _canvasHeight - _viewportY );
-		_context.scale( _viewportWidth / _canvasWidth, - _viewportHeight / _canvasHeight );
+		_context.setTransform( width / _canvasWidth, 0, 0, - height / _canvasHeight, x, _canvasHeight - y );
 		_context.translate( _canvasWidthHalf, _canvasHeightHalf );
 
 	};