Browse Source

DebugTools: render boxes with size as half extent, not full.

Also clarified the documentation in Physics::Box and
Physics::AxisAlignedBox classes.
pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
c455955d50
  1. 6
      src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp
  2. 4
      src/DebugTools/Implementation/BoxRenderer.cpp
  3. 2
      src/Physics/AxisAlignedBox.h
  4. 2
      src/Physics/Box.h

6
src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp

@ -34,11 +34,9 @@ namespace Magnum { namespace DebugTools { namespace Implementation {
template<UnsignedInt dimensions> AxisAlignedBoxRenderer<dimensions>::AxisAlignedBoxRenderer(Physics::AxisAlignedBox<dimensions>& axisAlignedBox): axisAlignedBox(axisAlignedBox) {}
template<UnsignedInt dimensions> void AxisAlignedBoxRenderer<dimensions>::draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) {
/* Half scale, because the box is 2x2(x2) */
typename DimensionTraits<dimensions>::MatrixType transformation =
this->shader->setTransformationProjectionMatrix(projectionMatrix*
DimensionTraits<dimensions>::MatrixType::translation((axisAlignedBox.transformedMin()+axisAlignedBox.transformedMax())/2)*
DimensionTraits<dimensions>::MatrixType::scaling((axisAlignedBox.transformedMax()-axisAlignedBox.transformedMin())/2);
this->shader->setTransformationProjectionMatrix(projectionMatrix*transformation)
DimensionTraits<dimensions>::MatrixType::scaling(axisAlignedBox.transformedMax()-axisAlignedBox.transformedMin()))
->setColor(options->color())
->use();
this->mesh->draw();

4
src/DebugTools/Implementation/BoxRenderer.cpp

@ -34,9 +34,7 @@ namespace Magnum { namespace DebugTools { namespace Implementation {
template<UnsignedInt dimensions> BoxRenderer<dimensions>::BoxRenderer(Physics::Box<dimensions>& box): box(box) {}
template<UnsignedInt dimensions> void BoxRenderer<dimensions>::draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) {
/* Half scale, because the box is 2x2(x2) */
this->shader->setTransformationProjectionMatrix(projectionMatrix*box.transformedTransformation()*
DimensionTraits<dimensions>::MatrixType::scaling(typename DimensionTraits<dimensions>::VectorType(0.5f)))
this->shader->setTransformationProjectionMatrix(projectionMatrix*box.transformedTransformation())
->setColor(options->color())
->use();
this->mesh->draw();

2
src/Physics/AxisAlignedBox.h

@ -39,6 +39,8 @@ namespace Magnum { namespace Physics {
/**
@brief Axis-aligned box
Unit-size means that half extents are equal to 1, equivalent to e.g. sphere
radius.
@see AxisAlignedBox2D, AxisAlignedBox3D
@todo Assert for rotation
*/

2
src/Physics/Box.h

@ -39,6 +39,8 @@ namespace Magnum { namespace Physics {
/**
@brief Unit-size box with assigned transformation matrix
Unit-size means that half extents are equal to 1, equivalent to e.g. sphere
radius.
@todo Use quat + position + size instead?
@see Box2D, Box3D
@todo Assert for skew

Loading…
Cancel
Save