axmol/cocos/editor-support/cocostudio/CCArmature.cpp

678 lines
16 KiB
C++
Raw Normal View History

2013-06-06 12:02:54 +08:00
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
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 "cocostudio/CCArmature.h"
#include "cocostudio/CCArmatureDataManager.h"
#include "cocostudio/CCArmatureDefine.h"
#include "cocostudio/CCDataReaderHelper.h"
#include "cocostudio/CCDatas.h"
#include "cocostudio/CCSkin.h"
2013-12-18 10:41:09 +08:00
#include "CCQuadCommand.h"
#include "CCRenderer.h"
#include "CCGroupCommand.h"
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
#if ENABLE_PHYSICS_BOX2D_DETECT
#include "Box2D/Box2D.h"
#elif ENABLE_PHYSICS_CHIPMUNK_DETECT
#include "chipmunk.h"
#endif
2013-06-06 12:02:54 +08:00
using namespace cocos2d;
2013-06-07 10:52:32 +08:00
namespace cocostudio {
2013-06-07 10:52:32 +08:00
Armature *Armature::create()
2013-06-06 12:02:54 +08:00
{
Armature *armature = new Armature();
2013-06-06 12:02:54 +08:00
if (armature && armature->init())
{
armature->autorelease();
return armature;
}
CC_SAFE_DELETE(armature);
return nullptr;
2013-06-06 12:02:54 +08:00
}
2013-06-07 10:52:32 +08:00
Armature *Armature::create(const char *name)
2013-06-06 12:02:54 +08:00
{
Armature *armature = new Armature();
2013-09-13 18:07:37 +08:00
if (armature && armature->init(name))
2013-06-06 12:02:54 +08:00
{
armature->autorelease();
return armature;
}
CC_SAFE_DELETE(armature);
return nullptr;
2013-06-06 12:02:54 +08:00
}
Armature *Armature::create(const char *name, Bone *parentBone)
2013-06-06 12:02:54 +08:00
{
Armature *armature = new Armature();
2013-06-07 10:52:32 +08:00
if (armature && armature->init(name, parentBone))
{
armature->autorelease();
return armature;
}
CC_SAFE_DELETE(armature);
return nullptr;
2013-06-06 12:02:54 +08:00
}
Armature::Armature()
: _armatureData(nullptr)
, _batchNode(nullptr)
, _parentBone(nullptr)
2013-09-15 20:24:25 +08:00
, _armatureTransformDirty(true)
, _animation(nullptr)
2013-06-06 12:02:54 +08:00
{
}
Armature::~Armature(void)
2013-06-06 12:02:54 +08:00
{
_boneDic.clear();
_topBoneList.clear();
CC_SAFE_DELETE(_animation);
2013-06-06 12:02:54 +08:00
}
2013-06-07 10:52:32 +08:00
bool Armature::init()
2013-06-06 12:02:54 +08:00
{
return init(nullptr);
2013-06-06 12:02:54 +08:00
}
bool Armature::init(const char *name)
2013-06-06 12:02:54 +08:00
{
bool bRet = false;
do
{
2013-06-07 10:52:32 +08:00
removeAllChildren();
2013-06-06 12:02:54 +08:00
CC_SAFE_DELETE(_animation);
_animation = new ArmatureAnimation();
_animation->init(this);
2013-06-06 12:02:54 +08:00
_boneDic.clear();
_topBoneList.clear();
2013-06-06 12:02:54 +08:00
2013-12-02 13:32:31 +08:00
_blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED;
2013-06-07 10:52:32 +08:00
_name = name == nullptr ? "" : name;
2013-06-06 12:02:54 +08:00
ArmatureDataManager *armatureDataManager = ArmatureDataManager::getInstance();
2013-06-07 10:52:32 +08:00
if(_name.length() != 0)
2013-06-06 12:02:54 +08:00
{
_name = name;
2013-06-07 10:52:32 +08:00
AnimationData *animationData = armatureDataManager->getAnimationData(name);
2013-09-16 12:02:57 +08:00
CCASSERT(animationData, "AnimationData not exist! ");
2013-06-07 10:52:32 +08:00
_animation->setAnimationData(animationData);
2013-06-07 10:52:32 +08:00
ArmatureData *armatureData = armatureDataManager->getArmatureData(name);
CCASSERT(armatureData, "");
2013-06-07 10:52:32 +08:00
_armatureData = armatureData;
2013-06-07 10:52:32 +08:00
2013-12-18 22:07:33 +08:00
for (auto& element : armatureData->boneDataDic)
2013-06-06 12:02:54 +08:00
{
2013-12-13 19:40:38 +08:00
Bone *bone = createBone(element.first.c_str());
2013-06-07 10:52:32 +08:00
//! init bone's Tween to 1st movement's 1st frame
2013-06-07 10:52:32 +08:00
do
{
MovementData *movData = animationData->getMovement(animationData->movementNames.at(0).c_str());
2013-06-06 12:02:54 +08:00
CC_BREAK_IF(!movData);
2013-06-07 10:52:32 +08:00
MovementBoneData *movBoneData = movData->getMovementBoneData(bone->getName().c_str());
2013-12-13 19:40:38 +08:00
CC_BREAK_IF(!movBoneData || movBoneData->frameList.size() <= 0);
2013-06-07 10:52:32 +08:00
FrameData *frameData = movBoneData->getFrameData(0);
2013-06-06 12:02:54 +08:00
CC_BREAK_IF(!frameData);
2013-06-07 10:52:32 +08:00
2013-06-06 12:02:54 +08:00
bone->getTweenData()->copy(frameData);
2013-06-07 10:52:32 +08:00
bone->changeDisplayByIndex(frameData->displayIndex, false);
}
while (0);
}
update(0);
updateOffsetPoint();
2013-06-06 12:02:54 +08:00
}
else
{
_name = "new_armature";
_armatureData = ArmatureData::create();
_armatureData->name = _name;
2013-06-07 10:52:32 +08:00
AnimationData *animationData = AnimationData::create();
animationData->name = _name;
2013-06-07 10:52:32 +08:00
armatureDataManager->addArmatureData(_name.c_str(), _armatureData);
armatureDataManager->addAnimationData(_name.c_str(), animationData);
2013-06-07 10:52:32 +08:00
_animation->setAnimationData(animationData);
2013-06-07 10:52:32 +08:00
2013-06-06 12:02:54 +08:00
}
2013-09-16 12:02:57 +08:00
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR));
2013-06-06 12:02:54 +08:00
unscheduleUpdate();
2013-06-07 10:52:32 +08:00
scheduleUpdate();
setCascadeOpacityEnabled(true);
setCascadeColorEnabled(true);
2013-06-06 12:02:54 +08:00
bRet = true;
}
while (0);
return bRet;
}
bool Armature::init(const char *name, Bone *parentBone)
2013-06-06 12:02:54 +08:00
{
_parentBone = parentBone;
2013-06-07 10:52:32 +08:00
return init(name);
2013-06-06 12:02:54 +08:00
}
Bone *Armature::createBone(const char *boneName)
2013-06-06 12:02:54 +08:00
{
Bone *existedBone = getBone(boneName);
if(existedBone != nullptr)
2013-06-07 10:52:32 +08:00
return existedBone;
BoneData *boneData = (BoneData *)_armatureData->getBoneData(boneName);
2013-06-07 10:52:32 +08:00
std::string parentName = boneData->parentName;
2013-06-06 12:02:54 +08:00
Bone *bone = nullptr;
2013-06-07 10:52:32 +08:00
if( parentName.length() != 0 )
2013-06-06 12:02:54 +08:00
{
createBone(parentName.c_str());
bone = Bone::create(boneName);
2013-06-06 12:02:54 +08:00
addBone(bone, parentName.c_str());
2013-06-07 10:52:32 +08:00
}
else
{
bone = Bone::create(boneName);
2013-06-06 12:02:54 +08:00
addBone(bone, "");
}
2013-06-07 10:52:32 +08:00
2013-06-06 12:02:54 +08:00
bone->setBoneData(boneData);
2013-06-07 10:52:32 +08:00
bone->getDisplayManager()->changeDisplayByIndex(-1, false);
2013-06-06 12:02:54 +08:00
return bone;
}
void Armature::addBone(Bone *bone, const char *parentName)
2013-06-06 12:02:54 +08:00
{
CCASSERT( bone != nullptr, "Argument must be non-nil");
CCASSERT(_boneDic.at(bone->getName()) == nullptr, "bone already added. It can't be added again");
2013-06-06 12:02:54 +08:00
if (nullptr != parentName)
2013-06-06 12:02:54 +08:00
{
Bone *boneParent = _boneDic.at(parentName);
2013-06-06 12:02:54 +08:00
if (boneParent)
2013-06-07 10:52:32 +08:00
{
boneParent->addChildBone(bone);
}
else
{
_topBoneList.pushBack(bone);
2013-06-07 10:52:32 +08:00
}
2013-06-06 12:02:54 +08:00
}
2013-06-07 10:52:32 +08:00
else
{
_topBoneList.pushBack(bone);
2013-06-07 10:52:32 +08:00
}
2013-06-06 12:02:54 +08:00
bone->setArmature(this);
2013-06-07 10:52:32 +08:00
_boneDic.insert(bone->getName(), bone);
2013-06-06 12:02:54 +08:00
addChild(bone);
}
void Armature::removeBone(Bone *bone, bool recursion)
2013-06-06 12:02:54 +08:00
{
CCASSERT(bone != nullptr, "bone must be added to the bone dictionary!");
2013-06-07 10:52:32 +08:00
bone->setArmature(nullptr);
2013-06-06 12:02:54 +08:00
bone->removeFromParent(recursion);
2013-06-07 10:52:32 +08:00
if (_topBoneList.contains(bone))
2013-06-07 10:52:32 +08:00
{
_topBoneList.eraseObject(bone);
2013-06-07 10:52:32 +08:00
}
_boneDic.erase(bone->getName());
removeChild(bone, true);
2013-06-06 12:02:54 +08:00
}
Bone *Armature::getBone(const char *name) const
2013-06-06 12:02:54 +08:00
{
return _boneDic.at(name);
2013-06-06 12:02:54 +08:00
}
void Armature::changeBoneParent(Bone *bone, const char *parentName)
2013-06-06 12:02:54 +08:00
{
CCASSERT(bone != nullptr, "bone must be added to the bone dictionary!");
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
if(bone->getParentBone())
{
bone->getParentBone()->getChildren().eraseObject(bone);
bone->setParentBone(nullptr);
2013-09-13 18:07:37 +08:00
}
2013-06-06 12:02:54 +08:00
if (parentName != nullptr)
2013-06-07 10:52:32 +08:00
{
Bone *boneParent = _boneDic.at(parentName);
2013-06-06 12:02:54 +08:00
2013-06-07 10:52:32 +08:00
if (boneParent)
{
boneParent->addChildBone(bone);
if (_topBoneList.contains(bone))
2013-09-13 18:07:37 +08:00
{
_topBoneList.eraseObject(bone);
2013-09-13 18:07:37 +08:00
}
}
else
{
_topBoneList.pushBack(bone);
2013-06-07 10:52:32 +08:00
}
}
2013-06-06 12:02:54 +08:00
}
const cocos2d::Map<std::string, Bone*>& Armature::getBoneDic() const
2013-06-06 12:02:54 +08:00
{
return _boneDic;
2013-06-06 12:02:54 +08:00
}
2013-12-11 03:07:15 +08:00
const kmMat4& Armature::getNodeToParentTransform() const
2013-06-06 12:02:54 +08:00
{
if (_transformDirty)
2013-09-15 20:24:25 +08:00
_armatureTransformDirty = true;
2013-09-13 18:07:37 +08:00
return Node::getNodeToParentTransform();
2013-06-06 12:02:54 +08:00
}
2013-06-07 10:52:32 +08:00
void Armature::updateOffsetPoint()
2013-06-06 12:02:54 +08:00
{
2013-06-07 10:52:32 +08:00
// Set contentsize and Calculate anchor point.
Rect rect = getBoundingBox();
2013-06-07 10:52:32 +08:00
setContentSize(rect.size);
2013-07-12 14:11:55 +08:00
_offsetPoint = Point(-rect.origin.x, -rect.origin.y);
2013-09-13 18:07:37 +08:00
if (rect.size.width != 0 && rect.size.height != 0)
{
2013-09-15 20:24:25 +08:00
setAnchorPoint(Point(_offsetPoint.x / rect.size.width, _offsetPoint.y / rect.size.height));
2013-09-13 18:07:37 +08:00
}
2013-06-06 12:02:54 +08:00
}
2013-12-19 15:43:32 +08:00
void Armature::setAnchorPoint(const Point& point)
{
if( ! point.equals(_anchorPoint))
{
_anchorPoint = point;
_anchorPointInPoints = Point(_contentSize.width * _anchorPoint.x - _offsetPoint.x, _contentSize.height * _anchorPoint.y - _offsetPoint.y);
_realAnchorPointInPoints = Point(_contentSize.width * _anchorPoint.x, _contentSize.height * _anchorPoint.y);
_transformDirty = _inverseDirty = true;
}
}
const Point& Armature::getAnchorPointInPoints() const
{
return _realAnchorPointInPoints;
}
void Armature::setAnimation(ArmatureAnimation *animation)
2013-09-13 18:07:37 +08:00
{
2013-09-15 20:24:25 +08:00
_animation = animation;
2013-06-06 12:02:54 +08:00
}
2013-11-05 19:53:38 +08:00
ArmatureAnimation *Armature::getAnimation() const
2013-06-06 12:02:54 +08:00
{
2013-09-15 20:24:25 +08:00
return _animation;
2013-09-13 18:07:37 +08:00
}
2013-06-06 12:02:54 +08:00
2013-11-05 19:53:38 +08:00
bool Armature::getArmatureTransformDirty() const
2013-06-06 12:02:54 +08:00
{
2013-09-15 20:24:25 +08:00
return _armatureTransformDirty;
}
2013-06-06 12:02:54 +08:00
void Armature::update(float dt)
2013-06-06 12:02:54 +08:00
{
_animation->update(dt);
2013-06-06 12:02:54 +08:00
2013-12-18 22:07:33 +08:00
std::for_each(_topBoneList.begin(), _topBoneList.end(), [&dt](Bone* bone){
bone->update(dt);
});
2013-09-13 18:07:37 +08:00
2013-09-15 20:24:25 +08:00
_armatureTransformDirty = false;
2013-06-06 12:02:54 +08:00
}
void Armature::draw()
2013-06-06 12:02:54 +08:00
{
if (_parentBone == nullptr && _batchNode == nullptr)
2013-06-07 10:52:32 +08:00
{
CC_NODE_DRAW_SETUP();
}
2013-12-17 17:00:01 +08:00
2013-12-18 22:07:33 +08:00
for (auto& object : _children)
2013-06-07 10:52:32 +08:00
{
if (Bone *bone = dynamic_cast<Bone *>(object))
2013-09-13 18:07:37 +08:00
{
2013-10-30 09:41:40 +08:00
Node *node = bone->getDisplayRenderNode();
2013-06-07 10:52:32 +08:00
if (nullptr == node)
2013-09-13 18:07:37 +08:00
continue;
2013-06-07 10:52:32 +08:00
2013-10-30 09:41:40 +08:00
switch (bone->getDisplayRenderNodeType())
2013-06-07 10:52:32 +08:00
{
2013-09-13 18:07:37 +08:00
case CS_DISPLAY_SPRITE:
2013-06-07 10:52:32 +08:00
{
2013-09-16 12:21:18 +08:00
Skin *skin = static_cast<Skin *>(node);
2013-09-13 18:07:37 +08:00
skin->updateTransform();
2013-12-17 17:00:01 +08:00
bool blendDirty = bone->isBlendDirty();
2013-12-17 17:00:01 +08:00
if (blendDirty)
2013-06-07 10:52:32 +08:00
{
skin->setBlendFunc(bone->getBlendFunc());
2013-06-07 10:52:32 +08:00
}
2013-12-17 17:00:01 +08:00
skin->draw();
2013-06-07 10:52:32 +08:00
}
2013-09-13 18:07:37 +08:00
break;
case CS_DISPLAY_ARMATURE:
2013-06-07 10:52:32 +08:00
{
2013-12-17 17:00:01 +08:00
node->draw();
2013-09-13 18:07:37 +08:00
}
break;
default:
2013-06-07 10:52:32 +08:00
{
2013-09-13 18:07:37 +08:00
node->visit();
CC_NODE_DRAW_SETUP();
}
break;
2013-06-07 10:52:32 +08:00
}
}
2013-09-13 18:07:37 +08:00
else if(Node *node = dynamic_cast<Node *>(object))
2013-06-07 10:52:32 +08:00
{
node->visit();
CC_NODE_DRAW_SETUP();
}
}
2013-06-06 12:02:54 +08:00
}
2013-09-13 18:07:37 +08:00
void Armature::visit()
2013-06-06 12:02:54 +08:00
{
2013-06-07 10:52:32 +08:00
// quick return if not visible. children won't be drawn.
if (!_visible)
2013-06-07 10:52:32 +08:00
{
return;
}
kmGLPushMatrix();
if (_grid && _grid->isActive())
2013-06-07 10:52:32 +08:00
{
_grid->beforeDraw();
2013-06-07 10:52:32 +08:00
}
transform();
sortAllChildren();
draw();
// reset for next frame
_orderOfArrival = 0;
2013-06-07 10:52:32 +08:00
if (_grid && _grid->isActive())
2013-06-07 10:52:32 +08:00
{
_grid->afterDraw(this);
2013-06-07 10:52:32 +08:00
}
kmGLPopMatrix();
2013-06-06 12:02:54 +08:00
}
Rect Armature::getBoundingBox() const
2013-06-06 12:02:54 +08:00
{
2013-06-07 10:52:32 +08:00
float minx, miny, maxx, maxy = 0;
bool first = true;
Rect boundingBox = Rect(0, 0, 0, 0);
2013-06-07 10:52:32 +08:00
2013-12-18 22:07:33 +08:00
for_each(_children.begin(), _children.end(), [&minx, &miny, &maxx, &maxy, &first, &boundingBox](Node *object)
2013-06-07 10:52:32 +08:00
{
if (Bone *bone = dynamic_cast<Bone *>(object))
2013-06-07 10:52:32 +08:00
{
2013-09-13 18:07:37 +08:00
Rect r = bone->getDisplayManager()->getBoundingBox();
2013-06-07 10:52:32 +08:00
2013-09-13 18:07:37 +08:00
if(first)
{
minx = r.getMinX();
miny = r.getMinY();
maxx = r.getMaxX();
maxy = r.getMaxY();
2013-06-07 10:52:32 +08:00
2013-09-13 18:07:37 +08:00
first = false;
}
else
{
minx = r.getMinX() < boundingBox.getMinX() ? r.getMinX() : boundingBox.getMinX();
miny = r.getMinY() < boundingBox.getMinY() ? r.getMinY() : boundingBox.getMinY();
maxx = r.getMaxX() > boundingBox.getMaxX() ? r.getMaxX() : boundingBox.getMaxX();
maxy = r.getMaxY() > boundingBox.getMaxY() ? r.getMaxY() : boundingBox.getMaxY();
}
boundingBox.setRect(minx, miny, maxx - minx, maxy - miny);
}
2013-12-18 22:07:33 +08:00
});
2013-06-07 10:52:32 +08:00
2013-12-11 03:07:15 +08:00
return RectApplyTransform(boundingBox, getNodeToParentTransform());
2013-06-06 12:02:54 +08:00
}
2013-11-05 19:53:38 +08:00
Bone *Armature::getBoneAtPoint(float x, float y) const
2013-06-06 12:02:54 +08:00
{
long length = _children.size();
Bone *bs;
2013-06-07 10:52:32 +08:00
for(long i = length - 1; i >= 0; i--)
2013-06-06 12:02:54 +08:00
{
bs = static_cast<Bone*>( _children.at(i) );
if(bs->getDisplayManager()->containPoint(x, y))
2013-06-06 12:02:54 +08:00
{
return bs;
2013-06-06 12:02:54 +08:00
}
2013-06-07 10:52:32 +08:00
}
return nullptr;
2013-06-06 12:02:54 +08:00
}
2013-10-30 09:41:40 +08:00
void Armature::setParentBone(Bone *parentBone)
{
_parentBone = parentBone;
2013-12-18 22:07:33 +08:00
for (auto& element : _boneDic)
2013-10-30 09:41:40 +08:00
{
element.second->setArmature(this);
2013-10-30 09:41:40 +08:00
}
}
2013-11-05 19:53:38 +08:00
Bone *Armature::getParentBone() const
2013-10-30 09:41:40 +08:00
{
return _parentBone;
}
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT
2013-11-01 14:36:44 +08:00
void CCArmature::setColliderFilter(ColliderFilter *filter)
{
2013-12-18 22:07:33 +08:00
for (auto& element : _boneDic)
2013-11-01 14:36:44 +08:00
{
element.second->setColliderFilter(filter);
2013-11-01 14:36:44 +08:00
}
}
#elif ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
void CCArmature::drawContour()
{
2013-12-18 22:07:33 +08:00
for(auto& element : _boneDic)
{
Bone *bone = element.second;
ColliderDetector *detector = bone->getColliderDetector();
if (!detector)
continue;
const cocos2d::Vector<ColliderBody*>& bodyList = detector->getColliderBodyList();
2013-12-18 22:07:33 +08:00
for (auto& object : bodyList)
{
ColliderBody *body = static_cast<ColliderBody*>(object);
2013-12-17 19:32:16 +08:00
const std::vector<Point> &vertexList = body->getCalculatedVertexList();
2013-12-17 19:32:16 +08:00
unsigned long length = vertexList.size();
Point *points = new Point[length];
2013-12-17 19:32:16 +08:00
for (unsigned long i = 0; i<length; i++)
{
2013-12-17 19:32:16 +08:00
Point p = vertexList.at(i);
2013-12-13 19:40:38 +08:00
points[i].x = p.x;
points[i].y = p.y;
}
2013-12-17 19:32:16 +08:00
DrawPrimitives::drawPoly( points, (unsigned int)length, true );
delete points;
}
}
}
#endif
2013-11-01 14:36:44 +08:00
2013-09-13 18:07:37 +08:00
#if ENABLE_PHYSICS_BOX2D_DETECT
2013-11-05 19:53:38 +08:00
b2Body *Armature::getBody() const
2013-09-13 18:07:37 +08:00
{
2013-09-15 20:24:25 +08:00
return _body;
2013-09-13 18:07:37 +08:00
}
void Armature::setBody(b2Body *body)
2013-09-13 18:07:37 +08:00
{
2013-09-15 20:24:25 +08:00
if (_body == body)
2013-09-13 18:07:37 +08:00
{
return;
}
2013-09-15 20:24:25 +08:00
_body = body;
_body->SetUserData(this);
2013-09-13 18:07:37 +08:00
2013-12-18 22:36:10 +08:00
for(auto& object : _children)
2013-09-13 18:07:37 +08:00
{
if (Bone *bone = dynamic_cast<Bone *>(object))
2013-09-13 18:07:37 +08:00
{
2013-12-18 22:36:10 +08:00
auto displayList = bone->getDisplayManager()->getDecorativeDisplayList();
2013-09-13 18:07:37 +08:00
for(auto displayObject : displayList)
2013-09-13 18:07:37 +08:00
{
ColliderDetector *detector = static_cast<DecorativeDisplay *>(displayObject)->getColliderDetector();
if (detector != nullptr)
2013-09-13 18:07:37 +08:00
{
2013-09-15 20:24:25 +08:00
detector->setBody(_body);
2013-09-13 18:07:37 +08:00
}
}
}
}
}
b2Fixture *Armature::getShapeList()
2013-09-13 18:07:37 +08:00
{
2013-09-15 20:24:25 +08:00
if (_body)
2013-09-13 18:07:37 +08:00
{
2013-09-15 20:24:25 +08:00
return _body->GetFixtureList();
2013-09-13 18:07:37 +08:00
}
else
{
return nullptr;
2013-09-13 18:07:37 +08:00
}
}
#elif ENABLE_PHYSICS_CHIPMUNK_DETECT
2013-11-05 19:53:38 +08:00
cpBody *Armature::getBody() const
2013-09-13 18:07:37 +08:00
{
2013-09-15 20:24:25 +08:00
return _body;
2013-09-13 18:07:37 +08:00
}
void Armature::setBody(cpBody *body)
2013-09-13 18:07:37 +08:00
{
2013-09-15 20:24:25 +08:00
if (_body == body)
2013-09-13 18:07:37 +08:00
{
return;
}
2013-09-15 20:24:25 +08:00
_body = body;
_body->data = this;
2013-09-13 18:07:37 +08:00
2013-12-18 22:07:33 +08:00
for (auto& object : _children)
2013-09-13 18:07:37 +08:00
{
if (Bone *bone = dynamic_cast<Bone *>(object))
2013-09-13 18:07:37 +08:00
{
2013-12-18 22:36:10 +08:00
auto displayList = bone->getDisplayManager()->getDecorativeDisplayList();
2013-09-13 18:07:37 +08:00
2013-12-18 22:36:10 +08:00
for_each(displayList.begin(), displayList.end(), [&body](DecorativeDisplay* displayObject)
2013-09-13 18:07:37 +08:00
{
2013-12-18 22:07:33 +08:00
ColliderDetector *detector = displayObject->getColliderDetector();
if (detector != nullptr)
2013-09-13 18:07:37 +08:00
{
2013-12-18 22:36:10 +08:00
detector->setBody(body);
2013-09-13 18:07:37 +08:00
}
2013-12-18 22:07:33 +08:00
});
2013-09-13 18:07:37 +08:00
}
}
}
cpShape *Armature::getShapeList()
2013-09-13 18:07:37 +08:00
{
2013-09-15 20:24:25 +08:00
if (_body)
2013-09-13 18:07:37 +08:00
{
2013-09-15 20:24:25 +08:00
return _body->shapeList_private;
2013-09-13 18:07:37 +08:00
}
else
{
return nullptr;
2013-09-13 18:07:37 +08:00
}
}
#endif
}