Browse Source

Physics shape rework #7: renamed Physics namespace to Shapes.

pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
6d8639cc76
  1. 4
      CMakeLists.txt
  2. 8
      doc/building.dox
  3. 6
      doc/cmake.dox
  4. 4
      doc/coding-style.dox
  5. 42
      doc/collision-detection.dox
  6. 2
      doc/compilation-speedup.dox
  7. 13
      doc/namespaces.dox
  8. 16
      modules/FindMagnum.cmake
  9. 8
      src/CMakeLists.txt
  10. 4
      src/DebugTools/CMakeLists.txt
  11. 2
      src/DebugTools/Implementation/AbstractShapeRenderer.h
  12. 4
      src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp
  13. 6
      src/DebugTools/Implementation/AxisAlignedBoxRenderer.h
  14. 4
      src/DebugTools/Implementation/BoxRenderer.cpp
  15. 6
      src/DebugTools/Implementation/BoxRenderer.h
  16. 4
      src/DebugTools/Implementation/LineSegmentRenderer.cpp
  17. 6
      src/DebugTools/Implementation/LineSegmentRenderer.h
  18. 4
      src/DebugTools/Implementation/PointRenderer.cpp
  19. 6
      src/DebugTools/Implementation/PointRenderer.h
  20. 4
      src/DebugTools/Implementation/SphereRenderer.cpp
  21. 6
      src/DebugTools/Implementation/SphereRenderer.h
  22. 2
      src/DebugTools/ResourceManager.h
  23. 46
      src/DebugTools/ShapeRenderer.cpp
  24. 14
      src/DebugTools/ShapeRenderer.h
  25. 10
      src/Shapes/AbstractShape.cpp
  26. 18
      src/Shapes/AbstractShape.h
  27. 8
      src/Shapes/AxisAlignedBox.cpp
  28. 14
      src/Shapes/AxisAlignedBox.h
  29. 2
      src/Shapes/Box.cpp
  30. 12
      src/Shapes/Box.h
  31. 18
      src/Shapes/CMakeLists.txt
  32. 10
      src/Shapes/Capsule.cpp
  33. 14
      src/Shapes/Capsule.h
  34. 8
      src/Shapes/Composition.cpp
  35. 24
      src/Shapes/Composition.h
  36. 20
      src/Shapes/Implementation/CollisionDispatch.cpp
  37. 6
      src/Shapes/Implementation/CollisionDispatch.h
  38. 2
      src/Shapes/Line.cpp
  39. 12
      src/Shapes/Line.h
  40. 8
      src/Shapes/LineSegment.h
  41. 4
      src/Shapes/Plane.cpp
  42. 14
      src/Shapes/Plane.h
  43. 2
      src/Shapes/Point.cpp
  44. 12
      src/Shapes/Point.h
  45. 14
      src/Shapes/Shape.cpp
  46. 32
      src/Shapes/Shape.h
  47. 8
      src/Shapes/ShapeGroup.cpp
  48. 14
      src/Shapes/ShapeGroup.h
  49. 8
      src/Shapes/Shapes.h
  50. 10
      src/Shapes/Sphere.cpp
  51. 14
      src/Shapes/Sphere.h
  52. 16
      src/Shapes/Test/AxisAlignedBoxTest.cpp
  53. 8
      src/Shapes/Test/BoxTest.cpp
  54. 20
      src/Shapes/Test/CMakeLists.txt
  55. 28
      src/Shapes/Test/CapsuleTest.cpp
  56. 62
      src/Shapes/Test/CompositionTest.cpp
  57. 8
      src/Shapes/Test/LineTest.cpp
  58. 28
      src/Shapes/Test/PlaneTest.cpp
  59. 8
      src/Shapes/Test/PointTest.cpp
  60. 10
      src/Shapes/Test/ShapeImplementationTest.cpp
  61. 28
      src/Shapes/Test/ShapeTest.cpp
  62. 6
      src/Shapes/Test/ShapeTestBase.h
  63. 36
      src/Shapes/Test/SphereTest.cpp
  64. 12
      src/Shapes/magnumShapesVisibility.h
  65. 10
      src/Shapes/shapeImplementation.cpp
  66. 40
      src/Shapes/shapeImplementation.h

4
CMakeLists.txt

@ -35,10 +35,10 @@ cmake_dependent_option(TARGET_DESKTOP_GLES "Build for OpenGL ES on desktop" OFF
# Parts of the library # Parts of the library
option(WITH_DEBUGTOOLS "Build DebugTools library" ON) option(WITH_DEBUGTOOLS "Build DebugTools library" ON)
cmake_dependent_option(WITH_MESHTOOLS "Build MeshTools library" ON "NOT WITH_DEBUGTOOLS" ON) cmake_dependent_option(WITH_MESHTOOLS "Build MeshTools library" ON "NOT WITH_DEBUGTOOLS" ON)
cmake_dependent_option(WITH_PHYSICS "Build Physics library" ON "NOT WITH_DEBUGTOOLS" ON)
cmake_dependent_option(WITH_PRIMITIVES "Builf Primitives library" ON "NOT WITH_DEBUGTOOLS" ON) cmake_dependent_option(WITH_PRIMITIVES "Builf Primitives library" ON "NOT WITH_DEBUGTOOLS" ON)
cmake_dependent_option(WITH_SCENEGRAPH "Build SceneGraph library" ON "NOT WITH_DEBUGTOOLS;NOT WITH_PHYSICS" ON) cmake_dependent_option(WITH_SCENEGRAPH "Build SceneGraph library" ON "NOT WITH_DEBUGTOOLS;NOT WITH_SHAPES" ON)
cmake_dependent_option(WITH_SHADERS "Build Shaders library" ON "NOT WITH_DEBUGTOOLS" ON) cmake_dependent_option(WITH_SHADERS "Build Shaders library" ON "NOT WITH_DEBUGTOOLS" ON)
cmake_dependent_option(WITH_SHAPES "Build Shapes library" ON "NOT WITH_DEBUGTOOLS" ON)
option(WITH_TEXT "Build Text library" ON) option(WITH_TEXT "Build Text library" ON)
cmake_dependent_option(WITH_TEXTURETOOLS "Build TextureTools library" ON "NOT WITH_TEXT" ON) cmake_dependent_option(WITH_TEXTURETOOLS "Build TextureTools library" ON "NOT WITH_TEXT" ON)
option(WITH_MAGNUMINFO "Build magnum-info utility" ON) option(WITH_MAGNUMINFO "Build magnum-info utility" ON)

8
doc/building.dox

@ -97,17 +97,17 @@ below). Using `WITH_*` CMake parameters you can specify which parts will be buil
and which not: and which not:
- `WITH_DEBUGTOOLS` - DebugTools library. Enables also building of MeshTools, - `WITH_DEBUGTOOLS` - DebugTools library. Enables also building of MeshTools,
Physics, Primitives, SceneGraph and Shaders libraries. Primitives, SceneGraph, Shaders and Shapes libraries.
- `WITH_MESHTOOLS` - MeshTools library. Enabled automatically if `WITH_DEBUGTOOLS` - `WITH_MESHTOOLS` - MeshTools library. Enabled automatically if `WITH_DEBUGTOOLS`
is enabled. is enabled.
- `WITH_PHYSICS` - Physics library. Enables also building of SceneGraph
library. Enabled automatically if `WITH_DEBUGTOOLS` is enabled.
- `WITH_PRIMITIVES` - Primitives library. Enabled automatically if `WITH_DEBUGTOOLS` - `WITH_PRIMITIVES` - Primitives library. Enabled automatically if `WITH_DEBUGTOOLS`
is enabled. is enabled.
- `WITH_SCENEGRAPH` - SceneGraph library. Enabled automatically if `WITH_DEBUGTOOLS` - `WITH_SCENEGRAPH` - SceneGraph library. Enabled automatically if `WITH_DEBUGTOOLS`
or `WITH_PHYSICS` is enabled. or `WITH_SHAPES` is enabled.
- `WITH_SHADERS` - Shaders library. Enabled automatically if `WITH_DEBUGTOOLS` - `WITH_SHADERS` - Shaders library. Enabled automatically if `WITH_DEBUGTOOLS`
is enabled. is enabled.
- `WITH_SHAPES` - Shapes library. Enables also building of SceneGraph library.
Enabled automatically if `WITH_DEBUGTOOLS` is enabled.
- `WITH_TEXT` - Text library. Enables also building of TextureTools library. - `WITH_TEXT` - Text library. Enables also building of TextureTools library.
- `WITH_TEXTURETOOLS` - TextureTools library. Enabled automatically if `WITH_TEXT` - `WITH_TEXTURETOOLS` - TextureTools library. Enabled automatically if `WITH_TEXT`
is enabled. is enabled.

6
doc/cmake.dox

@ -51,13 +51,13 @@ components. The base library depends on %Corrade, OpenGL and GLEW libraries (or
OpenGL ES libraries). Additional dependencies are specified by the components. OpenGL ES libraries). Additional dependencies are specified by the components.
The optional components are: The optional components are:
- `%DebugTools` -- DebugTools library (depends on `%MeshTools`, `%Physics`, - `%DebugTools` -- DebugTools library (depends on `%MeshTools`,
`%Primitives`, `%SceneGraph` and `%Shaders` components) `%Primitives`, `%SceneGraph`, `%Shaders` and `%Shapes` components)
- `%MeshTools` -- MeshTools library - `%MeshTools` -- MeshTools library
- `%Physics` -- Physics library (depends on `%SceneGraph` component)
- `%Primitives` -- Primitives library - `%Primitives` -- Primitives library
- `%SceneGraph` -- SceneGraph library - `%SceneGraph` -- SceneGraph library
- `%Shaders` -- Shaders library - `%Shaders` -- Shaders library
- `%Shapes` -- Shapes library (depends on `%SceneGraph` component)
- `%Text` -- Text library (depends on `%TextureTools` component) - `%Text` -- Text library (depends on `%TextureTools` component)
- `%TextureTools` -- TextureTools library - `%TextureTools` -- TextureTools library

4
doc/coding-style.dox

@ -100,9 +100,9 @@ void setPolygonMode(PolygonMode mode);
Additionally to @c \@todoc, @c \@debugoperator @c \@configurationvalue and Additionally to @c \@todoc, @c \@debugoperator @c \@configurationvalue and
@c \@configurationvalueref (same as in Corrade), these are defined: @c \@configurationvalueref (same as in Corrade), these are defined:
@subsubsection documentation-commands-collisionoperator Physics collision operators @subsubsection documentation-commands-collisionoperator Shape collision operators
Out-of-class operators for collision in Physics namespace should be marked with Out-of-class operators for collision in Shapes namespace should be marked with
@c \@collisionoperator, e.g.: @c \@collisionoperator, e.g.:
@code @code
// @collisionoperator{Point,Sphere} // @collisionoperator{Point,Sphere}

42
doc/collision-detection.dox

@ -22,7 +22,7 @@
DEALINGS IN THE SOFTWARE. DEALINGS IN THE SOFTWARE.
*/ */
namespace Magnum { namespace Physics { namespace Magnum { namespace Shapes {
/** @page collision-detection Collision detection /** @page collision-detection Collision detection
@brief Collection of simple shapes for high performance collision detection. @brief Collection of simple shapes for high performance collision detection.
@ -37,23 +37,23 @@ together using various operations.
@subsection collision-detection-shapes1D One-dimensional shapes @subsection collision-detection-shapes1D One-dimensional shapes
- @ref Physics::Point "Physics::Point*D" - @copybrief Physics::Point - @ref Shapes::Point "Shapes::Point*D" - @copybrief Shapes::Point
- @ref Physics::Line "Physics::Line*D" - @copybrief Physics::Line - @ref Shapes::Line "Shapes::Line*D" - @copybrief Shapes::Line
- @ref Physics::LineSegment "Physics::LineSegment*D" - @copybrief Physics::LineSegment - @ref Shapes::LineSegment "Shapes::LineSegment*D" - @copybrief Shapes::LineSegment
Because of numerical instability it's not possible to detect collisions of Because of numerical instability it's not possible to detect collisions of
line and point. Collision of two lines can be detected only in 2D. line and point. Collision of two lines can be detected only in 2D.
@subsection collision-detection-shapes2D Two-dimensional shapes @subsection collision-detection-shapes2D Two-dimensional shapes
- Physics::Plane - @copybrief Physics::Plane - Shapes::Plane - @copybrief Shapes::Plane
@subsection collision-detection-shapes3D Three-dimensional shapes @subsection collision-detection-shapes3D Three-dimensional shapes
- @ref Physics::Sphere "Physics::Sphere*D" - @copybrief Physics::Sphere - @ref Shapes::Sphere "Shapes::Sphere*D" - @copybrief Shapes::Sphere
- @ref Physics::Capsule "Physics::Capsule*D" - @copybrief Physics::Capsule - @ref Shapes::Capsule "Shapes::Capsule*D" - @copybrief Shapes::Capsule
- @ref Physics::AxisAlignedBox "Physics::AxisAlignedBox*D" - @copybrief Physics::AxisAlignedBox - @ref Shapes::AxisAlignedBox "Shapes::AxisAlignedBox*D" - @copybrief Shapes::AxisAlignedBox
- @ref Physics::Box "Physics::Box*D" - @copybrief Physics::Box - @ref Shapes::Box "Shapes::Box*D" - @copybrief Shapes::Box
The easiest (and most efficient) shape combination for detecting collisions The easiest (and most efficient) shape combination for detecting collisions
is point and sphere, followed by two spheres. Computing collision of two boxes is point and sphere, followed by two spheres. Computing collision of two boxes
@ -66,10 +66,10 @@ operations: AND, OR and NOT. These operations are mapped to operator&&(),
operator||() and operator!(), so for example creating negation of logical OR operator||() and operator!(), so for example creating negation of logical OR
of line segment and point is simple as this: of line segment and point is simple as this:
@code @code
Physics::LineSegment3D segment; Shapes::LineSegment3D segment;
Physics::Point3D point; Shapes::Point3D point;
Physics::ShapeGroup3D group = !(segment || point); Shapes::ShapeGroup3D group = !(segment || point);
@endcode @endcode
@note Logical operations are not the same as set operations -- intersection of @note Logical operations are not the same as set operations -- intersection of
@ -90,10 +90,10 @@ was not possible to change their properties such as sphere radius without
recreating the group again. You can, however, explicitly pass a reference to recreating the group again. You can, however, explicitly pass a reference to
original object, so you can change it later: original object, so you can change it later:
@code @code
Physics::LineSegment3D segment; Shapes::LineSegment3D segment;
Physics::Point3D point; Shapes::Point3D point;
Physics::ShapeGroup3D group = !(segment || std::ref(point)); Shapes::ShapeGroup3D group = !(segment || std::ref(point));
point.setPosition({1.0f, -6.0f, 0.5f}); point.setPosition({1.0f, -6.0f, 0.5f});
@endcode @endcode
@ -112,11 +112,11 @@ was detected with the simplified shape. It is in fact logical AND using
operator&&() - the collision is initially detected on first (simplified) shape operator&&() - the collision is initially detected on first (simplified) shape
and then on the other: and then on the other:
@code @code
Physics::Sphere3D sphere; Shapes::Sphere3D sphere;
Physics::Box3D box; Shapes::Box3D box;
Physics::AxisAlignedBox3D simplified; Shapes::AxisAlignedBox3D simplified;
Physics::ShapeGroup3D object = simplified && (sphere || box); Shapes::ShapeGroup3D object = simplified && (sphere || box);
@endcode @endcode
@section collision-detection-shape-collisions Detecting shape collisions @section collision-detection-shape-collisions Detecting shape collisions
@ -124,8 +124,8 @@ Physics::ShapeGroup3D object = simplified && (sphere || box);
Shape pairs which have collision detection implemented can be tested for Shape pairs which have collision detection implemented can be tested for
collision using operator%(), for example: collision using operator%(), for example:
@code @code
Physics::Point3D point; Shapes::Point3D point;
Physics::Sphere3D sphere; Shapes::Sphere3D sphere;
bool collide = point % sphere; bool collide = point % sphere;
@endcode @endcode

2
doc/compilation-speedup.dox

@ -46,9 +46,9 @@ available, each namespace has its own:
- Math/Math.h - Math/Math.h
- Magnum.h - Magnum.h
- DebugTools/DebugTools.h - DebugTools/DebugTools.h
- Physics/Physics.h
- SceneGraph/SceneGraph.h - SceneGraph/SceneGraph.h
- Shaders/Shaders.h - Shaders/Shaders.h
- Shapes/Shapes.h
- Text/Text.h - Text/Text.h
- Trade/Trade.h - Trade/Trade.h

13
doc/namespaces.dox

@ -155,16 +155,15 @@ This library is built when `WITH_SHADERS` is enabled and found as `%Shaders`
component in CMake. See @ref building and @ref cmake for more information. component in CMake. See @ref building and @ref cmake for more information.
*/ */
/** @dir Physics /** @dir Shapes
* @brief Namespace Magnum::Physics * @brief Namespace Magnum::Shapes
*/ */
/** @namespace Magnum::Physics /** @namespace Magnum::Shapes
@brief %Physics library @brief %Shape library
Collision detection system and rigid body objects. See @ref collision-detection Collision detection system. See @ref collision-detection for introduction.
for introduction.
This library is built when `WITH_PHYSICS` is enabled and found as `%Physics` This library is built when `WITH_SHAPES` is enabled and found as `%Shapes`
component in CMake. See @ref building and @ref cmake for more information. component in CMake. See @ref building and @ref cmake for more information.
*/ */

16
modules/FindMagnum.cmake

@ -14,13 +14,13 @@
# components. The base library depends on Corrade, OpenGL and GLEW # components. The base library depends on Corrade, OpenGL and GLEW
# libraries. Additional dependencies are specified by the components. The # libraries. Additional dependencies are specified by the components. The
# optional components are: # optional components are:
# DebugTools - DebugTools library (depends on MeshTools, Physics, # DebugTools - DebugTools library (depends on MeshTools, Primitives,
# Primitives, SceneGraph and Shaders components) # SceneGraph, Shaders and Shapes components)
# MeshTools - MeshTools library # MeshTools - MeshTools library
# Physics - Physics library (depends on SceneGraph component)
# Primitives - Primitives library # Primitives - Primitives library
# SceneGraph - SceneGraph library # SceneGraph - SceneGraph library
# Shaders - Shaders library # Shaders - Shaders library
# Shapes - Shapes library (depends on SceneGraph component)
# Text - Text library (depends on TextureTools component) # Text - Text library (depends on TextureTools component)
# TextureTools - TextureTools library # TextureTools - TextureTools library
# GlutApplication - GLUT application (depends on GLUT library) # GlutApplication - GLUT application (depends on GLUT library)
@ -232,11 +232,6 @@ foreach(component ${Magnum_FIND_COMPONENTS})
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES CompressIndices.h) set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES CompressIndices.h)
endif() endif()
# Physics library
if(${component} STREQUAL Physics)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Physics.h)
endif()
# Primitives library # Primitives library
if(${component} STREQUAL Primitives) if(${component} STREQUAL Primitives)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Cube.h) set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Cube.h)
@ -252,6 +247,11 @@ foreach(component ${Magnum_FIND_COMPONENTS})
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Shaders.h) set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Shaders.h)
endif() endif()
# Shapes library
if(${component} STREQUAL Shapes)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Shapes.h)
endif()
# Text library # Text library
if(${component} STREQUAL Text) if(${component} STREQUAL Text)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Text.h) set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES Text.h)

