Browse Source

Shapes: added InvertedSphere shape.

pull/23/head
Vladimír Vondruš 13 years ago
parent
commit
54465070ae
  1. 1
      src/Shapes/Composition.h
  2. 4
      src/Shapes/Shapes.h
  3. 2
      src/Shapes/Sphere.cpp
  4. 47
      src/Shapes/Sphere.h
  5. 2
      src/Shapes/shapeImplementation.cpp
  6. 29
      src/Shapes/shapeImplementation.h

1
src/Shapes/Composition.h

@ -79,6 +79,7 @@ template<UnsignedInt dimensions> class MAGNUM_SHAPES_EXPORT Composition {
Line, /**< Line */ Line, /**< Line */
LineSegment, /**< @ref LineSegment "Line segment" */ LineSegment, /**< @ref LineSegment "Line segment" */
Sphere, /**< Sphere */ Sphere, /**< Sphere */
InvertedSphere, /**< @ref InvertedSphere "Inverted sphere" */
Cylinder, /**< @ref Cylinder */ Cylinder, /**< @ref Cylinder */
Capsule, /**< Capsule */ Capsule, /**< Capsule */
AxisAlignedBox, /**< @ref AxisAlignedBox "Axis aligned box" */ AxisAlignedBox, /**< @ref AxisAlignedBox "Axis aligned box" */

4
src/Shapes/Shapes.h

@ -78,6 +78,10 @@ template<UnsignedInt> class Sphere;
typedef Sphere<2> Sphere2D; typedef Sphere<2> Sphere2D;
typedef Sphere<3> Sphere3D; typedef Sphere<3> Sphere3D;
template<UnsignedInt> class InvertedSphere;
typedef InvertedSphere<2> InvertedSphere2D;
typedef InvertedSphere<3> InvertedSphere3D;
class Plane; class Plane;
template<UnsignedInt> class Point; template<UnsignedInt> class Point;

2
src/Shapes/Sphere.cpp

@ -102,6 +102,8 @@ template<UnsignedInt dimensions> Collision<dimensions> Sphere<dimensions>::opera
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
template class MAGNUM_SHAPES_EXPORT Sphere<2>; template class MAGNUM_SHAPES_EXPORT Sphere<2>;
template class MAGNUM_SHAPES_EXPORT Sphere<3>; template class MAGNUM_SHAPES_EXPORT Sphere<3>;
template class MAGNUM_SHAPES_EXPORT InvertedSphere<2>;
template class MAGNUM_SHAPES_EXPORT InvertedSphere<3>;
#endif #endif
}} }}

47
src/Shapes/Sphere.h

@ -109,6 +109,53 @@ typedef Sphere<2> Sphere2D;
/** @brief Three-dimensional sphere */ /** @brief Three-dimensional sphere */
typedef Sphere<3> Sphere3D; typedef Sphere<3> Sphere3D;
/**
@brief Inverted sphere defined by position and radius
Inverted version of @ref Sphere, detecting collisions on the outside, not on
the inside. See @ref shapes for brief introduction.
@see @ref InvertedSphere2D, @ref InvertedSphere3D
*/
template<UnsignedInt dimensions> class MAGNUM_SHAPES_EXPORT InvertedSphere:
#ifdef DOXYGEN_GENERATING_OUTPUT
public Sphere<dimensions>
#else
private Sphere<dimensions>
#endif
{
public:
/**
* @brief Default constructor
*
* Creates zero-sized sphere at origin.
*/
constexpr /*implicit*/ InvertedSphere() = default;
/** @brief Constructor */
constexpr /*implicit*/ InvertedSphere(const typename DimensionTraits<dimensions, Float>::VectorType& position, Float radius): Sphere<dimensions>(position, radius) {}
using Sphere<dimensions>::Dimensions;
/** @brief Transformed shape */
InvertedSphere<dimensions> transformed(const typename DimensionTraits<dimensions, Float>::MatrixType& matrix) const {
return Sphere<dimensions>::transformed(matrix);
}
using Sphere<dimensions>::position;
using Sphere<dimensions>::setPosition;
using Sphere<dimensions>::radius;
using Sphere<dimensions>::setRadius;
private:
constexpr /*implicit*/ InvertedSphere(const Sphere<dimensions>& other): Sphere<dimensions>(other) {}
};
/** @brief Inverted two-dimensional sphere */
typedef InvertedSphere<2> InvertedSphere2D;
/** @brief Inverted three-dimensional sphere */
typedef InvertedSphere<3> InvertedSphere3D;
/** @collisionoccurenceoperator{Point,Sphere} */ /** @collisionoccurenceoperator{Point,Sphere} */
template<UnsignedInt dimensions> inline bool operator%(const Point<dimensions>& a, const Sphere<dimensions>& b) { return b % a; } template<UnsignedInt dimensions> inline bool operator%(const Point<dimensions>& a, const Sphere<dimensions>& b) { return b % a; }

