Skip to content

Commit cc85ec1

Browse files
committed
Fixed scaleX and scaleY
1 parent 9567828 commit cc85ec1

1 file changed

Lines changed: 19 additions & 52 deletions

File tree

src/gameobjects/components/TransformMatrix.js

Lines changed: 19 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
var Class = require('../../utils/Class');
8+
var MATH_CONST = require('../../math/const');
89
var Vector2 = require('../../math/Vector2');
910

1011
/**
@@ -25,8 +26,8 @@ var Vector2 = require('../../math/Vector2');
2526
* @since 3.0.0
2627
*
2728
* @param {number} [a=1] - The Scale X value.
28-
* @param {number} [b=0] - The Shear Y value.
29-
* @param {number} [c=0] - The Shear X value.
29+
* @param {number} [b=0] - The Skew Y value.
30+
* @param {number} [c=0] - The Skew X value.
3031
* @param {number} [d=1] - The Scale Y value.
3132
* @param {number} [tx=0] - The Translate X value.
3233
* @param {number} [ty=0] - The Translate Y value.
@@ -91,7 +92,7 @@ var TransformMatrix = new Class({
9192
},
9293

9394
/**
94-
* The Shear Y value.
95+
* The Skew Y value.
9596
*
9697
* @name Phaser.GameObjects.Components.TransformMatrix#b
9798
* @type {number}
@@ -112,7 +113,7 @@ var TransformMatrix = new Class({
112113
},
113114

114115
/**
115-
* The Shear X value.
116+
* The Skew X value.
116117
*
117118
* @name Phaser.GameObjects.Components.TransformMatrix#c
118119
* @type {number}
@@ -249,7 +250,7 @@ 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+
return Math.acos(this.a / this.scaleX) * ((Math.atan(-this.c / this.a) < 0) ? -1 : 1);
253254
}
254255

255256
},
@@ -273,18 +274,18 @@ var TransformMatrix = new Class({
273274
var b = matrix[1];
274275
var c = matrix[2];
275276
var d = matrix[3];
276-
277+
277278
if (a || b)
278279
{
279-
var r = Math.sqrt(a * a + b * b);
280+
// var r = Math.sqrt(a * a + b * b);
280281

281-
return (b > 0) ? Math.acos(a / r) : -Math.acos(a / r);
282+
return (b > 0) ? Math.acos(a / this.scaleX) : -Math.acos(a / this.scaleX);
282283
}
283284
else if (c || d)
284285
{
285-
var s = Math.sqrt(c * c + d * d);
286+
// var s = Math.sqrt(c * c + d * d);
286287

287-
return Math.PI * 0.5 - (d > 0 ? Math.acos(-c / s) : -Math.acos(c / s));
288+
return MATH_CONST.TAU - ((d > 0) ? Math.acos(-c / this.scaleY) : -Math.acos(c / this.scaleY));
288289
}
289290
else
290291
{
@@ -295,7 +296,7 @@ var TransformMatrix = new Class({
295296
},
296297

297298
/**
298-
* The horizontal scale of the Matrix.
299+
* The decomposed horizontal scale of the Matrix. This value is always positive.
299300
*
300301
* @name Phaser.GameObjects.Components.TransformMatrix#scaleX
301302
* @type {number}
@@ -306,32 +307,13 @@ var TransformMatrix = new Class({
306307

307308
get: function ()
308309
{
309-
var matrix = this.matrix;
310-
var a = matrix[0];
311-
var b = matrix[1];
312-
var c = matrix[2];
313-
var d = matrix[3];
314-
315-
var determ = a * d - b * c;
316-
317-
if (a || b)
318-
{
319-
return determ / Math.sqrt(a * a + b * b);
320-
}
321-
else if (c || d)
322-
{
323-
return Math.sqrt(c * c + d * d);
324-
}
325-
else
326-
{
327-
return 0;
328-
}
310+
return Math.sqrt((this.a * this.a) + (this.b * this.b));
329311
}
330312

331313
},
332314

333315
/**
334-
* The vertical scale of the Matrix.
316+
* The decomposed vertical scale of the Matrix. This value is always positive.
335317
*
336318
* @name Phaser.GameObjects.Components.TransformMatrix#scaleY
337319
* @type {number}
@@ -342,26 +324,7 @@ var TransformMatrix = new Class({
342324

343325
get: function ()
344326
{
345-
var matrix = this.matrix;
346-
var a = matrix[0];
347-
var b = matrix[1];
348-
var c = matrix[2];
349-
var d = matrix[3];
350-
351-
var determ = a * d - b * c;
352-
353-
if (a || b)
354-
{
355-
return Math.sqrt(a * a + b * b);
356-
}
357-
else if (c || d)
358-
{
359-
return determ / Math.sqrt(c * c + d * d);
360-
}
361-
else
362-
{
363-
return 0;
364-
}
327+
return Math.sqrt((this.c * this.c) + (this.d * this.d));
365328
}
366329

367330
},
@@ -888,6 +851,10 @@ var TransformMatrix = new Class({
888851
matrix[4] = x;
889852
matrix[5] = y;
890853

854+
// Double-check against input, scaling, etc
855+
scaleX = Math.abs(scaleX);
856+
scaleY = Math.abs(scaleY);
857+
891858
// Rotate and Scale
892859
matrix[0] = radianCos * scaleX;
893860
matrix[1] = radianSin * scaleX;

0 commit comments

Comments
 (0)