diff --git a/src/DebugTools/Implementation/AbstractShapeRenderer.h b/src/DebugTools/Implementation/AbstractShapeRenderer.h index 4670c0d5d..a20134871 100644 --- a/src/DebugTools/Implementation/AbstractShapeRenderer.h +++ b/src/DebugTools/Implementation/AbstractShapeRenderer.h @@ -31,9 +31,15 @@ #include "Shaders/Shaders.h" #include "Trade/Trade.h" -namespace Magnum { namespace DebugTools { namespace Implementation { +namespace Magnum { -template struct MeshData; +namespace Physics { namespace Implementation { + template struct AbstractShape; +}} + +namespace DebugTools { namespace Implementation { + +template struct MeshData; template<> struct MeshData<2> { typedef Trade::MeshData2D Type; }; template<> struct MeshData<3> { typedef Trade::MeshData3D Type; }; diff --git a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp index daaa4673e..00ac739f6 100644 --- a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp +++ b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp @@ -31,12 +31,12 @@ namespace Magnum { namespace DebugTools { namespace Implementation { -template AxisAlignedBoxRenderer::AxisAlignedBoxRenderer(Physics::AxisAlignedBox& axisAlignedBox): axisAlignedBox(axisAlignedBox) {} +template AxisAlignedBoxRenderer::AxisAlignedBoxRenderer(const Physics::Implementation::AbstractShape* axisAlignedBox): axisAlignedBox(static_cast>*>(axisAlignedBox)->shape) {} template void AxisAlignedBoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) { this->wireframeShader->setTransformationProjectionMatrix(projectionMatrix* - DimensionTraits::MatrixType::translation((axisAlignedBox.transformedMin()+axisAlignedBox.transformedMax())/2)* - DimensionTraits::MatrixType::scaling(axisAlignedBox.transformedMax()-axisAlignedBox.transformedMin())) + DimensionTraits::MatrixType::translation((axisAlignedBox.min()+axisAlignedBox.max())/2)* + DimensionTraits::MatrixType::scaling(axisAlignedBox.max()-axisAlignedBox.min())) ->setColor(options->color()) ->use(); this->wireframeMesh->draw(); diff --git a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.h b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.h index 9247fa2a1..fe59ca713 100644 --- a/src/DebugTools/Implementation/AxisAlignedBoxRenderer.h +++ b/src/DebugTools/Implementation/AxisAlignedBoxRenderer.h @@ -34,12 +34,12 @@ namespace Magnum { namespace DebugTools { namespace Implementation { template class AxisAlignedBoxRenderer: public AbstractBoxRenderer { public: - AxisAlignedBoxRenderer(Physics::AxisAlignedBox& axisAlignedBox); + AxisAlignedBoxRenderer(const Physics::Implementation::AbstractShape* axisAlignedBox); void draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) override; private: - Physics::AxisAlignedBox& axisAlignedBox; + const Physics::AxisAlignedBox& axisAlignedBox; }; }}} diff --git a/src/DebugTools/Implementation/BoxRenderer.cpp b/src/DebugTools/Implementation/BoxRenderer.cpp index a39356a91..4b515883b 100644 --- a/src/DebugTools/Implementation/BoxRenderer.cpp +++ b/src/DebugTools/Implementation/BoxRenderer.cpp @@ -31,10 +31,10 @@ namespace Magnum { namespace DebugTools { namespace Implementation { -template BoxRenderer::BoxRenderer(Physics::Box& box): box(box) {} +template BoxRenderer::BoxRenderer(const Physics::Implementation::AbstractShape* box): box(static_cast>*>(box)->shape) {} template void BoxRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) { - this->wireframeShader->setTransformationProjectionMatrix(projectionMatrix*box.transformedTransformation()) + this->wireframeShader->setTransformationProjectionMatrix(projectionMatrix*box.transformation()) ->setColor(options->color()) ->use(); this->wireframeMesh->draw(); diff --git a/src/DebugTools/Implementation/BoxRenderer.h b/src/DebugTools/Implementation/BoxRenderer.h index 90b459113..0f93b9a4a 100644 --- a/src/DebugTools/Implementation/BoxRenderer.h +++ b/src/DebugTools/Implementation/BoxRenderer.h @@ -34,12 +34,12 @@ namespace Magnum { namespace DebugTools { namespace Implementation { template class BoxRenderer: public AbstractBoxRenderer { public: - BoxRenderer(Physics::Box& box); + BoxRenderer(const Physics::Implementation::AbstractShape* box); void draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) override; private: - Physics::Box& box; + const Physics::Box& box; }; }}} diff --git a/src/DebugTools/Implementation/LineSegmentRenderer.cpp b/src/DebugTools/Implementation/LineSegmentRenderer.cpp index 5ef695b9c..51fc909ad 100644 --- a/src/DebugTools/Implementation/LineSegmentRenderer.cpp +++ b/src/DebugTools/Implementation/LineSegmentRenderer.cpp @@ -26,7 +26,7 @@ #include "Mesh.h" #include "DebugTools/ShapeRenderer.h" -#include "Physics/Line.h" +#include "Physics/LineSegment.h" #include "Primitives/Line.h" #include "Shaders/Flat.h" #include "Trade/MeshData2D.h" @@ -50,13 +50,13 @@ namespace { template<> inline Trade::MeshData3D meshData<3>() { return Primitives::Line3D::wireframe(); } } -template LineSegmentRenderer::LineSegmentRenderer(Physics::Line& line): AbstractShapeRenderer(meshKey(), vertexBufferKey(), {}), line(line) { +template LineSegmentRenderer::LineSegmentRenderer(const Physics::Implementation::AbstractShape* line): AbstractShapeRenderer(meshKey(), vertexBufferKey(), {}), line(static_cast>*>(line)->shape) { if(!this->wireframeMesh) this->createResources(meshData()); } template void LineSegmentRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) { this->wireframeShader->setTransformationProjectionMatrix(projectionMatrix* - Implementation::lineSegmentRendererTransformation(line.transformedA(), line.transformedB())) + Implementation::lineSegmentRendererTransformation(line.a(), line.b())) ->setColor(options->color()) ->use(); this->wireframeMesh->draw(); diff --git a/src/DebugTools/Implementation/LineSegmentRenderer.h b/src/DebugTools/Implementation/LineSegmentRenderer.h index a67208825..2152cefd3 100644 --- a/src/DebugTools/Implementation/LineSegmentRenderer.h +++ b/src/DebugTools/Implementation/LineSegmentRenderer.h @@ -34,12 +34,12 @@ namespace Magnum { namespace DebugTools { namespace Implementation { template class LineSegmentRenderer: public AbstractShapeRenderer { public: - LineSegmentRenderer(Physics::Line& line); + LineSegmentRenderer(const Physics::Implementation::AbstractShape* line); void draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) override; private: - Physics::Line& line; + const Physics::LineSegment& line; }; }}} diff --git a/src/DebugTools/Implementation/PointRenderer.cpp b/src/DebugTools/Implementation/PointRenderer.cpp index de84bcd2a..c1799ac64 100644 --- a/src/DebugTools/Implementation/PointRenderer.cpp +++ b/src/DebugTools/Implementation/PointRenderer.cpp @@ -48,14 +48,14 @@ namespace { template<> inline Trade::MeshData3D meshData<3>() { return Primitives::Crosshair3D::wireframe(); } } -template PointRenderer::PointRenderer(Physics::Point& point): AbstractShapeRenderer(meshKey(), vertexBufferKey(), {}), point(point) { +template PointRenderer::PointRenderer(const Physics::Implementation::AbstractShape* point): AbstractShapeRenderer(meshKey(), vertexBufferKey(), {}), point(static_cast>*>(point)->shape) { if(!this->wireframeMesh) this->createResources(meshData()); } template void PointRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) { /* Half scale, because the point is 2x2(x2) */ this->wireframeShader->setTransformationProjectionMatrix(projectionMatrix* - DimensionTraits::MatrixType::translation(point.transformedPosition())* + DimensionTraits::MatrixType::translation(point.position())* DimensionTraits::MatrixType::scaling(typename DimensionTraits::VectorType(options->pointSize()/2))) ->setColor(options->color()) ->use(); diff --git a/src/DebugTools/Implementation/PointRenderer.h b/src/DebugTools/Implementation/PointRenderer.h index 4ac4c78c7..4aeea85b9 100644 --- a/src/DebugTools/Implementation/PointRenderer.h +++ b/src/DebugTools/Implementation/PointRenderer.h @@ -34,12 +34,12 @@ namespace Magnum { namespace DebugTools { namespace Implementation { template class PointRenderer: public AbstractShapeRenderer { public: - PointRenderer(Physics::Point& point); + PointRenderer(const Physics::Implementation::AbstractShape* point); void draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) override; private: - Physics::Point& point; + const Physics::Point& point; }; }}} diff --git a/src/DebugTools/Implementation/SphereRenderer.cpp b/src/DebugTools/Implementation/SphereRenderer.cpp index a45bc12ee..859fe6120 100644 --- a/src/DebugTools/Implementation/SphereRenderer.cpp +++ b/src/DebugTools/Implementation/SphereRenderer.cpp @@ -37,12 +37,12 @@ AbstractSphereRenderer<2>::AbstractSphereRenderer(): AbstractShapeRenderer<2>("s if(!wireframeMesh) createResources(Primitives::Circle::wireframe(40)); } -template SphereRenderer::SphereRenderer(Physics::Sphere& sphere): sphere(sphere) {} +template SphereRenderer::SphereRenderer(const Physics::Implementation::AbstractShape* sphere): sphere(static_cast>*>(sphere)->shape) {} template void SphereRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) { this->wireframeShader->setTransformationProjectionMatrix(projectionMatrix* - DimensionTraits::MatrixType::translation(sphere.transformedPosition())* - DimensionTraits::MatrixType::scaling(typename DimensionTraits::VectorType(sphere.transformedRadius()))) + DimensionTraits::MatrixType::translation(sphere.position())* + DimensionTraits::MatrixType::scaling(typename DimensionTraits::VectorType(sphere.radius()))) ->setColor(options->color()) ->use(); this->wireframeMesh->draw(); diff --git a/src/DebugTools/Implementation/SphereRenderer.h b/src/DebugTools/Implementation/SphereRenderer.h index e7cf52922..4822ee899 100644 --- a/src/DebugTools/Implementation/SphereRenderer.h +++ b/src/DebugTools/Implementation/SphereRenderer.h @@ -41,12 +41,12 @@ template<> class AbstractSphereRenderer<2>: public AbstractShapeRenderer<2> { template class SphereRenderer: public AbstractSphereRenderer { public: - SphereRenderer(Physics::Sphere& sphere); + SphereRenderer(const Physics::Implementation::AbstractShape* sphere); void draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) override; private: - Physics::Sphere& sphere; + const Physics::Sphere& sphere; }; }}} diff --git a/src/DebugTools/ShapeRenderer.cpp b/src/DebugTools/ShapeRenderer.cpp index 7bf36b95c..fe02f6a56 100644 --- a/src/DebugTools/ShapeRenderer.cpp +++ b/src/DebugTools/ShapeRenderer.cpp @@ -25,14 +25,8 @@ #include "ShapeRenderer.h" #include "ResourceManager.h" -#include "Physics/AbstractShape.h" -#include "Physics/AxisAlignedBox.h" -#include "Physics/Box.h" #include "Physics/ObjectShape.h" -#include "Physics/LineSegment.h" -#include "Physics/Point.h" #include "Physics/ShapeGroup.h" -#include "Physics/Sphere.h" #include "SceneGraph/AbstractCamera.h" #include "Implementation/AxisAlignedBoxRenderer.h" @@ -45,51 +39,53 @@ namespace Magnum { namespace DebugTools { namespace Implementation { -template<> void createDebugMesh(ShapeRenderer<2>* renderer, Physics::AbstractShape<2>* shape) { +template<> void createDebugMesh(ShapeRenderer<2>* renderer, const Physics::Implementation::AbstractShape<2>* shape) { switch(shape->type()) { - case Physics::AbstractShape2D::Type::AxisAlignedBox: - renderer->renderers.push_back(new Implementation::AxisAlignedBoxRenderer<2>(*static_cast(shape))); + case Physics::AbstractObjectShape2D::Type::AxisAlignedBox: + renderer->renderers.push_back(new Implementation::AxisAlignedBoxRenderer<2>(shape)); break; - case Physics::AbstractShape2D::Type::Box: - renderer->renderers.push_back(new Implementation::BoxRenderer<2>(*static_cast(shape))); + case Physics::AbstractObjectShape2D::Type::Box: + renderer->renderers.push_back(new Implementation::BoxRenderer<2>(shape)); break; - case Physics::AbstractShape2D::Type::LineSegment: - renderer->renderers.push_back(new Implementation::LineSegmentRenderer<2>(*static_cast(shape))); + case Physics::AbstractObjectShape2D::Type::LineSegment: + renderer->renderers.push_back(new Implementation::LineSegmentRenderer<2>(shape)); break; - case Physics::AbstractShape2D::Type::Point: - renderer->renderers.push_back(new Implementation::PointRenderer<2>(*static_cast(shape))); + case Physics::AbstractObjectShape2D::Type::Point: + renderer->renderers.push_back(new Implementation::PointRenderer<2>(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()); + case Physics::AbstractObjectShape2D::Type::ShapeGroup: { + const Physics::ShapeGroup2D& group = + static_cast*>(shape)->shape; + for(std::size_t i = 0; i != group.size(); ++i) + createDebugMesh(renderer, Physics::Implementation::getAbstractShape(group, i)); } break; - case Physics::AbstractShape2D::Type::Sphere: - renderer->renderers.push_back(new Implementation::SphereRenderer<2>(*static_cast(shape))); + case Physics::AbstractObjectShape2D::Type::Sphere: + renderer->renderers.push_back(new Implementation::SphereRenderer<2>(shape)); break; default: Warning() << "DebugTools::ShapeRenderer2D::createShapeRenderer(): type" << shape->type() << "not implemented"; } } -template<> void createDebugMesh(ShapeRenderer<3>* renderer, Physics::AbstractShape<3>* shape) { +template<> void createDebugMesh(ShapeRenderer<3>* renderer, const Physics::Implementation::AbstractShape<3>* shape) { switch(shape->type()) { - case Physics::AbstractShape3D::Type::AxisAlignedBox: - renderer->renderers.push_back(new Implementation::AxisAlignedBoxRenderer<3>(*static_cast(shape))); + case Physics::AbstractObjectShape3D::Type::AxisAlignedBox: + renderer->renderers.push_back(new Implementation::AxisAlignedBoxRenderer<3>(shape)); break; - case Physics::AbstractShape3D::Type::Box: - renderer->renderers.push_back(new Implementation::BoxRenderer<3>(*static_cast(shape))); + case Physics::AbstractObjectShape3D::Type::Box: + renderer->renderers.push_back(new Implementation::BoxRenderer<3>(shape)); break; - case Physics::AbstractShape3D::Type::LineSegment: - renderer->renderers.push_back(new Implementation::LineSegmentRenderer<3>(*static_cast(shape))); + case Physics::AbstractObjectShape3D::Type::LineSegment: + renderer->renderers.push_back(new Implementation::LineSegmentRenderer<3>(shape)); break; - case Physics::AbstractShape3D::Type::Point: - renderer->renderers.push_back(new Implementation::PointRenderer<3>(*static_cast(shape))); + case Physics::AbstractObjectShape3D::Type::Point: + renderer->renderers.push_back(new Implementation::PointRenderer<3>(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()); + case Physics::AbstractObjectShape3D::Type::ShapeGroup: { + const Physics::ShapeGroup3D& group = + static_cast*>(shape)->shape; + for(std::size_t i = 0; i != group.size(); ++i) + createDebugMesh(renderer, Physics::Implementation::getAbstractShape(group, i)); } break; default: Warning() << "DebugTools::ShapeRenderer3D::createShapeRenderer(): type" << shape->type() << "not implemented"; @@ -98,9 +94,8 @@ template<> void createDebugMesh(ShapeRenderer<3>* renderer, Physics::AbstractSha } -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(Physics::AbstractObjectShape* shape, ResourceKey options, SceneGraph::DrawableGroup* drawables): SceneGraph::Drawable(shape->object(), drawables), options(ResourceManager::instance()->get(options)) { + Implementation::createDebugMesh(this, Physics::Implementation::getAbstractShape(shape)); } template ShapeRenderer::~ShapeRenderer() { diff --git a/src/DebugTools/ShapeRenderer.h b/src/DebugTools/ShapeRenderer.h index d52d20af2..378babba9 100644 --- a/src/DebugTools/ShapeRenderer.h +++ b/src/DebugTools/ShapeRenderer.h @@ -32,6 +32,7 @@ #include "Resource.h" #include "SceneGraph/Drawable.h" #include "Physics/Physics.h" +#include "Physics/shapeImplementation.h" #include "magnumDebugToolsVisibility.h" @@ -45,7 +46,7 @@ template class ShapeRenderer; namespace Implementation { template class AbstractShapeRenderer; - template void createDebugMesh(ShapeRenderer* renderer, Physics::AbstractShape* shape); + template void createDebugMesh(ShapeRenderer* renderer, const Physics::Implementation::AbstractShape* shape); } /** @@ -138,7 +139,7 @@ new DebugTools::ShapeRenderer2D(shape, "red", debugDrawables); @see ShapeRenderer2D, ShapeRenderer3D */ template class MAGNUM_DEBUGTOOLS_EXPORT ShapeRenderer: public SceneGraph::Drawable { - friend void Implementation::createDebugMesh<>(ShapeRenderer*, Physics::AbstractShape*); + friend void Implementation::createDebugMesh<>(ShapeRenderer*, const Physics::Implementation::AbstractShape*); public: /** @@ -150,11 +151,10 @@ template class MAGNUM_DEBUGTOOLS_EXPORT ShapeRenderer: p * @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. - * - * @attention Passed object must have assigned shape. + * @p shape must be available for the whole lifetime of the renderer + * and if it is group, it must not change its internal structure. */ - explicit ShapeRenderer(Physics::ObjectShape* shape, ResourceKey options = ResourceKey(), SceneGraph::DrawableGroup* drawables = nullptr); + explicit ShapeRenderer(Physics::AbstractObjectShape* shape, ResourceKey options = ResourceKey(), SceneGraph::DrawableGroup* drawables = nullptr); ~ShapeRenderer();