From e5e4ff79ee5ab7be6bdee7f4ef043c6766efd3c9 Mon Sep 17 00:00:00 2001 From: "Mr.doob" Date: Mon, 11 Apr 2011 16:15:46 +0100 Subject: [PATCH] Fixed Vector3::setRotationFromMatrix --- examples/webgl_sandbox.html | 11 +++++++++-- src/core/Matrix4.js | 15 +++++++++++++++ src/core/Vector3.js | 6 +++--- src/renderers/WebGLRenderer.js | 2 ++ 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/examples/webgl_sandbox.html b/examples/webgl_sandbox.html index 7260b58d04..3fac70f2d5 100644 --- a/examples/webgl_sandbox.html +++ b/examples/webgl_sandbox.html @@ -52,13 +52,13 @@ - - + + @@ -84,6 +84,7 @@ + @@ -101,12 +102,15 @@ + + + @@ -118,7 +122,10 @@ + + + diff --git a/src/core/Matrix4.js b/src/core/Matrix4.js index a41df09e79..8f91053e7e 100644 --- a/src/core/Matrix4.js +++ b/src/core/Matrix4.js @@ -69,6 +69,21 @@ THREE.Matrix4.prototype = { lookAt : function ( eye, center, up ) { + /* + var x = THREE.Matrix4.__v1, y = THREE.Matrix4.__v2, z = THREE.Matrix4.__v3; + + z.sub( center, eye ).normalize(); + x.cross( up, z ).normalize(); + y.cross( z, x ).normalize(); + + this.n11 = x.x; this.n12 = x.y; this.n13 = x.z; this.n14 = - x.dot( eye ); + this.n21 = y.x; this.n22 = y.y; this.n23 = y.z; this.n24 = - y.dot( eye ); + this.n31 = z.x; this.n32 = z.y; this.n33 = z.z; this.n34 = - z.dot( eye ); + this.n41 = 0; this.n42 = 0; this.n43 = 0; this.n44 = 1; + + return this; + */ + var x = THREE.Matrix4.__v1, y = THREE.Matrix4.__v2, z = THREE.Matrix4.__v3; z.sub( eye, center ).normalize(); diff --git a/src/core/Vector3.js b/src/core/Vector3.js index a15db9a005..4a866cd370 100644 --- a/src/core/Vector3.js +++ b/src/core/Vector3.js @@ -290,14 +290,14 @@ THREE.Vector3.prototype = { setRotationFromMatrix : function ( m ) { - this.y = Math.asin( m.n13 ); - var cosY = Math.cos( this.y ); + this.y = Math.asin( m.n13 ); + if ( Math.abs( cosY ) > 0.00001 ) { this.x = Math.atan2( - m.n23 / cosY, m.n33 / cosY ); - this.z = Math.atan2( - m.n13 / cosY, m.n11 / cosY ); + this.z = Math.atan2( - m.n12 / cosY, m.n11 / cosY ); } else { diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 3c82ade82b..596bc4ed72 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -4538,6 +4538,7 @@ THREE.WebGLRenderer = function ( parameters ) { } else { _gl.bindTexture( _gl.TEXTURE_2D, texture.__webglTexture ); + // _gl.texImage2D( _gl.TEXTURE_2D, 0, _gl.RGBA, _gl.RGBA, _gl.UNSIGNED_BYTE, texture.image ); _gl.texSubImage2D( _gl.TEXTURE_2D, 0, 0, 0, _gl.RGBA, _gl.UNSIGNED_BYTE, texture.image ); } @@ -4580,6 +4581,7 @@ THREE.WebGLRenderer = function ( parameters ) { for ( var i = 0; i < 6; ++i ) { + // _gl.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, _gl.RGBA, _gl.RGBA, _gl.UNSIGNED_BYTE, texture.image[ i ] ); _gl.texSubImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, 0, 0, _gl.RGBA, _gl.UNSIGNED_BYTE, texture.image[ i ] ); } -- GitLab