Skip to content

Commit da6db3f

Browse files
committed
Added transform methods
1 parent c3ba80c commit da6db3f

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

src/gameobjects/components/Transform.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
var MATH_CONST = require('../../math/const');
88
var WrapAngle = require('../../math/angle/Wrap');
99
var WrapAngleDegrees = require('../../math/angle/WrapDegrees');
10+
var TransformMatrix = require('./TransformMatrix');
1011

1112
// global bitmask flag for GameObject.renderMask (used by Scale)
1213
var _FLAG = 4; // 0100
@@ -368,6 +369,44 @@ var Transform = {
368369
this.w = value;
369370

370371
return this;
372+
},
373+
374+
getLocalTransformMatrix: function (tempMatrix)
375+
{
376+
return tempMatrix.applyITRS(this.x, this.y, this._rotation, this._scaleX, this._scaleY);
377+
},
378+
379+
getWorldTransformMatrix: function (tempMatrix, tempParentMatrix)
380+
{
381+
this.getLocalTransformMatrix(tempMatrix);
382+
383+
var parent = this.parentContainer;
384+
385+
if (!parent)
386+
{
387+
return tempMatrix;
388+
}
389+
390+
var parents = [];
391+
392+
do
393+
{
394+
parents.push(parent);
395+
parent = parent.parentContainer;
396+
}
397+
while (parent);
398+
399+
// We've got all the ancestors in the 'parents' array, let's loop it
400+
for (var i = 0; i < parents.length; i++)
401+
{
402+
parent = parents[i];
403+
404+
parent.getLocalTransformMatrix(tempParentMatrix);
405+
406+
tempMatrix.multiply(tempParentMatrix);
407+
}
408+
409+
return tempMatrix;
371410
}
372411

373412
};

0 commit comments

Comments
 (0)