mirror of https://github.com/axmolengine/axmol.git
add Two APIs to Node.
1. add getNodeToParentTransform(Node* ancestor) 2. add getNodeToParentAffineTransform(Node* ancestor)
This commit is contained in:
parent
0ea8dca299
commit
c4d8ebc780
|
@ -1761,6 +1761,28 @@ AffineTransform Node::getNodeToParentAffineTransform() const
|
|||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Mat4 Node::getNodeToParentTransform(Node* ancestor) const
|
||||
{
|
||||
Mat4 t(this->getNodeToParentTransform());
|
||||
|
||||
for (Node *p = _parent; p != nullptr && p != ancestor ; p = p->getParent())
|
||||
{
|
||||
t = p->getNodeToParentTransform() * t;
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
AffineTransform Node::getNodeToParentAffineTransform(Node* ancestor) const
|
||||
{
|
||||
AffineTransform t(this->getNodeToParentAffineTransform());
|
||||
|
||||
for (Node *p = _parent; p != nullptr && p != ancestor; p = p->getParent())
|
||||
t = AffineTransformConcat(t, p->getNodeToParentAffineTransform());
|
||||
|
||||
return t;
|
||||
}
|
||||
const Mat4& Node::getNodeToParentTransform() const
|
||||
{
|
||||
if (_transformDirty)
|
||||
|
@ -1916,24 +1938,12 @@ const Mat4& Node::getParentToNodeTransform() const
|
|||
|
||||
AffineTransform Node::getNodeToWorldAffineTransform() const
|
||||
{
|
||||
AffineTransform t(this->getNodeToParentAffineTransform());
|
||||
|
||||
for (Node *p = _parent; p != nullptr; p = p->getParent())
|
||||
t = AffineTransformConcat(t, p->getNodeToParentAffineTransform());
|
||||
|
||||
return t;
|
||||
return this->getNodeToParentAffineTransform(nullptr);
|
||||
}
|
||||
|
||||
Mat4 Node::getNodeToWorldTransform() const
|
||||
{
|
||||
Mat4 t(this->getNodeToParentTransform());
|
||||
|
||||
for (Node *p = _parent; p != nullptr; p = p->getParent())
|
||||
{
|
||||
t = p->getNodeToParentTransform() * t;
|
||||
}
|
||||
|
||||
return t;
|
||||
return this->getNodeToParentTransform(nullptr);
|
||||
}
|
||||
|
||||
AffineTransform Node::getWorldToNodeAffineTransform() const
|
||||
|
|
|
@ -1488,6 +1488,29 @@ public:
|
|||
virtual const Mat4& getNodeToParentTransform() const;
|
||||
virtual AffineTransform getNodeToParentAffineTransform() const;
|
||||
|
||||
/**
|
||||
* Returns the matrix that transform the node's (local) space coordinates into the parent's space coordinates.
|
||||
* The matrix is in Pixels.
|
||||
* Note: If acenstor is not a valid ancestor of the node, the API would return the same value as @see getNodeToWorldTransform
|
||||
*
|
||||
* @param ancestor The parent's node pointer.
|
||||
* @since v3.7
|
||||
* @return The transformation matrix.
|
||||
*/
|
||||
virtual Mat4 getNodeToParentTransform(Node* ancestor) const;
|
||||
|
||||
/**
|
||||
* Returns the affline transform matrix that transform the node's (local) space coordinates into the parent's space coordinates.
|
||||
* The matrix is in Pixels.
|
||||
*
|
||||
* Note: If acenstor is not a valid ancestor of the node, the API would return the same value as @see getNodeToWorldAffineTransform
|
||||
*
|
||||
* @param ancestor The parent's node pointer.
|
||||
* @since v3.7
|
||||
* @return The affline transformation matrix.
|
||||
*/
|
||||
virtual AffineTransform getNodeToParentAffineTransform(Node* ancestor) const;
|
||||
|
||||
/**
|
||||
* Sets the transformation matrix manually.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue