Skip to content

Commit

Permalink
GRAPHICS: Add Renderable::getSize()
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Feb 4, 2014
1 parent 13e222c commit bdf751f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/graphics/renderable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,33 @@ 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]);
}

void Renderable::getPosition(float &x, float &y, float &z) const {
const Ogre::Vector3 &p = _rootNode->getPosition();

Expand Down
5 changes: 5 additions & 0 deletions src/graphics/renderable.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class Renderable {
/** Set the base scale. All scaling will be done relative to the base scale. */
void setBaseScale(float x, float y, float z);

/** Get the size of the renderable. */
void getSize(float &width, float &height, float &depth) const;

/** Get the current position of the renderable. */
virtual void getPosition(float &x, float &y, float &z) const;
/** Get the current orientation of the renderable. */
Expand Down Expand Up @@ -127,6 +130,8 @@ class Renderable {

private:
void destroy();

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

} // End of namespace Graphics
Expand Down

0 comments on commit bdf751f

Please sign in to comment.