File tree Expand file tree Collapse file tree
src/gameobjects/components Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -238,9 +238,10 @@ var TransformMatrix = new Class({
238238 } ,
239239
240240 /**
241- * The rotation of the Matrix.
241+ * The rotation of the Matrix, normalized to be within the Phaser right-handed
242+ * clockwise rotation space. Value is in radians.
242243 *
243- * @name Phaser.GameObjects.Components.TransformMatrix#rotation
244+ * @name Phaser.GameObjects.Components.TransformMatrix#rotationNormalized
244245 * @type {number }
245246 * @readonly
246247 * @since 3.4.0
@@ -249,7 +250,33 @@ var TransformMatrix = new Class({
249250
250251 get : function ( )
251252 {
252- return Math . acos ( this . a / this . scaleX ) * ( Math . atan ( - this . c / this . a ) < 0 ? - 1 : 1 ) ;
253+ // Previous version:
254+ // return Math.acos(this.a / this.scaleX) * (Math.atan(-this.c / this.a) < 0 ? -1 : 1);
255+
256+ // Normalized version:
257+ var matrix = this . matrix ;
258+
259+ var a = matrix [ 0 ] ;
260+ var b = matrix [ 1 ] ;
261+ var c = matrix [ 2 ] ;
262+ var d = matrix [ 3 ] ;
263+
264+ if ( a || b )
265+ {
266+ var r = Math . sqrt ( a * a + b * b ) ;
267+
268+ return ( b > 0 ) ? Math . acos ( a / r ) : - Math . acos ( a / r ) ;
269+ }
270+ else if ( c || d )
271+ {
272+ var s = Math . sqrt ( c * c + d * d ) ;
273+
274+ return Math . PI * 0.5 - ( d > 0 ? Math . acos ( - c / s ) : - Math . acos ( c / s ) ) ;
275+ }
276+ else
277+ {
278+ return 0 ;
279+ }
253280 }
254281
255282 } ,
You can’t perform that action at this time.
0 commit comments