is there a better method for doing this?
Code: Select all
class CSDummySceneNode : public ISceneNode
{
public:
aabbox3d<f32> TotalBoundingBox;
CSDummySceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id = -1,
const core::vector3df& position = core::vector3df(0, 0, 0),
const core::vector3df& rotation = core::vector3df(0, 0, 0),
const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f))
: ISceneNode(parent, mgr, id, position, rotation, scale)
{
}
virtual void OnRegisterSceneNode()
{
if (IsVisible) SceneManager->registerNodeForRendering(this);
ISceneNode::OnRegisterSceneNode();
}
//! Renders the node.
virtual void render()
{
video::IVideoDriver* driver = SceneManager->getVideoDriver();
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
driver->setTransform(video::ETS_WORLD, IdentityMatrix);
// for debug purposes only:
video::SMaterial mat;
// overwrite half transparency
if (DebugDataVisible & scene::EDS_HALF_TRANSPARENCY)
mat.MaterialType = video::EMT_TRANSPARENT_ADD_COLOR;
driver->setMaterial(mat);
// for debug purposes only:
if (DebugDataVisible)
{
video::SMaterial m;
m.Lighting = false;
m.AntiAliasing = 0;
driver->setMaterial(m);
if (DebugDataVisible & scene::EDS_BBOX)
{
driver->draw3DBox(getTotalTransformedBoundingBox(), video::SColor(255, 255, 255, 255));
}
if (DebugDataVisible & scene::EDS_BBOX_BUFFERS)
{
driver->draw3DBox(getTotalTransformedBoundingBox(), video::SColor(255, 190, 128, 128));
}
}
}
virtual const core::aabbox3d<f32>& getBoundingBox() const
{
return aabbox3d<f32>(-1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f);
}
core::aabbox3d<f32> getTotalTransformedBoundingBoxRecursive(ISceneNode* node, aabbox3d<f32> &box)
{
ISceneNodeList::ConstIterator it = node->getChildren().begin();
for (; it != node->getChildren().end(); ++it)
{
aabbox3d<f32> box2 = (*it)->getTransformedBoundingBox();
if (!box2.isFullInside(box))
{
if (box2.MinEdge.X < box.MinEdge.X) box.MinEdge.X = box2.MinEdge.X;
if (box2.MinEdge.Y < box.MinEdge.Y) box.MinEdge.Y = box2.MinEdge.Y;
if (box2.MinEdge.Z < box.MinEdge.Z) box.MinEdge.Z = box2.MinEdge.Z;
if (box2.MaxEdge.X > box.MaxEdge.X) box.MaxEdge.X = box2.MaxEdge.X;
if (box2.MaxEdge.Y > box.MaxEdge.Y) box.MaxEdge.Y = box2.MaxEdge.Y;
if (box2.MaxEdge.Z > box.MaxEdge.Z) box.MaxEdge.Z = box2.MaxEdge.Z;
}
box = getTotalTransformedBoundingBoxRecursive((*it), box);
}
return box;
}
core::aabbox3d<f32> getTotalTransformedBoundingBox()
{
aabbox3d<f32> box(-0.5,-0.5,-0.5,.5,.5,.5);
box = getTotalTransformedBoundingBoxRecursive(this, box);
return box;
}
};