Skip to content

Commit

Permalink
* Workaround for Opera bug (clearRect not working with context with n…
Browse files Browse the repository at this point in the history
…egative scale)

* Additional `Matrix4` and `Vector3` methods
  • Loading branch information
mrdoob committed Aug 21, 2010
1 parent 010f582 commit 216b4ee
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 22 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ Thanks to the power of the internets (and github <3) these people have kindly he

### Change Log ###

2010 08 21 - **r16** (35.592 kb)

* Workaround for Opera bug (clearRect not working with context with negative scale)
* Additional `Matrix4` and `Vector3` methods


2010 07 23 - **r15** (32.440 kb)

* Using new object `UV` instead of `Vector2` where it should be used
Expand Down
4 changes: 2 additions & 2 deletions build/Three.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions build/ThreeDebug.js

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions examples/camera_free.html
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@

renderer = new THREE.CanvasRenderer();
renderer.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
renderer.autoClear = false;

container.appendChild(renderer.domElement);

Expand Down Expand Up @@ -264,7 +263,6 @@
debugContext.closePath();
debugContext.stroke();

renderer.clear();
renderer.render(scene, camera);

stats.update();
Expand Down
2 changes: 2 additions & 0 deletions src/core/Color.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

THREE.Color = function ( hex ) {

/*
this.r; this.g; this.b; this.a;
this.hex;
*/

this.__styleString = 'rgba(0, 0, 0, 1)';

Expand Down
15 changes: 10 additions & 5 deletions src/core/Rectangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
* @author mr.doob / http://mrdoob.com/
*/

THREE.Rectangle = function ( x1, y1, x2, y2 ) {
THREE.Rectangle = function () {

var _x1 = x1, _y1 = y1,
_x2 = x2, _y2 = y2,
_width = _x2 - _x1, _height = _y2 - _y1,
_isEmpty = false;
var _x1, _y1, _x2, _y2,
_width, _height,
_isEmpty = true;

function resize() {

Expand Down Expand Up @@ -162,6 +161,12 @@ THREE.Rectangle = function ( x1, y1, x2, y2 ) {

};

this.isEmpty = function () {

return _isEmpty;

};

this.toString = function () {

return "THREE.Rectangle (x1: " + _x1 + ", y1: " + _y2 + ", x2: " + _x2 + ", y1: " + _y1 + ", width: " + _width + ", height: " + _height + ")";
Expand Down
8 changes: 8 additions & 0 deletions src/core/Vector3.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ THREE.Vector3.prototype = {

},

divideScalar: function ( s ) {

this.x /= s;
this.y /= s;
this.z /= s;

},

dot: function ( v ) {

return this.x * v.x + this.y * v.y + this.z * v.z;
Expand Down
32 changes: 23 additions & 9 deletions src/renderers/CanvasRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ THREE.CanvasRenderer = function () {
_context = _canvas.getContext( '2d' ),
_width, _height, _widthHalf, _heightHalf,
_clipRect = new THREE.Rectangle(),
_clearRect = new THREE.Rectangle( 0, 0, 0, 0 ),
_clearRect = new THREE.Rectangle(),
_bboxRect = new THREE.Rectangle(),
_vector2 = new THREE.Vector2(),

Expand All @@ -28,19 +28,29 @@ THREE.CanvasRenderer = function () {
_canvas.width = _width;
_canvas.height = _height;

_context.setTransform( 1, 0, 0, -1, _widthHalf, _heightHalf );

_clipRect.set( - _widthHalf, - _heightHalf, _widthHalf, _heightHalf );

};

this.clear = function () {

_clearRect.inflate( 1 );
_clearRect.minSelf( _clipRect );
_context.clearRect( _clearRect.getX(), _clearRect.getY(), _clearRect.getWidth(), _clearRect.getHeight() );
_clearRect.empty();
if ( !_clearRect.isEmpty() ) {

_clearRect.inflate( 1 );
_clearRect.minSelf( _clipRect );

/*
_context.setTransform( 1, 0, 0, - 1, _widthHalf, _heightHalf );
_context.clearRect( _clearRect.getX(), _clearRect.getY(), _clearRect.getWidth(), _clearRect.getHeight() );
*/

// Opera workaround
_context.setTransform( 1, 0, 0, 1, _widthHalf, _heightHalf );
_context.clearRect( _clearRect.getX(), - ( _clearRect.getHeight() + _clearRect.getY() ), _clearRect.getWidth(), _clearRect.getHeight() );

_clearRect.empty();

}
};

this.render = function ( scene, camera ) {
Expand All @@ -50,19 +60,21 @@ THREE.CanvasRenderer = function () {
width, height, scaleX, scaleY, offsetX, offsetY,
bitmap, bitmapWidth, bitmapHeight;

this.project( scene, camera );

if ( this.autoClear ) {

this.clear();

}

_context.setTransform( 1, 0, 0, - 1, _widthHalf, _heightHalf );

/* DEBUG
_context.fillStyle = 'rgba(0, 255, 255, 0.5)';
_context.fillRect( _clipRect.getX(), _clipRect.getY(), _clipRect.getWidth(), _clipRect.getHeight() );
*/

this.project( scene, camera );

for ( e = 0, el = this.renderList.length; e < el; e++ ) {

element = this.renderList[ e ];
Expand Down Expand Up @@ -497,6 +509,8 @@ THREE.CanvasRenderer = function () {
_context.strokeRect( _clearRect.getX(), _clearRect.getY(), _clearRect.getWidth(), _clearRect.getHeight() );
*/

_context.setTransform( 1, 0, 0, 1, 0, 0 );

};

function drawTexturedTriangle( bitmap, v1x, v1y, v2x, v2y, v3x, v3y, uv1u, uv1v, uv2u, uv2v, uv3u, uv3v ) {
Expand Down
2 changes: 1 addition & 1 deletion utils/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# MERGER

rev = 14
rev = 16

files = []
files.append('Three.js')
Expand Down
2 changes: 1 addition & 1 deletion utils/builder_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# MERGER

rev = 14
rev = 16

files = []
files.append('Three.js')
Expand Down

0 comments on commit 216b4ee

Please sign in to comment.