8
src/CMakeLists.txt

@ -194,10 +194,6 @@ if(WITH_MESHTOOLS)
add_subdirectory(MeshTools) add_subdirectory(MeshTools)
endif() endif()
if(WITH_PHYSICS)
add_subdirectory(Physics)
endif()
if(WITH_PRIMITIVES) if(WITH_PRIMITIVES)
add_subdirectory(Primitives) add_subdirectory(Primitives)
endif() endif()
@ -210,6 +206,10 @@ if(WITH_SHADERS)
add_subdirectory(Shaders) add_subdirectory(Shaders)
endif() endif()
if(WITH_SHAPES)
add_subdirectory(Shapes)
endif()
if(WITH_TEXT) if(WITH_TEXT)
add_subdirectory(Text) add_subdirectory(Text)
endif() endif()

4
src/DebugTools/CMakeLists.txt

@ -55,10 +55,10 @@ endif()
target_link_libraries(MagnumDebugTools target_link_libraries(MagnumDebugTools
Magnum Magnum
MagnumMeshTools MagnumMeshTools
MagnumPhysics
MagnumPrimitives MagnumPrimitives
MagnumSceneGraph MagnumSceneGraph
MagnumShaders) MagnumShaders
MagnumShapes)
install(TARGETS MagnumDebugTools DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(TARGETS MagnumDebugTools DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
install(FILES ${MagnumDebugTools_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/DebugTools) install(FILES ${MagnumDebugTools_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/DebugTools)

2
src/DebugTools/Implementation/AbstractShapeRenderer.h

@ -33,7 +33,7 @@
namespace Magnum { namespace Magnum {
namespace Physics { namespace Implementation { namespace Shapes { namespace Implementation {
template<UnsignedInt> struct AbstractShape; template<UnsignedInt> struct AbstractShape;
}} }}

4
src/DebugTools/Implementation/AxisAlignedBoxRenderer.cpp

@ -26,12 +26,12 @@
#include "Mesh.h" #include "Mesh.h"
#include "DebugTools/ShapeRenderer.h" #include "DebugTools/ShapeRenderer.h"
#include "Physics/AxisAlignedBox.h" #include "Shapes/AxisAlignedBox.h"
#include "Shaders/Flat.h" #include "Shaders/Flat.h"
namespace Magnum { namespace DebugTools { namespace Implementation { namespace Magnum { namespace DebugTools { namespace Implementation {
template<UnsignedInt dimensions> AxisAlignedBoxRenderer<dimensions>::AxisAlignedBoxRenderer(const Physics::Implementation::AbstractShape<dimensions>* axisAlignedBox): axisAlignedBox(static_cast<const Physics::Implementation::Shape<Physics::AxisAlignedBox<dimensions>>*>(axisAlignedBox)->shape) {} template<UnsignedInt dimensions> AxisAlignedBoxRenderer<dimensions>::AxisAlignedBoxRenderer(const Shapes::Implementation::AbstractShape<dimensions>* axisAlignedBox): axisAlignedBox(static_cast<const Shapes::Implementation::Shape<Shapes::AxisAlignedBox<dimensions>>*>(axisAlignedBox)->shape) {}
template<UnsignedInt dimensions> void AxisAlignedBoxRenderer<dimensions>::draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) { template<UnsignedInt dimensions> void AxisAlignedBoxRenderer<dimensions>::draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) {
this->wireframeShader->setTransformationProjectionMatrix(projectionMatrix* this->wireframeShader->setTransformationProjectionMatrix(projectionMatrix*

6
src/DebugTools/Implementation/AxisAlignedBoxRenderer.h

@ -26,7 +26,7 @@
#include "AbstractBoxRenderer.h" #include "AbstractBoxRenderer.h"
#include "Physics/Physics.h" #include "Shapes/Shapes.h"
#include "corradeCompatibility.h" #include "corradeCompatibility.h"
@ -34,12 +34,12 @@ namespace Magnum { namespace DebugTools { namespace Implementation {
template<UnsignedInt dimensions> class AxisAlignedBoxRenderer: public AbstractBoxRenderer<dimensions> { template<UnsignedInt dimensions> class AxisAlignedBoxRenderer: public AbstractBoxRenderer<dimensions> {
public: public:
AxisAlignedBoxRenderer(const Physics::Implementation::AbstractShape<dimensions>* axisAlignedBox); AxisAlignedBoxRenderer(const Shapes::Implementation::AbstractShape<dimensions>* axisAlignedBox);
void draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) override; void draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) override;
private: private:
const Physics::AxisAlignedBox<dimensions>& axisAlignedBox; const Shapes::AxisAlignedBox<dimensions>& axisAlignedBox;
}; };
}}} }}}

4
src/DebugTools/Implementation/BoxRenderer.cpp

@ -26,12 +26,12 @@
#include "Mesh.h" #include "Mesh.h"
#include "DebugTools/ShapeRenderer.h" #include "DebugTools/ShapeRenderer.h"
#include "Physics/Box.h" #include "Shapes/Box.h"
#include "Shaders/Flat.h" #include "Shaders/Flat.h"
namespace Magnum { namespace DebugTools { namespace Implementation { namespace Magnum { namespace DebugTools { namespace Implementation {
template<UnsignedInt dimensions> BoxRenderer<dimensions>::BoxRenderer(const Physics::Implementation::AbstractShape<dimensions>* box): box(static_cast<const Physics::Implementation::Shape<Physics::Box<dimensions>>*>(box)->shape) {} template<UnsignedInt dimensions> BoxRenderer<dimensions>::BoxRenderer(const Shapes::Implementation::AbstractShape<dimensions>* box): box(static_cast<const Shapes::Implementation::Shape<Shapes::Box<dimensions>>*>(box)->shape) {}
template<UnsignedInt dimensions> void BoxRenderer<dimensions>::draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) { template<UnsignedInt dimensions> void BoxRenderer<dimensions>::draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) {
this->wireframeShader->setTransformationProjectionMatrix(projectionMatrix*box.transformation()) this->wireframeShader->setTransformationProjectionMatrix(projectionMatrix*box.transformation())

6
src/DebugTools/Implementation/BoxRenderer.h

@ -26,7 +26,7 @@
#include "AbstractBoxRenderer.h" #include "AbstractBoxRenderer.h"
#include "Physics/Physics.h" #include "Shapes/Shapes.h"
#include "corradeCompatibility.h" #include "corradeCompatibility.h"
@ -34,12 +34,12 @@ namespace Magnum { namespace DebugTools { namespace Implementation {
template<UnsignedInt dimensions> class BoxRenderer: public AbstractBoxRenderer<dimensions> { template<UnsignedInt dimensions> class BoxRenderer: public AbstractBoxRenderer<dimensions> {
public: public:
BoxRenderer(const Physics::Implementation::AbstractShape<dimensions>* box); BoxRenderer(const Shapes::Implementation::AbstractShape<dimensions>* box);
void draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) override; void draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) override;
private: private:
const Physics::Box<dimensions>& box; const Shapes::Box<dimensions>& box;
}; };
}}} }}}

4
src/DebugTools/Implementation/LineSegmentRenderer.cpp

@ -26,7 +26,7 @@
#include "Mesh.h" #include "Mesh.h"
#include "DebugTools/ShapeRenderer.h" #include "DebugTools/ShapeRenderer.h"
#include "Physics/LineSegment.h" #include "Shapes/LineSegment.h"
#include "Primitives/Line.h" #include "Primitives/Line.h"
#include "Shaders/Flat.h" #include "Shaders/Flat.h"
#include "Trade/MeshData2D.h" #include "Trade/MeshData2D.h"
@ -50,7 +50,7 @@ namespace {
template<> inline Trade::MeshData3D meshData<3>() { return Primitives::Line3D::wireframe(); } template<> inline Trade::MeshData3D meshData<3>() { return Primitives::Line3D::wireframe(); }
} }
template<UnsignedInt dimensions> LineSegmentRenderer<dimensions>::LineSegmentRenderer(const Physics::Implementation::AbstractShape<dimensions>* line): AbstractShapeRenderer<dimensions>(meshKey<dimensions>(), vertexBufferKey<dimensions>(), {}), line(static_cast<const Physics::Implementation::Shape<Physics::LineSegment<dimensions>>*>(line)->shape) { template<UnsignedInt dimensions> LineSegmentRenderer<dimensions>::LineSegmentRenderer(const Shapes::Implementation::AbstractShape<dimensions>* line): AbstractShapeRenderer<dimensions>(meshKey<dimensions>(), vertexBufferKey<dimensions>(), {}), line(static_cast<const Shapes::Implementation::Shape<Shapes::LineSegment<dimensions>>*>(line)->shape) {
if(!this->wireframeMesh) this->createResources(meshData<dimensions>()); if(!this->wireframeMesh) this->createResources(meshData<dimensions>());
} }

6
src/DebugTools/Implementation/LineSegmentRenderer.h

@ -26,7 +26,7 @@
#include "AbstractShapeRenderer.h" #include "AbstractShapeRenderer.h"
#include "Physics/Physics.h" #include "Shapes/Shapes.h"
#include "corradeCompatibility.h" #include "corradeCompatibility.h"
@ -34,12 +34,12 @@ namespace Magnum { namespace DebugTools { namespace Implementation {
template<UnsignedInt dimensions> class LineSegmentRenderer: public AbstractShapeRenderer<dimensions> { template<UnsignedInt dimensions> class LineSegmentRenderer: public AbstractShapeRenderer<dimensions> {
public: public:
LineSegmentRenderer(const Physics::Implementation::AbstractShape<dimensions>* line); LineSegmentRenderer(const Shapes::Implementation::AbstractShape<dimensions>* line);
void draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) override; void draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) override;
private: private:
const Physics::LineSegment<dimensions>& line; const Shapes::LineSegment<dimensions>& line;
}; };
}}} }}}

4
src/DebugTools/Implementation/PointRenderer.cpp

@ -26,7 +26,7 @@
#include "Mesh.h" #include "Mesh.h"
#include "DebugTools/ShapeRenderer.h" #include "DebugTools/ShapeRenderer.h"
#include "Physics/Point.h" #include "Shapes/Point.h"
#include "Primitives/Crosshair.h" #include "Primitives/Crosshair.h"
#include "Shaders/Flat.h" #include "Shaders/Flat.h"
#include "Trade/MeshData2D.h" #include "Trade/MeshData2D.h"
@ -48,7 +48,7 @@ namespace {
template<> inline Trade::MeshData3D meshData<3>() { return Primitives::Crosshair3D::wireframe(); } template<> inline Trade::MeshData3D meshData<3>() { return Primitives::Crosshair3D::wireframe(); }
} }
template<UnsignedInt dimensions> PointRenderer<dimensions>::PointRenderer(const Physics::Implementation::AbstractShape<dimensions>* point): AbstractShapeRenderer<dimensions>(meshKey<dimensions>(), vertexBufferKey<dimensions>(), {}), point(static_cast<const Physics::Implementation::Shape<Physics::Point<dimensions>>*>(point)->shape) { template<UnsignedInt dimensions> PointRenderer<dimensions>::PointRenderer(const Shapes::Implementation::AbstractShape<dimensions>* point): AbstractShapeRenderer<dimensions>(meshKey<dimensions>(), vertexBufferKey<dimensions>(), {}), point(static_cast<const Shapes::Implementation::Shape<Shapes::Point<dimensions>>*>(point)->shape) {
if(!this->wireframeMesh) this->createResources(meshData<dimensions>()); if(!this->wireframeMesh) this->createResources(meshData<dimensions>());
} }

6
src/DebugTools/Implementation/PointRenderer.h

@ -26,7 +26,7 @@
#include "AbstractShapeRenderer.h" #include "AbstractShapeRenderer.h"
#include "Physics/Physics.h" #include "Shapes/Shapes.h"
#include "corradeCompatibility.h" #include "corradeCompatibility.h"
@ -34,12 +34,12 @@ namespace Magnum { namespace DebugTools { namespace Implementation {
template<UnsignedInt dimensions> class PointRenderer: public AbstractShapeRenderer<dimensions> { template<UnsignedInt dimensions> class PointRenderer: public AbstractShapeRenderer<dimensions> {
public: public:
PointRenderer(const Physics::Implementation::AbstractShape<dimensions>* point); PointRenderer(const Shapes::Implementation::AbstractShape<dimensions>* point);
void draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) override; void draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) override;
private: private:
const Physics::Point<dimensions>& point; const Shapes::Point<dimensions>& point;
}; };
}}} }}}

4
src/DebugTools/Implementation/SphereRenderer.cpp

@ -26,7 +26,7 @@
#include "Mesh.h" #include "Mesh.h"
#include "DebugTools/ShapeRenderer.h" #include "DebugTools/ShapeRenderer.h"
#include "Physics/Sphere.h" #include "Shapes/Sphere.h"
#include "Primitives/Circle.h" #include "Primitives/Circle.h"
#include "Shaders/Flat.h" #include "Shaders/Flat.h"
#include "Trade/MeshData2D.h" #include "Trade/MeshData2D.h"
@ -37,7 +37,7 @@ AbstractSphereRenderer<2>::AbstractSphereRenderer(): AbstractShapeRenderer<2>("s
if(!wireframeMesh) createResources(Primitives::Circle::wireframe(40)); if(!wireframeMesh) createResources(Primitives::Circle::wireframe(40));
} }
template<UnsignedInt dimensions> SphereRenderer<dimensions>::SphereRenderer(const Physics::Implementation::AbstractShape<dimensions>* sphere): sphere(static_cast<const Physics::Implementation::Shape<Physics::Sphere<dimensions>>*>(sphere)->shape) {} template<UnsignedInt dimensions> SphereRenderer<dimensions>::SphereRenderer(const Shapes::Implementation::AbstractShape<dimensions>* sphere): sphere(static_cast<const Shapes::Implementation::Shape<Shapes::Sphere<dimensions>>*>(sphere)->shape) {}
template<UnsignedInt dimensions> void SphereRenderer<dimensions>::draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) { template<UnsignedInt dimensions> void SphereRenderer<dimensions>::draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) {
this->wireframeShader->setTransformationProjectionMatrix(projectionMatrix* this->wireframeShader->setTransformationProjectionMatrix(projectionMatrix*

6
src/DebugTools/Implementation/SphereRenderer.h

@ -26,7 +26,7 @@
#include "AbstractShapeRenderer.h" #include "AbstractShapeRenderer.h"
#include "Physics/Physics.h" #include "Shapes/Shapes.h"
#include "corradeCompatibility.h" #include "corradeCompatibility.h"
@ -41,12 +41,12 @@ template<> class AbstractSphereRenderer<2>: public AbstractShapeRenderer<2> {
template<UnsignedInt dimensions> class SphereRenderer: public AbstractSphereRenderer<dimensions> { template<UnsignedInt dimensions> class SphereRenderer: public AbstractSphereRenderer<dimensions> {
public: public:
SphereRenderer(const Physics::Implementation::AbstractShape<dimensions>* sphere); SphereRenderer(const Shapes::Implementation::AbstractShape<dimensions>* sphere);
void draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) override; void draw(Resource<ShapeRendererOptions>& options, const typename DimensionTraits<dimensions>::MatrixType& projectionMatrix) override;
private: private:
const Physics::Sphere<dimensions>& sphere; const Shapes::Sphere<dimensions>& sphere;
}; };
}}} }}}

2
src/DebugTools/ResourceManager.h

@ -36,7 +36,7 @@
#include "../ResourceManager.h" #include "../ResourceManager.h"
#include "SceneGraph/SceneGraph.h" #include "SceneGraph/SceneGraph.h"
#include "Physics/Physics.h" #include "Shapes/Shapes.h"
#include "DebugTools.h" #include "DebugTools.h"
#include "magnumDebugToolsVisibility.h" #include "magnumDebugToolsVisibility.h"

46
src/DebugTools/ShapeRenderer.cpp

