add getAABBRecursively

This commit is contained in:
lvlong 2015-04-03 18:04:33 +08:00
parent 591fff4046
commit 4c6eec9ec1
2 changed files with 35 additions and 8 deletions

View File

@ -820,6 +820,21 @@ const BlendFunc& Sprite3D::getBlendFunc() const
return _blend;
}
const AABB& Sprite3D::getAABBRecursively()
{
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
{
Mat4 nodeToWorldTransform(getNodeToWorldTransform());
@ -831,15 +846,19 @@ const AABB& Sprite3D::getAABB() const
}
else
{
_aabb.reset();
Mat4 transform(nodeToWorldTransform);
for (const auto& it : _meshes) {
if (it->isVisible())
_aabb.merge(it->getAABB());
if (_meshes.size() > 0)
{
_aabb.reset();
Mat4 transform(nodeToWorldTransform);
for (const auto& it : _meshes)
{
if (it->isVisible())
_aabb.merge(it->getAABB());
}
_aabb.transform(transform);
_nodeToWorldTransform = nodeToWorldTransform;
}
_aabb.transform(transform);
_nodeToWorldTransform = nodeToWorldTransform;
}
return _aabb;

View File

@ -126,6 +126,14 @@ public:
*/
const AABB& getAABB() const;
/*
* Get AABB Recursively
* Because some times we may have an empty Sprite3D Node as parent, but
* the Sprite3D don't contain any meshes, so getAABB()
* will return a wrong value at that time.
*/
const AABB& getAABBRecursively();
/**
* Executes an action, and returns the action that is executed. For Sprite3D special logic are needed to take care of Fading.
*