mrdoob/three.js — comment on commit 9809101319612e9e0abc9f13e7b42c22cd569e24
File:  line 0
By mrdoob:

I managed to fix `getRotationFromMatrix` and get it working:

```javascript
applyMatrix: function ( matrix ) {

this.matrix.multiply( matrix, this.matrix );
this.position.getPositionFromMatrix( this.matrix );
this.scale.getScaleFromMatrix( this.matrix );
this.rotation.getRotationFromMatrix( this.matrix, this.scale );

},
```

```javascript
getRotationFromMatrix: function ( m, scale ) {

var sx = scale ? scale.x : 1;
var sy = scale ? scale.y : 1;
var sz = scale ? scale.z : 1;

var m11 = m.n11 / sx, m12 = m.n12 / sy, m13 = m.n13 / sz;
var m21 = m.n21 / sx, m22 = m.n22 / sy, m23 = m.n23 / sz;
var m33 = m.n33 / sz;

this.y = Math.asin( m13 );

var cosY = Math.cos( this.y );

if ( Math.abs( cosY ) > 0.00001 ) {

this.x = Math.atan2( - m23 / cosY, m33 / cosY );
this.z = Math.atan2( - m12 / cosY, m11 / cosY );

} else {

this.x = 0;
this.z = Math.atan2( m21, m22 );

}

return this;

}
```