/* Copyright © 2010, 2011, 2012 Vladimír Vondruš This file is part of Magnum. Magnum is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3 only, as published by the Free Software Foundation. Magnum is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License version 3 for more details. */ #include "ShapeRenderer.h" #include "ResourceManager.h" #include "Physics/AbstractShape.h" #include "Physics/AxisAlignedBox.h" #include "Physics/Box.h" #include "Physics/ObjectShape.h" #include "Physics/ShapeGroup.h" #include "Implementation/AxisAlignedBoxRenderer.h" #include "Implementation/BoxRenderer.h" namespace Magnum { namespace DebugTools { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { template<> void createDebugMesh(ShapeRenderer<2>* renderer, Physics::AbstractShape<2>* shape) { switch(shape->type()) { case Physics::AbstractShape2D::Type::AxisAlignedBox: renderer->renderers.push_back(new Implementation::AxisAlignedBoxRenderer<2>(*static_cast(shape))); case Physics::AbstractShape2D::Type::Box: renderer->renderers.push_back(new Implementation::BoxRenderer<2>(*static_cast(shape))); break; case Physics::AbstractShape2D::Type::ShapeGroup: { Physics::ShapeGroup2D* group = static_cast(shape); if(group->first()) createDebugMesh(renderer, group->first()); if(group->second()) createDebugMesh(renderer, group->second()); } break; default: Warning() << "DebugTools::ShapeRenderer2D::createShapeRenderer(): type" << shape->type() << "not implemented"; } } template<> void createDebugMesh(ShapeRenderer<3>* renderer, Physics::AbstractShape<3>* shape) { switch(shape->type()) { case Physics::AbstractShape3D::Type::AxisAlignedBox: renderer->renderers.push_back(new Implementation::AxisAlignedBoxRenderer<3>(*static_cast(shape))); case Physics::AbstractShape3D::Type::Box: renderer->renderers.push_back(new Implementation::BoxRenderer<3>(*static_cast(shape))); break; case Physics::AbstractShape3D::Type::ShapeGroup: { Physics::ShapeGroup3D* group = static_cast(shape); if(group->first()) createDebugMesh(renderer, group->first()); if(group->second()) createDebugMesh(renderer, group->second()); } break; default: Warning() << "DebugTools::ShapeRenderer3D::createShapeRenderer(): type" << shape->type() << "not implemented"; } } } #endif template ShapeRenderer::ShapeRenderer(Physics::ObjectShape* shape, ResourceKey options, SceneGraph::DrawableGroup* drawables): SceneGraph::Drawable(shape->object(), drawables), options(ResourceManager::instance()->get(options)) { CORRADE_ASSERT(shape->shape() != nullptr, "DebugTools::ShapeRenderer: cannot create renderer for empty shape", ); Implementation::createDebugMesh(this, shape->shape()); } template ShapeRenderer::~ShapeRenderer() { for(auto i: renderers) delete i; } template void ShapeRenderer::draw(const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractCamera* camera) { for(auto i: renderers) i->draw(options, transformationMatrix, camera); } template class ShapeRenderer<2>; template class ShapeRenderer<3>; }}