2
src/Shapes/shapeImplementation.cpp

@ -35,6 +35,7 @@ Debug operator<<(Debug debug, ShapeDimensionTraits<2>::Type value) {
_val(Line) _val(Line)
_val(LineSegment) _val(LineSegment)
_val(Sphere) _val(Sphere)
_val(InvertedSphere)
_val(Capsule) _val(Capsule)
_val(Cylinder) _val(Cylinder)
_val(AxisAlignedBox) _val(AxisAlignedBox)
@ -53,6 +54,7 @@ Debug operator<<(Debug debug, ShapeDimensionTraits<3>::Type value) {
_val(Line) _val(Line)
_val(LineSegment) _val(LineSegment)
_val(Sphere) _val(Sphere)
_val(InvertedSphere)
_val(Capsule) _val(Capsule)
_val(Cylinder) _val(Cylinder)
_val(AxisAlignedBox) _val(AxisAlignedBox)

29
src/Shapes/shapeImplementation.h

@ -62,11 +62,12 @@ template<> struct ShapeDimensionTraits<2> {
Line = 2, Line = 2,
LineSegment = 3, LineSegment = 3,
Sphere = 5, Sphere = 5,
Cylinder = 7, InvertedSphere = 7,
Capsule = 11, Cylinder = 11,
AxisAlignedBox = 13, Capsule = 13,
Box = 17, AxisAlignedBox = 17,
Composition = 19 Box = 19,
Composition = 23
}; };
}; };
@ -76,12 +77,13 @@ template<> struct ShapeDimensionTraits<3> {
Line = 2, Line = 2,
LineSegment = 3, LineSegment = 3,
Sphere = 5, Sphere = 5,
Cylinder = 7, InvertedSphere = 7,
Capsule = 11, Cylinder = 11,
AxisAlignedBox = 13, Capsule = 13,
Box = 17, AxisAlignedBox = 17,
Plane = 19, Box = 19,
Composition = 23 Plane = 23,
Composition = 29
}; };
}; };
@ -112,6 +114,11 @@ template<UnsignedInt dimensions> struct TypeOf<Shapes::Sphere<dimensions>> {
return ShapeDimensionTraits<dimensions>::Type::Sphere; return ShapeDimensionTraits<dimensions>::Type::Sphere;
} }
}; };
template<UnsignedInt dimensions> struct TypeOf<Shapes::InvertedSphere<dimensions>> {
constexpr static typename ShapeDimensionTraits<dimensions>::Type type() {
return ShapeDimensionTraits<dimensions>::Type::InvertedSphere;
}
};
template<UnsignedInt dimensions> struct TypeOf<Shapes::Cylinder<dimensions>> { template<UnsignedInt dimensions> struct TypeOf<Shapes::Cylinder<dimensions>> {
constexpr static typename ShapeDimensionTraits<dimensions>::Type type() { constexpr static typename ShapeDimensionTraits<dimensions>::Type type() {
return ShapeDimensionTraits<dimensions>::Type::Cylinder; return ShapeDimensionTraits<dimensions>::Type::Cylinder;

Loading…
Cancel
Save