diff --git a/src/DebugTools/CMakeLists.txt b/src/DebugTools/CMakeLists.txt index 3f828e7dd..3c6f7ade9 100644 --- a/src/DebugTools/CMakeLists.txt +++ b/src/DebugTools/CMakeLists.txt @@ -7,7 +7,8 @@ set(MagnumDebugTools_SRCS Implementation/AbstractBoxRenderer.cpp Implementation/AbstractShapeRenderer.cpp Implementation/AxisAlignedBoxRenderer.cpp - Implementation/BoxRenderer.cpp) + Implementation/BoxRenderer.cpp + Implementation/PointRenderer.cpp) set(MagnumDebugTools_HEADERS DebugTools.h diff --git a/src/DebugTools/Implementation/PointRenderer.cpp b/src/DebugTools/Implementation/PointRenderer.cpp new file mode 100644 index 000000000..b13f9456b --- /dev/null +++ b/src/DebugTools/Implementation/PointRenderer.cpp @@ -0,0 +1,59 @@ +/* + 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 "PointRenderer.h" + +#include "Mesh.h" +#include "DebugTools/ShapeRenderer.h" +#include "Physics/Point.h" +#include "Primitives/Crosshair.h" +#include "Shaders/FlatShader.h" +#include "Trade/MeshData2D.h" +#include "Trade/MeshData3D.h" + +namespace Magnum { namespace DebugTools { namespace Implementation { + +namespace { + template ResourceKey meshKey(); + template<> inline ResourceKey meshKey<2>() { return ResourceKey("point2d"); } + template<> inline ResourceKey meshKey<3>() { return ResourceKey("point3d"); } + + template ResourceKey vertexBufferKey(); + template<> inline ResourceKey vertexBufferKey<2>() { return ResourceKey("point2d-vertices"); } + template<> inline ResourceKey vertexBufferKey<3>() { return ResourceKey("point3d-vertices"); } + + template typename MeshData::Type meshData(); + template<> inline Trade::MeshData2D meshData<2>() { return Primitives::Crosshair2D::wireframe(); } + template<> inline Trade::MeshData3D meshData<3>() { return Primitives::Crosshair3D::wireframe(); } +} + +template PointRenderer::PointRenderer(Physics::Point& point): AbstractShapeRenderer(meshKey(), vertexBufferKey(), {}), point(point) { + if(!this->mesh) this->createResources(meshData()); +} + +template void PointRenderer::draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) { + /* Half scale, because the point is 2x2(x2) */ + this->shader->setTransformationProjectionMatrix(projectionMatrix* + DimensionTraits::MatrixType::translation(point.transformedPosition())* + DimensionTraits::MatrixType::scaling(typename DimensionTraits::VectorType(options->pointSize()/2))) + ->setColor(options->color()) + ->use(); + this->mesh->draw(); +} + +template class PointRenderer<2>; +template class PointRenderer<3>; + +}}} diff --git a/src/DebugTools/Implementation/PointRenderer.h b/src/DebugTools/Implementation/PointRenderer.h new file mode 100644 index 000000000..31e22c746 --- /dev/null +++ b/src/DebugTools/Implementation/PointRenderer.h @@ -0,0 +1,38 @@ +#ifndef Magnum_DebugTools_Implementation_PointRenderer_h +#define Magnum_DebugTools_Implementation_PointRenderer_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 "AbstractShapeRenderer.h" + +#include "Physics/Physics.h" + +#include "corradeCompatibility.h" + +namespace Magnum { namespace DebugTools { namespace Implementation { + +template class PointRenderer: public AbstractShapeRenderer { + public: + PointRenderer(Physics::Point& point); + + void draw(Resource& options, const typename DimensionTraits::MatrixType& projectionMatrix) override; + + private: + Physics::Point& point; +}; + +}}} + +#endif diff --git a/src/DebugTools/ShapeRenderer.cpp b/src/DebugTools/ShapeRenderer.cpp index 1f4851897..54a6cf21a 100644 --- a/src/DebugTools/ShapeRenderer.cpp +++ b/src/DebugTools/ShapeRenderer.cpp @@ -20,11 +20,13 @@ #include "Physics/AxisAlignedBox.h" #include "Physics/Box.h" #include "Physics/ObjectShape.h" +#include "Physics/Point.h" #include "Physics/ShapeGroup.h" #include "SceneGraph/AbstractCamera.h" #include "Implementation/AxisAlignedBoxRenderer.h" #include "Implementation/BoxRenderer.h" +#include "Implementation/PointRenderer.h" namespace Magnum { namespace DebugTools { @@ -39,6 +41,9 @@ template<> void createDebugMesh(ShapeRenderer<2>* renderer, Physics::AbstractSha case Physics::AbstractShape2D::Type::Box: renderer->renderers.push_back(new Implementation::BoxRenderer<2>(*static_cast(shape))); break; + case Physics::AbstractShape2D::Type::Point: + renderer->renderers.push_back(new Implementation::PointRenderer<2>(*static_cast(shape))); + break; case Physics::AbstractShape2D::Type::ShapeGroup: { Physics::ShapeGroup2D* group = static_cast(shape); if(group->first()) createDebugMesh(renderer, group->first()); @@ -57,6 +62,9 @@ template<> void createDebugMesh(ShapeRenderer<3>* renderer, Physics::AbstractSha case Physics::AbstractShape3D::Type::Box: renderer->renderers.push_back(new Implementation::BoxRenderer<3>(*static_cast(shape))); break; + case Physics::AbstractShape3D::Type::Point: + renderer->renderers.push_back(new Implementation::PointRenderer<3>(*static_cast(shape))); + break; case Physics::AbstractShape3D::Type::ShapeGroup: { Physics::ShapeGroup3D* group = static_cast(shape); if(group->first()) createDebugMesh(renderer, group->first());