diff --git a/src/Physics/AbstractShape.cpp b/src/Physics/AbstractShape.cpp index c6d2511d9..adedf7f85 100644 --- a/src/Physics/AbstractShape.cpp +++ b/src/Physics/AbstractShape.cpp @@ -19,7 +19,7 @@ namespace Magnum { namespace Physics { -template bool AbstractShape::collides(const AbstractShape* other) const { +template bool AbstractShape::collides(const AbstractShape* other) const { /* Operate only with simpler types than this */ if(static_cast(other->type()) > static_cast(type())) return other->collides(this); diff --git a/src/Physics/AbstractShape.h b/src/Physics/AbstractShape.h index 85aee4ad3..9b2f882b7 100644 --- a/src/Physics/AbstractShape.h +++ b/src/Physics/AbstractShape.h @@ -28,7 +28,7 @@ namespace Magnum { namespace Physics { #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { - template struct ShapeDimensionTraits {}; + template struct ShapeDimensionTraits {}; template<> struct ShapeDimensionTraits<2> { enum class Type { @@ -68,10 +68,10 @@ namespace Implementation { See @ref collision-detection for brief introduction. @see AbstractShape2D, AbstractShape3D */ -template class MAGNUM_PHYSICS_EXPORT AbstractShape { +template class MAGNUM_PHYSICS_EXPORT AbstractShape { public: /** @brief Dimension count */ - static const std::uint8_t Dimensions = dimensions; + static const UnsignedInt Dimensions = dimensions; /** * @brief Shape type @@ -130,7 +130,7 @@ typedef AbstractShape<3> AbstractShape3D; #ifdef DOXYGEN_GENERATING_OUTPUT /** @debugoperator{Magnum::Physics::AbstractShape} */ -template Debug operator<<(Debug debug, typename AbstractShape::Type value); +template Debug operator<<(Debug debug, typename AbstractShape::Type value); #endif }} diff --git a/src/Physics/AxisAlignedBox.cpp b/src/Physics/AxisAlignedBox.cpp index 822315464..36714d8bb 100644 --- a/src/Physics/AxisAlignedBox.cpp +++ b/src/Physics/AxisAlignedBox.cpp @@ -21,19 +21,19 @@ namespace Magnum { namespace Physics { -template void AxisAlignedBox::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { +template void AxisAlignedBox::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { _transformedMin = matrix.transformPoint(_min); _transformedMax = matrix.transformPoint(_max); } -template bool AxisAlignedBox::collides(const AbstractShape* other) const { +template bool AxisAlignedBox::collides(const AbstractShape* other) const { if(other->type() == AbstractShape::Type::Point) return *this % *static_cast*>(other); return AbstractShape::collides(other); } -template bool AxisAlignedBox::operator%(const Point& other) const { +template bool AxisAlignedBox::operator%(const Point& other) const { return (other.transformedPosition() >= _transformedMin).all() && (other.transformedPosition() < _transformedMax).all(); } diff --git a/src/Physics/AxisAlignedBox.h b/src/Physics/AxisAlignedBox.h index aa4756c49..15137238c 100644 --- a/src/Physics/AxisAlignedBox.h +++ b/src/Physics/AxisAlignedBox.h @@ -33,7 +33,7 @@ namespace Magnum { namespace Physics { @see AxisAlignedBox2D, AxisAlignedBox3D @todo Assert for rotation */ -template class MAGNUM_PHYSICS_EXPORT AxisAlignedBox: public AbstractShape { +template class MAGNUM_PHYSICS_EXPORT AxisAlignedBox: public AbstractShape { public: /** @brief Constructor */ inline explicit AxisAlignedBox(const typename DimensionTraits::VectorType& min, const typename DimensionTraits::VectorType& max): _min(min), _max(max), _transformedMin(min), _transformedMax(max) {} @@ -89,7 +89,7 @@ typedef AxisAlignedBox<2> AxisAlignedBox2D; typedef AxisAlignedBox<3> AxisAlignedBox3D; /** @collisionoperator{Point,AxisAlignedBox} */ -template inline bool operator%(const Point& a, const AxisAlignedBox& b) { return b % a; } +template inline bool operator%(const Point& a, const AxisAlignedBox& b) { return b % a; } }} diff --git a/src/Physics/Box.cpp b/src/Physics/Box.cpp index 677855a3b..189625c6f 100644 --- a/src/Physics/Box.cpp +++ b/src/Physics/Box.cpp @@ -19,7 +19,7 @@ namespace Magnum { namespace Physics { -template void Box::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { +template void Box::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { _transformedTransformation = matrix*_transformation; } diff --git a/src/Physics/Box.h b/src/Physics/Box.h index acb24e091..9507e66e8 100644 --- a/src/Physics/Box.h +++ b/src/Physics/Box.h @@ -34,7 +34,7 @@ namespace Magnum { namespace Physics { @see Box2D, Box3D @todo Assert for skew */ -template class MAGNUM_PHYSICS_EXPORT Box: public AbstractShape { +template class MAGNUM_PHYSICS_EXPORT Box: public AbstractShape { public: /** @brief Constructor */ inline explicit Box(const typename DimensionTraits::MatrixType& transformation): _transformation(transformation), _transformedTransformation(transformation) {} diff --git a/src/Physics/Capsule.cpp b/src/Physics/Capsule.cpp index 9fcf061c8..f48311eb6 100644 --- a/src/Physics/Capsule.cpp +++ b/src/Physics/Capsule.cpp @@ -26,14 +26,14 @@ using namespace Magnum::Math::Geometry; namespace Magnum { namespace Physics { -template void Capsule::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { +template void Capsule::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { _transformedA = matrix.transformPoint(_a); _transformedB = matrix.transformPoint(_b); - float scaling = (matrix.rotationScaling()*typename DimensionTraits::VectorType(1/Constants::sqrt3())).length(); + Float scaling = (matrix.rotationScaling()*typename DimensionTraits::VectorType(1/Constants::sqrt3())).length(); _transformedRadius = scaling*_radius; } -template bool Capsule::collides(const AbstractShape* other) const { +template bool Capsule::collides(const AbstractShape* other) const { if(other->type() == AbstractShape::Type::Point) return *this % *static_cast*>(other); if(other->type() == AbstractShape::Type::Sphere) @@ -42,12 +42,12 @@ template bool Capsule::collides(const Abstr return AbstractShape::collides(other); } -template bool Capsule::operator%(const Point& other) const { +template bool Capsule::operator%(const Point& other) const { return Distance::lineSegmentPointSquared(transformedA(), transformedB(), other.transformedPosition()) < Math::pow<2>(transformedRadius()); } -template bool Capsule::operator%(const Sphere& other) const { +template bool Capsule::operator%(const Sphere& other) const { return Distance::lineSegmentPointSquared(transformedA(), transformedB(), other.transformedPosition()) < Math::pow<2>(transformedRadius()+other.transformedRadius()); } diff --git a/src/Physics/Capsule.h b/src/Physics/Capsule.h index 0e0184a08..a2a7a0529 100644 --- a/src/Physics/Capsule.h +++ b/src/Physics/Capsule.h @@ -35,10 +35,10 @@ applying transformation, the scale factor is averaged from all axes. @see Capsule2D, Capsule3D @todo Assert for asymmetric scaling */ -template class MAGNUM_PHYSICS_EXPORT Capsule: public AbstractShape { +template class MAGNUM_PHYSICS_EXPORT Capsule: public AbstractShape { public: /** @brief Constructor */ - inline explicit Capsule(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b, float radius): _a(a), _transformedA(a), _b(b), _transformedB(b), _radius(radius), _transformedRadius(radius) {} + inline explicit Capsule(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b, Float radius): _a(a), _transformedA(a), _b(b), _transformedB(b), _radius(radius), _transformedRadius(radius) {} inline typename AbstractShape::Type type() const override { return AbstractShape::Type::Capsule; @@ -69,10 +69,10 @@ template class MAGNUM_PHYSICS_EXPORT Capsule: public Ab } /** @brief Radius */ - inline float radius() const { return _radius; } + inline Float radius() const { return _radius; } /** @brief Set radius */ - inline void setRadius(float radius) { _radius = radius; } + inline void setRadius(Float radius) { _radius = radius; } /** @brief Transformed first point */ inline typename DimensionTraits::VectorType transformedA() const { @@ -85,7 +85,7 @@ template class MAGNUM_PHYSICS_EXPORT Capsule: public Ab } /** @brief Transformed radius */ - inline float transformedRadius() const { + inline Float transformedRadius() const { return _transformedRadius; } @@ -98,7 +98,7 @@ template class MAGNUM_PHYSICS_EXPORT Capsule: public Ab private: typename DimensionTraits::VectorType _a, _transformedA, _b, _transformedB; - float _radius, _transformedRadius; + Float _radius, _transformedRadius; }; /** @brief Two-dimensional capsule */ @@ -108,10 +108,10 @@ typedef Capsule<2> Capsule2D; typedef Capsule<3> Capsule3D; /** @collisionoperator{Point,Capsule} */ -template inline bool operator%(const Point& a, const Capsule& b) { return b % a; } +template inline bool operator%(const Point& a, const Capsule& b) { return b % a; } /** @collisionoperator{Sphere,Capsule} */ -template inline bool operator%(const Sphere& a, const Capsule& b) { return b % a; } +template inline bool operator%(const Sphere& a, const Capsule& b) { return b % a; } }} diff --git a/src/Physics/Line.cpp b/src/Physics/Line.cpp index 8f02bc887..d3835441e 100644 --- a/src/Physics/Line.cpp +++ b/src/Physics/Line.cpp @@ -20,7 +20,7 @@ namespace Magnum { namespace Physics { -template void Line::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { +template void Line::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { _transformedA = matrix.transformPoint(_a); _transformedB = matrix.transformPoint(_b); } diff --git a/src/Physics/Line.h b/src/Physics/Line.h index 79c721d09..0e9c949f9 100644 --- a/src/Physics/Line.h +++ b/src/Physics/Line.h @@ -32,7 +32,7 @@ namespace Magnum { namespace Physics { @see Line2D, Line3D @todo collision detection of two Line2D */ -template class MAGNUM_PHYSICS_EXPORT Line: public AbstractShape { +template class MAGNUM_PHYSICS_EXPORT Line: public AbstractShape { public: /** @brief Constructor */ inline explicit Line(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b): _a(a), _transformedA(a), _b(b), _transformedB(b) {} diff --git a/src/Physics/LineSegment.h b/src/Physics/LineSegment.h index f36c878f7..d057257bf 100644 --- a/src/Physics/LineSegment.h +++ b/src/Physics/LineSegment.h @@ -28,7 +28,7 @@ namespace Magnum { namespace Physics { @see LineSegment2D, LineSegment3D */ -template class LineSegment: public Line { +template class LineSegment: public Line { public: /** @brief Constructor */ inline explicit LineSegment(const typename DimensionTraits::VectorType& a, const typename DimensionTraits::VectorType& b): Line(a, b) {} diff --git a/src/Physics/ObjectShape.cpp b/src/Physics/ObjectShape.cpp index 220655125..b37d9eeee 100644 --- a/src/Physics/ObjectShape.cpp +++ b/src/Physics/ObjectShape.cpp @@ -22,27 +22,27 @@ namespace Magnum { namespace Physics { -template ObjectShape::ObjectShape(SceneGraph::AbstractObject* object, ObjectShapeGroup* group): SceneGraph::AbstractGroupedFeature>(object, group), _shape(nullptr) { +template ObjectShape::ObjectShape(SceneGraph::AbstractObject* object, ObjectShapeGroup* group): SceneGraph::AbstractGroupedFeature>(object, group), _shape(nullptr) { this->setCachedTransformations(SceneGraph::AbstractFeature::CachedTransformation::Absolute); } -template ObjectShape::~ObjectShape() { +template ObjectShape::~ObjectShape() { delete _shape; } -template ObjectShapeGroup* ObjectShape::group() { +template ObjectShapeGroup* ObjectShape::group() { return static_cast*>(SceneGraph::AbstractGroupedFeature>::group()); } -template const ObjectShapeGroup* ObjectShape::group() const { +template const ObjectShapeGroup* ObjectShape::group() const { return static_cast*>(SceneGraph::AbstractGroupedFeature>::group()); } -template void ObjectShape::markDirty() { +template void ObjectShape::markDirty() { group()->setDirty(); } -template void ObjectShape::clean(const typename DimensionTraits::MatrixType& absoluteTransformationMatrix) { +template void ObjectShape::clean(const typename DimensionTraits::MatrixType& absoluteTransformationMatrix) { if(_shape) _shape->applyTransformationMatrix(absoluteTransformationMatrix); } diff --git a/src/Physics/ObjectShape.h b/src/Physics/ObjectShape.h index 0f7aa6e31..9eb35379e 100644 --- a/src/Physics/ObjectShape.h +++ b/src/Physics/ObjectShape.h @@ -49,7 +49,7 @@ shape->setShape(Physics::Sphere3D({}, 0.75f) || Physics::AxisAlignedBox3D({}, {3 @see @ref scenegraph, ObjectShape2D, ObjectShape3D, ObjectShapeGroup2D, ObjectShapeGroup3D, DebugTools::ShapeRenderer */ -template class MAGNUM_PHYSICS_EXPORT ObjectShape: public SceneGraph::AbstractGroupedFeature> { +template class MAGNUM_PHYSICS_EXPORT ObjectShape: public SceneGraph::AbstractGroupedFeature> { public: /** * @brief Constructor diff --git a/src/Physics/ObjectShapeGroup.cpp b/src/Physics/ObjectShapeGroup.cpp index 39766effd..1fea2b8ea 100644 --- a/src/Physics/ObjectShapeGroup.cpp +++ b/src/Physics/ObjectShapeGroup.cpp @@ -20,7 +20,7 @@ namespace Magnum { namespace Physics { -template void ObjectShapeGroup::setClean() { +template void ObjectShapeGroup::setClean() { /* Clean all objects */ if(!this->isEmpty()) { std::vector*> objects(this->size()); @@ -33,7 +33,7 @@ template void ObjectShapeGroup::setClean() dirty = false; } -template ObjectShape* ObjectShapeGroup::firstCollision(const ObjectShape* shape) { +template ObjectShape* ObjectShapeGroup::firstCollision(const ObjectShape* shape) { /* Nothing to test with, done */ if(!shape->shape()) return nullptr; diff --git a/src/Physics/ObjectShapeGroup.h b/src/Physics/ObjectShapeGroup.h index 46db09721..ffc736708 100644 --- a/src/Physics/ObjectShapeGroup.h +++ b/src/Physics/ObjectShapeGroup.h @@ -35,7 +35,7 @@ namespace Magnum { namespace Physics { See ObjectShape for more information. @see @ref scenegraph, ObjectShapeGroup2D, ObjectShapeGroup3D */ -template class MAGNUM_PHYSICS_EXPORT ObjectShapeGroup: public SceneGraph::FeatureGroup> { +template class MAGNUM_PHYSICS_EXPORT ObjectShapeGroup: public SceneGraph::FeatureGroup> { friend class ObjectShape; public: diff --git a/src/Physics/Physics.h b/src/Physics/Physics.h index 5667d4491..ac9712de0 100644 --- a/src/Physics/Physics.h +++ b/src/Physics/Physics.h @@ -19,55 +19,55 @@ * @brief Forward declarations for Magnum::Physics namespace */ -#include +#include "Types.h" namespace Magnum { namespace Physics { /** @todoc remove when doxygen is sane again */ #ifndef DOXYGEN_GENERATING_OUTPUT -template class AbstractShape; +template class AbstractShape; typedef AbstractShape<2> AbstractShape2D; typedef AbstractShape<3> AbstractShape3D; -template class AxisAlignedBox; +template class AxisAlignedBox; typedef AxisAlignedBox<2> AxisAlignedBox2D; typedef AxisAlignedBox<3> AxisAlignedBox3D; -template class Box; +template class Box; typedef Box<2> Box2D; typedef Box<3> Box3D; -template class Capsule; +template class Capsule; typedef Capsule<2> Capsule2D; typedef Capsule<3> Capsule3D; -template class Line; +template class Line; typedef Line<2> Line2D; typedef Line<3> Line3D; -template class LineSegment; +template class LineSegment; typedef LineSegment<2> LineSegment2D; typedef LineSegment<3> LineSegment3D; -template class ObjectShape; +template class ObjectShape; typedef ObjectShape<2> ObjectShape2D; typedef ObjectShape<3> ObjectShape3D; -template class ObjectShapeGroup; +template class ObjectShapeGroup; typedef ObjectShapeGroup<2> ObjectShapeGroup2D; typedef ObjectShapeGroup<3> ObjectShapeGroup3D; class Plane; -template class Point; +template class Point; typedef Point<2> Point2D; typedef Point<3> Point3D; -template class ShapeGroup; +template class ShapeGroup; typedef ShapeGroup<2> ShapeGroup2D; typedef ShapeGroup<3> ShapeGroup3D; -template class Sphere; +template class Sphere; typedef Sphere<2> Sphere2D; typedef Sphere<3> Sphere3D; #endif diff --git a/src/Physics/Plane.cpp b/src/Physics/Plane.cpp index b354447d9..098c0e071 100644 --- a/src/Physics/Plane.cpp +++ b/src/Physics/Plane.cpp @@ -40,12 +40,12 @@ bool Plane::collides(const AbstractShape<3>* other) const { } bool Plane::operator%(const Line3D& other) const { - float t = Intersection::planeLine(transformedPosition(), transformedNormal(), other.transformedA(), other.transformedB()); - return t != t || (t != std::numeric_limits::infinity() && t != -std::numeric_limits::infinity()); + Float t = Intersection::planeLine(transformedPosition(), transformedNormal(), other.transformedA(), other.transformedB()); + return t != t || (t != std::numeric_limits::infinity() && t != -std::numeric_limits::infinity()); } bool Plane::operator%(const LineSegment3D& other) const { - float t = Intersection::planeLine(transformedPosition(), transformedNormal(), other.transformedA(), other.transformedB()); + Float t = Intersection::planeLine(transformedPosition(), transformedNormal(), other.transformedA(), other.transformedB()); return t > 0.0f && t < 1.0f; } diff --git a/src/Physics/Point.cpp b/src/Physics/Point.cpp index 94d7d20af..880c91edb 100644 --- a/src/Physics/Point.cpp +++ b/src/Physics/Point.cpp @@ -20,7 +20,7 @@ namespace Magnum { namespace Physics { -template void Point::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { +template void Point::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { _transformedPosition = matrix.transformPoint(_position); } diff --git a/src/Physics/Point.h b/src/Physics/Point.h index 10ebf9583..406197023 100644 --- a/src/Physics/Point.h +++ b/src/Physics/Point.h @@ -31,7 +31,7 @@ namespace Magnum { namespace Physics { @see Point2D, Point3D */ -template class MAGNUM_PHYSICS_EXPORT Point: public AbstractShape { +template class MAGNUM_PHYSICS_EXPORT Point: public AbstractShape { public: /** @brief Constructor */ inline explicit Point(const typename DimensionTraits::VectorType& position): _position(position), _transformedPosition(position) {} diff --git a/src/Physics/ShapeGroup.cpp b/src/Physics/ShapeGroup.cpp index d77a0ce18..5c5a957b9 100644 --- a/src/Physics/ShapeGroup.cpp +++ b/src/Physics/ShapeGroup.cpp @@ -17,18 +17,18 @@ namespace Magnum { namespace Physics { -template ShapeGroup::ShapeGroup(ShapeGroup&& other): operation(other.operation), a(other.a), b(other.b) { +template ShapeGroup::ShapeGroup(ShapeGroup&& other): operation(other.operation), a(other.a), b(other.b) { other.operation = Implementation::GroupOperation::AlwaysFalse; other.a = nullptr; other.b = nullptr; } -template ShapeGroup::~ShapeGroup() { +template ShapeGroup::~ShapeGroup() { if(!(operation & Implementation::GroupOperation::RefA)) delete a; if(!(operation & Implementation::GroupOperation::RefB)) delete b; } -template ShapeGroup& ShapeGroup::operator=(ShapeGroup&& other) { +template ShapeGroup& ShapeGroup::operator=(ShapeGroup&& other) { if(!(operation & Implementation::GroupOperation::RefA)) delete a; if(!(operation & Implementation::GroupOperation::RefB)) delete b; @@ -43,12 +43,12 @@ template ShapeGroup& ShapeGroup return *this; } -template void ShapeGroup::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { +template void ShapeGroup::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { if(a) a->applyTransformationMatrix(matrix); if(b) b->applyTransformationMatrix(matrix); } -template bool ShapeGroup::collides(const AbstractShape* other) const { +template bool ShapeGroup::collides(const AbstractShape* other) const { switch(operation & ~Implementation::GroupOperation::RefAB) { case Implementation::GroupOperation::And: return a->collides(other) && b->collides(other); case Implementation::GroupOperation::Or: return a->collides(other) || b->collides(other); diff --git a/src/Physics/ShapeGroup.h b/src/Physics/ShapeGroup.h index fde6d895a..132686f77 100644 --- a/src/Physics/ShapeGroup.h +++ b/src/Physics/ShapeGroup.h @@ -58,7 +58,7 @@ Result of logical operations on shapes. See @ref collision-detection for brief introduction. @see ShapeGroup2D, ShapeGroup3D */ -template class MAGNUM_PHYSICS_EXPORT ShapeGroup: public AbstractShape { +template class MAGNUM_PHYSICS_EXPORT ShapeGroup: public AbstractShape { #ifndef DOXYGEN_GENERATING_OUTPUT // template friend constexpr operator~(const T& a) -> enableIfIsBaseType; // template friend constexpr operator~(T&& a) -> enableIfIsBaseType; @@ -186,7 +186,7 @@ is used here, so this operation can be used for providing simplified shape version, because collision with @p b is computed only if @p a collides. See @ref collision-detection-shape-simplification for an example. */ -template inline constexpr ShapeGroup operator&&(T a, U b); +template inline constexpr ShapeGroup operator&&(T a, U b); /** @relates ShapeGroup @brief Logical OR of two shapes @@ -195,7 +195,7 @@ template inline constexpr ShapeGroup< is used, so if collision with @p a is detected, collision with @p b is not computed. */ -template inline constexpr ShapeGroup operator||(T a, U b); +template inline constexpr ShapeGroup operator||(T a, U b); #else #define op(type, char) \ template inline constexpr auto operator char(const T& a, const U& b) -> enableIfAreBaseType { \ diff --git a/src/Physics/Sphere.cpp b/src/Physics/Sphere.cpp index f5c7e5d51..752d3875f 100644 --- a/src/Physics/Sphere.cpp +++ b/src/Physics/Sphere.cpp @@ -27,7 +27,7 @@ using namespace Magnum::Math::Geometry; namespace Magnum { namespace Physics { namespace { - template static typename DimensionTraits::VectorType unitVector(); + template static typename DimensionTraits::VectorType unitVector(); template<> inline Vector2 unitVector<2>() { return Vector2(1/Constants::sqrt2()); @@ -38,13 +38,13 @@ namespace { } } -template void Sphere::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { +template void Sphere::applyTransformationMatrix(const typename DimensionTraits::MatrixType& matrix) { _transformedPosition = matrix.transformPoint(_position); - float scaling = (matrix.rotationScaling()*unitVector()).length(); + Float scaling = (matrix.rotationScaling()*unitVector()).length(); _transformedRadius = scaling*_radius; } -template bool Sphere::collides(const AbstractShape* other) const { +template bool Sphere::collides(const AbstractShape* other) const { if(other->type() == AbstractShape::Type::Point) return *this % *static_cast*>(other); if(other->type() == AbstractShape::Type::Line) @@ -57,22 +57,22 @@ template bool Sphere::collides(const Abstra return AbstractShape::collides(other); } -template bool Sphere::operator%(const Point& other) const { +template bool Sphere::operator%(const Point& other) const { return (other.transformedPosition()-transformedPosition()).dot() < Math::pow<2>(transformedRadius()); } -template bool Sphere::operator%(const Line& other) const { +template bool Sphere::operator%(const Line& other) const { return Distance::linePointSquared(other.transformedA(), other.transformedB(), transformedPosition()) < Math::pow<2>(transformedRadius()); } -template bool Sphere::operator%(const LineSegment& other) const { +template bool Sphere::operator%(const LineSegment& other) const { return Distance::lineSegmentPointSquared(other.transformedA(), other.transformedB(), transformedPosition()) < Math::pow<2>(transformedRadius()); } -template bool Sphere::operator%(const Sphere& other) const { +template bool Sphere::operator%(const Sphere& other) const { return (other.transformedPosition()-transformedPosition()).dot() < Math::pow<2>(transformedRadius()+other.transformedRadius()); } diff --git a/src/Physics/Sphere.h b/src/Physics/Sphere.h index 5c60df747..ed84b3b59 100644 --- a/src/Physics/Sphere.h +++ b/src/Physics/Sphere.h @@ -35,10 +35,10 @@ applying transformation, the scale factor is averaged from all axes. @see Sphere2D, Sphere3D @todo Assert for asymmetric scaling */ -template class MAGNUM_PHYSICS_EXPORT Sphere: public AbstractShape { +template class MAGNUM_PHYSICS_EXPORT Sphere: public AbstractShape { public: /** @brief Constructor */ - inline explicit Sphere(const typename DimensionTraits::VectorType& position, float radius): _position(position), _transformedPosition(position), _radius(radius), _transformedRadius(radius) {} + inline explicit Sphere(const typename DimensionTraits::VectorType& position, Float radius): _position(position), _transformedPosition(position), _radius(radius), _transformedRadius(radius) {} inline typename AbstractShape::Type type() const override { return AbstractShape::Type::Sphere; @@ -59,10 +59,10 @@ template class MAGNUM_PHYSICS_EXPORT Sphere: public Abs } /** @brief Radius */ - inline float radius() const { return _radius; } + inline Float radius() const { return _radius; } /** @brief Set radius */ - inline void setRadius(float radius) { _radius = radius; } + inline void setRadius(Float radius) { _radius = radius; } /** @brief Transformed position */ inline typename DimensionTraits::VectorType transformedPosition() const { @@ -70,7 +70,7 @@ template class MAGNUM_PHYSICS_EXPORT Sphere: public Abs } /** @brief Transformed radius */ - inline float transformedRadius() const { + inline Float transformedRadius() const { return _transformedRadius; } @@ -89,7 +89,7 @@ template class MAGNUM_PHYSICS_EXPORT Sphere: public Abs private: typename DimensionTraits::VectorType _position, _transformedPosition; - float _radius, _transformedRadius; + Float _radius, _transformedRadius; }; /** @brief Two-dimensional sphere */ @@ -99,13 +99,13 @@ typedef Sphere<2> Sphere2D; typedef Sphere<3> Sphere3D; /** @collisionoperator{Point,Sphere} */ -template inline bool operator%(const Point& a, const Sphere& b) { return b % a; } +template inline bool operator%(const Point& a, const Sphere& b) { return b % a; } /** @collisionoperator{Line,Sphere} */ -template inline bool operator%(const Line& a, const Sphere& b) { return b % a; } +template inline bool operator%(const Line& a, const Sphere& b) { return b % a; } /** @collisionoperator{LineSegment,Sphere} */ -template inline bool operator%(const LineSegment& a, const Sphere& b) { return b % a; } +template inline bool operator%(const LineSegment& a, const Sphere& b) { return b % a; } }}