Skip to content

Commit 06d359d

Browse files
committed
Matrix4.transform is a new method that will generate a transform matrix from the given position and scale vectors and a rotation quaternion.
Removed un-used methods.
1 parent d3e318a commit 06d359d

1 file changed

Lines changed: 47 additions & 86 deletions

File tree

src/math/Matrix4.js

Lines changed: 47 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ var Matrix4 = new Class({
6363
return new Matrix4(this);
6464
},
6565

66-
// TODO - Should work with basic values
67-
6866
/**
6967
* This method is an alias for `Matrix4.copy`.
7068
*
@@ -80,90 +78,6 @@ var Matrix4 = new Class({
8078
return this.copy(src);
8179
},
8280

83-
// TODO - Docs
84-
fromRotationXYTranslation: function (rotation, position, translateFirst)
85-
{
86-
var x = position.x;
87-
var y = position.y;
88-
var z = position.z;
89-
90-
var sx = Math.sin(rotation.x);
91-
var cx = Math.cos(rotation.x);
92-
93-
var sy = Math.sin(rotation.y);
94-
var cy = Math.cos(rotation.y);
95-
96-
var a30 = x;
97-
var a31 = y;
98-
var a32 = z;
99-
100-
// Rotate X
101-
102-
var b21 = -sx;
103-
104-
// Rotate Y
105-
106-
var c01 = 0 - b21 * sy;
107-
108-
var c02 = 0 - cx * sy;
109-
110-
var c21 = b21 * cy;
111-
112-
var c22 = cx * cy;
113-
114-
// Translate
115-
if (!translateFirst)
116-
{
117-
// a30 = cy * x + 0 * y + sy * z;
118-
a30 = cy * x + sy * z;
119-
a31 = c01 * x + cx * y + c21 * z;
120-
a32 = c02 * x + sx * y + c22 * z;
121-
}
122-
123-
return this.setValues(
124-
cy,
125-
c01,
126-
c02,
127-
0,
128-
0,
129-
cx,
130-
sx,
131-
0,
132-
sy,
133-
c21,
134-
c22,
135-
0,
136-
a30,
137-
a31,
138-
a32,
139-
1
140-
);
141-
},
142-
143-
setValues: function (m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33)
144-
{
145-
var out = this.val;
146-
147-
out[0] = m00;
148-
out[1] = m01;
149-
out[2] = m02;
150-
out[3] = m03;
151-
out[4] = m10;
152-
out[5] = m11;
153-
out[6] = m12;
154-
out[7] = m13;
155-
out[8] = m20;
156-
out[9] = m21;
157-
out[10] = m22;
158-
out[11] = m23;
159-
out[12] = m30;
160-
out[13] = m31;
161-
out[14] = m32;
162-
out[15] = m33;
163-
164-
return this;
165-
},
166-
16781
/**
16882
* Copy the values of a given Matrix into this Matrix.
16983
*
@@ -267,6 +181,53 @@ var Matrix4 = new Class({
267181
return this;
268182
},
269183

184+
/**
185+
* Generates a transform matrix based on the given position, scale and rotation.
186+
*
187+
* @method Phaser.Math.Matrix4#transform
188+
* @since 3.50.0
189+
*
190+
* @param {Phaser.Math.Vector3} position - The position vector.
191+
* @param {Phaser.Math.Vector3} scale - The scale vector.
192+
* @param {Phaser.Math.Quaternion} rotation - The rotation quaternion.
193+
*
194+
* @return {Phaser.Math.Matrix4} This Matrix4.
195+
*/
196+
transform: function (position, scale, rotation)
197+
{
198+
// var rotMatrix = rotation.toMatrix4(_tempMat1);
199+
var rotMatrix = _tempMat1.fromQuat(rotation);
200+
201+
var rm = rotMatrix.val;
202+
var m = this.val;
203+
204+
var sx = scale.x;
205+
var sy = scale.y;
206+
var sz = scale.z;
207+
208+
m[0] = rm[0] * sx;
209+
m[1] = rm[1] * sx;
210+
m[2] = rm[2] * sx;
211+
m[3] = 0;
212+
213+
m[4] = rm[4] * sy;
214+
m[5] = rm[5] * sy;
215+
m[6] = rm[6] * sy;
216+
m[7] = 0;
217+
218+
m[8] = rm[8] * sz;
219+
m[9] = rm[9] * sz;
220+
m[10] = rm[10] * sz;
221+
m[11] = 0;
222+
223+
m[12] = position.x;
224+
m[13] = position.y;
225+
m[14] = position.z;
226+
m[15] = 1;
227+
228+
return this;
229+
},
230+
270231
/**
271232
* Set the `x`, `y` and `z` values of this Matrix.
272233
*

0 commit comments

Comments
 (0)