@ -25,8 +25,8 @@
#include "ShapeRenderer.h" #include "ShapeRenderer.h"
#include "ResourceManager.h" #include "ResourceManager.h"
#include "Physics/Composition.h" #include "Shapes/Composition.h"
#include "Physics/Shape.h" #include "Shapes/Shape.h"
#include "SceneGraph/AbstractCamera.h" #include "SceneGraph/AbstractCamera.h"
#include "Implementation/AxisAlignedBoxRenderer.h" #include "Implementation/AxisAlignedBoxRenderer.h"
@ -39,27 +39,27 @@ namespace Magnum { namespace DebugTools {
namespace Implementation { namespace Implementation {
template<> void createDebugMesh(ShapeRenderer<2>* renderer, const Physics::Implementation::AbstractShape<2>* shape) { template<> void createDebugMesh(ShapeRenderer<2>* renderer, const Shapes::Implementation::AbstractShape<2>* shape) {
switch(shape->type()) { switch(shape->type()) {
case Physics::AbstractShape2D::Type::AxisAlignedBox: case Shapes::AbstractShape2D::Type::AxisAlignedBox:
renderer->renderers.push_back(new Implementation::AxisAlignedBoxRenderer<2>(shape)); renderer->renderers.push_back(new Implementation::AxisAlignedBoxRenderer<2>(shape));
break; break;
case Physics::AbstractShape2D::Type::Box: case Shapes::AbstractShape2D::Type::Box:
renderer->renderers.push_back(new Implementation::BoxRenderer<2>(shape)); renderer->renderers.push_back(new Implementation::BoxRenderer<2>(shape));
break; break;
case Physics::AbstractShape2D::Type::LineSegment: case Shapes::AbstractShape2D::Type::LineSegment:
renderer->renderers.push_back(new Implementation::LineSegmentRenderer<2>(shape)); renderer->renderers.push_back(new Implementation::LineSegmentRenderer<2>(shape));
break; break;
case Physics::AbstractShape2D::Type::Point: case Shapes::AbstractShape2D::Type::Point:
renderer->renderers.push_back(new Implementation::PointRenderer<2>(shape)); renderer->renderers.push_back(new Implementation::PointRenderer<2>(shape));
break; break;
case Physics::AbstractShape2D::Type::Composition: { case Shapes::AbstractShape2D::Type::Composition: {
const Physics::Composition2D& composition = const Shapes::Composition2D& composition =
static_cast<const Physics::Implementation::Shape<Physics::Composition2D>*>(shape)->shape; static_cast<const Shapes::Implementation::Shape<Shapes::Composition2D>*>(shape)->shape;
for(std::size_t i = 0; i != composition.size(); ++i) for(std::size_t i = 0; i != composition.size(); ++i)
createDebugMesh(renderer, Physics::Implementation::getAbstractShape(composition, i)); createDebugMesh(renderer, Shapes::Implementation::getAbstractShape(composition, i));
} break; } break;
case Physics::AbstractShape2D::Type::Sphere: case Shapes::AbstractShape2D::Type::Sphere:
renderer->renderers.push_back(new Implementation::SphereRenderer<2>(shape)); renderer->renderers.push_back(new Implementation::SphereRenderer<2>(shape));
break; break;
default: default:
@ -67,25 +67,25 @@ template<> void createDebugMesh(ShapeRenderer<2>* renderer, const Physics::Imple
} }
} }
template<> void createDebugMesh(ShapeRenderer<3>* renderer, const Physics::Implementation::AbstractShape<3>* shape) { template<> void createDebugMesh(ShapeRenderer<3>* renderer, const Shapes::Implementation::AbstractShape<3>* shape) {
switch(shape->type()) { switch(shape->type()) {
case Physics::AbstractShape3D::Type::AxisAlignedBox: case Shapes::AbstractShape3D::Type::AxisAlignedBox:
renderer->renderers.push_back(new Implementation::AxisAlignedBoxRenderer<3>(shape)); renderer->renderers.push_back(new Implementation::AxisAlignedBoxRenderer<3>(shape));
break; break;
case Physics::AbstractShape3D::Type::Box: case Shapes::AbstractShape3D::Type::Box:
renderer->renderers.push_back(new Implementation::BoxRenderer<3>(shape)); renderer->renderers.push_back(new Implementation::BoxRenderer<3>(shape));
break; break;
case Physics::AbstractShape3D::Type::LineSegment: case Shapes::AbstractShape3D::Type::LineSegment:
renderer->renderers.push_back(new Implementation::LineSegmentRenderer<3>(shape)); renderer->renderers.push_back(new Implementation::LineSegmentRenderer<3>(shape));
break; break;
case Physics::AbstractShape3D::Type::Point: case Shapes::AbstractShape3D::Type::Point:
renderer->renderers.push_back(new Implementation::PointRenderer<3>(shape)); renderer->renderers.push_back(new Implementation::PointRenderer<3>(shape));
break; break;
case Physics::AbstractShape3D::Type::Composition: { case Shapes::AbstractShape3D::Type::Composition: {
const Physics::Composition3D& composition = const Shapes::Composition3D& composition =
static_cast<const Physics::Implementation::Shape<Physics::Composition3D>*>(shape)->shape; static_cast<const Shapes::Implementation::Shape<Shapes::Composition3D>*>(shape)->shape;
for(std::size_t i = 0; i != composition.size(); ++i) for(std::size_t i = 0; i != composition.size(); ++i)
createDebugMesh(renderer, Physics::Implementation::getAbstractShape(composition, i)); createDebugMesh(renderer, Shapes::Implementation::getAbstractShape(composition, i));
} break; } break;
default: default:
Warning() << "DebugTools::ShapeRenderer3D::createShapeRenderer(): type" << shape->type() << "not implemented"; Warning() << "DebugTools::ShapeRenderer3D::createShapeRenderer(): type" << shape->type() << "not implemented";
@ -94,8 +94,8 @@ template<> void createDebugMesh(ShapeRenderer<3>* renderer, const Physics::Imple
} }
template<UnsignedInt dimensions> ShapeRenderer<dimensions>::ShapeRenderer(Physics::AbstractShape<dimensions>* shape, ResourceKey options, SceneGraph::DrawableGroup<dimensions>* drawables): SceneGraph::Drawable<dimensions>(shape->object(), drawables), options(ResourceManager::instance()->get<ShapeRendererOptions>(options)) { template<UnsignedInt dimensions> ShapeRenderer<dimensions>::ShapeRenderer(Shapes::AbstractShape<dimensions>* shape, ResourceKey options, SceneGraph::DrawableGroup<dimensions>* drawables): SceneGraph::Drawable<dimensions>(shape->object(), drawables), options(ResourceManager::instance()->get<ShapeRendererOptions>(options)) {
Implementation::createDebugMesh(this, Physics::Implementation::getAbstractShape(shape)); Implementation::createDebugMesh(this, Shapes::Implementation::getAbstractShape(shape));
} }
template<UnsignedInt dimensions> ShapeRenderer<dimensions>::~ShapeRenderer() { template<UnsignedInt dimensions> ShapeRenderer<dimensions>::~ShapeRenderer() {

14
src/DebugTools/ShapeRenderer.h

@ -31,8 +31,8 @@
#include "Color.h" #include "Color.h"
#include "Resource.h" #include "Resource.h"
#include "SceneGraph/Drawable.h" #include "SceneGraph/Drawable.h"
#include "Physics/Physics.h" #include "Shapes/Shapes.h"
#include "Physics/shapeImplementation.h" #include "Shapes/shapeImplementation.h"
#include "magnumDebugToolsVisibility.h" #include "magnumDebugToolsVisibility.h"
@ -46,7 +46,7 @@ template<UnsignedInt> class ShapeRenderer;
namespace Implementation { namespace Implementation {
template<UnsignedInt> class AbstractShapeRenderer; template<UnsignedInt> class AbstractShapeRenderer;
template<UnsignedInt dimensions> void createDebugMesh(ShapeRenderer<dimensions>* renderer, const Physics::Implementation::AbstractShape<dimensions>* shape); template<UnsignedInt dimensions> void createDebugMesh(ShapeRenderer<dimensions>* renderer, const Shapes::Implementation::AbstractShape<dimensions>* shape);
} }
/** /**
@ -103,7 +103,7 @@ class ShapeRendererOptions {
* @brief Set point size * @brief Set point size
* @return Pointer to self (for method chaining) * @return Pointer to self (for method chaining)
* *
* Size of rendered crosshairs, representing Physics::Point shapes. * Size of rendered crosshairs, representing Shapes::Point shapes.
* Default is `0.25f`. * Default is `0.25f`.
*/ */
inline ShapeRendererOptions* setPointSize(Float size) { inline ShapeRendererOptions* setPointSize(Float size) {
@ -132,14 +132,14 @@ DebugTools::ResourceManager::instance()->set("red", (new DebugTools::ShapeRender
->setColor({1.0f, 0.0f, 0.0f})); ->setColor({1.0f, 0.0f, 0.0f}));
// Create debug renderer for given shape, use "red" options for it // Create debug renderer for given shape, use "red" options for it
Physics::ObjectShape2D* shape; Shapes::ObjectShape2D* shape;
new DebugTools::ShapeRenderer2D(shape, "red", debugDrawables); new DebugTools::ShapeRenderer2D(shape, "red", debugDrawables);
@endcode @endcode
@see ShapeRenderer2D, ShapeRenderer3D @see ShapeRenderer2D, ShapeRenderer3D
*/ */
template<UnsignedInt dimensions> class MAGNUM_DEBUGTOOLS_EXPORT ShapeRenderer: public SceneGraph::Drawable<dimensions> { template<UnsignedInt dimensions> class MAGNUM_DEBUGTOOLS_EXPORT ShapeRenderer: public SceneGraph::Drawable<dimensions> {
friend void Implementation::createDebugMesh<>(ShapeRenderer<dimensions>*, const Physics::Implementation::AbstractShape<dimensions>*); friend void Implementation::createDebugMesh<>(ShapeRenderer<dimensions>*, const Shapes::Implementation::AbstractShape<dimensions>*);
public: public:
/** /**
@ -154,7 +154,7 @@ template<UnsignedInt dimensions> class MAGNUM_DEBUGTOOLS_EXPORT ShapeRenderer: p
* @p shape must be available for the whole lifetime of the renderer * @p shape must be available for the whole lifetime of the renderer
* and if it is group, it must not change its internal structure. * and if it is group, it must not change its internal structure.
*/ */
explicit ShapeRenderer(Physics::AbstractShape<dimensions>* shape, ResourceKey options = ResourceKey(), SceneGraph::DrawableGroup<dimensions>* drawables = nullptr); explicit ShapeRenderer(Shapes::AbstractShape<dimensions>* shape, ResourceKey options = ResourceKey(), SceneGraph::DrawableGroup<dimensions>* drawables = nullptr);
~ShapeRenderer(); ~ShapeRenderer();

10
src/Physics/AbstractShape.cpp → src/Shapes/AbstractShape.cpp

@ -26,10 +26,10 @@
#include <Utility/Debug.h> #include <Utility/Debug.h>
#include "Physics/ShapeGroup.h" #include "Shapes/ShapeGroup.h"
#include "Physics/Implementation/CollisionDispatch.h" #include "Shapes/Implementation/CollisionDispatch.h"
namespace Magnum { namespace Physics { namespace Magnum { namespace Shapes {
template<UnsignedInt dimensions> AbstractShape<dimensions>::AbstractShape(SceneGraph::AbstractObject<dimensions>* object, ShapeGroup<dimensions>* group): SceneGraph::AbstractGroupedFeature<dimensions, AbstractShape<dimensions>>(object, group) { template<UnsignedInt dimensions> AbstractShape<dimensions>::AbstractShape(SceneGraph::AbstractObject<dimensions>* object, ShapeGroup<dimensions>* group): SceneGraph::AbstractGroupedFeature<dimensions, AbstractShape<dimensions>>(object, group) {
this->setCachedTransformations(SceneGraph::AbstractFeature<dimensions>::CachedTransformation::Absolute); this->setCachedTransformations(SceneGraph::AbstractFeature<dimensions>::CachedTransformation::Absolute);
@ -56,8 +56,8 @@ template<UnsignedInt dimensions> void AbstractShape<dimensions>::markDirty() {
} }
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
template class MAGNUM_PHYSICS_EXPORT AbstractShape<2>; template class MAGNUM_SHAPES_EXPORT AbstractShape<2>;
template class MAGNUM_PHYSICS_EXPORT AbstractShape<3>; template class MAGNUM_SHAPES_EXPORT AbstractShape<3>;
#endif #endif
}} }}

18
src/Physics/AbstractShape.h → src/Shapes/AbstractShape.h

@ -1,5 +1,5 @@
#ifndef Magnum_Physics_AbstractShape_h #ifndef Magnum_Shapes_AbstractShape_h
#define Magnum_Physics_AbstractShape_h #define Magnum_Shapes_AbstractShape_h
/* /*
This file is part of Magnum. This file is part of Magnum.
@ -25,19 +25,19 @@
*/ */
/** @file /** @file
* @brief Class Magnum::Physics::AbstractShape, typedef Magnum::Physics::AbstractShape2D, Magnum::Physics::AbstractShape3D * @brief Class Magnum::Shapes::AbstractShape, typedef Magnum::Shapes::AbstractShape2D, Magnum::Shapes::AbstractShape3D
*/ */
#include "Magnum.h" #include "Magnum.h"
#include "DimensionTraits.h" #include "DimensionTraits.h"
#include "Physics/magnumPhysicsVisibility.h" #include "Shapes/magnumShapesVisibility.h"
#include "Physics/shapeImplementation.h" #include "Shapes/shapeImplementation.h"
#include "SceneGraph/AbstractGroupedFeature.h" #include "SceneGraph/AbstractGroupedFeature.h"
namespace Magnum { namespace Physics { namespace Magnum { namespace Shapes {
namespace Implementation { namespace Implementation {
template<UnsignedInt dimensions> inline const AbstractShape<dimensions>* getAbstractShape(const Physics::AbstractShape<dimensions>* shape) { template<UnsignedInt dimensions> inline const AbstractShape<dimensions>* getAbstractShape(const Shapes::AbstractShape<dimensions>* shape) {
return shape->abstractTransformedShape(); return shape->abstractTransformedShape();
} }
} }
@ -48,7 +48,7 @@ namespace Implementation {
This class is not directly instantiable, see Shape instead. This class is not directly instantiable, see Shape instead.
@see AbstractShape2D, AbstractShape3D @see AbstractShape2D, AbstractShape3D
*/ */
template<UnsignedInt dimensions> class MAGNUM_PHYSICS_EXPORT AbstractShape: public SceneGraph::AbstractGroupedFeature<dimensions, AbstractShape<dimensions>> { template<UnsignedInt dimensions> class MAGNUM_SHAPES_EXPORT AbstractShape: public SceneGraph::AbstractGroupedFeature<dimensions, AbstractShape<dimensions>> {
friend const Implementation::AbstractShape<dimensions>* Implementation::getAbstractShape<>(const AbstractShape<dimensions>*); friend const Implementation::AbstractShape<dimensions>* Implementation::getAbstractShape<>(const AbstractShape<dimensions>*);
public: public:
@ -105,7 +105,7 @@ template<UnsignedInt dimensions> class MAGNUM_PHYSICS_EXPORT AbstractShape: publ
void markDirty() override; void markDirty() override;
private: private:
virtual const Implementation::AbstractShape<dimensions> MAGNUM_PHYSICS_LOCAL * abstractTransformedShape() const = 0; virtual const Implementation::AbstractShape<dimensions> MAGNUM_SHAPES_LOCAL * abstractTransformedShape() const = 0;
}; };
/** @brief Base class for two-dimensional object shapes */ /** @brief Base class for two-dimensional object shapes */

8
src/Physics/AxisAlignedBox.cpp → src/Shapes/AxisAlignedBox.cpp

@ -26,9 +26,9 @@
#include "Math/Matrix3.h" #include "Math/Matrix3.h"
#include "Math/Matrix4.h" #include "Math/Matrix4.h"
#include "Physics/Point.h" #include "Shapes/Point.h"
namespace Magnum { namespace Physics { namespace Magnum { namespace Shapes {
template<UnsignedInt dimensions> AxisAlignedBox<dimensions> AxisAlignedBox<dimensions>::transformed(const typename DimensionTraits<dimensions>::MatrixType& matrix) const { template<UnsignedInt dimensions> AxisAlignedBox<dimensions> AxisAlignedBox<dimensions>::transformed(const typename DimensionTraits<dimensions>::MatrixType& matrix) const {
return AxisAlignedBox<dimensions>(matrix.transformPoint(_min), return AxisAlignedBox<dimensions>(matrix.transformPoint(_min),
@ -41,8 +41,8 @@ template<UnsignedInt dimensions> bool AxisAlignedBox<dimensions>::operator%(cons
} }
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
template class MAGNUM_PHYSICS_EXPORT AxisAlignedBox<2>; template class MAGNUM_SHAPES_EXPORT AxisAlignedBox<2>;
template class MAGNUM_PHYSICS_EXPORT AxisAlignedBox<3>; template class MAGNUM_SHAPES_EXPORT AxisAlignedBox<3>;
#endif #endif
}} }}

14
src/Physics/AxisAlignedBox.h → src/Shapes/AxisAlignedBox.h

@ -1,5 +1,5 @@
#ifndef Magnum_Physics_AxisAlignedBox_h #ifndef Magnum_Shapes_AxisAlignedBox_h
#define Magnum_Physics_AxisAlignedBox_h #define Magnum_Shapes_AxisAlignedBox_h
/* /*
This file is part of Magnum. This file is part of Magnum.
@ -25,15 +25,15 @@
*/ */
/** @file /** @file
* @brief Class Magnum::Physics::AxisAlignedBox, typedef Magnum::Physics::AxisAlignedBox2D, Magnum::Physics.:AxisAlignedBox3D * @brief Class Magnum::Shapes::AxisAlignedBox, typedef Magnum::Shapes::AxisAlignedBox2D, Magnum::Shapes.:AxisAlignedBox3D
*/ */
#include "Math/Vector3.h" #include "Math/Vector3.h"
#include "DimensionTraits.h" #include "DimensionTraits.h"
#include "Physics/Physics.h" #include "Shapes/Shapes.h"
#include "Physics/magnumPhysicsVisibility.h" #include "Shapes/magnumShapesVisibility.h"
namespace Magnum { namespace Physics { namespace Magnum { namespace Shapes {
/** /**
@brief Axis-aligned box @brief Axis-aligned box
@ -43,7 +43,7 @@ radius.
@see AxisAlignedBox2D, AxisAlignedBox3D @see AxisAlignedBox2D, AxisAlignedBox3D
@todo Assert for rotation @todo Assert for rotation
*/ */
template<UnsignedInt dimensions> class MAGNUM_PHYSICS_EXPORT AxisAlignedBox { template<UnsignedInt dimensions> class MAGNUM_SHAPES_EXPORT AxisAlignedBox {
public: public:
enum: UnsignedInt { enum: UnsignedInt {
Dimensions = dimensions /**< Dimension count */ Dimensions = dimensions /**< Dimension count */

2
src/Physics/Box.cpp → src/Shapes/Box.cpp

@ -24,7 +24,7 @@
#include "Box.h" #include "Box.h"
namespace Magnum { namespace Physics { namespace Magnum { namespace Shapes {
template<UnsignedInt dimensions> Box<dimensions> Box<dimensions>::transformed(const typename DimensionTraits<dimensions>::MatrixType& matrix) const { template<UnsignedInt dimensions> Box<dimensions> Box<dimensions>::transformed(const typename DimensionTraits<dimensions>::MatrixType& matrix) const {
return Box<dimensions>(matrix*_transformation); return Box<dimensions>(matrix*_transformation);

12
src/Physics/Box.h → src/Shapes/Box.h

@ -1,5 +1,5 @@
#ifndef Magnum_Physics_Box_h #ifndef Magnum_Shapes_Box_h
#define Magnum_Physics_Box_h #define Magnum_Shapes_Box_h
/* /*
This file is part of Magnum. This file is part of Magnum.
@ -25,15 +25,15 @@
*/ */
/** @file /** @file
* @brief Class Magnum::Physics::Box, typedef Magnum::Physics::Box2D, Magnum::Physics::Box3D * @brief Class Magnum::Shapes::Box, typedef Magnum::Shapes::Box2D, Magnum::Shapes::Box3D
*/ */
#include "Math/Matrix3.h" #include "Math/Matrix3.h"
#include "Math/Matrix4.h" #include "Math/Matrix4.h"
#include "DimensionTraits.h" #include "DimensionTraits.h"
#include "Physics/magnumPhysicsVisibility.h" #include "Shapes/magnumShapesVisibility.h"
namespace Magnum { namespace Physics { namespace Magnum { namespace Shapes {
/** /**
@brief Unit-size box with assigned transformation matrix @brief Unit-size box with assigned transformation matrix
@ -44,7 +44,7 @@ radius.
@see Box2D, Box3D @see Box2D, Box3D
@todo Assert for skew @todo Assert for skew
*/ */
template<UnsignedInt dimensions> class MAGNUM_PHYSICS_EXPORT Box { template<UnsignedInt dimensions> class MAGNUM_SHAPES_EXPORT Box {
public: public:
enum: UnsignedInt { enum: UnsignedInt {
Dimensions = dimensions /**< Dimension count */ Dimensions = dimensions /**< Dimension count */

18
src/Physics/CMakeLists.txt → src/Shapes/CMakeLists.txt

@ -22,7 +22,7 @@
# DEALINGS IN THE SOFTWARE. # DEALINGS IN THE SOFTWARE.
# #
set(MagnumPhysics_SRCS set(MagnumShapes_SRCS
AbstractShape.cpp AbstractShape.cpp
AxisAlignedBox.cpp AxisAlignedBox.cpp
Box.cpp Box.cpp
@ -39,7 +39,7 @@ set(MagnumPhysics_SRCS
Implementation/CollisionDispatch.cpp) Implementation/CollisionDispatch.cpp)
set(MagnumPhysics_HEADERS set(MagnumShapes_HEADERS
AbstractShape.h AbstractShape.h
AxisAlignedBox.h AxisAlignedBox.h
Box.h Box.h
@ -49,23 +49,23 @@ set(MagnumPhysics_HEADERS
LineSegment.h LineSegment.h
Shape.h Shape.h
ShapeGroup.h ShapeGroup.h
Physics.h Shapes.h
Plane.h Plane.h
Point.h Point.h
Sphere.h Sphere.h
magnumPhysicsVisibility.h magnumShapesVisibility.h
shapeImplementation.h) shapeImplementation.h)
add_library(MagnumPhysics ${SHARED_OR_STATIC} ${MagnumPhysics_SRCS}) add_library(MagnumShapes ${SHARED_OR_STATIC} ${MagnumShapes_SRCS})
if(BUILD_STATIC_PIC) if(BUILD_STATIC_PIC)
# TODO: CMake 2.8.9 has this as POSITION_INDEPENDENT_CODE property # TODO: CMake 2.8.9 has this as POSITION_INDEPENDENT_CODE property
set_target_properties(MagnumPhysics PROPERTIES COMPILE_FLAGS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}) set_target_properties(MagnumShapes PROPERTIES COMPILE_FLAGS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS})
endif() endif()
target_link_libraries(MagnumPhysics Magnum MagnumSceneGraph) target_link_libraries(MagnumShapes Magnum MagnumSceneGraph)
install(TARGETS MagnumPhysics DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(TARGETS MagnumShapes DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
install(FILES ${MagnumPhysics_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Physics) install(FILES ${MagnumShapes_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Shapes)
if(BUILD_TESTS) if(BUILD_TESTS)
add_subdirectory(Test) add_subdirectory(Test)

10
src/Physics/Capsule.cpp → src/Shapes/Capsule.cpp

@ -29,12 +29,12 @@
#include "Math/Matrix4.h" #include "Math/Matrix4.h"
#include "Math/Geometry/Distance.h" #include "Math/Geometry/Distance.h"
#include "Magnum.h" #include "Magnum.h"
#include "Physics/Point.h" #include "Shapes/Point.h"
#include "Physics/Sphere.h" #include "Shapes/Sphere.h"
using namespace Magnum::Math::Geometry; using namespace Magnum::Math::Geometry;
namespace Magnum { namespace Physics { namespace Magnum { namespace Shapes {
template<UnsignedInt dimensions> Capsule<dimensions> Capsule<dimensions>::transformed(const typename DimensionTraits<dimensions>::MatrixType& matrix) const { template<UnsignedInt dimensions> Capsule<dimensions> Capsule<dimensions>::transformed(const typename DimensionTraits<dimensions>::MatrixType& matrix) const {
return Capsule<dimensions>(matrix.transformPoint(_a), matrix.transformPoint(_b), return Capsule<dimensions>(matrix.transformPoint(_a), matrix.transformPoint(_b),
@ -52,8 +52,8 @@ template<UnsignedInt dimensions> bool Capsule<dimensions>::operator%(const Spher
} }
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
template class MAGNUM_PHYSICS_EXPORT Capsule<2>; template class MAGNUM_SHAPES_EXPORT Capsule<2>;
template class MAGNUM_PHYSICS_EXPORT Capsule<3>; template class MAGNUM_SHAPES_EXPORT Capsule<3>;
#endif #endif
}} }}

14
src/Physics/Capsule.h → src/Shapes/Capsule.h

@ -1,5 +1,5 @@
#ifndef Magnum_Physics_Capsule_h #ifndef Magnum_Shapes_Capsule_h
#define Magnum_Physics_Capsule_h #define Magnum_Shapes_Capsule_h
/* /*
This file is part of Magnum. This file is part of Magnum.
@ -25,15 +25,15 @@
*/ */
/** @file /** @file
* @brief Class Magnum::Physics::Capsule, typedef Magnum::Physics::Capsule2D, Magnum::Physics::Capsule3D * @brief Class Magnum::Shapes::Capsule, typedef Magnum::Shapes::Capsule2D, Magnum::Shapes::Capsule3D
*/ */
#include "Math/Vector3.h" #include "Math/Vector3.h"
#include "DimensionTraits.h" #include "DimensionTraits.h"
#include "Physics/Physics.h" #include "Shapes/Shapes.h"
#include "Physics/magnumPhysicsVisibility.h" #include "Shapes/magnumShapesVisibility.h"
namespace Magnum { namespace Physics { namespace Magnum { namespace Shapes {
/** /**
@brief %Capsule defined by cylinder start and end point and radius @brief %Capsule defined by cylinder start and end point and radius
@ -43,7 +43,7 @@ applying transformation, the scale factor is averaged from all axes.
@see Capsule2D, Capsule3D @see Capsule2D, Capsule3D
@todo Assert for asymmetric scaling @todo Assert for asymmetric scaling
*/ */
template<UnsignedInt dimensions> class MAGNUM_PHYSICS_EXPORT Capsule { template<UnsignedInt dimensions> class MAGNUM_SHAPES_EXPORT Capsule {
public: public:
enum: UnsignedInt { enum: UnsignedInt {
Dimensions = dimensions /**< Dimension count */ Dimensions = dimensions /**< Dimension count */

8
src/Physics/Composition.cpp → src/Shapes/Composition.cpp

@ -27,9 +27,9 @@
#include <algorithm> #include <algorithm>
#include <Utility/Assert.h> #include <Utility/Assert.h>
#include "Physics/Implementation/CollisionDispatch.h" #include "Shapes/Implementation/CollisionDispatch.h"
namespace Magnum { namespace Physics { namespace Magnum { namespace Shapes {
/* /*
Hierarchy implementation notes: Hierarchy implementation notes:
@ -160,8 +160,8 @@ template<UnsignedInt dimensions> bool Composition<dimensions>::collides(const Im
} }
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
template class MAGNUM_PHYSICS_EXPORT Composition<2>; template class MAGNUM_SHAPES_EXPORT Composition<2>;
template class MAGNUM_PHYSICS_EXPORT Composition<3>; template class MAGNUM_SHAPES_EXPORT Composition<3>;
#endif #endif
}} }}

24
src/Physics/Composition.h → src/Shapes/Composition.h

@ -1,5 +1,5 @@
#ifndef Magnum_Physics_Composition_h #ifndef Magnum_Shapes_Composition_h
#define Magnum_Physics_Composition_h #define Magnum_Shapes_Composition_h
/* /*
This file is part of Magnum. This file is part of Magnum.
@ -25,7 +25,7 @@
*/ */
/** @file /** @file
* @brief Class Magnum::Physics::Composition, enum Magnum::Physics::CompositionOperation * @brief Class Magnum::Shapes::Composition, enum Magnum::Shapes::CompositionOperation
*/ */
#include <type_traits> #include <type_traits>
@ -33,11 +33,11 @@
#include <Utility/Assert.h> #include <Utility/Assert.h>
#include "DimensionTraits.h" #include "DimensionTraits.h"
#include "Physics/Physics.h" #include "Shapes/Shapes.h"
#include "Physics/magnumPhysicsVisibility.h" #include "Shapes/magnumShapesVisibility.h"
#include "Physics/shapeImplementation.h" #include "Shapes/shapeImplementation.h"
namespace Magnum { namespace Physics { namespace Magnum { namespace Shapes {
namespace Implementation { namespace Implementation {
template<class> struct ShapeHelper; template<class> struct ShapeHelper;
@ -63,7 +63,7 @@ enum class CompositionOperation: UnsignedByte {
Result of logical operations on shapes. Result of logical operations on shapes.
See @ref collision-detection for brief introduction. See @ref collision-detection for brief introduction.
*/ */
template<UnsignedInt dimensions> class MAGNUM_PHYSICS_EXPORT Composition { template<UnsignedInt dimensions> class MAGNUM_SHAPES_EXPORT Composition {
friend Implementation::AbstractShape<dimensions>* Implementation::getAbstractShape<>(Composition<dimensions>&, std::size_t); friend Implementation::AbstractShape<dimensions>* Implementation::getAbstractShape<>(Composition<dimensions>&, std::size_t);
friend const Implementation::AbstractShape<dimensions>* Implementation::getAbstractShape<>(const Composition<dimensions>&, std::size_t); friend const Implementation::AbstractShape<dimensions>* Implementation::getAbstractShape<>(const Composition<dimensions>&, std::size_t);
friend struct Implementation::ShapeHelper<Composition<dimensions>>; friend struct Implementation::ShapeHelper<Composition<dimensions>>;
@ -193,7 +193,7 @@ typedef Composition<2> Composition2D;
typedef Composition<3> Composition3D; typedef Composition<3> Composition3D;
#ifdef DOXYGEN_GENERATING_OUTPUT #ifdef DOXYGEN_GENERATING_OUTPUT
/** @debugoperator{Magnum::Physics::Composition} */ /** @debugoperator{Magnum::Shapes::Composition} */
template<UnsignedInt dimensions> Debug operator<<(Debug debug, typename Composition<dimensions>::Type value); template<UnsignedInt dimensions> Debug operator<<(Debug debug, typename Composition<dimensions>::Type value);
#endif #endif
@ -257,7 +257,7 @@ template<class T, class U> inline auto operator||(T&& a, U&& b) -> enableIfAreSh
template<UnsignedInt dimensions> template<class T> Composition<dimensions>::Composition(CompositionOperation operation, T&& a): _shapeCount(shapeCount(a)), _nodeCount(nodeCount(a)+1), _shapes(new Implementation::AbstractShape<dimensions>*[_shapeCount]), _nodes(new Node[_nodeCount]) { template<UnsignedInt dimensions> template<class T> Composition<dimensions>::Composition(CompositionOperation operation, T&& a): _shapeCount(shapeCount(a)), _nodeCount(nodeCount(a)+1), _shapes(new Implementation::AbstractShape<dimensions>*[_shapeCount]), _nodes(new Node[_nodeCount]) {
CORRADE_ASSERT(operation == CompositionOperation::Not, CORRADE_ASSERT(operation == CompositionOperation::Not,
"Physics::Composition::Composition(): unary operation expected", ); "Shapes::Composition::Composition(): unary operation expected", );
_nodes[0].operation = operation; _nodes[0].operation = operation;
/* 0 = no children, 1 = left child only */ /* 0 = no children, 1 = left child only */
@ -269,7 +269,7 @@ template<UnsignedInt dimensions> template<class T> Composition<dimensions>::Comp
template<UnsignedInt dimensions> template<class T, class U> Composition<dimensions>::Composition(CompositionOperation operation, T&& a, U&& b): _shapeCount(shapeCount(a) + shapeCount(b)), _nodeCount(nodeCount(a) + nodeCount(b) + 1), _shapes(new Implementation::AbstractShape<dimensions>*[_shapeCount]), _nodes(new Node[_nodeCount]) { template<UnsignedInt dimensions> template<class T, class U> Composition<dimensions>::Composition(CompositionOperation operation, T&& a, U&& b): _shapeCount(shapeCount(a) + shapeCount(b)), _nodeCount(nodeCount(a) + nodeCount(b) + 1), _shapes(new Implementation::AbstractShape<dimensions>*[_shapeCount]), _nodes(new Node[_nodeCount]) {
CORRADE_ASSERT(operation != CompositionOperation::Not, CORRADE_ASSERT(operation != CompositionOperation::Not,
"Physics::Composition::Composition(): binary operation expected", ); "Shapes::Composition::Composition(): binary operation expected", );
_nodes[0].operation = operation; _nodes[0].operation = operation;
/* 0 = no children, 1 = left child only, 2 = right child only, >2 = both */ /* 0 = no children, 1 = left child only, 2 = right child only, >2 = both */
@ -288,7 +288,7 @@ template<UnsignedInt dimensions> template<class T, class U> Composition<dimensio
template<UnsignedInt dimensions> template<class T> inline const T& Composition<dimensions>::get(std::size_t i) const { template<UnsignedInt dimensions> template<class T> inline const T& Composition<dimensions>::get(std::size_t i) const {
CORRADE_ASSERT(_shapes[i]->type() == Implementation::TypeOf<T>::type(), CORRADE_ASSERT(_shapes[i]->type() == Implementation::TypeOf<T>::type(),
"Physics::Composition::get(): given shape is not of type" << Implementation::TypeOf<T>::type() << "Shapes::Composition::get(): given shape is not of type" << Implementation::TypeOf<T>::type() <<
"but" << _shapes[i]->type(), *static_cast<T*>(nullptr)); "but" << _shapes[i]->type(), *static_cast<T*>(nullptr));
return static_cast<Implementation::Shape<T>*>(_shapes[i])->shape; return static_cast<Implementation::Shape<T>*>(_shapes[i])->shape;
} }

20
src/Physics/Implementation/CollisionDispatch.cpp → src/Shapes/Implementation/CollisionDispatch.cpp

@ -24,16 +24,16 @@
#include "CollisionDispatch.h" #include "CollisionDispatch.h"
#include "Physics/AxisAlignedBox.h" #include "Shapes/AxisAlignedBox.h"
#include "Physics/Box.h" #include "Shapes/Box.h"
#include "Physics/Capsule.h" #include "Shapes/Capsule.h"
#include "Physics/LineSegment.h" #include "Shapes/LineSegment.h"
#include "Physics/Plane.h" #include "Shapes/Plane.h"
#include "Physics/Point.h" #include "Shapes/Point.h"
#include "Physics/Sphere.h" #include "Shapes/Sphere.h"
#include "Physics/shapeImplementation.h" #include "Shapes/shapeImplementation.h"
namespace Magnum { namespace Physics { namespace Implementation { namespace Magnum { namespace Shapes { namespace Implementation {
namespace { namespace {
inline constexpr UnsignedInt operator*(ShapeDimensionTraits<2>::Type a, ShapeDimensionTraits<2>::Type b) { inline constexpr UnsignedInt operator*(ShapeDimensionTraits<2>::Type a, ShapeDimensionTraits<2>::Type b) {

6
src/Physics/Implementation/CollisionDispatch.h → src/Shapes/Implementation/CollisionDispatch.h

@ -1,5 +1,5 @@
#ifndef Magnum_Physics_Implementation_CollisionDispatch_h #ifndef Magnum_Shapes_Implementation_CollisionDispatch_h
#define Magnum_Physics_Implementation_CollisionDispatch_h #define Magnum_Shapes_Implementation_CollisionDispatch_h
/* /*
This file is part of Magnum. This file is part of Magnum.
@ -26,7 +26,7 @@
#include "Types.h" #include "Types.h"
namespace Magnum { namespace Physics { namespace Implementation { namespace Magnum { namespace Shapes { namespace Implementation {
template<UnsignedInt> struct AbstractShape; template<UnsignedInt> struct AbstractShape;

2
src/Physics/Line.cpp → src/Shapes/Line.cpp

@ -27,7 +27,7 @@
#include "Math/Matrix3.h" #include "Math/Matrix3.h"
#include "Math/Matrix4.h" #include "Math/Matrix4.h"
namespace Magnum { namespace Physics { namespace Magnum { namespace Shapes {
template<UnsignedInt dimensions> Line<dimensions> Line<dimensions>::transformed(const typename DimensionTraits<dimensions>::MatrixType& matrix) const { template<UnsignedInt dimensions> Line<dimensions> Line<dimensions>::transformed(const typename DimensionTraits<dimensions>::MatrixType& matrix) const {
return Line<dimensions>(matrix.transformPoint(_a), return Line<dimensions>(matrix.transformPoint(_a),

12
src/Physics/Line.h → src/Shapes/Line.h

@ -1,5 +1,5 @@
#ifndef Magnum_Physics_Line_h #ifndef Magnum_Shapes_Line_h
#define Magnum_Physics_Line_h #define Magnum_Shapes_Line_h
/* /*
This file is part of Magnum. This file is part of Magnum.
@ -25,14 +25,14 @@
*/ */
/** @file /** @file
* @brief Class Magnum::Physics::Line, typedef Magnum::Physics::Line2D, Magnum::Physics::Line3D * @brief Class Magnum::Shapes::Line, typedef Magnum::Shapes::Line2D, Magnum::Shapes::Line3D
*/ */
#include "Math/Vector3.h" #include "Math/Vector3.h"
#include "DimensionTraits.h" #include "DimensionTraits.h"
#include "Physics/magnumPhysicsVisibility.h" #include "Shapes/magnumShapesVisibility.h"
namespace Magnum { namespace Physics { namespace Magnum { namespace Shapes {
/** /**
@brief Infinite line, defined by two points @brief Infinite line, defined by two points
@ -40,7 +40,7 @@ namespace Magnum { namespace Physics {
@see Line2D, Line3D @see Line2D, Line3D
@todo collision detection of two Line2D @todo collision detection of two Line2D
*/ */
template<UnsignedInt dimensions> class MAGNUM_PHYSICS_EXPORT Line { template<UnsignedInt dimensions> class MAGNUM_SHAPES_EXPORT Line {
public: public:
enum: UnsignedInt { enum: UnsignedInt {
Dimensions = dimensions /**< Dimension count */ Dimensions = dimensions /**< Dimension count */

8
src/Physics/LineSegment.h → src/Shapes/LineSegment.h

@ -1,5 +1,5 @@
#ifndef Magnum_Physics_LineSegment_h #ifndef Magnum_Shapes_LineSegment_h
#define Magnum_Physics_LineSegment_h #define Magnum_Shapes_LineSegment_h
/* /*
This file is part of Magnum. This file is part of Magnum.
@ -25,12 +25,12 @@
*/ */
/** @file /** @file
* @brief Class Magnum::Physics::LineSegment, typedef Magnum::Physics::LineSegment2D, Magnum::Physics::LineSegment3D * @brief Class Magnum::Shapes::LineSegment, typedef Magnum::Shapes::LineSegment2D, Magnum::Shapes::LineSegment3D
*/ */
#include "Line.h" #include "Line.h"
namespace Magnum { namespace Physics { namespace Magnum { namespace Shapes {
/** /**
@brief %Line segment, defined by starting and ending point @brief %Line segment, defined by starting and ending point

4
src/Physics/Plane.cpp → src/Shapes/Plane.cpp

@ -28,11 +28,11 @@
#include "Math/Matrix4.h" #include "Math/Matrix4.h"
#include "Math/Geometry/Intersection.h" #include "Math/Geometry/Intersection.h"
#include "Physics/LineSegment.h" #include "Shapes/LineSegment.h"
using namespace Magnum::Math::Geometry; using namespace Magnum::Math::Geometry;
namespace Magnum { namespace Physics { namespace Magnum { namespace Shapes {
Plane Plane::transformed(const Matrix4& matrix) const { Plane Plane::transformed(const Matrix4& matrix) const {
return Plane(matrix.transformPoint(_position), return Plane(matrix.transformPoint(_position),

14
src/Physics/Plane.h → src/Shapes/Plane.h

@ -1,5 +1,5 @@
#ifndef Magnum_Physics_Plane_h #ifndef Magnum_Shapes_Plane_h
#define Magnum_Physics_Plane_h #define Magnum_Shapes_Plane_h
/* /*
This file is part of Magnum. This file is part of Magnum.
@ -25,18 +25,18 @@
*/ */
/** @file /** @file
* @brief Class Magnum::Physics::Plane * @brief Class Magnum::Shapes::Plane
*/ */
#include "Math/Vector3.h" #include "Math/Vector3.h"
#include "Magnum.h" #include "Magnum.h"
#include "Physics/Physics.h" #include "Shapes/Shapes.h"
#include "Physics/magnumPhysicsVisibility.h" #include "Shapes/magnumShapesVisibility.h"
namespace Magnum { namespace Physics { namespace Magnum { namespace Shapes {
/** @brief Infinite plane, defined by position and normal (3D only) */ /** @brief Infinite plane, defined by position and normal (3D only) */
class MAGNUM_PHYSICS_EXPORT Plane { class MAGNUM_SHAPES_EXPORT Plane {
public: public:
enum: UnsignedInt { enum: UnsignedInt {
Dimensions = 3 /**< Dimension count */ Dimensions = 3 /**< Dimension count */

2
src/Physics/Point.cpp → src/Shapes/Point.cpp

@ -27,7 +27,7 @@
#include "Math/Matrix3.h" #include "Math/Matrix3.h"
#include "Math/Matrix4.h" #include "Math/Matrix4.h"
namespace Magnum { namespace Physics { namespace Magnum { namespace Shapes {
template<UnsignedInt dimensions> Point<dimensions> Point<dimensions>::transformed(const typename DimensionTraits<dimensions>::MatrixType& matrix) const { template<UnsignedInt dimensions> Point<dimensions> Point<dimensions>::transformed(const typename DimensionTraits<dimensions>::MatrixType& matrix) const {
return Point<dimensions>(matrix.transformPoint(_position)); return Point<dimensions>(matrix.transformPoint(_position));

12
src/Physics/Point.h → src/Shapes/Point.h

@ -1,5 +1,5 @@
#ifndef Magnum_Physics_Point_h #ifndef Magnum_Shapes_Point_h
#define Magnum_Physics_Point_h #define Magnum_Shapes_Point_h
/* /*
This file is part of Magnum. This file is part of Magnum.
@ -25,21 +25,21 @@
*/ */
/** @file /** @file
* @brief Class Magnum::Physics::Point, typedef Magnum::Physics::Point2D, Magnum::Physics::Point3D * @brief Class Magnum::Shapes::Point, typedef Magnum::Shapes::Point2D, Magnum::Shapes::Point3D
*/ */
#include "Math/Vector3.h" #include "Math/Vector3.h"
#include "DimensionTraits.h" #include "DimensionTraits.h"
#include "Physics/magnumPhysicsVisibility.h" #include "Shapes/magnumShapesVisibility.h"
namespace Magnum { namespace Physics { namespace Magnum { namespace Shapes {
/** /**
@brief %Point @brief %Point
@see Point2D, Point3D @see Point2D, Point3D
*/ */
template<UnsignedInt dimensions> class MAGNUM_PHYSICS_EXPORT Point { template<UnsignedInt dimensions> class MAGNUM_SHAPES_EXPORT Point {
public: public:
enum: UnsignedInt { enum: UnsignedInt {
Dimensions = dimensions /**< Dimension count */ Dimensions = dimensions /**< Dimension count */

14
src/Physics/Shape.cpp → src/Shapes/Shape.cpp

@ -24,25 +24,25 @@
#include "Shape.h" #include "Shape.h"
#include "Physics/Composition.h" #include "Shapes/Composition.h"
namespace Magnum { namespace Physics { namespace Implementation { namespace Magnum { namespace Shapes { namespace Implementation {
template<UnsignedInt dimensions> void ShapeHelper<Composition<dimensions>>::set(Physics::Shape<Composition<dimensions>>& shape, const Composition<dimensions>& composition) { template<UnsignedInt dimensions> void ShapeHelper<Composition<dimensions>>::set(Shapes::Shape<Composition<dimensions>>& shape, const Composition<dimensions>& composition) {
shape._transformedShape.shape = shape._shape.shape = composition; shape._transformedShape.shape = shape._shape.shape = composition;
} }
template<UnsignedInt dimensions> void ShapeHelper<Composition<dimensions>>::set(Physics::Shape<Composition<dimensions>>& shape, Composition<dimensions>&& composition) { template<UnsignedInt dimensions> void ShapeHelper<Composition<dimensions>>::set(Shapes::Shape<Composition<dimensions>>& shape, Composition<dimensions>&& composition) {
shape._transformedShape.shape = shape._shape.shape = std::move(composition); shape._transformedShape.shape = shape._shape.shape = std::move(composition);
} }
template<UnsignedInt dimensions> void ShapeHelper<Composition<dimensions>>::transform(Physics::Shape<Composition<dimensions>>& shape, const typename DimensionTraits<dimensions>::MatrixType& absoluteTransformationMatrix) { template<UnsignedInt dimensions> void ShapeHelper<Composition<dimensions>>::transform(Shapes::Shape<Composition<dimensions>>& shape, const typename DimensionTraits<dimensions>::MatrixType& absoluteTransformationMatrix) {
CORRADE_INTERNAL_ASSERT(shape._shape.shape.size() == shape._transformedShape.shape.size()); CORRADE_INTERNAL_ASSERT(shape._shape.shape.size() == shape._transformedShape.shape.size());
for(std::size_t i = 0; i != shape.shape().size(); ++i) for(std::size_t i = 0; i != shape.shape().size(); ++i)
shape._shape.shape._shapes[i]->transform(absoluteTransformationMatrix, shape._transformedShape.shape._shapes[i]); shape._shape.shape._shapes[i]->transform(absoluteTransformationMatrix, shape._transformedShape.shape._shapes[i]);
} }
template struct MAGNUM_PHYSICS_EXPORT ShapeHelper<Composition<2>>; template struct MAGNUM_SHAPES_EXPORT ShapeHelper<Composition<2>>;
template struct MAGNUM_PHYSICS_EXPORT ShapeHelper<Composition<3>>; template struct MAGNUM_SHAPES_EXPORT ShapeHelper<Composition<3>>;
}}} }}}

32
src/Physics/Shape.h → src/Shapes/Shape.h

@ -1,5 +1,5 @@
#ifndef Magnum_Physics_Shape_h #ifndef Magnum_Shapes_Shape_h
#define Magnum_Physics_Shape_h #define Magnum_Shapes_Shape_h
/* /*
This file is part of Magnum. This file is part of Magnum.
@ -25,15 +25,15 @@
*/ */
/** @file /** @file
* @brief Class Magnum::Physics::Shape * @brief Class Magnum::Shapes::Shape
*/ */
#include "Physics/AbstractShape.h" #include "Shapes/AbstractShape.h"
#include "Physics/Physics.h" #include "Shapes/Shapes.h"
#include "magnumPhysicsVisibility.h" #include "magnumShapesVisibility.h"
namespace Magnum { namespace Physics { namespace Magnum { namespace Shapes {
namespace Implementation { namespace Implementation {
template<class> struct ShapeHelper; template<class> struct ShapeHelper;
@ -52,16 +52,16 @@ Add the feature to the object and some shape group (you can also use
ShapeGroup::add() and ShapeGroup::remove() later) and configure the ShapeGroup::add() and ShapeGroup::remove() later) and configure the
shape. shape.
@code @code
Physics::ShapeGroup3D shapes; Shapes::ShapeGroup3D shapes;
Object3D* object; Object3D* object;
auto shape = new Physics::Shape<Physics::Sphere3D>(object, {{}, 0.75f}, &shapes); auto shape = new Shapes::Shape<Shapes::Sphere3D>(object, {{}, 0.75f}, &shapes);
@endcode @endcode
@see @ref scenegraph, ShapeGroup2D, ShapeGroup3D, @see @ref scenegraph, ShapeGroup2D, ShapeGroup3D,
DebugTools::ShapeRenderer DebugTools::ShapeRenderer
*/ */
template<class T> class MAGNUM_PHYSICS_EXPORT Shape: public AbstractShape<T::Dimensions> { template<class T> class MAGNUM_SHAPES_EXPORT Shape: public AbstractShape<T::Dimensions> {
friend struct Implementation::ShapeHelper<T>; friend struct Implementation::ShapeHelper<T>;
public: public:
@ -130,20 +130,20 @@ template<class T> void Shape<T>::clean(const typename DimensionTraits<T::Dimensi
namespace Implementation { namespace Implementation {
template<class T> struct ShapeHelper { template<class T> struct ShapeHelper {
inline static void set(Physics::Shape<T>& shape, const T& s) { inline static void set(Shapes::Shape<T>& shape, const T& s) {
shape._shape.shape = s; shape._shape.shape = s;
} }
inline static void transform(Physics::Shape<T>& shape, const typename DimensionTraits<T::Dimensions>::MatrixType& absoluteTransformationMatrix) { inline static void transform(Shapes::Shape<T>& shape, const typename DimensionTraits<T::Dimensions>::MatrixType& absoluteTransformationMatrix) {
shape._transformedShape.shape = shape._shape.shape.transformed(absoluteTransformationMatrix); shape._transformedShape.shape = shape._shape.shape.transformed(absoluteTransformationMatrix);
} }
}; };
template<UnsignedInt dimensions> struct MAGNUM_PHYSICS_EXPORT ShapeHelper<Composition<dimensions>> { template<UnsignedInt dimensions> struct MAGNUM_SHAPES_EXPORT ShapeHelper<Composition<dimensions>> {
static void set(Physics::Shape<Composition<dimensions>>& shape, const Composition<dimensions>& composition); static void set(Shapes::Shape<Composition<dimensions>>& shape, const Composition<dimensions>& composition);
static void set(Physics::Shape<Composition<dimensions>>& shape, Composition<dimensions>&& composition); static void set(Shapes::Shape<Composition<dimensions>>& shape, Composition<dimensions>&& composition);
static void transform(Physics::Shape<Composition<dimensions>>& shape, const typename DimensionTraits<dimensions>::MatrixType& absoluteTransformationMatrix); static void transform(Shapes::Shape<Composition<dimensions>>& shape, const typename DimensionTraits<dimensions>::MatrixType& absoluteTransformationMatrix);
}; };
} }

8
src/Physics/ShapeGroup.cpp → src/Shapes/ShapeGroup.cpp

@ -24,9 +24,9 @@
#include "ShapeGroup.h" #include "ShapeGroup.h"
#include "Physics/AbstractShape.h" #include "Shapes/AbstractShape.h"
namespace Magnum { namespace Physics { namespace Magnum { namespace Shapes {
template<UnsignedInt dimensions> void ShapeGroup<dimensions>::setClean() { template<UnsignedInt dimensions> void ShapeGroup<dimensions>::setClean() {
/* Clean all objects */ /* Clean all objects */
@ -51,8 +51,8 @@ template<UnsignedInt dimensions> AbstractShape<dimensions>* ShapeGroup<dimension
} }
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
template class MAGNUM_PHYSICS_EXPORT ShapeGroup<2>; template class MAGNUM_SHAPES_EXPORT ShapeGroup<2>;
template class MAGNUM_PHYSICS_EXPORT ShapeGroup<3>; template class MAGNUM_SHAPES_EXPORT ShapeGroup<3>;
#endif #endif
}} }}

14
src/Physics/ShapeGroup.h → src/Shapes/ShapeGroup.h

@ -1,5 +1,5 @@
#ifndef Magnum_Physics_ShapeGroup_h #ifndef Magnum_Shapes_ShapeGroup_h
#define Magnum_Physics_ShapeGroup_h #define Magnum_Shapes_ShapeGroup_h
/* /*
This file is part of Magnum. This file is part of Magnum.
@ -25,17 +25,17 @@
*/ */
/** @file /** @file
* @brief Class Magnum::Physics::ShapeGroup, typedef Magnum::Physics::ShapeGroup2D, Magnum::Physics::ShapeGroup3D * @brief Class Magnum::Shapes::ShapeGroup, typedef Magnum::Shapes::ShapeGroup2D, Magnum::Shapes::ShapeGroup3D
*/ */
#include <vector> #include <vector>
#include "Physics/AbstractShape.h" #include "Shapes/AbstractShape.h"
#include "SceneGraph/FeatureGroup.h" #include "SceneGraph/FeatureGroup.h"
#include "magnumPhysicsVisibility.h" #include "magnumShapesVisibility.h"
namespace Magnum { namespace Physics { namespace Magnum { namespace Shapes {
/** /**
@brief Group of shapes @brief Group of shapes
@ -43,7 +43,7 @@ namespace Magnum { namespace Physics {
See Shape for more information. See Shape for more information.
@see @ref scenegraph, ShapeGroup2D, ShapeGroup3D @see @ref scenegraph, ShapeGroup2D, ShapeGroup3D
*/ */
template<UnsignedInt dimensions> class MAGNUM_PHYSICS_EXPORT ShapeGroup: public SceneGraph::FeatureGroup<dimensions, AbstractShape<dimensions>> { template<UnsignedInt dimensions> class MAGNUM_SHAPES_EXPORT ShapeGroup: public SceneGraph::FeatureGroup<dimensions, AbstractShape<dimensions>> {
friend class AbstractShape<dimensions>; friend class AbstractShape<dimensions>;
public: public:

8
src/Physics/Physics.h → src/Shapes/Shapes.h

@ -1,5 +1,5 @@
#ifndef Magnum_Physics_Physics_h #ifndef Magnum_Shapes_Shapes_h
#define Magnum_Physics_Physics_h #define Magnum_Shapes_Shapes_h
/* /*
This file is part of Magnum. This file is part of Magnum.
@ -25,12 +25,12 @@
*/ */
/** @file /** @file
* @brief Forward declarations for Magnum::Physics namespace * @brief Forward declarations for Magnum::Shapes namespace
*/ */
#include "Types.h" #include "Types.h"
namespace Magnum { namespace Physics { namespace Magnum { namespace Shapes {
/** @todoc remove when doxygen is sane again */ /** @todoc remove when doxygen is sane again */
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT

10
src/Physics/Sphere.cpp → src/Shapes/Sphere.cpp

@ -29,12 +29,12 @@
#include "Math/Matrix4.h" #include "Math/Matrix4.h"
#include "Math/Geometry/Distance.h" #include "Math/Geometry/Distance.h"
#include "Magnum.h" #include "Magnum.h"
#include "Physics/LineSegment.h" #include "Shapes/LineSegment.h"
#include "Physics/Point.h" #include "Shapes/Point.h"
using namespace Magnum::Math::Geometry; using namespace Magnum::Math::Geometry;
namespace Magnum { namespace Physics { namespace Magnum { namespace Shapes {
namespace { namespace {
template<UnsignedInt dimensions> static typename DimensionTraits<dimensions>::VectorType unitVector(); template<UnsignedInt dimensions> static typename DimensionTraits<dimensions>::VectorType unitVector();
@ -70,8 +70,8 @@ template<UnsignedInt dimensions> bool Sphere<dimensions>::operator%(const Sphere
} }
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
template class MAGNUM_PHYSICS_EXPORT Sphere<2>; template class MAGNUM_SHAPES_EXPORT Sphere<2>;
template class MAGNUM_PHYSICS_EXPORT Sphere<3>; template class MAGNUM_SHAPES_EXPORT Sphere<3>;
#endif #endif
}} }}

14
src/Physics/Sphere.h → src/Shapes/Sphere.h

@ -1,5 +1,5 @@
#ifndef Magnum_Physics_Sphere_h #ifndef Magnum_Shapes_Sphere_h
#define Magnum_Physics_Sphere_h #define Magnum_Shapes_Sphere_h
/* /*
This file is part of Magnum. This file is part of Magnum.
@ -25,15 +25,15 @@
*/ */
/** @file /** @file
* @brief Class Magnum::Physics::Sphere, typedef Magnum::Physics::Sphere2D, Magnum::Physics::Sphere3D * @brief Class Magnum::Shapes::Sphere, typedef Magnum::Shapes::Sphere2D, Magnum::Shapes::Sphere3D
*/ */
#include "Math/Vector3.h" #include "Math/Vector3.h"
#include "DimensionTraits.h" #include "DimensionTraits.h"
#include "Physics/Physics.h" #include "Shapes/Shapes.h"
#include "Physics/magnumPhysicsVisibility.h" #include "Shapes/magnumShapesVisibility.h"
namespace Magnum { namespace Physics { namespace Magnum { namespace Shapes {
/** /**
@brief %Sphere defined by position and radius @brief %Sphere defined by position and radius
@ -43,7 +43,7 @@ applying transformation, the scale factor is averaged from all axes.
@see Sphere2D, Sphere3D @see Sphere2D, Sphere3D
@todo Assert for asymmetric scaling @todo Assert for asymmetric scaling
*/ */
template<UnsignedInt dimensions> class MAGNUM_PHYSICS_EXPORT Sphere { template<UnsignedInt dimensions> class MAGNUM_SHAPES_EXPORT Sphere {
public: public:
enum: UnsignedInt { enum: UnsignedInt {
Dimensions = dimensions /**< Dimension count */ Dimensions = dimensions /**< Dimension count */

16
src/Physics/Test/AxisAlignedBoxTest.cpp → src/Shapes/Test/AxisAlignedBoxTest.cpp

@ -24,12 +24,12 @@
#include "Math/Matrix4.h" #include "Math/Matrix4.h"
#include "Magnum.h" #include "Magnum.h"
#include "Physics/AxisAlignedBox.h" #include "Shapes/AxisAlignedBox.h"
#include "Physics/Point.h" #include "Shapes/Point.h"
#include "ShapeTestBase.h" #include "ShapeTestBase.h"
namespace Magnum { namespace Physics { namespace Test { namespace Magnum { namespace Shapes { namespace Test {
class AxisAlignedBoxTest: public Corrade::TestSuite::Tester { class AxisAlignedBoxTest: public Corrade::TestSuite::Tester {
public: public:
@ -45,16 +45,16 @@ AxisAlignedBoxTest::AxisAlignedBoxTest() {
} }
void AxisAlignedBoxTest::transformed() { void AxisAlignedBoxTest::transformed() {
const auto box = Physics::AxisAlignedBox3D({-1.0f, -2.0f, -3.0f}, {1.0f, 2.0f, 3.0f}) const auto box = Shapes::AxisAlignedBox3D({-1.0f, -2.0f, -3.0f}, {1.0f, 2.0f, 3.0f})
.transformed(Matrix4::translation(Vector3(1.0f))*Matrix4::scaling({2.0f, -1.0f, 1.5f})); .transformed(Matrix4::translation(Vector3(1.0f))*Matrix4::scaling({2.0f, -1.0f, 1.5f}));
CORRADE_COMPARE(box.min(), Vector3(-1.0f, 3.0f, -3.5f)); CORRADE_COMPARE(box.min(), Vector3(-1.0f, 3.0f, -3.5f));
CORRADE_COMPARE(box.max(), Vector3(3.0f, -1.0f, 5.5f)); CORRADE_COMPARE(box.max(), Vector3(3.0f, -1.0f, 5.5f));
} }
void AxisAlignedBoxTest::collisionPoint() { void AxisAlignedBoxTest::collisionPoint() {
Physics::AxisAlignedBox3D box({-1.0f, -2.0f, -3.0f}, {1.0f, 2.0f, 3.0f}); Shapes::AxisAlignedBox3D box({-1.0f, -2.0f, -3.0f}, {1.0f, 2.0f, 3.0f});
Physics::Point3D point1({-1.5f, -1.0f, 2.0f}); Shapes::Point3D point1({-1.5f, -1.0f, 2.0f});
Physics::Point3D point2({0.5f, 1.0f, -2.5f}); Shapes::Point3D point2({0.5f, 1.0f, -2.5f});
VERIFY_NOT_COLLIDES(box, point1); VERIFY_NOT_COLLIDES(box, point1);
VERIFY_COLLIDES(box, point2); VERIFY_COLLIDES(box, point2);
@ -62,4 +62,4 @@ void AxisAlignedBoxTest::collisionPoint() {
}}} }}}
CORRADE_TEST_MAIN(Magnum::Physics::Test::AxisAlignedBoxTest) CORRADE_TEST_MAIN(Magnum::Shapes::Test::AxisAlignedBoxTest)

8
src/Physics/Test/BoxTest.cpp → src/Shapes/Test/BoxTest.cpp

@ -26,9 +26,9 @@
#include "Math/Matrix4.h" #include "Math/Matrix4.h"
#include "Magnum.h" #include "Magnum.h"
#include "Physics/Box.h" #include "Shapes/Box.h"
namespace Magnum { namespace Physics { namespace Test { namespace Magnum { namespace Shapes { namespace Test {
class BoxTest: public Corrade::TestSuite::Tester { class BoxTest: public Corrade::TestSuite::Tester {
public: public:
@ -42,11 +42,11 @@ BoxTest::BoxTest() {
} }
void BoxTest::transformed() { void BoxTest::transformed() {
const auto box = Physics::Box3D(Matrix4::translation({1.0f, 2.0f, -3.0f})) const auto box = Shapes::Box3D(Matrix4::translation({1.0f, 2.0f, -3.0f}))
.transformed(Matrix4::scaling({2.0f, -1.0f, 1.5f})); .transformed(Matrix4::scaling({2.0f, -1.0f, 1.5f}));
CORRADE_COMPARE(box.transformation(), Matrix4::scaling({2.0f, -1.0f, 1.5f})*Matrix4::translation({1.0f, 2.0f, -3.0f})); CORRADE_COMPARE(box.transformation(), Matrix4::scaling({2.0f, -1.0f, 1.5f})*Matrix4::translation({1.0f, 2.0f, -3.0f}));
} }
}}} }}}
CORRADE_TEST_MAIN(Magnum::Physics::Test::BoxTest) CORRADE_TEST_MAIN(Magnum::Shapes::Test::BoxTest)

20
src/Physics/Test/CMakeLists.txt → src/Shapes/Test/CMakeLists.txt

@ -22,14 +22,14 @@
# DEALINGS IN THE SOFTWARE. # DEALINGS IN THE SOFTWARE.
# #
corrade_add_test(PhysicsShapeImplementationTest ShapeImplementationTest.cpp LIBRARIES MagnumPhysics) corrade_add_test(ShapesShapeImplementationTest ShapeImplementationTest.cpp LIBRARIES MagnumShapes)
corrade_add_test(PhysicsAxisAlignedBoxTest AxisAlignedBoxTest.cpp LIBRARIES MagnumPhysics) corrade_add_test(ShapesAxisAlignedBoxTest AxisAlignedBoxTest.cpp LIBRARIES MagnumShapes)
corrade_add_test(PhysicsBoxTest BoxTest.cpp LIBRARIES MagnumPhysics) corrade_add_test(ShapesBoxTest BoxTest.cpp LIBRARIES MagnumShapes)
corrade_add_test(PhysicsCapsuleTest CapsuleTest.cpp LIBRARIES MagnumPhysics) corrade_add_test(ShapesCapsuleTest CapsuleTest.cpp LIBRARIES MagnumShapes)
corrade_add_test(PhysicsLineTest LineTest.cpp LIBRARIES MagnumPhysics) corrade_add_test(ShapesLineTest LineTest.cpp LIBRARIES MagnumShapes)
corrade_add_test(PhysicsPlaneTest PlaneTest.cpp LIBRARIES MagnumPhysics) corrade_add_test(ShapesPlaneTest PlaneTest.cpp LIBRARIES MagnumShapes)
corrade_add_test(PhysicsPointTest PointTest.cpp LIBRARIES MagnumPhysics) corrade_add_test(ShapesPointTest PointTest.cpp LIBRARIES MagnumShapes)
corrade_add_test(PhysicsCompositionTest CompositionTest.cpp LIBRARIES MagnumPhysics) corrade_add_test(ShapesCompositionTest CompositionTest.cpp LIBRARIES MagnumShapes)
corrade_add_test(PhysicsSphereTest SphereTest.cpp LIBRARIES MagnumPhysics) corrade_add_test(ShapesSphereTest SphereTest.cpp LIBRARIES MagnumShapes)
corrade_add_test(PhysicsShapeTest ShapeTest.cpp LIBRARIES MagnumPhysics) corrade_add_test(ShapesShapeTest ShapeTest.cpp LIBRARIES MagnumShapes)

28
src/Physics/Test/CapsuleTest.cpp → src/Shapes/Test/CapsuleTest.cpp

@ -24,13 +24,13 @@
#include "Math/Matrix4.h" #include "Math/Matrix4.h"
#include "Magnum.h" #include "Magnum.h"
#include "Physics/Capsule.h" #include "Shapes/Capsule.h"
#include "Physics/Point.h" #include "Shapes/Point.h"
#include "Physics/Sphere.h" #include "Shapes/Sphere.h"
#include "ShapeTestBase.h" #include "ShapeTestBase.h"
namespace Magnum { namespace Physics { namespace Test { namespace Magnum { namespace Shapes { namespace Test {
class CapsuleTest: public Corrade::TestSuite::Tester { class CapsuleTest: public Corrade::TestSuite::Tester {
public: public:
@ -49,7 +49,7 @@ CapsuleTest::CapsuleTest() {
} }
void CapsuleTest::transformed() { void CapsuleTest::transformed() {
const Physics::Capsule3D capsule({1.0f, 2.0f, 3.0f}, {-1.0f, -2.0f, -3.0f}, 7.0f); const Shapes::Capsule3D capsule({1.0f, 2.0f, 3.0f}, {-1.0f, -2.0f, -3.0f}, 7.0f);
const auto transformed = capsule.transformed(Matrix4::rotation(Deg(90.0f), Vector3::zAxis())); const auto transformed = capsule.transformed(Matrix4::rotation(Deg(90.0f), Vector3::zAxis()));
CORRADE_COMPARE(transformed.a(), Vector3(-2.0f, 1.0f, 3.0f)); CORRADE_COMPARE(transformed.a(), Vector3(-2.0f, 1.0f, 3.0f));
@ -62,10 +62,10 @@ void CapsuleTest::transformed() {
} }
void CapsuleTest::collisionPoint() { void CapsuleTest::collisionPoint() {
Physics::Capsule3D capsule({-1.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}, 2.0f); Shapes::Capsule3D capsule({-1.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}, 2.0f);
Physics::Point3D point({2.0f, 0.0f, 0.0f}); Shapes::Point3D point({2.0f, 0.0f, 0.0f});
Physics::Point3D point1({2.9f, 1.0f, 0.0f}); Shapes::Point3D point1({2.9f, 1.0f, 0.0f});
Physics::Point3D point2({1.0f, 3.1f, 0.0f}); Shapes::Point3D point2({1.0f, 3.1f, 0.0f});
VERIFY_COLLIDES(capsule, point); VERIFY_COLLIDES(capsule, point);
VERIFY_COLLIDES(capsule, point1); VERIFY_COLLIDES(capsule, point1);
@ -73,10 +73,10 @@ void CapsuleTest::collisionPoint() {
} }
void CapsuleTest::collisionSphere() { void CapsuleTest::collisionSphere() {
Physics::Capsule3D capsule({-1.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}, 2.0f); Shapes::Capsule3D capsule({-1.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}, 2.0f);
Physics::Sphere3D sphere({3.0f, 0.0f, 0.0f}, 0.9f); Shapes::Sphere3D sphere({3.0f, 0.0f, 0.0f}, 0.9f);
Physics::Sphere3D sphere1({3.5f, 1.0f, 0.0f}, 0.6f); Shapes::Sphere3D sphere1({3.5f, 1.0f, 0.0f}, 0.6f);
Physics::Sphere3D sphere2({1.0f, 4.1f, 0.0f}, 1.0f); Shapes::Sphere3D sphere2({1.0f, 4.1f, 0.0f}, 1.0f);
VERIFY_COLLIDES(capsule, sphere); VERIFY_COLLIDES(capsule, sphere);
VERIFY_COLLIDES(capsule, sphere1); VERIFY_COLLIDES(capsule, sphere1);
@ -85,4 +85,4 @@ void CapsuleTest::collisionSphere() {
}}} }}}
CORRADE_TEST_MAIN(Magnum::Physics::Test::CapsuleTest) CORRADE_TEST_MAIN(Magnum::Shapes::Test::CapsuleTest)

62
src/Physics/Test/CompositionTest.cpp → src/Shapes/Test/CompositionTest.cpp

@ -25,14 +25,14 @@
#include <TestSuite/Tester.h> #include <TestSuite/Tester.h>
#include "Math/Matrix4.h" #include "Math/Matrix4.h"
#include "Physics/Point.h" #include "Shapes/Point.h"
#include "Physics/AxisAlignedBox.h" #include "Shapes/AxisAlignedBox.h"
#include "Physics/Composition.h" #include "Shapes/Composition.h"
#include "Physics/Sphere.h" #include "Shapes/Sphere.h"
#include "ShapeTestBase.h" #include "ShapeTestBase.h"
namespace Magnum { namespace Physics { namespace Test { namespace Magnum { namespace Shapes { namespace Test {
class CompositionTest: public Corrade::TestSuite::Tester { class CompositionTest: public Corrade::TestSuite::Tester {
public: public:
@ -56,75 +56,75 @@ CompositionTest::CompositionTest() {
} }
void CompositionTest::negated() { void CompositionTest::negated() {
const Physics::Composition2D a = !Physics::Point2D(Vector2::xAxis(0.5f)); const Shapes::Composition2D a = !Shapes::Point2D(Vector2::xAxis(0.5f));
CORRADE_COMPARE(a.size(), 1); CORRADE_COMPARE(a.size(), 1);
CORRADE_COMPARE(a.type(0), Composition2D::Type::Point); CORRADE_COMPARE(a.type(0), Composition2D::Type::Point);
CORRADE_COMPARE(a.get<Physics::Point2D>(0).position(), Vector2::xAxis(0.5f)); CORRADE_COMPARE(a.get<Shapes::Point2D>(0).position(), Vector2::xAxis(0.5f));
VERIFY_NOT_COLLIDES(a, Physics::Sphere2D({}, 1.0f)); VERIFY_NOT_COLLIDES(a, Shapes::Sphere2D({}, 1.0f));
} }
void CompositionTest::anded() { void CompositionTest::anded() {
const Physics::Composition2D a = Physics::Sphere2D({}, 1.0f) && Physics::Point2D(Vector2::xAxis(0.5f)); const Shapes::Composition2D a = Shapes::Sphere2D({}, 1.0f) && Shapes::Point2D(Vector2::xAxis(0.5f));
CORRADE_COMPARE(a.size(), 2); CORRADE_COMPARE(a.size(), 2);
CORRADE_COMPARE(a.type(0), Composition2D::Type::Sphere); CORRADE_COMPARE(a.type(0), Composition2D::Type::Sphere);
CORRADE_COMPARE(a.type(1), Composition2D::Type::Point); CORRADE_COMPARE(a.type(1), Composition2D::Type::Point);
CORRADE_COMPARE(a.get<Physics::Sphere2D>(0).position(), Vector2()); CORRADE_COMPARE(a.get<Shapes::Sphere2D>(0).position(), Vector2());
CORRADE_COMPARE(a.get<Physics::Sphere2D>(0).radius(), 1.0f); CORRADE_COMPARE(a.get<Shapes::Sphere2D>(0).radius(), 1.0f);
CORRADE_COMPARE(a.get<Physics::Point2D>(1).position(), Vector2::xAxis(0.5f)); CORRADE_COMPARE(a.get<Shapes::Point2D>(1).position(), Vector2::xAxis(0.5f));
VERIFY_NOT_COLLIDES(a, Physics::Point2D()); VERIFY_NOT_COLLIDES(a, Shapes::Point2D());
VERIFY_COLLIDES(a, Physics::Sphere2D(Vector2::xAxis(0.5f), 0.25f)); VERIFY_COLLIDES(a, Shapes::Sphere2D(Vector2::xAxis(0.5f), 0.25f));
} }
void CompositionTest::ored() { void CompositionTest::ored() {
const Physics::Composition2D a = Physics::Sphere2D({}, 1.0f) || Physics::Point2D(Vector2::xAxis(1.5f)); const Shapes::Composition2D a = Shapes::Sphere2D({}, 1.0f) || Shapes::Point2D(Vector2::xAxis(1.5f));
CORRADE_COMPARE(a.size(), 2); CORRADE_COMPARE(a.size(), 2);
CORRADE_COMPARE(a.type(0), Composition2D::Type::Sphere); CORRADE_COMPARE(a.type(0), Composition2D::Type::Sphere);
CORRADE_COMPARE(a.type(1), Composition2D::Type::Point); CORRADE_COMPARE(a.type(1), Composition2D::Type::Point);
CORRADE_COMPARE(a.get<Physics::Sphere2D>(0).position(), Vector2()); CORRADE_COMPARE(a.get<Shapes::Sphere2D>(0).position(), Vector2());
CORRADE_COMPARE(a.get<Physics::Sphere2D>(0).radius(), 1.0f); CORRADE_COMPARE(a.get<Shapes::Sphere2D>(0).radius(), 1.0f);
CORRADE_COMPARE(a.get<Physics::Point2D>(1).position(), Vector2::xAxis(1.5f)); CORRADE_COMPARE(a.get<Shapes::Point2D>(1).position(), Vector2::xAxis(1.5f));
VERIFY_COLLIDES(a, Physics::Point2D()); VERIFY_COLLIDES(a, Shapes::Point2D());
VERIFY_COLLIDES(a, Physics::Sphere2D(Vector2::xAxis(1.5f), 0.25f)); VERIFY_COLLIDES(a, Shapes::Sphere2D(Vector2::xAxis(1.5f), 0.25f));
} }
void CompositionTest::multipleUnary() { void CompositionTest::multipleUnary() {
const Physics::Composition2D a = !!!!Physics::Point2D(Vector2::xAxis(0.5f)); const Shapes::Composition2D a = !!!!Shapes::Point2D(Vector2::xAxis(0.5f));
CORRADE_COMPARE(a.size(), 1); CORRADE_COMPARE(a.size(), 1);
CORRADE_COMPARE(a.type(0), Composition2D::Type::Point); CORRADE_COMPARE(a.type(0), Composition2D::Type::Point);
CORRADE_COMPARE(a.get<Physics::Point2D>(0).position(), Vector2::xAxis(0.5f)); CORRADE_COMPARE(a.get<Shapes::Point2D>(0).position(), Vector2::xAxis(0.5f));
VERIFY_COLLIDES(a, Physics::Sphere2D({}, 1.0f)); VERIFY_COLLIDES(a, Shapes::Sphere2D({}, 1.0f));
} }
void CompositionTest::hierarchy() { void CompositionTest::hierarchy() {
const Physics::Composition3D a = Physics::Sphere3D({}, 1.0f) && const Shapes::Composition3D a = Shapes::Sphere3D({}, 1.0f) &&
(Physics::Point3D(Vector3::xAxis(1.5f)) || !Physics::AxisAlignedBox3D({}, Vector3(0.5f))); (Shapes::Point3D(Vector3::xAxis(1.5f)) || !Shapes::AxisAlignedBox3D({}, Vector3(0.5f)));
CORRADE_COMPARE(a.size(), 3); CORRADE_COMPARE(a.size(), 3);
CORRADE_COMPARE(a.type(0), Composition3D::Type::Sphere); CORRADE_COMPARE(a.type(0), Composition3D::Type::Sphere);
CORRADE_COMPARE(a.type(1), Composition3D::Type::Point); CORRADE_COMPARE(a.type(1), Composition3D::Type::Point);
CORRADE_COMPARE(a.type(2), Composition3D::Type::AxisAlignedBox); CORRADE_COMPARE(a.type(2), Composition3D::Type::AxisAlignedBox);
CORRADE_COMPARE(a.get<Physics::Point3D>(1).position(), Vector3::xAxis(1.5f)); CORRADE_COMPARE(a.get<Shapes::Point3D>(1).position(), Vector3::xAxis(1.5f));
VERIFY_COLLIDES(a, Physics::Sphere3D(Vector3::xAxis(1.5f), 0.6f)); VERIFY_COLLIDES(a, Shapes::Sphere3D(Vector3::xAxis(1.5f), 0.6f));
VERIFY_NOT_COLLIDES(a, Physics::Point3D(Vector3(0.25f))); VERIFY_NOT_COLLIDES(a, Shapes::Point3D(Vector3(0.25f)));
} }
void CompositionTest::empty() { void CompositionTest::empty() {
const Physics::Composition2D a; const Shapes::Composition2D a;
CORRADE_COMPARE(a.size(), 0); CORRADE_COMPARE(a.size(), 0);
VERIFY_NOT_COLLIDES(a, Physics::Sphere2D({}, 1.0f)); VERIFY_NOT_COLLIDES(a, Shapes::Sphere2D({}, 1.0f));
} }
}}} }}}
CORRADE_TEST_MAIN(Magnum::Physics::Test::CompositionTest) CORRADE_TEST_MAIN(Magnum::Shapes::Test::CompositionTest)

8
src/Physics/Test/LineTest.cpp → src/Shapes/Test/LineTest.cpp

@ -26,9 +26,9 @@
#include "Math/Matrix4.h" #include "Math/Matrix4.h"
#include "Magnum.h" #include "Magnum.h"
#include "Physics/Line.h" #include "Shapes/Line.h"
namespace Magnum { namespace Physics { namespace Test { namespace Magnum { namespace Shapes { namespace Test {
class LineTest: public Corrade::TestSuite::Tester { class LineTest: public Corrade::TestSuite::Tester {
public: public:
@ -42,7 +42,7 @@ LineTest::LineTest() {
} }
void LineTest::transformed() { void LineTest::transformed() {
const auto line = Physics::Line3D({1.0f, 2.0f, 3.0f}, {-1.0f, -2.0f, -3.0f}) const auto line = Shapes::Line3D({1.0f, 2.0f, 3.0f}, {-1.0f, -2.0f, -3.0f})
.transformed(Matrix4::rotation(Deg(90.0f), Vector3::zAxis())); .transformed(Matrix4::rotation(Deg(90.0f), Vector3::zAxis()));
CORRADE_COMPARE(line.a(), Vector3(-2.0f, 1.0f, 3.0f)); CORRADE_COMPARE(line.a(), Vector3(-2.0f, 1.0f, 3.0f));
CORRADE_COMPARE(line.b(), Vector3(2.0f, -1.0f, -3.0f)); CORRADE_COMPARE(line.b(), Vector3(2.0f, -1.0f, -3.0f));
@ -50,4 +50,4 @@ void LineTest::transformed() {
}}} }}}
CORRADE_TEST_MAIN(Magnum::Physics::Test::LineTest) CORRADE_TEST_MAIN(Magnum::Shapes::Test::LineTest)

28
src/Physics/Test/PlaneTest.cpp → src/Shapes/Test/PlaneTest.cpp

@ -23,13 +23,13 @@
*/ */
#include "Math/Matrix4.h" #include "Math/Matrix4.h"
#include "Physics/LineSegment.h" #include "Shapes/LineSegment.h"
#include "Physics/Point.h" #include "Shapes/Point.h"
#include "Physics/Plane.h" #include "Shapes/Plane.h"
#include "ShapeTestBase.h" #include "ShapeTestBase.h"
namespace Magnum { namespace Physics { namespace Test { namespace Magnum { namespace Shapes { namespace Test {
class PlaneTest: public Corrade::TestSuite::Tester { class PlaneTest: public Corrade::TestSuite::Tester {
public: public:
@ -47,7 +47,7 @@ PlaneTest::PlaneTest() {
} }
void PlaneTest::transformed() { void PlaneTest::transformed() {
const Physics::Plane plane({1.0f, 2.0f, 3.0f}, {Constants::sqrt2(), -Constants::sqrt2(), 0}); const Shapes::Plane plane({1.0f, 2.0f, 3.0f}, {Constants::sqrt2(), -Constants::sqrt2(), 0});
const auto transformed = plane.transformed(Matrix4::rotation(Deg(90.0f), Vector3::xAxis())); const auto transformed = plane.transformed(Matrix4::rotation(Deg(90.0f), Vector3::xAxis()));
CORRADE_COMPARE(transformed.position(), Vector3(1.0f, -3.0f, 2.0f)); CORRADE_COMPARE(transformed.position(), Vector3(1.0f, -3.0f, 2.0f));
@ -60,10 +60,10 @@ void PlaneTest::transformed() {
} }
void PlaneTest::collisionLine() { void PlaneTest::collisionLine() {
Physics::Plane plane(Vector3(), Vector3::yAxis()); Shapes::Plane plane(Vector3(), Vector3::yAxis());
Physics::Line3D line({0.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f}); Shapes::Line3D line({0.0f, 0.0f, 0.0f}, {1.0f, 0.0f, 0.0f});
Physics::Line3D line2({0.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}); Shapes::Line3D line2({0.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f});
Physics::Line3D line3({0.0f, 1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}); Shapes::Line3D line3({0.0f, 1.0f, 0.0f}, {1.0f, 1.0f, 0.0f});
VERIFY_COLLIDES(plane, line); VERIFY_COLLIDES(plane, line);
VERIFY_COLLIDES(plane, line2); VERIFY_COLLIDES(plane, line2);
@ -71,10 +71,10 @@ void PlaneTest::collisionLine() {
} }
void PlaneTest::collisionLineSegment() { void PlaneTest::collisionLineSegment() {
Physics::Plane plane(Vector3(), Vector3::yAxis()); Shapes::Plane plane(Vector3(), Vector3::yAxis());
Physics::LineSegment3D line({0.0f, -0.1f, 0.0f}, {0.0f, 7.0f, 0.0f}); Shapes::LineSegment3D line({0.0f, -0.1f, 0.0f}, {0.0f, 7.0f, 0.0f});
Physics::LineSegment3D line2({0.0f, 0.1f, 0.0f}, {0.0f, 7.0f, 0.0f}); Shapes::LineSegment3D line2({0.0f, 0.1f, 0.0f}, {0.0f, 7.0f, 0.0f});
Physics::LineSegment3D line3({0.0f, -7.0f, 0.0f}, {0.0f, -0.1f, 0.0f}); Shapes::LineSegment3D line3({0.0f, -7.0f, 0.0f}, {0.0f, -0.1f, 0.0f});
VERIFY_COLLIDES(plane, line); VERIFY_COLLIDES(plane, line);
VERIFY_NOT_COLLIDES(plane, line2); VERIFY_NOT_COLLIDES(plane, line2);
@ -83,4 +83,4 @@ void PlaneTest::collisionLineSegment() {
}}} }}}
CORRADE_TEST_MAIN(Magnum::Physics::Test::PlaneTest) CORRADE_TEST_MAIN(Magnum::Shapes::Test::PlaneTest)

8
src/Physics/Test/PointTest.cpp → src/Shapes/Test/PointTest.cpp

@ -26,9 +26,9 @@
#include "Math/Matrix4.h" #include "Math/Matrix4.h"
#include "Magnum.h" #include "Magnum.h"
#include "Physics/Point.h" #include "Shapes/Point.h"
namespace Magnum { namespace Physics { namespace Test { namespace Magnum { namespace Shapes { namespace Test {
class PointTest: public Corrade::TestSuite::Tester { class PointTest: public Corrade::TestSuite::Tester {
public: public:
@ -42,11 +42,11 @@ PointTest::PointTest() {
} }
void PointTest::transformed() { void PointTest::transformed() {
const auto point = Physics::Point3D({1.0f, 2.0f, 3.0f}) const auto point = Shapes::Point3D({1.0f, 2.0f, 3.0f})
.transformed(Matrix4::translation({5.0f, 6.0f, 7.0f})); .transformed(Matrix4::translation({5.0f, 6.0f, 7.0f}));
CORRADE_COMPARE(point.position(), Vector3(6.0f, 8.0f, 10.0f)); CORRADE_COMPARE(point.position(), Vector3(6.0f, 8.0f, 10.0f));
} }
}}} }}}
CORRADE_TEST_MAIN(Magnum::Physics::Test::PointTest) CORRADE_TEST_MAIN(Magnum::Shapes::Test::PointTest)

10
src/Physics/Test/ShapeImplementationTest.cpp → src/Shapes/Test/ShapeImplementationTest.cpp

@ -25,9 +25,9 @@
#include <sstream> #include <sstream>
#include <TestSuite/Tester.h> #include <TestSuite/Tester.h>
#include "Physics/shapeImplementation.h" #include "Shapes/shapeImplementation.h"
namespace Magnum { namespace Physics { namespace Test { namespace Magnum { namespace Shapes { namespace Test {
class ShapeImplementationTest: public Corrade::TestSuite::Tester { class ShapeImplementationTest: public Corrade::TestSuite::Tester {
public: public:
@ -43,13 +43,13 @@ ShapeImplementationTest::ShapeImplementationTest() {
void ShapeImplementationTest::debug() { void ShapeImplementationTest::debug() {
std::ostringstream o; std::ostringstream o;
Debug(&o) << Implementation::ShapeDimensionTraits<2>::Type::Composition; Debug(&o) << Implementation::ShapeDimensionTraits<2>::Type::Composition;
CORRADE_COMPARE(o.str(), "Physics::Shape2D::Type::Composition\n"); CORRADE_COMPARE(o.str(), "Shapes::Shape2D::Type::Composition\n");
o.str({}); o.str({});
Debug(&o) << Implementation::ShapeDimensionTraits<3>::Type::Plane; Debug(&o) << Implementation::ShapeDimensionTraits<3>::Type::Plane;
CORRADE_COMPARE(o.str(), "Physics::Shape3D::Type::Plane\n"); CORRADE_COMPARE(o.str(), "Shapes::Shape3D::Type::Plane\n");
} }
}}} }}}
CORRADE_TEST_MAIN(Magnum::Physics::Test::ShapeImplementationTest) CORRADE_TEST_MAIN(Magnum::Shapes::Test::ShapeImplementationTest)

28
src/Physics/Test/ShapeTest.cpp → src/Shapes/Test/ShapeTest.cpp

@ -24,16 +24,16 @@
#include <TestSuite/Tester.h> #include <TestSuite/Tester.h>
#include "Physics/ShapeGroup.h" #include "Shapes/ShapeGroup.h"
#include "Physics/Shape.h" #include "Shapes/Shape.h"
#include "Physics/Point.h" #include "Shapes/Point.h"
#include "Physics/Composition.h" #include "Shapes/Composition.h"
#include "Physics/Sphere.h" #include "Shapes/Sphere.h"
#include "SceneGraph/MatrixTransformation2D.h" #include "SceneGraph/MatrixTransformation2D.h"
#include "SceneGraph/MatrixTransformation3D.h" #include "SceneGraph/MatrixTransformation3D.h"
#include "SceneGraph/Scene.h" #include "SceneGraph/Scene.h"
namespace Magnum { namespace Physics { namespace Test { namespace Magnum { namespace Shapes { namespace Test {
class ShapeTest: public Corrade::TestSuite::Tester { class ShapeTest: public Corrade::TestSuite::Tester {
public: public:
@ -60,11 +60,11 @@ void ShapeTest::clean() {
ShapeGroup3D shapes; ShapeGroup3D shapes;
Object3D a(&scene); Object3D a(&scene);
auto shape = new Physics::Shape<Physics::Point3D>(&a, {{1.0f, -2.0f, 3.0f}}, &shapes); auto shape = new Shapes::Shape<Shapes::Point3D>(&a, {{1.0f, -2.0f, 3.0f}}, &shapes);
a.scale(Vector3(-2.0f)); a.scale(Vector3(-2.0f));
Object3D b(&scene); Object3D b(&scene);
new Physics::Shape<Physics::Point3D>(&b, &shapes); new Shapes::Shape<Shapes::Point3D>(&b, &shapes);
/* Everything is dirty at the beginning */ /* Everything is dirty at the beginning */
CORRADE_VERIFY(shapes.isDirty()); CORRADE_VERIFY(shapes.isDirty());
@ -100,13 +100,13 @@ void ShapeTest::firstCollision() {
ShapeGroup3D shapes; ShapeGroup3D shapes;
Object3D a(&scene); Object3D a(&scene);
auto aShape = new Shape<Physics::Sphere3D>(&a, {{1.0f, -2.0f, 3.0f}, 1.5f}, &shapes); auto aShape = new Shape<Shapes::Sphere3D>(&a, {{1.0f, -2.0f, 3.0f}, 1.5f}, &shapes);
Object3D b(&scene); Object3D b(&scene);
auto bShape = new Shape<Physics::Point3D>(&b, {{3.0f, -2.0f, 3.0f}}, &shapes); auto bShape = new Shape<Shapes::Point3D>(&b, {{3.0f, -2.0f, 3.0f}}, &shapes);
Object3D c(&scene); Object3D c(&scene);
new Shape<Physics::Composition3D>(&c, &shapes); new Shape<Shapes::Composition3D>(&c, &shapes);
/* No collisions initially */ /* No collisions initially */
CORRADE_VERIFY(!shapes.firstCollision(aShape)); CORRADE_VERIFY(!shapes.firstCollision(aShape));
@ -129,11 +129,11 @@ void ShapeTest::shapeGroup() {
/* Verify construction */ /* Verify construction */
Object2D a(&scene); Object2D a(&scene);
auto shape = new Shape<Physics::Composition2D>(&a, Physics::Sphere2D({}, 0.5f) || Physics::Point2D({0.25f, -1.0f})); auto shape = new Shape<Shapes::Composition2D>(&a, Shapes::Sphere2D({}, 0.5f) || Shapes::Point2D({0.25f, -1.0f}));
CORRADE_COMPARE(shape->transformedShape().size(), 2); CORRADE_COMPARE(shape->transformedShape().size(), 2);
/* Verify the original shape is updated */ /* Verify the original shape is updated */
const auto& point = shape->transformedShape().get<Physics::Point2D>(1); const auto& point = shape->transformedShape().get<Shapes::Point2D>(1);
a.translate(Vector2::xAxis(5.0f)); a.translate(Vector2::xAxis(5.0f));
a.setClean(); a.setClean();
CORRADE_COMPARE(point.position(), Vector2(5.25f, -1.0f)); CORRADE_COMPARE(point.position(), Vector2(5.25f, -1.0f));
@ -141,4 +141,4 @@ void ShapeTest::shapeGroup() {
}}} }}}
CORRADE_TEST_MAIN(Magnum::Physics::Test::ShapeTest) CORRADE_TEST_MAIN(Magnum::Shapes::Test::ShapeTest)

6
src/Physics/Test/ShapeTestBase.h → src/Shapes/Test/ShapeTestBase.h

@ -1,5 +1,5 @@
#ifndef Magnum_Physics_Test_ShapeTestBase_h #ifndef Magnum_Shapes_Test_ShapeTestBase_h
#define Magnum_Physics_Test_ShapeTestBase_h #define Magnum_Shapes_Test_ShapeTestBase_h
/* /*
This file is part of Magnum. This file is part of Magnum.
@ -26,7 +26,7 @@
#include <TestSuite/Tester.h> #include <TestSuite/Tester.h>
namespace Magnum { namespace Physics { namespace Test { namespace Magnum { namespace Shapes { namespace Test {
#define VERIFY_COLLIDES(a, b) \ #define VERIFY_COLLIDES(a, b) \
CORRADE_VERIFY(a % b); \ CORRADE_VERIFY(a % b); \

36
src/Physics/Test/SphereTest.cpp → src/Shapes/Test/SphereTest.cpp

@ -24,13 +24,13 @@
#include "Math/Matrix4.h" #include "Math/Matrix4.h"
#include "Magnum.h" #include "Magnum.h"
#include "Physics/LineSegment.h" #include "Shapes/LineSegment.h"
#include "Physics/Point.h" #include "Shapes/Point.h"
#include "Physics/Sphere.h" #include "Shapes/Sphere.h"
#include "ShapeTestBase.h" #include "ShapeTestBase.h"
namespace Magnum { namespace Physics { namespace Test { namespace Magnum { namespace Shapes { namespace Test {
class SphereTest: public Corrade::TestSuite::Tester { class SphereTest: public Corrade::TestSuite::Tester {
public: public:
@ -52,7 +52,7 @@ SphereTest::SphereTest() {
} }
void SphereTest::transformed() { void SphereTest::transformed() {
const Physics::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 7.0f); const Shapes::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 7.0f);
const auto transformed = sphere.transformed(Matrix4::rotation(Deg(90.0f), Vector3::yAxis())); const auto transformed = sphere.transformed(Matrix4::rotation(Deg(90.0f), Vector3::yAxis()));
CORRADE_COMPARE(transformed.position(), Vector3(3.0f, 2.0f, -1.0f)); CORRADE_COMPARE(transformed.position(), Vector3(3.0f, 2.0f, -1.0f));
@ -69,36 +69,36 @@ void SphereTest::transformed() {
} }
void SphereTest::collisionPoint() { void SphereTest::collisionPoint() {
Physics::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 2.0f); Shapes::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 2.0f);
Physics::Point3D point({1.0f, 3.0f, 3.0f}); Shapes::Point3D point({1.0f, 3.0f, 3.0f});
Physics::Point3D point2({1.0f, 3.0f, 1.0f}); Shapes::Point3D point2({1.0f, 3.0f, 1.0f});
VERIFY_COLLIDES(sphere, point); VERIFY_COLLIDES(sphere, point);
VERIFY_NOT_COLLIDES(sphere, point2); VERIFY_NOT_COLLIDES(sphere, point2);
} }
void SphereTest::collisionLine() { void SphereTest::collisionLine() {
Physics::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 2.0f); Shapes::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 2.0f);
Physics::Line3D line({1.0f, 1.5f, 3.5f}, {1.0f, 2.5f, 2.5f}); Shapes::Line3D line({1.0f, 1.5f, 3.5f}, {1.0f, 2.5f, 2.5f});
Physics::Line3D line2({1.0f, 2.0f, 5.1f}, {1.0f, 3.0f, 5.1f}); Shapes::Line3D line2({1.0f, 2.0f, 5.1f}, {1.0f, 3.0f, 5.1f});
VERIFY_COLLIDES(sphere, line); VERIFY_COLLIDES(sphere, line);
VERIFY_NOT_COLLIDES(sphere, line2); VERIFY_NOT_COLLIDES(sphere, line2);
} }
void SphereTest::collisionLineSegment() { void SphereTest::collisionLineSegment() {
Physics::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 2.0f); Shapes::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 2.0f);
Physics::LineSegment3D line({1.0f, 2.0f, 4.9f}, {1.0f, 2.0f, 7.0f}); Shapes::LineSegment3D line({1.0f, 2.0f, 4.9f}, {1.0f, 2.0f, 7.0f});
Physics::LineSegment3D line2({1.0f, 2.0f, 5.1f}, {1.0f, 2.0f, 7.0f}); Shapes::LineSegment3D line2({1.0f, 2.0f, 5.1f}, {1.0f, 2.0f, 7.0f});
VERIFY_COLLIDES(sphere, line); VERIFY_COLLIDES(sphere, line);
VERIFY_NOT_COLLIDES(sphere, line2); VERIFY_NOT_COLLIDES(sphere, line2);
} }
void SphereTest::collisionSphere() { void SphereTest::collisionSphere() {
Physics::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 2.0f); Shapes::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 2.0f);
Physics::Sphere3D sphere1({1.0f, 3.0f, 5.0f}, 1.0f); Shapes::Sphere3D sphere1({1.0f, 3.0f, 5.0f}, 1.0f);
Physics::Sphere3D sphere2({1.0f, 3.0f, 0.0f}, 1.0f); Shapes::Sphere3D sphere2({1.0f, 3.0f, 0.0f}, 1.0f);
VERIFY_COLLIDES(sphere, sphere1); VERIFY_COLLIDES(sphere, sphere1);
VERIFY_NOT_COLLIDES(sphere, sphere2); VERIFY_NOT_COLLIDES(sphere, sphere2);
@ -106,4 +106,4 @@ void SphereTest::collisionSphere() {
}}} }}}
CORRADE_TEST_MAIN(Magnum::Physics::Test::SphereTest) CORRADE_TEST_MAIN(Magnum::Shapes::Test::SphereTest)

12
src/Physics/magnumPhysicsVisibility.h → src/Shapes/magnumShapesVisibility.h

@ -1,5 +1,5 @@
#ifndef Magnum_Physics_magnumPhysicsVisibility_h #ifndef Magnum_Shapes_magnumShapesVisibility_h
#define Magnum_Physics_magnumPhysicsVisibility_h #define Magnum_Shapes_magnumShapesVisibility_h
/* /*
This file is part of Magnum. This file is part of Magnum.
@ -26,11 +26,11 @@
#include <Utility/Visibility.h> #include <Utility/Visibility.h>
#ifdef MagnumPhysics_EXPORTS #ifdef MagnumShapes_EXPORTS
#define MAGNUM_PHYSICS_EXPORT CORRADE_VISIBILITY_EXPORT #define MAGNUM_SHAPES_EXPORT CORRADE_VISIBILITY_EXPORT
#else #else
#define MAGNUM_PHYSICS_EXPORT CORRADE_VISIBILITY_IMPORT #define MAGNUM_SHAPES_EXPORT CORRADE_VISIBILITY_IMPORT
#endif #endif
#define MAGNUM_PHYSICS_LOCAL CORRADE_VISIBILITY_LOCAL #define MAGNUM_SHAPES_LOCAL CORRADE_VISIBILITY_LOCAL
#endif #endif

10
src/Physics/shapeImplementation.cpp → src/Shapes/shapeImplementation.cpp

@ -26,11 +26,11 @@
#include <Utility/Debug.h> #include <Utility/Debug.h>
namespace Magnum { namespace Physics { namespace Implementation { namespace Magnum { namespace Shapes { namespace Implementation {
Debug operator<<(Debug debug, ShapeDimensionTraits<2>::Type value) { Debug operator<<(Debug debug, ShapeDimensionTraits<2>::Type value) {
switch(value) { switch(value) {
#define _val(value) case ShapeDimensionTraits<2>::Type::value: return debug << "Physics::Shape2D::Type::" #value; #define _val(value) case ShapeDimensionTraits<2>::Type::value: return debug << "Shapes::Shape2D::Type::" #value;
_val(Point) _val(Point)
_val(Line) _val(Line)
_val(LineSegment) _val(LineSegment)
@ -42,12 +42,12 @@ Debug operator<<(Debug debug, ShapeDimensionTraits<2>::Type value) {
#undef _val #undef _val
} }
return debug << "Physics::Shape2D::Type::(unknown)"; return debug << "Shapes::Shape2D::Type::(unknown)";
} }
Debug operator<<(Debug debug, ShapeDimensionTraits<3>::Type value) { Debug operator<<(Debug debug, ShapeDimensionTraits<3>::Type value) {
switch(value) { switch(value) {
#define _val(value) case ShapeDimensionTraits<3>::Type::value: return debug << "Physics::Shape3D::Type::" #value; #define _val(value) case ShapeDimensionTraits<3>::Type::value: return debug << "Shapes::Shape3D::Type::" #value;
_val(Point) _val(Point)
_val(Line) _val(Line)
_val(LineSegment) _val(LineSegment)
@ -60,7 +60,7 @@ Debug operator<<(Debug debug, ShapeDimensionTraits<3>::Type value) {
#undef _val #undef _val
} }
return debug << "Physics::Shape3D::Type::(unknown)"; return debug << "Shapes::Shape3D::Type::(unknown)";
} }
template<UnsignedInt dimensions> AbstractShape<dimensions>::~AbstractShape() = default; template<UnsignedInt dimensions> AbstractShape<dimensions>::~AbstractShape() = default;

40
src/Physics/shapeImplementation.h → src/Shapes/shapeImplementation.h

@ -1,5 +1,5 @@
#ifndef Magnum_Physics_shapeImplementation_h #ifndef Magnum_Shapes_shapeImplementation_h
#define Magnum_Physics_shapeImplementation_h #define Magnum_Shapes_shapeImplementation_h
/* /*
This file is part of Magnum. This file is part of Magnum.
@ -29,10 +29,10 @@
#include "DimensionTraits.h" #include "DimensionTraits.h"
#include "Magnum.h" #include "Magnum.h"
#include "Physics/Physics.h" #include "Shapes/Shapes.h"
#include "Physics/magnumPhysicsVisibility.h" #include "Shapes/magnumShapesVisibility.h"
namespace Magnum { namespace Physics { namespace Implementation { namespace Magnum { namespace Shapes { namespace Implementation {
/* Shape type for given dimension count */ /* Shape type for given dimension count */
@ -65,54 +65,54 @@ template<> struct ShapeDimensionTraits<3> {
}; };
}; };
Debug MAGNUM_PHYSICS_EXPORT operator<<(Debug debug, ShapeDimensionTraits<2>::Type value); Debug MAGNUM_SHAPES_EXPORT operator<<(Debug debug, ShapeDimensionTraits<2>::Type value);
Debug MAGNUM_PHYSICS_EXPORT operator<<(Debug debug, ShapeDimensionTraits<3>::Type value); Debug MAGNUM_SHAPES_EXPORT operator<<(Debug debug, ShapeDimensionTraits<3>::Type value);
/* Enum value corresponding to given type */ /* Enum value corresponding to given type */
template<class> struct TypeOf; template<class> struct TypeOf;
template<UnsignedInt dimensions> struct TypeOf<Physics::Point<dimensions>> { template<UnsignedInt dimensions> struct TypeOf<Shapes::Point<dimensions>> {
inline constexpr static typename ShapeDimensionTraits<dimensions>::Type type() { inline constexpr static typename ShapeDimensionTraits<dimensions>::Type type() {
return ShapeDimensionTraits<dimensions>::Type::Point; return ShapeDimensionTraits<dimensions>::Type::Point;
} }
}; };
template<UnsignedInt dimensions> struct TypeOf<Physics::Line<dimensions>> { template<UnsignedInt dimensions> struct TypeOf<Shapes::Line<dimensions>> {
inline constexpr static typename ShapeDimensionTraits<dimensions>::Type type() { inline constexpr static typename ShapeDimensionTraits<dimensions>::Type type() {
return ShapeDimensionTraits<dimensions>::Type::Line; return ShapeDimensionTraits<dimensions>::Type::Line;
} }
}; };
template<UnsignedInt dimensions> struct TypeOf<Physics::LineSegment<dimensions>> { template<UnsignedInt dimensions> struct TypeOf<Shapes::LineSegment<dimensions>> {
inline constexpr static typename ShapeDimensionTraits<dimensions>::Type type() { inline constexpr static typename ShapeDimensionTraits<dimensions>::Type type() {
return ShapeDimensionTraits<dimensions>::Type::LineSegment; return ShapeDimensionTraits<dimensions>::Type::LineSegment;
} }
}; };
template<UnsignedInt dimensions> struct TypeOf<Physics::Sphere<dimensions>> { template<UnsignedInt dimensions> struct TypeOf<Shapes::Sphere<dimensions>> {
inline constexpr static typename ShapeDimensionTraits<dimensions>::Type type() { inline constexpr static typename ShapeDimensionTraits<dimensions>::Type type() {
return ShapeDimensionTraits<dimensions>::Type::Sphere; return ShapeDimensionTraits<dimensions>::Type::Sphere;
} }
}; };
template<UnsignedInt dimensions> struct TypeOf<Physics::Capsule<dimensions>> { template<UnsignedInt dimensions> struct TypeOf<Shapes::Capsule<dimensions>> {
inline constexpr static typename ShapeDimensionTraits<dimensions>::Type type() { inline constexpr static typename ShapeDimensionTraits<dimensions>::Type type() {
return ShapeDimensionTraits<dimensions>::Type::Capsule; return ShapeDimensionTraits<dimensions>::Type::Capsule;
} }
}; };
template<UnsignedInt dimensions> struct TypeOf<Physics::AxisAlignedBox<dimensions>> { template<UnsignedInt dimensions> struct TypeOf<Shapes::AxisAlignedBox<dimensions>> {
inline constexpr static typename ShapeDimensionTraits<dimensions>::Type type() { inline constexpr static typename ShapeDimensionTraits<dimensions>::Type type() {
return ShapeDimensionTraits<dimensions>::Type::AxisAlignedBox; return ShapeDimensionTraits<dimensions>::Type::AxisAlignedBox;
} }
}; };
template<UnsignedInt dimensions> struct TypeOf<Physics::Box<dimensions>> { template<UnsignedInt dimensions> struct TypeOf<Shapes::Box<dimensions>> {
inline constexpr static typename ShapeDimensionTraits<dimensions>::Type type() { inline constexpr static typename ShapeDimensionTraits<dimensions>::Type type() {
return ShapeDimensionTraits<dimensions>::Type::Box; return ShapeDimensionTraits<dimensions>::Type::Box;
} }
}; };
template<> struct TypeOf<Physics::Plane> { template<> struct TypeOf<Shapes::Plane> {
inline constexpr static typename ShapeDimensionTraits<3>::Type type() { inline constexpr static typename ShapeDimensionTraits<3>::Type type() {
return ShapeDimensionTraits<3>::Type::Plane; return ShapeDimensionTraits<3>::Type::Plane;
} }
}; };
template<UnsignedInt dimensions> struct TypeOf<Physics::Composition<dimensions>> { template<UnsignedInt dimensions> struct TypeOf<Shapes::Composition<dimensions>> {
inline constexpr static typename ShapeDimensionTraits<dimensions>::Type type() { inline constexpr static typename ShapeDimensionTraits<dimensions>::Type type() {
return ShapeDimensionTraits<dimensions>::Type::Composition; return ShapeDimensionTraits<dimensions>::Type::Composition;
} }
@ -120,13 +120,13 @@ template<UnsignedInt dimensions> struct TypeOf<Physics::Composition<dimensions>>
/* Polymorphic shape wrappers */ /* Polymorphic shape wrappers */
template<UnsignedInt dimensions> struct MAGNUM_PHYSICS_EXPORT AbstractShape { template<UnsignedInt dimensions> struct MAGNUM_SHAPES_EXPORT AbstractShape {
explicit AbstractShape(); explicit AbstractShape();
virtual ~AbstractShape(); virtual ~AbstractShape();
virtual typename ShapeDimensionTraits<dimensions>::Type MAGNUM_PHYSICS_LOCAL type() const = 0; virtual typename ShapeDimensionTraits<dimensions>::Type MAGNUM_SHAPES_LOCAL type() const = 0;
virtual AbstractShape<dimensions> MAGNUM_PHYSICS_LOCAL * clone() const = 0; virtual AbstractShape<dimensions> MAGNUM_SHAPES_LOCAL * clone() const = 0;
virtual void MAGNUM_PHYSICS_LOCAL transform(const typename DimensionTraits<dimensions>::MatrixType& matrix, AbstractShape<dimensions>* result) const = 0; virtual void MAGNUM_SHAPES_LOCAL transform(const typename DimensionTraits<dimensions>::MatrixType& matrix, AbstractShape<dimensions>* result) const = 0;
}; };
template<class T> struct Shape: AbstractShape<T::Dimensions> { template<class T> struct Shape: AbstractShape<T::Dimensions> {
Loading…
Cancel
Save