Browse Source

Physics: using new type aliases in whole Physics namespace.

pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
5f049c50b8
  1. 2
      src/Physics/AbstractShape.cpp
  2. 8
      src/Physics/AbstractShape.h
  3. 6
      src/Physics/AxisAlignedBox.cpp
  4. 4
      src/Physics/AxisAlignedBox.h
  5. 2
      src/Physics/Box.cpp
  6. 2
      src/Physics/Box.h
  7. 10
      src/Physics/Capsule.cpp
  8. 16
      src/Physics/Capsule.h
  9. 2
      src/Physics/Line.cpp
  10. 2
      src/Physics/Line.h
  11. 2
      src/Physics/LineSegment.h
  12. 12
      src/Physics/ObjectShape.cpp
  13. 2
      src/Physics/ObjectShape.h
  14. 4
      src/Physics/ObjectShapeGroup.cpp
  15. 2
      src/Physics/ObjectShapeGroup.h
  16. 24
      src/Physics/Physics.h
  17. 6
      src/Physics/Plane.cpp
  18. 2
      src/Physics/Point.cpp
  19. 2
      src/Physics/Point.h
  20. 10
      src/Physics/ShapeGroup.cpp
  21. 6
      src/Physics/ShapeGroup.h
  22. 16
      src/Physics/Sphere.cpp
  23. 18
      src/Physics/Sphere.h

2
src/Physics/AbstractShape.cpp

