You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

137 lines
4.1 KiB

#ifndef Magnum_Physics_AbstractShape_h
#define Magnum_Physics_AbstractShape_h
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
This file is part of Magnum.
Magnum is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 3
only, as published by the Free Software Foundation.
Magnum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License version 3 for more details.
*/
/** @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<std::uint8_t dimensions> 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<std::uint8_t dimensions> 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<dimensions>::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<dimensions>::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<dimensions>* 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<std::uint8_t dimensions> Debug operator<<(Debug debug, typename AbstractShape<dimensions>::Type value);
#endif
}}
#endif