modify getAABBRecursively

This commit is contained in:
yangxiao 2015-04-08 16:40:04 +08:00
parent 3b01222787
commit a7a39d71f5
2 changed files with 28 additions and 9 deletions

View File

@ -820,6 +820,22 @@ const BlendFunc& Sprite3D::getBlendFunc() const
return _blend; return _blend;
} }
AABB Sprite3D::getAABBRecursively()
{
AABB aabb;
const Vector<Node*>& children = getChildren();
for (const auto& iter : children)
{
Sprite3D* child = dynamic_cast<Sprite3D*>(iter);
if(child)
{
aabb.merge(child->getAABBRecursively());
}
}
aabb.merge(getAABB());
return aabb;
}
const AABB& Sprite3D::getAABB() const const AABB& Sprite3D::getAABB() const
{ {
Mat4 nodeToWorldTransform(getNodeToWorldTransform()); Mat4 nodeToWorldTransform(getNodeToWorldTransform());
@ -832,15 +848,18 @@ const AABB& Sprite3D::getAABB() const
else else
{ {
_aabb.reset(); _aabb.reset();
Mat4 transform(nodeToWorldTransform); if (_meshes.size())
for (const auto& it : _meshes) { {
if (it->isVisible()) Mat4 transform(nodeToWorldTransform);
_aabb.merge(it->getAABB()); for (const auto& it : _meshes) {
if (it->isVisible())
_aabb.merge(it->getAABB());
}
_aabb.transform(transform);
_nodeToWorldTransform = nodeToWorldTransform;
_aabbDirty = false;
} }
_aabb.transform(transform);
_nodeToWorldTransform = nodeToWorldTransform;
_aabbDirty = false;
} }
return _aabb; return _aabb;

View File

@ -141,7 +141,7 @@ public:
* the Sprite3D don't contain any meshes, so getAABB() * the Sprite3D don't contain any meshes, so getAABB()
* will return a wrong value at that time. * will return a wrong value at that time.
*/ */
const AABB& getAABBRecursively(); AABB getAABBRecursively();
/** /**
* Executes an action, and returns the action that is executed. For Sprite3D special logic are needed to take care of Fading. * Executes an action, and returns the action that is executed. For Sprite3D special logic are needed to take care of Fading.