CCAttachNode.h 2.5 KB

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