@ -19,7 +19,7 @@
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
template<std::uint8_t dimensions> bool AbstractShape<dimensions>::collides(const AbstractShape* other) const { template<UnsignedInt dimensions> bool AbstractShape<dimensions>::collides(const AbstractShape* other) const {
/* Operate only with simpler types than this */ /* Operate only with simpler types than this */
if(static_cast<int>(other->type()) > static_cast<int>(type())) if(static_cast<int>(other->type()) > static_cast<int>(type()))
return other->collides(this); return other->collides(this);

8
src/Physics/AbstractShape.h

@ -28,7 +28,7 @@ namespace Magnum { namespace Physics {
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
namespace Implementation { namespace Implementation {
template<std::uint8_t dimensions> struct ShapeDimensionTraits {}; template<UnsignedInt dimensions> struct ShapeDimensionTraits {};
template<> struct ShapeDimensionTraits<2> { template<> struct ShapeDimensionTraits<2> {
enum class Type { enum class Type {
@ -68,10 +68,10 @@ namespace Implementation {
See @ref collision-detection for brief introduction. See @ref collision-detection for brief introduction.
@see AbstractShape2D, AbstractShape3D @see AbstractShape2D, AbstractShape3D
*/ */
template<std::uint8_t dimensions> class MAGNUM_PHYSICS_EXPORT AbstractShape { template<UnsignedInt dimensions> class MAGNUM_PHYSICS_EXPORT AbstractShape {
public: public:
/** @brief Dimension count */ /** @brief Dimension count */
static const std::uint8_t Dimensions = dimensions; static const UnsignedInt Dimensions = dimensions;
/** /**
* @brief Shape type * @brief Shape type
@ -130,7 +130,7 @@ typedef AbstractShape<3> AbstractShape3D;
#ifdef DOXYGEN_GENERATING_OUTPUT #ifdef DOXYGEN_GENERATING_OUTPUT
/** @debugoperator{Magnum::Physics::AbstractShape} */ /** @debugoperator{Magnum::Physics::AbstractShape} */
template<std::uint8_t dimensions> Debug operator<<(Debug debug, typename AbstractShape<dimensions>::Type value); template<UnsignedInt dimensions> Debug operator<<(Debug debug, typename AbstractShape<dimensions>::Type value);
#endif #endif
}} }}

6
src/Physics/AxisAlignedBox.cpp

@ -21,19 +21,19 @@
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
template<std::uint8_t dimensions> void AxisAlignedBox<dimensions>::applyTransformationMatrix(const typename DimensionTraits<dimensions>::MatrixType& matrix) { template<UnsignedInt dimensions> void AxisAlignedBox<dimensions>::applyTransformationMatrix(const typename DimensionTraits<dimensions>::MatrixType& matrix) {
_transformedMin = matrix.transformPoint(_min); _transformedMin = matrix.transformPoint(_min);
_transformedMax = matrix.transformPoint(_max); _transformedMax = matrix.transformPoint(_max);
} }
template<std::uint8_t dimensions> bool AxisAlignedBox<dimensions>::collides(const AbstractShape<dimensions>* other) const { template<UnsignedInt dimensions> bool AxisAlignedBox<dimensions>::collides(const AbstractShape<dimensions>* other) const {
if(other->type() == AbstractShape<dimensions>::Type::Point) if(other->type() == AbstractShape<dimensions>::Type::Point)
return *this % *static_cast<const Point<dimensions>*>(other); return *this % *static_cast<const Point<dimensions>*>(other);
return AbstractShape<dimensions>::collides(other); return AbstractShape<dimensions>::collides(other);
} }
template<std::uint8_t dimensions> bool AxisAlignedBox<dimensions>::operator%(const Point<dimensions>& other) const { template<UnsignedInt dimensions> bool AxisAlignedBox<dimensions>::operator%(const Point<dimensions>& other) const {
return (other.transformedPosition() >= _transformedMin).all() && return (other.transformedPosition() >= _transformedMin).all() &&
(other.transformedPosition() < _transformedMax).all(); (other.transformedPosition() < _transformedMax).all();
} }

4
src/Physics/AxisAlignedBox.h

@ -33,7 +33,7 @@ namespace Magnum { namespace Physics {
@see AxisAlignedBox2D, AxisAlignedBox3D @see AxisAlignedBox2D, AxisAlignedBox3D
@todo Assert for rotation @todo Assert for rotation
*/ */
template<std::uint8_t dimensions> class MAGNUM_PHYSICS_EXPORT AxisAlignedBox: public AbstractShape<dimensions> { template<UnsignedInt dimensions> class MAGNUM_PHYSICS_EXPORT AxisAlignedBox: public AbstractShape<dimensions> {
public: public:
/** @brief Constructor */ /** @brief Constructor */
inline explicit AxisAlignedBox(const typename DimensionTraits<dimensions>::VectorType& min, const typename DimensionTraits<dimensions>::VectorType& max): _min(min), _max(max), _transformedMin(min), _transformedMax(max) {} inline explicit AxisAlignedBox(const typename DimensionTraits<dimensions>::VectorType& min, const typename DimensionTraits<dimensions>::VectorType& max): _min(min), _max(max), _transformedMin(min), _transformedMax(max) {}
@ -89,7 +89,7 @@ typedef AxisAlignedBox<2> AxisAlignedBox2D;
typedef AxisAlignedBox<3> AxisAlignedBox3D; typedef AxisAlignedBox<3> AxisAlignedBox3D;
/** @collisionoperator{Point,AxisAlignedBox} */ /** @collisionoperator{Point,AxisAlignedBox} */
template<std::uint8_t dimensions> inline bool operator%(const Point<dimensions>& a, const AxisAlignedBox<dimensions>& b) { return b % a; } template<UnsignedInt dimensions> inline bool operator%(const Point<dimensions>& a, const AxisAlignedBox<dimensions>& b) { return b % a; }
}} }}

2
src/Physics/Box.cpp

@ -19,7 +19,7 @@
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
template<std::uint8_t dimensions> void Box<dimensions>::applyTransformationMatrix(const typename DimensionTraits<dimensions>::MatrixType& matrix) { template<UnsignedInt dimensions> void Box<dimensions>::applyTransformationMatrix(const typename DimensionTraits<dimensions>::MatrixType& matrix) {
_transformedTransformation = matrix*_transformation; _transformedTransformation = matrix*_transformation;
} }

2
src/Physics/Box.h

@ -34,7 +34,7 @@ namespace Magnum { namespace Physics {
@see Box2D, Box3D @see Box2D, Box3D
@todo Assert for skew @todo Assert for skew
*/ */
template<std::uint8_t dimensions> class MAGNUM_PHYSICS_EXPORT Box: public AbstractShape<dimensions> { template<UnsignedInt dimensions> class MAGNUM_PHYSICS_EXPORT Box: public AbstractShape<dimensions> {
public: public:
/** @brief Constructor */ /** @brief Constructor */
inline explicit Box(const typename DimensionTraits<dimensions>::MatrixType& transformation): _transformation(transformation), _transformedTransformation(transformation) {} inline explicit Box(const typename DimensionTraits<dimensions>::MatrixType& transformation): _transformation(transformation), _transformedTransformation(transformation) {}

10
src/Physics/Capsule.cpp

@ -26,14 +26,14 @@ using namespace Magnum::Math::Geometry;
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
template<std::uint8_t dimensions> void Capsule<dimensions>::applyTransformationMatrix(const typename DimensionTraits<dimensions>::MatrixType& matrix) { template<UnsignedInt dimensions> void Capsule<dimensions>::applyTransformationMatrix(const typename DimensionTraits<dimensions>::MatrixType& matrix) {
_transformedA = matrix.transformPoint(_a); _transformedA = matrix.transformPoint(_a);
_transformedB = matrix.transformPoint(_b); _transformedB = matrix.transformPoint(_b);
float scaling = (matrix.rotationScaling()*typename DimensionTraits<dimensions>::VectorType(1/Constants::sqrt3())).length(); Float scaling = (matrix.rotationScaling()*typename DimensionTraits<dimensions>::VectorType(1/Constants::sqrt3())).length();
_transformedRadius = scaling*_radius; _transformedRadius = scaling*_radius;
} }
template<std::uint8_t dimensions> bool Capsule<dimensions>::collides(const AbstractShape<dimensions>* other) const { template<UnsignedInt dimensions> bool Capsule<dimensions>::collides(const AbstractShape<dimensions>* other) const {
if(other->type() == AbstractShape<dimensions>::Type::Point) if(other->type() == AbstractShape<dimensions>::Type::Point)
return *this % *static_cast<const Point<dimensions>*>(other); return *this % *static_cast<const Point<dimensions>*>(other);
if(other->type() == AbstractShape<dimensions>::Type::Sphere) if(other->type() == AbstractShape<dimensions>::Type::Sphere)
@ -42,12 +42,12 @@ template<std::uint8_t dimensions> bool Capsule<dimensions>::collides(const Abstr
return AbstractShape<dimensions>::collides(other); return AbstractShape<dimensions>::collides(other);
} }
template<std::uint8_t dimensions> bool Capsule<dimensions>::operator%(const Point<dimensions>& other) const { template<UnsignedInt dimensions> bool Capsule<dimensions>::operator%(const Point<dimensions>& other) const {
return Distance::lineSegmentPointSquared(transformedA(), transformedB(), other.transformedPosition()) < return Distance::lineSegmentPointSquared(transformedA(), transformedB(), other.transformedPosition()) <
Math::pow<2>(transformedRadius()); Math::pow<2>(transformedRadius());
} }
template<std::uint8_t dimensions> bool Capsule<dimensions>::operator%(const Sphere<dimensions>& other) const { template<UnsignedInt dimensions> bool Capsule<dimensions>::operator%(const Sphere<dimensions>& other) const {
return Distance::lineSegmentPointSquared(transformedA(), transformedB(), other.transformedPosition()) < return Distance::lineSegmentPointSquared(transformedA(), transformedB(), other.transformedPosition()) <
Math::pow<2>(transformedRadius()+other.transformedRadius()); Math::pow<2>(transformedRadius()+other.transformedRadius());
} }

16
src/Physics/Capsule.h

@ -35,10 +35,10 @@ applying transformation, the scale factor is averaged from all axes.
@see Capsule2D, Capsule3D @see Capsule2D, Capsule3D
@todo Assert for asymmetric scaling @todo Assert for asymmetric scaling
*/ */
template<std::uint8_t dimensions> class MAGNUM_PHYSICS_EXPORT Capsule: public AbstractShape<dimensions> { template<UnsignedInt dimensions> class MAGNUM_PHYSICS_EXPORT Capsule: public AbstractShape<dimensions> {
public: public:
/** @brief Constructor */ /** @brief Constructor */
inline explicit Capsule(const typename DimensionTraits<dimensions>::VectorType& a, const typename DimensionTraits<dimensions>::VectorType& b, float radius): _a(a), _transformedA(a), _b(b), _transformedB(b), _radius(radius), _transformedRadius(radius) {} inline explicit Capsule(const typename DimensionTraits<dimensions>::VectorType& a, const typename DimensionTraits<dimensions>::VectorType& b, Float radius): _a(a), _transformedA(a), _b(b), _transformedB(b), _radius(radius), _transformedRadius(radius) {}
inline typename AbstractShape<dimensions>::Type type() const override { inline typename AbstractShape<dimensions>::Type type() const override {
return AbstractShape<dimensions>::Type::Capsule; return AbstractShape<dimensions>::Type::Capsule;
@ -69,10 +69,10 @@ template<std::uint8_t dimensions> class MAGNUM_PHYSICS_EXPORT Capsule: public Ab
} }
/** @brief Radius */ /** @brief Radius */
inline float radius() const { return _radius; } inline Float radius() const { return _radius; }
/** @brief Set radius */ /** @brief Set radius */
inline void setRadius(float radius) { _radius = radius; } inline void setRadius(Float radius) { _radius = radius; }
/** @brief Transformed first point */ /** @brief Transformed first point */
inline typename DimensionTraits<dimensions>::VectorType transformedA() const { inline typename DimensionTraits<dimensions>::VectorType transformedA() const {
@ -85,7 +85,7 @@ template<std::uint8_t dimensions> class MAGNUM_PHYSICS_EXPORT Capsule: public Ab
} }
/** @brief Transformed radius */ /** @brief Transformed radius */
inline float transformedRadius() const { inline Float transformedRadius() const {
return _transformedRadius; return _transformedRadius;
} }
@ -98,7 +98,7 @@ template<std::uint8_t dimensions> class MAGNUM_PHYSICS_EXPORT Capsule: public Ab
private: private:
typename DimensionTraits<dimensions>::VectorType _a, _transformedA, typename DimensionTraits<dimensions>::VectorType _a, _transformedA,
_b, _transformedB; _b, _transformedB;
float _radius, _transformedRadius; Float _radius, _transformedRadius;
}; };
/** @brief Two-dimensional capsule */ /** @brief Two-dimensional capsule */
@ -108,10 +108,10 @@ typedef Capsule<2> Capsule2D;
typedef Capsule<3> Capsule3D; typedef Capsule<3> Capsule3D;
/** @collisionoperator{Point,Capsule} */ /** @collisionoperator{Point,Capsule} */
template<std::uint8_t dimensions> inline bool operator%(const Point<dimensions>& a, const Capsule<dimensions>& b) { return b % a; } template<UnsignedInt dimensions> inline bool operator%(const Point<dimensions>& a, const Capsule<dimensions>& b) { return b % a; }
/** @collisionoperator{Sphere,Capsule} */ /** @collisionoperator{Sphere,Capsule} */
template<std::uint8_t dimensions> inline bool operator%(const Sphere<dimensions>& a, const Capsule<dimensions>& b) { return b % a; } template<UnsignedInt dimensions> inline bool operator%(const Sphere<dimensions>& a, const Capsule<dimensions>& b) { return b % a; }
}} }}

2
src/Physics/Line.cpp

@ -20,7 +20,7 @@
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
template<std::uint8_t dimensions> void Line<dimensions>::applyTransformationMatrix(const typename DimensionTraits<dimensions>::MatrixType& matrix) { template<UnsignedInt dimensions> void Line<dimensions>::applyTransformationMatrix(const typename DimensionTraits<dimensions>::MatrixType& matrix) {
_transformedA = matrix.transformPoint(_a); _transformedA = matrix.transformPoint(_a);
_transformedB = matrix.transformPoint(_b); _transformedB = matrix.transformPoint(_b);
} }

2
src/Physics/Line.h

@ -32,7 +32,7 @@ namespace Magnum { namespace Physics {
@see Line2D, Line3D @see Line2D, Line3D
@todo collision detection of two Line2D @todo collision detection of two Line2D
*/ */
template<std::uint8_t dimensions> class MAGNUM_PHYSICS_EXPORT Line: public AbstractShape<dimensions> { template<UnsignedInt dimensions> class MAGNUM_PHYSICS_EXPORT Line: public AbstractShape<dimensions> {
public: public:
/** @brief Constructor */ /** @brief Constructor */
inline explicit Line(const typename DimensionTraits<dimensions>::VectorType& a, const typename DimensionTraits<dimensions>::VectorType& b): _a(a), _transformedA(a), _b(b), _transformedB(b) {} inline explicit Line(const typename DimensionTraits<dimensions>::VectorType& a, const typename DimensionTraits<dimensions>::VectorType& b): _a(a), _transformedA(a), _b(b), _transformedB(b) {}

2
src/Physics/LineSegment.h

@ -28,7 +28,7 @@ namespace Magnum { namespace Physics {
@see LineSegment2D, LineSegment3D @see LineSegment2D, LineSegment3D
*/ */
template<std::uint8_t dimensions> class LineSegment: public Line<dimensions> { template<UnsignedInt dimensions> class LineSegment: public Line<dimensions> {
public: public:
/** @brief Constructor */ /** @brief Constructor */
inline explicit LineSegment(const typename DimensionTraits<dimensions>::VectorType& a, const typename DimensionTraits<dimensions>::VectorType& b): Line<dimensions>(a, b) {} inline explicit LineSegment(const typename DimensionTraits<dimensions>::VectorType& a, const typename DimensionTraits<dimensions>::VectorType& b): Line<dimensions>(a, b) {}

12
src/Physics/ObjectShape.cpp

@ -22,27 +22,27 @@
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
template<std::uint8_t dimensions> ObjectShape<dimensions>::ObjectShape(SceneGraph::AbstractObject<dimensions>* object, ObjectShapeGroup<dimensions>* group): SceneGraph::AbstractGroupedFeature<dimensions, ObjectShape<dimensions>>(object, group), _shape(nullptr) { template<UnsignedInt dimensions> ObjectShape<dimensions>::ObjectShape(SceneGraph::AbstractObject<dimensions>* object, ObjectShapeGroup<dimensions>* group): SceneGraph::AbstractGroupedFeature<dimensions, ObjectShape<dimensions>>(object, group), _shape(nullptr) {
this->setCachedTransformations(SceneGraph::AbstractFeature<dimensions>::CachedTransformation::Absolute); this->setCachedTransformations(SceneGraph::AbstractFeature<dimensions>::CachedTransformation::Absolute);
} }
template<std::uint8_t dimensions> ObjectShape<dimensions>::~ObjectShape() { template<UnsignedInt dimensions> ObjectShape<dimensions>::~ObjectShape() {
delete _shape; delete _shape;
} }
template<std::uint8_t dimensions> ObjectShapeGroup<dimensions>* ObjectShape<dimensions>::group() { template<UnsignedInt dimensions> ObjectShapeGroup<dimensions>* ObjectShape<dimensions>::group() {
return static_cast<ObjectShapeGroup<dimensions>*>(SceneGraph::AbstractGroupedFeature<dimensions, ObjectShape<dimensions>>::group()); return static_cast<ObjectShapeGroup<dimensions>*>(SceneGraph::AbstractGroupedFeature<dimensions, ObjectShape<dimensions>>::group());
} }
template<std::uint8_t dimensions> const ObjectShapeGroup<dimensions>* ObjectShape<dimensions>::group() const { template<UnsignedInt dimensions> const ObjectShapeGroup<dimensions>* ObjectShape<dimensions>::group() const {
return static_cast<const ObjectShapeGroup<dimensions>*>(SceneGraph::AbstractGroupedFeature<dimensions, ObjectShape<dimensions>>::group()); return static_cast<const ObjectShapeGroup<dimensions>*>(SceneGraph::AbstractGroupedFeature<dimensions, ObjectShape<dimensions>>::group());
} }
template<std::uint8_t dimensions> void ObjectShape<dimensions>::markDirty() { template<UnsignedInt dimensions> void ObjectShape<dimensions>::markDirty() {
group()->setDirty(); group()->setDirty();
} }
template<std::uint8_t dimensions> void ObjectShape<dimensions>::clean(const typename DimensionTraits<dimensions>::MatrixType& absoluteTransformationMatrix) { template<UnsignedInt dimensions> void ObjectShape<dimensions>::clean(const typename DimensionTraits<dimensions>::MatrixType& absoluteTransformationMatrix) {
if(_shape) _shape->applyTransformationMatrix(absoluteTransformationMatrix); if(_shape) _shape->applyTransformationMatrix(absoluteTransformationMatrix);
} }

2
src/Physics/ObjectShape.h

@ -49,7 +49,7 @@ shape->setShape(Physics::Sphere3D({}, 0.75f) || Physics::AxisAlignedBox3D({}, {3
@see @ref scenegraph, ObjectShape2D, ObjectShape3D, ObjectShapeGroup2D, @see @ref scenegraph, ObjectShape2D, ObjectShape3D, ObjectShapeGroup2D,
ObjectShapeGroup3D, DebugTools::ShapeRenderer ObjectShapeGroup3D, DebugTools::ShapeRenderer
*/ */
template<std::uint8_t dimensions> class MAGNUM_PHYSICS_EXPORT ObjectShape: public SceneGraph::AbstractGroupedFeature<dimensions, ObjectShape<dimensions>> { template<UnsignedInt dimensions> class MAGNUM_PHYSICS_EXPORT ObjectShape: public SceneGraph::AbstractGroupedFeature<dimensions, ObjectShape<dimensions>> {
public: public:
/** /**
* @brief Constructor * @brief Constructor

4
src/Physics/ObjectShapeGroup.cpp

@ -20,7 +20,7 @@
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
template<std::uint8_t dimensions> void ObjectShapeGroup<dimensions>::setClean() { template<UnsignedInt dimensions> void ObjectShapeGroup<dimensions>::setClean() {
/* Clean all objects */ /* Clean all objects */
if(!this->isEmpty()) { if(!this->isEmpty()) {
std::vector<SceneGraph::AbstractObject<dimensions>*> objects(this->size()); std::vector<SceneGraph::AbstractObject<dimensions>*> objects(this->size());
@ -33,7 +33,7 @@ template<std::uint8_t dimensions> void ObjectShapeGroup<dimensions>::setClean()
dirty = false; dirty = false;
} }
template<std::uint8_t dimensions> ObjectShape<dimensions>* ObjectShapeGroup<dimensions>::firstCollision(const ObjectShape<dimensions>* shape) { template<UnsignedInt dimensions> ObjectShape<dimensions>* ObjectShapeGroup<dimensions>::firstCollision(const ObjectShape<dimensions>* shape) {
/* Nothing to test with, done */ /* Nothing to test with, done */
if(!shape->shape()) return nullptr; if(!shape->shape()) return nullptr;

2
src/Physics/ObjectShapeGroup.h

@ -35,7 +35,7 @@ namespace Magnum { namespace Physics {
See ObjectShape for more information. See ObjectShape for more information.
@see @ref scenegraph, ObjectShapeGroup2D, ObjectShapeGroup3D @see @ref scenegraph, ObjectShapeGroup2D, ObjectShapeGroup3D
*/ */
template<std::uint8_t dimensions> class MAGNUM_PHYSICS_EXPORT ObjectShapeGroup: public SceneGraph::FeatureGroup<dimensions, ObjectShape<dimensions>> { template<UnsignedInt dimensions> class MAGNUM_PHYSICS_EXPORT ObjectShapeGroup: public SceneGraph::FeatureGroup<dimensions, ObjectShape<dimensions>> {
friend class ObjectShape<dimensions>; friend class ObjectShape<dimensions>;
public: public:

24
src/Physics/Physics.h

@ -19,55 +19,55 @@
* @brief Forward declarations for Magnum::Physics namespace * @brief Forward declarations for Magnum::Physics namespace
*/ */
#include <cstdint> #include "Types.h"
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
/** @todoc remove when doxygen is sane again */ /** @todoc remove when doxygen is sane again */
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
template<std::uint8_t> class AbstractShape; template<UnsignedInt> class AbstractShape;
typedef AbstractShape<2> AbstractShape2D; typedef AbstractShape<2> AbstractShape2D;
typedef AbstractShape<3> AbstractShape3D; typedef AbstractShape<3> AbstractShape3D;
template<std::uint8_t> class AxisAlignedBox; template<UnsignedInt> class AxisAlignedBox;
typedef AxisAlignedBox<2> AxisAlignedBox2D; typedef AxisAlignedBox<2> AxisAlignedBox2D;
typedef AxisAlignedBox<3> AxisAlignedBox3D; typedef AxisAlignedBox<3> AxisAlignedBox3D;
template<std::uint8_t> class Box; template<UnsignedInt> class Box;
typedef Box<2> Box2D; typedef Box<2> Box2D;
typedef Box<3> Box3D; typedef Box<3> Box3D;
template<std::uint8_t> class Capsule; template<UnsignedInt> class Capsule;
typedef Capsule<2> Capsule2D; typedef Capsule<2> Capsule2D;
typedef Capsule<3> Capsule3D; typedef Capsule<3> Capsule3D;
template<std::uint8_t> class Line; template<UnsignedInt> class Line;
typedef Line<2> Line2D; typedef Line<2> Line2D;
typedef Line<3> Line3D; typedef Line<3> Line3D;
template<std::uint8_t> class LineSegment; template<UnsignedInt> class LineSegment;
typedef LineSegment<2> LineSegment2D; typedef LineSegment<2> LineSegment2D;
typedef LineSegment<3> LineSegment3D; typedef LineSegment<3> LineSegment3D;
template<std::uint8_t> class ObjectShape; template<UnsignedInt> class ObjectShape;
typedef ObjectShape<2> ObjectShape2D; typedef ObjectShape<2> ObjectShape2D;
typedef ObjectShape<3> ObjectShape3D; typedef ObjectShape<3> ObjectShape3D;
template<std::uint8_t> class ObjectShapeGroup; template<UnsignedInt> class ObjectShapeGroup;
typedef ObjectShapeGroup<2> ObjectShapeGroup2D; typedef ObjectShapeGroup<2> ObjectShapeGroup2D;
typedef ObjectShapeGroup<3> ObjectShapeGroup3D; typedef ObjectShapeGroup<3> ObjectShapeGroup3D;
class Plane; class Plane;
template<std::uint8_t> class Point; template<UnsignedInt> class Point;
typedef Point<2> Point2D; typedef Point<2> Point2D;
typedef Point<3> Point3D; typedef Point<3> Point3D;
template<std::uint8_t> class ShapeGroup; template<UnsignedInt> class ShapeGroup;
typedef ShapeGroup<2> ShapeGroup2D; typedef ShapeGroup<2> ShapeGroup2D;
typedef ShapeGroup<3> ShapeGroup3D; typedef ShapeGroup<3> ShapeGroup3D;
template<std::uint8_t> class Sphere; template<UnsignedInt> class Sphere;
typedef Sphere<2> Sphere2D; typedef Sphere<2> Sphere2D;
typedef Sphere<3> Sphere3D; typedef Sphere<3> Sphere3D;
#endif #endif

6
src/Physics/Plane.cpp

@ -40,12 +40,12 @@ bool Plane::collides(const AbstractShape<3>* other) const {
} }
bool Plane::operator%(const Line3D& other) const { bool Plane::operator%(const Line3D& other) const {
float t = Intersection::planeLine(transformedPosition(), transformedNormal(), other.transformedA(), other.transformedB()); Float t = Intersection::planeLine(transformedPosition(), transformedNormal(), other.transformedA(), other.transformedB());
return t != t || (t != std::numeric_limits<float>::infinity() && t != -std::numeric_limits<float>::infinity()); return t != t || (t != std::numeric_limits<Float>::infinity() && t != -std::numeric_limits<Float>::infinity());
} }
bool Plane::operator%(const LineSegment3D& other) const { 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; return t > 0.0f && t < 1.0f;
} }

2
src/Physics/Point.cpp

@ -20,7 +20,7 @@
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
template<std::uint8_t dimensions> void Point<dimensions>::applyTransformationMatrix(const typename DimensionTraits<dimensions>::MatrixType& matrix) { template<UnsignedInt dimensions> void Point<dimensions>::applyTransformationMatrix(const typename DimensionTraits<dimensions>::MatrixType& matrix) {
_transformedPosition = matrix.transformPoint(_position); _transformedPosition = matrix.transformPoint(_position);
} }

2
src/Physics/Point.h

@ -31,7 +31,7 @@ namespace Magnum { namespace Physics {
@see Point2D, Point3D @see Point2D, Point3D
*/ */
template<std::uint8_t dimensions> class MAGNUM_PHYSICS_EXPORT Point: public AbstractShape<dimensions> { template<UnsignedInt dimensions> class MAGNUM_PHYSICS_EXPORT Point: public AbstractShape<dimensions> {
public: public:
/** @brief Constructor */ /** @brief Constructor */
inline explicit Point(const typename DimensionTraits<dimensions>::VectorType& position): _position(position), _transformedPosition(position) {} inline explicit Point(const typename DimensionTraits<dimensions>::VectorType& position): _position(position), _transformedPosition(position) {}

10
src/Physics/ShapeGroup.cpp

@ -17,18 +17,18 @@
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
template<std::uint8_t dimensions> ShapeGroup<dimensions>::ShapeGroup(ShapeGroup<dimensions>&& other): operation(other.operation), a(other.a), b(other.b) { template<UnsignedInt dimensions> ShapeGroup<dimensions>::ShapeGroup(ShapeGroup<dimensions>&& other): operation(other.operation), a(other.a), b(other.b) {
other.operation = Implementation::GroupOperation::AlwaysFalse; other.operation = Implementation::GroupOperation::AlwaysFalse;
other.a = nullptr; other.a = nullptr;
other.b = nullptr; other.b = nullptr;
} }
template<std::uint8_t dimensions> ShapeGroup<dimensions>::~ShapeGroup() { template<UnsignedInt dimensions> ShapeGroup<dimensions>::~ShapeGroup() {
if(!(operation & Implementation::GroupOperation::RefA)) delete a; if(!(operation & Implementation::GroupOperation::RefA)) delete a;
if(!(operation & Implementation::GroupOperation::RefB)) delete b; if(!(operation & Implementation::GroupOperation::RefB)) delete b;
} }
template<std::uint8_t dimensions> ShapeGroup<dimensions>& ShapeGroup<dimensions>::operator=(ShapeGroup<dimensions>&& other) { template<UnsignedInt dimensions> ShapeGroup<dimensions>& ShapeGroup<dimensions>::operator=(ShapeGroup<dimensions>&& other) {
if(!(operation & Implementation::GroupOperation::RefA)) delete a; if(!(operation & Implementation::GroupOperation::RefA)) delete a;
if(!(operation & Implementation::GroupOperation::RefB)) delete b; if(!(operation & Implementation::GroupOperation::RefB)) delete b;
@ -43,12 +43,12 @@ template<std::uint8_t dimensions> ShapeGroup<dimensions>& ShapeGroup<dimensions>
return *this; return *this;
} }
template<std::uint8_t dimensions> void ShapeGroup<dimensions>::applyTransformationMatrix(const typename DimensionTraits<dimensions>::MatrixType& matrix) { template<UnsignedInt dimensions> void ShapeGroup<dimensions>::applyTransformationMatrix(const typename DimensionTraits<dimensions>::MatrixType& matrix) {
if(a) a->applyTransformationMatrix(matrix); if(a) a->applyTransformationMatrix(matrix);
if(b) b->applyTransformationMatrix(matrix); if(b) b->applyTransformationMatrix(matrix);
} }
template<std::uint8_t dimensions> bool ShapeGroup<dimensions>::collides(const AbstractShape<dimensions>* other) const { template<UnsignedInt dimensions> bool ShapeGroup<dimensions>::collides(const AbstractShape<dimensions>* other) const {
switch(operation & ~Implementation::GroupOperation::RefAB) { switch(operation & ~Implementation::GroupOperation::RefAB) {
case Implementation::GroupOperation::And: return a->collides(other) && b->collides(other); case Implementation::GroupOperation::And: return a->collides(other) && b->collides(other);
case Implementation::GroupOperation::Or: return a->collides(other) || b->collides(other); case Implementation::GroupOperation::Or: return a->collides(other) || b->collides(other);

6
src/Physics/ShapeGroup.h

@ -58,7 +58,7 @@ Result of logical operations on shapes.
See @ref collision-detection for brief introduction. See @ref collision-detection for brief introduction.
@see ShapeGroup2D, ShapeGroup3D @see ShapeGroup2D, ShapeGroup3D
*/ */
template<std::uint8_t dimensions> class MAGNUM_PHYSICS_EXPORT ShapeGroup: public AbstractShape<dimensions> { template<UnsignedInt dimensions> class MAGNUM_PHYSICS_EXPORT ShapeGroup: public AbstractShape<dimensions> {
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
// template<class T> friend constexpr operator~(const T& a) -> enableIfIsBaseType; // template<class T> friend constexpr operator~(const T& a) -> enableIfIsBaseType;
// template<class T> friend constexpr operator~(T&& a) -> enableIfIsBaseType; // template<class T> 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. version, because collision with @p b is computed only if @p a collides.
See @ref collision-detection-shape-simplification for an example. See @ref collision-detection-shape-simplification for an example.
*/ */
template<std::uint8_t dimensions, class T, class U> inline constexpr ShapeGroup<dimensions> operator&&(T a, U b); template<UnsignedInt dimensions, class T, class U> inline constexpr ShapeGroup<dimensions> operator&&(T a, U b);
/** @relates ShapeGroup /** @relates ShapeGroup
@brief Logical OR of two shapes @brief Logical OR of two shapes
@ -195,7 +195,7 @@ template<std::uint8_t dimensions, class T, class U> inline constexpr ShapeGroup<
is used, so if collision with @p a is detected, collision with @p b is not is used, so if collision with @p a is detected, collision with @p b is not
computed. computed.
*/ */
template<std::uint8_t dimensions, class T, class U> inline constexpr ShapeGroup<dimensions> operator||(T a, U b); template<UnsignedInt dimensions, class T, class U> inline constexpr ShapeGroup<dimensions> operator||(T a, U b);
#else #else
#define op(type, char) \ #define op(type, char) \
template<class T, class U> inline constexpr auto operator char(const T& a, const U& b) -> enableIfAreBaseType { \ template<class T, class U> inline constexpr auto operator char(const T& a, const U& b) -> enableIfAreBaseType { \

16
src/Physics/Sphere.cpp

@ -27,7 +27,7 @@ using namespace Magnum::Math::Geometry;
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
namespace { namespace {
template<std::uint8_t dimensions> static typename DimensionTraits<dimensions>::VectorType unitVector(); template<UnsignedInt dimensions> static typename DimensionTraits<dimensions>::VectorType unitVector();
template<> inline Vector2 unitVector<2>() { template<> inline Vector2 unitVector<2>() {
return Vector2(1/Constants::sqrt2()); return Vector2(1/Constants::sqrt2());
@ -38,13 +38,13 @@ namespace {
} }
} }
template<std::uint8_t dimensions> void Sphere<dimensions>::applyTransformationMatrix(const typename DimensionTraits<dimensions>::MatrixType& matrix) { template<UnsignedInt dimensions> void Sphere<dimensions>::applyTransformationMatrix(const typename DimensionTraits<dimensions>::MatrixType& matrix) {
_transformedPosition = matrix.transformPoint(_position); _transformedPosition = matrix.transformPoint(_position);
float scaling = (matrix.rotationScaling()*unitVector<dimensions>()).length(); Float scaling = (matrix.rotationScaling()*unitVector<dimensions>()).length();
_transformedRadius = scaling*_radius; _transformedRadius = scaling*_radius;
} }
template<std::uint8_t dimensions> bool Sphere<dimensions>::collides(const AbstractShape<dimensions>* other) const { template<UnsignedInt dimensions> bool Sphere<dimensions>::collides(const AbstractShape<dimensions>* other) const {
if(other->type() == AbstractShape<dimensions>::Type::Point) if(other->type() == AbstractShape<dimensions>::Type::Point)
return *this % *static_cast<const Point<dimensions>*>(other); return *this % *static_cast<const Point<dimensions>*>(other);
if(other->type() == AbstractShape<dimensions>::Type::Line) if(other->type() == AbstractShape<dimensions>::Type::Line)
@ -57,22 +57,22 @@ template<std::uint8_t dimensions> bool Sphere<dimensions>::collides(const Abstra
return AbstractShape<dimensions>::collides(other); return AbstractShape<dimensions>::collides(other);
} }
template<std::uint8_t dimensions> bool Sphere<dimensions>::operator%(const Point<dimensions>& other) const { template<UnsignedInt dimensions> bool Sphere<dimensions>::operator%(const Point<dimensions>& other) const {
return (other.transformedPosition()-transformedPosition()).dot() < return (other.transformedPosition()-transformedPosition()).dot() <
Math::pow<2>(transformedRadius()); Math::pow<2>(transformedRadius());
} }
template<std::uint8_t dimensions> bool Sphere<dimensions>::operator%(const Line<dimensions>& other) const { template<UnsignedInt dimensions> bool Sphere<dimensions>::operator%(const Line<dimensions>& other) const {
return Distance::linePointSquared(other.transformedA(), other.transformedB(), transformedPosition()) < return Distance::linePointSquared(other.transformedA(), other.transformedB(), transformedPosition()) <
Math::pow<2>(transformedRadius()); Math::pow<2>(transformedRadius());
} }
template<std::uint8_t dimensions> bool Sphere<dimensions>::operator%(const LineSegment<dimensions>& other) const { template<UnsignedInt dimensions> bool Sphere<dimensions>::operator%(const LineSegment<dimensions>& other) const {
return Distance::lineSegmentPointSquared(other.transformedA(), other.transformedB(), transformedPosition()) < return Distance::lineSegmentPointSquared(other.transformedA(), other.transformedB(), transformedPosition()) <
Math::pow<2>(transformedRadius()); Math::pow<2>(transformedRadius());
} }
template<std::uint8_t dimensions> bool Sphere<dimensions>::operator%(const Sphere<dimensions>& other) const { template<UnsignedInt dimensions> bool Sphere<dimensions>::operator%(const Sphere<dimensions>& other) const {
return (other.transformedPosition()-transformedPosition()).dot() < return (other.transformedPosition()-transformedPosition()).dot() <
Math::pow<2>(transformedRadius()+other.transformedRadius()); Math::pow<2>(transformedRadius()+other.transformedRadius());
} }

18
src/Physics/Sphere.h

@ -35,10 +35,10 @@ applying transformation, the scale factor is averaged from all axes.
@see Sphere2D, Sphere3D @see Sphere2D, Sphere3D
@todo Assert for asymmetric scaling @todo Assert for asymmetric scaling
*/ */
template<std::uint8_t dimensions> class MAGNUM_PHYSICS_EXPORT Sphere: public AbstractShape<dimensions> { template<UnsignedInt dimensions> class MAGNUM_PHYSICS_EXPORT Sphere: public AbstractShape<dimensions> {
public: public:
/** @brief Constructor */ /** @brief Constructor */
inline explicit Sphere(const typename DimensionTraits<dimensions>::VectorType& position, float radius): _position(position), _transformedPosition(position), _radius(radius), _transformedRadius(radius) {} inline explicit Sphere(const typename DimensionTraits<dimensions>::VectorType& position, Float radius): _position(position), _transformedPosition(position), _radius(radius), _transformedRadius(radius) {}
inline typename AbstractShape<dimensions>::Type type() const override { inline typename AbstractShape<dimensions>::Type type() const override {
return AbstractShape<dimensions>::Type::Sphere; return AbstractShape<dimensions>::Type::Sphere;
@ -59,10 +59,10 @@ template<std::uint8_t dimensions> class MAGNUM_PHYSICS_EXPORT Sphere: public Abs
} }
/** @brief Radius */ /** @brief Radius */
inline float radius() const { return _radius; } inline Float radius() const { return _radius; }
/** @brief Set radius */ /** @brief Set radius */
inline void setRadius(float radius) { _radius = radius; } inline void setRadius(Float radius) { _radius = radius; }
/** @brief Transformed position */ /** @brief Transformed position */
inline typename DimensionTraits<dimensions>::VectorType transformedPosition() const { inline typename DimensionTraits<dimensions>::VectorType transformedPosition() const {
@ -70,7 +70,7 @@ template<std::uint8_t dimensions> class MAGNUM_PHYSICS_EXPORT Sphere: public Abs
} }
/** @brief Transformed radius */ /** @brief Transformed radius */
inline float transformedRadius() const { inline Float transformedRadius() const {
return _transformedRadius; return _transformedRadius;
} }
@ -89,7 +89,7 @@ template<std::uint8_t dimensions> class MAGNUM_PHYSICS_EXPORT Sphere: public Abs
private: private:
typename DimensionTraits<dimensions>::VectorType _position, typename DimensionTraits<dimensions>::VectorType _position,
_transformedPosition; _transformedPosition;
float _radius, _transformedRadius; Float _radius, _transformedRadius;
}; };
/** @brief Two-dimensional sphere */ /** @brief Two-dimensional sphere */
@ -99,13 +99,13 @@ typedef Sphere<2> Sphere2D;
typedef Sphere<3> Sphere3D; typedef Sphere<3> Sphere3D;
/** @collisionoperator{Point,Sphere} */ /** @collisionoperator{Point,Sphere} */
template<std::uint8_t 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; }
/** @collisionoperator{Line,Sphere} */ /** @collisionoperator{Line,Sphere} */
template<std::uint8_t dimensions> inline bool operator%(const Line<dimensions>& a, const Sphere<dimensions>& b) { return b % a; } template<UnsignedInt dimensions> inline bool operator%(const Line<dimensions>& a, const Sphere<dimensions>& b) { return b % a; }
/** @collisionoperator{LineSegment,Sphere} */ /** @collisionoperator{LineSegment,Sphere} */
template<std::uint8_t dimensions> inline bool operator%(const LineSegment<dimensions>& a, const Sphere<dimensions>& b) { return b % a; } template<UnsignedInt dimensions> inline bool operator%(const LineSegment<dimensions>& a, const Sphere<dimensions>& b) { return b % a; }
}} }}

Loading…
Cancel
Save