Browse Source

DebugTools: support for Point shape in ShapeRenderer.

pull/7/head
Vladimír Vondruš 13 years ago
parent
commit
540c322f5b
  1. 3
      src/DebugTools/CMakeLists.txt
  2. 59
      src/DebugTools/Implementation/PointRenderer.cpp
  3. 38
      src/DebugTools/Implementation/PointRenderer.h
  4. 8
      src/DebugTools/ShapeRenderer.cpp

3
src/DebugTools/CMakeLists.txt

@ -7,7 +7,8 @@ set(MagnumDebugTools_SRCS
Implementation/AbstractBoxRenderer.cpp Implementation/AbstractBoxRenderer.cpp
Implementation/AbstractShapeRenderer.cpp Implementation/AbstractShapeRenderer.cpp
Implementation/AxisAlignedBoxRenderer.cpp Implementation/AxisAlignedBoxRenderer.cpp
Implementation/BoxRenderer.cpp) Implementation/BoxRenderer.cpp
Implementation/PointRenderer.cpp)
set(MagnumDebugTools_HEADERS set(MagnumDebugTools_HEADERS
DebugTools.h DebugTools.h

59
src/DebugTools/Implementation/PointRenderer.cpp

@ -0,0 +1,59 @@
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
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<std::uint8_t dimensions> ResourceKey meshKey();
template<> inline ResourceKey meshKey<2>() { return ResourceKey("point2d"); }
template<> inline ResourceKey meshKey<3>() { return ResourceKey("point3d"); }
template<std::uint8_t dimensions> ResourceKey vertexBufferKey();
template<> inline ResourceKey vertexBufferKey<2>() { return ResourceKey("point2d-vertices"); }
template<> inline ResourceKey vertexBufferKey<3>() { return ResourceKey("point3d-vertices"); }
template<std::uint8_t dimensions> typename MeshData<dimensions>::Type meshData();
template<> inline Trade::MeshData2D meshData<2>() { return Primitives::Crosshair2D::wireframe(); }
template<> inline Trade::MeshData3D meshData<3>() { return Primitives::Crosshair3D::wireframe(); }
}
template<std::uint8_t dimensions> PointRenderer<dimensions>::PointRenderer(Physics::Point<dimensions>& point): AbstractShapeRenderer<dimensions>(meshKey<dimensions>(), vertexBufferKey<dimensions>(), {}), point(point) {
if(!this->mesh) this->createResources(meshData<dimensions>());
}
template<std::uint8_t dimensions> void PointRenderer<dimensions>::draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) {
/* Half scale, because the point is 2x2(x2) */
this->shader->setTransformationProjectionMatrix(projectionMatrix*
DimensionTraits<dimensions>::MatrixType::translation(point.transformedPosition())*
DimensionTraits<dimensions>::MatrixType::scaling(typename DimensionTraits<dimensions>::VectorType(options->pointSize()/2)))
->setColor(options->color())
->use();
this->mesh->draw();
}
template class PointRenderer<2>;
template class PointRenderer<3>;
}}}

38
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š <mosra@centrum.cz>
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<std::uint8_t dimensions> class PointRenderer: public AbstractShapeRenderer<dimensions> {
public:
PointRenderer(Physics::Point<dimensions>& point);
void draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) override;
private:
Physics::Point<dimensions>& point;
};
}}}
#endif

8
src/DebugTools/ShapeRenderer.cpp

@ -20,11 +20,13 @@
#include "Physics/AxisAlignedBox.h" #include "Physics/AxisAlignedBox.h"
#include "Physics/Box.h" #include "Physics/Box.h"
#include "Physics/ObjectShape.h" #include "Physics/ObjectShape.h"
#include "Physics/Point.h"
#include "Physics/ShapeGroup.h" #include "Physics/ShapeGroup.h"
#include "SceneGraph/AbstractCamera.h" #include "SceneGraph/AbstractCamera.h"
#include "Implementation/AxisAlignedBoxRenderer.h" #include "Implementation/AxisAlignedBoxRenderer.h"
#include "Implementation/BoxRenderer.h" #include "Implementation/BoxRenderer.h"
#include "Implementation/PointRenderer.h"
namespace Magnum { namespace DebugTools { namespace Magnum { namespace DebugTools {
@ -39,6 +41,9 @@ template<> void createDebugMesh(ShapeRenderer<2>* renderer, Physics::AbstractSha
case Physics::AbstractShape2D::Type::Box: case Physics::AbstractShape2D::Type::Box:
renderer->renderers.push_back(new Implementation::BoxRenderer<2>(*static_cast<Physics::Box2D*>(shape))); renderer->renderers.push_back(new Implementation::BoxRenderer<2>(*static_cast<Physics::Box2D*>(shape)));
break; break;
case Physics::AbstractShape2D::Type::Point:
renderer->renderers.push_back(new Implementation::PointRenderer<2>(*static_cast<Physics::Point2D*>(shape)));
break;
case Physics::AbstractShape2D::Type::ShapeGroup: { case Physics::AbstractShape2D::Type::ShapeGroup: {
Physics::ShapeGroup2D* group = static_cast<Physics::ShapeGroup2D*>(shape); Physics::ShapeGroup2D* group = static_cast<Physics::ShapeGroup2D*>(shape);
if(group->first()) createDebugMesh(renderer, group->first()); if(group->first()) createDebugMesh(renderer, group->first());
@ -57,6 +62,9 @@ template<> void createDebugMesh(ShapeRenderer<3>* renderer, Physics::AbstractSha
case Physics::AbstractShape3D::Type::Box: case Physics::AbstractShape3D::Type::Box:
renderer->renderers.push_back(new Implementation::BoxRenderer<3>(*static_cast<Physics::Box3D*>(shape))); renderer->renderers.push_back(new Implementation::BoxRenderer<3>(*static_cast<Physics::Box3D*>(shape)));
break; break;
case Physics::AbstractShape3D::Type::Point:
renderer->renderers.push_back(new Implementation::PointRenderer<3>(*static_cast<Physics::Point3D*>(shape)));
break;
case Physics::AbstractShape3D::Type::ShapeGroup: { case Physics::AbstractShape3D::Type::ShapeGroup: {
Physics::ShapeGroup3D* group = static_cast<Physics::ShapeGroup3D*>(shape); Physics::ShapeGroup3D* group = static_cast<Physics::ShapeGroup3D*>(shape);
if(group->first()) createDebugMesh(renderer, group->first()); if(group->first()) createDebugMesh(renderer, group->first());

Loading…
Cancel
Save