#ifndef Magnum_DebugTools_ShapeRenderer_h #define Magnum_DebugTools_ShapeRenderer_h /* 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 "Color.h" #include "Resource.h" #include "SceneGraph/Drawable.h" #include "Physics/Physics.h" #include "magnumDebugToolsVisibility.h" namespace Magnum { namespace DebugTools { template class ShapeRenderer; #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { template class AbstractShapeRenderer; template void createDebugMesh(ShapeRenderer* renderer, Physics::AbstractShape* shape); } #endif /** @brief Shape renderer options See ShapeRenderer documentation for more information. */ class ShapeRendererOptions { public: /** @brief Color of rendered shape */ inline constexpr Color3<> color() const { return _color; } /** * @brief Set color of rendered shape * @return Pointer to self (for method chaining) * * Default is black. */ inline ShapeRendererOptions* setColor(const Color3<>& color) { _color = color; return this; } private: Color3<> _color; }; /** @brief Shape renderer Visualizes collision shape. @section ShapeRenderer-usage Basic usage ResourceManager must be instanced for the whole lifetime of debug renderers. You can specify options via ShapeRendererOptions struct - add it to the manager and then create debug renderer with the same options key. This way you can easily share the same options with more renderers. If no options for given key exist, default is used. Example code: @code // Instance the manager at first DebugTools::ResourceManager manager; // Group of drawables, preferrably dedicated for debug renderers, so you can // easily enable or disable debug draw SceneGraph::DrawableGroup2D debugDrawables; // Create some options DebugTools::ResourceManager::instance()->set("red", (new DebugTools::ShapeRendererOptions())->setColor({1.0f, 0.0f, 0.0f}), ResourceDataState::Final, ResourcePolicy::Persistent); // Create debug renderer for given shape, use "red" options for it Physics::ObjectShape2D* shape; new DebugTools::ShapeRenderer2D(shape, "red", debugDrawables); @endcode @see ShapeRenderer2D, ShapeRenderer3D */ template class MAGNUM_DEBUGTOOLS_EXPORT ShapeRenderer: public SceneGraph::Drawable { #ifndef DOXYGEN_GENERATING_OUTPUT friend void Implementation::createDebugMesh<>(ShapeRenderer*, Physics::AbstractShape*); #endif public: /** * @brief Constructor * @param shape Shape for which to create debug renderer * @param options Options resource key. See * @ref ShapeRenderer-usage "class documentation" for more * information. * @param drawables Drawable group * * The renderer is automatically added to shape's object features, * @p shape must be available for the whole lifetime of the renderer. */ explicit ShapeRenderer(Physics::ObjectShape* shape, ResourceKey options = ResourceKey(), SceneGraph::DrawableGroup* drawables = nullptr); ~ShapeRenderer(); protected: /** @todoc Remove GLfloat when Doxygen properly treats this as override */ void draw(const typename DimensionTraits::MatrixType& transformationMatrix, SceneGraph::AbstractCamera* camera) override; private: Resource options; std::vector*> renderers; }; /** @brief Two-dimensional shape renderer */ typedef ShapeRenderer<2> ShapeRenderer2D; /** @brief Three-dimensional shape renderer */ typedef ShapeRenderer<3> ShapeRenderer3D; }} #endif