From 54465070ae9fe52179041e0ae96654f3fc812b28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 26 Sep 2013 00:55:51 +0200 Subject: [PATCH] Shapes: added InvertedSphere shape. --- src/Shapes/Composition.h | 1 + src/Shapes/Shapes.h | 4 +++ src/Shapes/Sphere.cpp | 2 ++ src/Shapes/Sphere.h | 47 ++++++++++++++++++++++++++++++ src/Shapes/shapeImplementation.cpp | 2 ++ src/Shapes/shapeImplementation.h | 29 +++++++++++------- 6 files changed, 74 insertions(+), 11 deletions(-) diff --git a/src/Shapes/Composition.h b/src/Shapes/Composition.h index 1783ee593..55431878b 100644 --- a/src/Shapes/Composition.h +++ b/src/Shapes/Composition.h @@ -79,6 +79,7 @@ template class MAGNUM_SHAPES_EXPORT Composition { Line, /**< Line */ LineSegment, /**< @ref LineSegment "Line segment" */ Sphere, /**< Sphere */ + InvertedSphere, /**< @ref InvertedSphere "Inverted sphere" */ Cylinder, /**< @ref Cylinder */ Capsule, /**< Capsule */ AxisAlignedBox, /**< @ref AxisAlignedBox "Axis aligned box" */ diff --git a/src/Shapes/Shapes.h b/src/Shapes/Shapes.h index 2bda9882c..dcb300193 100644 --- a/src/Shapes/Shapes.h +++ b/src/Shapes/Shapes.h @@ -78,6 +78,10 @@ template class Sphere; typedef Sphere<2> Sphere2D; typedef Sphere<3> Sphere3D; +template class InvertedSphere; +typedef InvertedSphere<2> InvertedSphere2D; +typedef InvertedSphere<3> InvertedSphere3D; + class Plane; template class Point; diff --git a/src/Shapes/Sphere.cpp b/src/Shapes/Sphere.cpp index f08f8d923..dd3668172 100644 --- a/src/Shapes/Sphere.cpp +++ b/src/Shapes/Sphere.cpp @@ -102,6 +102,8 @@ template Collision Sphere::opera #ifndef DOXYGEN_GENERATING_OUTPUT template class MAGNUM_SHAPES_EXPORT Sphere<2>; template class MAGNUM_SHAPES_EXPORT Sphere<3>; +template class MAGNUM_SHAPES_EXPORT InvertedSphere<2>; +template class MAGNUM_SHAPES_EXPORT InvertedSphere<3>; #endif }} diff --git a/src/Shapes/Sphere.h b/src/Shapes/Sphere.h index 9bd3a6118..8d0bbc346 100644 --- a/src/Shapes/Sphere.h +++ b/src/Shapes/Sphere.h @@ -109,6 +109,53 @@ typedef Sphere<2> Sphere2D; /** @brief Three-dimensional sphere */ 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 class MAGNUM_SHAPES_EXPORT InvertedSphere: + #ifdef DOXYGEN_GENERATING_OUTPUT + public Sphere + #else + private Sphere + #endif +{ + public: + /** + * @brief Default constructor + * + * Creates zero-sized sphere at origin. + */ + constexpr /*implicit*/ InvertedSphere() = default; + + /** @brief Constructor */ + constexpr /*implicit*/ InvertedSphere(const typename DimensionTraits::VectorType& position, Float radius): Sphere(position, radius) {} + + using Sphere::Dimensions; + + /** @brief Transformed shape */ + InvertedSphere transformed(const typename DimensionTraits::MatrixType& matrix) const { + return Sphere::transformed(matrix); + } + + using Sphere::position; + using Sphere::setPosition; + using Sphere::radius; + using Sphere::setRadius; + + private: + constexpr /*implicit*/ InvertedSphere(const Sphere& other): Sphere(other) {} +}; + +/** @brief Inverted two-dimensional sphere */ +typedef InvertedSphere<2> InvertedSphere2D; + +/** @brief Inverted three-dimensional sphere */ +typedef InvertedSphere<3> InvertedSphere3D; + /** @collisionoccurenceoperator{Point,Sphere} */ template inline bool operator%(const Point& a, const Sphere& b) { return b % a; } diff --git a/src/Shapes/shapeImplementation.cpp b/src/Shapes/shapeImplementation.cpp index 9a9ab4a4f..3a783de32 100644 --- a/src/Shapes/shapeImplementation.cpp +++ b/src/Shapes/shapeImplementation.cpp @@ -35,6 +35,7 @@ Debug operator<<(Debug debug, ShapeDimensionTraits<2>::Type value) { _val(Line) _val(LineSegment) _val(Sphere) + _val(InvertedSphere) _val(Capsule) _val(Cylinder) _val(AxisAlignedBox) @@ -53,6 +54,7 @@ Debug operator<<(Debug debug, ShapeDimensionTraits<3>::Type value) { _val(Line) _val(LineSegment) _val(Sphere) + _val(InvertedSphere) _val(Capsule) _val(Cylinder) _val(AxisAlignedBox) diff --git a/src/Shapes/shapeImplementation.h b/src/Shapes/shapeImplementation.h index a91457775..8febd6a8a 100644 --- a/src/Shapes/shapeImplementation.h +++ b/src/Shapes/shapeImplementation.h @@ -62,11 +62,12 @@ template<> struct ShapeDimensionTraits<2> { Line = 2, LineSegment = 3, Sphere = 5, - Cylinder = 7, - Capsule = 11, - AxisAlignedBox = 13, - Box = 17, - Composition = 19 + InvertedSphere = 7, + Cylinder = 11, + Capsule = 13, + AxisAlignedBox = 17, + Box = 19, + Composition = 23 }; }; @@ -76,12 +77,13 @@ template<> struct ShapeDimensionTraits<3> { Line = 2, LineSegment = 3, Sphere = 5, - Cylinder = 7, - Capsule = 11, - AxisAlignedBox = 13, - Box = 17, - Plane = 19, - Composition = 23 + InvertedSphere = 7, + Cylinder = 11, + Capsule = 13, + AxisAlignedBox = 17, + Box = 19, + Plane = 23, + Composition = 29 }; }; @@ -112,6 +114,11 @@ template struct TypeOf> { return ShapeDimensionTraits::Type::Sphere; } }; +template struct TypeOf> { + constexpr static typename ShapeDimensionTraits::Type type() { + return ShapeDimensionTraits::Type::InvertedSphere; + } +}; template struct TypeOf> { constexpr static typename ShapeDimensionTraits::Type type() { return ShapeDimensionTraits::Type::Cylinder;