Skip to content

Commit

Permalink
GRAPHICS: Add getNodeSize()
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Mar 21, 2014
1 parent a14220f commit af34baf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
52 changes: 28 additions & 24 deletions src/graphics/renderable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,31 +169,8 @@ void Renderable::setBaseScale(float x, float y, float z) {
setScale(1.0, 1.0, 1.0);
}

void Renderable::addBoundBox(Ogre::AxisAlignedBox &bound, const Ogre::SceneNode &node) {
// Move all attached visible objects into the bounding box
for (Ogre::SceneNode::ConstObjectIterator o = node.getAttachedObjectIterator(); o.hasMoreElements(); o.moveNext())
bound.merge(o.current()->second->getWorldBoundingBox(true));

// Recurse into the child nodes
for (Ogre::Node::ConstChildNodeIterator c = node.getChildIterator(); c.hasMoreElements(); c.moveNext())
addBoundBox(bound, *((Ogre::SceneNode *) c.current()->second));
}

void Renderable::getSize(float &width, float &height, float &depth) const {
if (!_rootNode) {
width = height = depth = 0.0;
return;
}

Ogre::AxisAlignedBox bound;
addBoundBox(bound, *_rootNode);

const Ogre::Vector3 &min = bound.getMinimum();
const Ogre::Vector3 &max = bound.getMaximum();

width = ABS(max[0] - min[0]);
height = ABS(max[1] - min[1]);
depth = ABS(max[2] - min[2]);
getNodeSize(_rootNode, width, height, depth);
}

void Renderable::getPosition(float &x, float &y, float &z) const {
Expand Down Expand Up @@ -298,4 +275,31 @@ void Renderable::destroyAnimation(Ogre::Animation *anim) {
destroyAnimation(anim->getName().c_str());
}

static void addBoundBox(Ogre::AxisAlignedBox &bound, const Ogre::SceneNode &node) {
// Move all attached visible objects into the bounding box
for (Ogre::SceneNode::ConstObjectIterator o = node.getAttachedObjectIterator(); o.hasMoreElements(); o.moveNext())
bound.merge(o.current()->second->getWorldBoundingBox(true));

// Recurse into the child nodes
for (Ogre::Node::ConstChildNodeIterator c = node.getChildIterator(); c.hasMoreElements(); c.moveNext())
addBoundBox(bound, *((Ogre::SceneNode *) c.current()->second));
}

void getNodeSize(Ogre::SceneNode *node, float &width, float &height, float &depth) {
if (!node) {
width = height = depth = 0.0;
return;
}

Ogre::AxisAlignedBox bound;
addBoundBox(bound, *node);

const Ogre::Vector3 &min = bound.getMinimum();
const Ogre::Vector3 &max = bound.getMaximum();

width = ABS(max[0] - min[0]);
height = ABS(max[1] - min[1]);
depth = ABS(max[2] - min[2]);
}

} // End of namespace Graphics
5 changes: 3 additions & 2 deletions src/graphics/renderable.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,11 @@ class Renderable {

private:
void destroy();

static void addBoundBox(Ogre::AxisAlignedBox &bound, const Ogre::SceneNode &node);
};

/** Get the size of a SceneNode. */
void getNodeSize(Ogre::SceneNode *node, float &width, float &height, float &depth);

} // End of namespace Graphics

#endif // GRAPHICS_RENDERABLE_H

0 comments on commit af34baf

Please sign in to comment.