#ifndef Magnum_Physics_AbstractShape_h #define Magnum_Physics_AbstractShape_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš This file is part of Magnum. Magnum is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3 only, as published by the Free Software Foundation. Magnum is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License version 3 for more details. */ /** @file * @brief Class Magnum::Physics::AbstractShape */ #include "Magnum.h" #include "DimensionTraits.h" #include "magnumPhysicsVisibility.h" namespace Magnum { namespace Physics { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { template struct ShapeDimensionTraits {}; template<> struct ShapeDimensionTraits<2> { enum class Type { Point, Line, LineSegment, Sphere, Capsule, AxisAlignedBox, Box, ShapeGroup }; }; template<> struct ShapeDimensionTraits<3> { enum class Type { Point, Line, LineSegment, Sphere, Capsule, AxisAlignedBox, Box, ShapeGroup, Plane }; }; } #endif /** @brief Base class for shapes See @ref collision-detection for brief introduction. @see AbstractShape2D, AbstractShape3D */ template class MAGNUM_PHYSICS_EXPORT AbstractShape { public: /** @brief Dimension count */ static const std::uint8_t Dimensions = dimensions; /** * @brief Shape type * * @internal Sorted by complexity, so the shape which is later in * the list provides collision detection for previous shapes, not * the other way around. */ #ifdef DOXYGEN_GENERATING_OUTPUT enum class Type { Point, /**< Point */ Line, /**< Line */ LineSegment, /**< @ref LineSegment "Line segment" */ Sphere, /**< Sphere */ Capsule, /**< Capsule */ AxisAlignedBox, /**< @ref AxisAlignedBox "Axis aligned box" */ Box, /**< Box */ ShapeGroup, /**< @ref ShapeGroup "Shape group" */ Plane /**< Plane (3D only) */ }; #else typedef typename Implementation::ShapeDimensionTraits::Type Type; #endif /** @brief Destructor */ virtual inline ~AbstractShape() {} /** @brief Shape type */ virtual Type type() const = 0; /** * @brief Apply transformation matrix * * Applies transformation matrix to user-defined shape properties and * caches them for later usage in collision detection. */ virtual void applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) = 0; /** * @brief Detect collision with other shape * * Default implementation returns false. * * @internal If other shape is more complex than this, returns * `other->collides(this)`. */ virtual bool collides(const AbstractShape* other) const; }; /** @brief Abstract two-dimensional shape */ typedef AbstractShape<2> AbstractShape2D; /** @brief Abstract three-dimensional shape */ typedef AbstractShape<3> AbstractShape3D; /** @debugoperator{Magnum::Physics::AbstractShape} */ #ifndef DOXYGEN_GENERATING_OUTPUT Debug MAGNUM_PHYSICS_EXPORT operator<<(Debug debug, AbstractShape2D::Type value); Debug MAGNUM_PHYSICS_EXPORT operator<<(Debug debug, AbstractShape3D::Type value); #else template Debug operator<<(Debug debug, typename AbstractShape::Type value); #endif }} #endif