2014-07-29 10:49:06 +08:00
|
|
|
/****************************************************************************
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2014-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2014-07-29 10:49:06 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "3d/CCAttachNode.h"
|
2014-07-30 18:32:34 +08:00
|
|
|
#include "3d/CCSkeleton3D.h"
|
2014-07-29 10:49:06 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
AttachNode* AttachNode::create(Bone3D* attachBone)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
auto attachnode = new AttachNode();
|
2014-07-29 10:49:06 +08:00
|
|
|
attachnode->_attachBone = attachBone;
|
|
|
|
attachnode->autorelease();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-07-29 10:49:06 +08:00
|
|
|
return attachnode;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
AttachNode::AttachNode() : _attachBone(nullptr) {}
|
|
|
|
AttachNode::~AttachNode() {}
|
2014-07-29 10:49:06 +08:00
|
|
|
|
|
|
|
Mat4 AttachNode::getWorldToNodeTransform() const
|
|
|
|
{
|
|
|
|
static Mat4 mat;
|
|
|
|
mat.setIdentity();
|
|
|
|
auto parent = getParent();
|
|
|
|
if (parent)
|
|
|
|
{
|
2015-02-11 18:14:22 +08:00
|
|
|
mat = parent->getWorldToNodeTransform() * _attachBone->getWorldMat() * Node::getNodeToParentTransform();
|
2014-07-29 10:49:06 +08:00
|
|
|
}
|
|
|
|
else
|
2014-07-31 18:14:01 +08:00
|
|
|
{
|
2015-02-11 18:14:22 +08:00
|
|
|
mat = _attachBone->getWorldMat() * Node::getNodeToParentTransform();
|
2014-07-31 18:14:01 +08:00
|
|
|
}
|
2014-07-29 10:49:06 +08:00
|
|
|
return mat;
|
|
|
|
}
|
|
|
|
|
2014-12-16 16:34:35 +08:00
|
|
|
Mat4 AttachNode::getNodeToWorldTransform() const
|
|
|
|
{
|
2015-02-11 18:14:22 +08:00
|
|
|
return Node::getNodeToWorldTransform();
|
|
|
|
}
|
|
|
|
|
|
|
|
const Mat4& AttachNode::getNodeToParentTransform() const
|
|
|
|
{
|
|
|
|
Node::getNodeToParentTransform();
|
|
|
|
_transformToParent = _attachBone->getWorldMat() * _transform;
|
|
|
|
return _transformToParent;
|
2014-12-16 16:34:35 +08:00
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void AttachNode::visit(Renderer* renderer, const Mat4& parentTransform, uint32_t /*parentFlags*/)
|
2014-07-29 10:49:06 +08:00
|
|
|
{
|
2015-02-11 18:14:22 +08:00
|
|
|
Node::visit(renderer, parentTransform, Node::FLAGS_DIRTY_MASK);
|
2014-07-29 10:49:06 +08:00
|
|
|
}
|
|
|
|
NS_CC_END
|