CCAttachNode.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /****************************************************************************
  2. Copyright (c) 2014-2016 Chukong Technologies Inc.
  3. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #ifndef __CCATTACHNODE_H__
  22. #define __CCATTACHNODE_H__
  23. #include "math/CCMath.h"
  24. #include "2d/CCNode.h"
  25. NS_CC_BEGIN
  26. /**
  27. * @addtogroup _3d
  28. * @{
  29. */
  30. class Bone3D;
  31. /**
  32. * @brief attach a node to a bone
  33. * usage: auto sprite = Sprite3D::create("girl.c3b");
  34. * auto weapon = Sprite3D::create("weapon.c3b");
  35. * auto attachNode = sprite->getAttachNode("left hand");
  36. * attachNode->addChild(weapon);
  37. */
  38. class CC_DLL AttachNode : public Node
  39. {
  40. public:
  41. /**
  42. * creates an AttachNode
  43. * @param attachBone The bone to which the AttachNode is going to attach, the attacheBone must be a bone of the AttachNode's parent
  44. */
  45. static AttachNode* create(Bone3D* attachBone);
  46. //override
  47. virtual Mat4 getWorldToNodeTransform() const override;
  48. virtual Mat4 getNodeToWorldTransform() const override;
  49. virtual const Mat4& getNodeToParentTransform() const override;
  50. virtual void visit(Renderer *renderer, const Mat4& parentTransform, uint32_t parentFlags) override;
  51. CC_CONSTRUCTOR_ACCESS:
  52. AttachNode();
  53. virtual ~AttachNode();
  54. protected:
  55. Bone3D* _attachBone;
  56. mutable Mat4 _transformToParent;
  57. };
  58. // end of 3d group
  59. /// @}
  60. NS_CC_END
  61. #endif // __CCATTACHNODE_H__