Skip to content

Commit e858be4

Browse files
authored
Merge pull request #2 from dabingnn/master
add fromRTS for mat23
2 parents 318ff72 + 469c246 commit e858be4

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

lib/mat23.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,35 @@ mat23.fromTranslation = function (out, v) {
332332
return out;
333333
};
334334

335+
/**
336+
* Creates a matrix from a rotation, vector translation and vector scale
337+
* This is equivalent to (but faster than):
338+
*
339+
* mat23.identity(dest);
340+
* mat23.translate(dest, vec);
341+
* let tmp = mat23.create();
342+
* mat23.fromRotation(tmp, rot);
343+
* mat23.multiply(dest, dest, tmp);
344+
* mat23.fromScaling(tmp, scale);
345+
* mat23.multiply(dest, dest, tmp);
346+
*
347+
* @param {mat23} out mat23 receiving operation result
348+
* @param {number} r Rotation radian
349+
* @param {vec2} v Translation vector
350+
* @param {vec2} s Scaling vector
351+
* @returns {mat23} out
352+
*/
353+
mat23.fromRTS = function (out, r, t, s) {
354+
let sr = Math.sin(r), cr = Math.cos(r);
355+
out.m00 = cr * s.x;
356+
out.m01 = sr * s.x;
357+
out.m02 = -sr * s.y;
358+
out.m03 = cr * s.y;
359+
out.m04 = t.x;
360+
out.m05 = t.y;
361+
return out;
362+
};
363+
335364
/**
336365
* Returns a string representation of a mat23
337366
*

0 commit comments

Comments
 (0)