Browse Source

Using fixed-size 8bit integer for dimension count.

There can be only one, two or three dimensions, so why to use eight
times larger type than needed?
vectorfields
Vladimír Vondruš 14 years ago
parent
commit
1077370937
  1. 4
      src/AbstractTexture.h
  2. 2
      src/BufferedImage.cpp
  3. 4
      src/BufferedImage.h
  4. 4
      src/Framebuffer.h
  5. 2
      src/Image.cpp
  6. 4
      src/Image.h
  7. 4
      src/ImageWrapper.h
  8. 2
      src/Physics/AbstractShape.cpp
  9. 6
      src/Physics/AbstractShape.h
  10. 2
      src/Physics/AxisAlignedBox.cpp
  11. 2
      src/Physics/AxisAlignedBox.h
  12. 2
      src/Physics/Box.cpp
  13. 2
      src/Physics/Box.h
  14. 8
      src/Physics/Capsule.cpp
  15. 10
      src/Physics/Capsule.h
  16. 2
      src/Physics/Line.cpp
  17. 2
      src/Physics/Line.h
  18. 2
      src/Physics/LineSegment.h
  19. 4
      src/Physics/Plane.h
  20. 2
      src/Physics/Point.cpp
  21. 2
      src/Physics/Point.h
  22. 10
      src/Physics/ShapeGroup.cpp
  23. 6
      src/Physics/ShapeGroup.h
  24. 8
      src/Physics/ShapedObject.cpp
  25. 6
      src/Physics/ShapedObject.h
  26. 2
      src/Physics/ShapedObjectGroup.cpp
  27. 5
      src/Physics/ShapedObjectGroup.h
  28. 14
      src/Physics/Sphere.cpp
  29. 14
      src/Physics/Sphere.h
  30. 12
      src/SceneGraph/Camera.cpp
  31. 8
      src/SceneGraph/Camera.h
  32. 12
      src/SceneGraph/Object.cpp
  33. 14
      src/SceneGraph/Object.h
  34. 2
      src/SceneGraph/Scene.h
  35. 4
      src/Texture.h
  36. 4
      src/Trade/ImageData.h

4
src/AbstractTexture.h

@ -19,6 +19,8 @@
* @brief Class Magnum::AbstractTexture * @brief Class Magnum::AbstractTexture
*/ */
#include <cstdint>
#include "Magnum.h" #include "Magnum.h"
#include "Color.h" #include "Color.h"
@ -660,7 +662,7 @@ class MAGNUM_EXPORT AbstractTexture {
protected: protected:
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
template<size_t textureDimensions> struct DataHelper {}; template<std::uint8_t textureDimensions> struct DataHelper {};
#endif #endif
const GLenum _target; /**< @brief Target */ const GLenum _target; /**< @brief Target */

2
src/BufferedImage.cpp

@ -17,7 +17,7 @@
namespace Magnum { namespace Magnum {
template<size_t dimensions> void BufferedImage<dimensions>::setData(const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage) { template<std::uint8_t dimensions> void BufferedImage<dimensions>::setData(const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Components components, ComponentType type, const GLvoid* data, Buffer::Usage usage) {
_components = components; _components = components;
_type = type; _type = type;
_size = size; _size = size;

4
src/BufferedImage.h

@ -36,9 +36,9 @@ Trade::ImageData.
@see BufferedImage1D, BufferedImage2D, BufferedImage3D, Buffer @see BufferedImage1D, BufferedImage2D, BufferedImage3D, Buffer
@requires_gles30 (no extension providing this functionality) @requires_gles30 (no extension providing this functionality)
*/ */
template<size_t dimensions> class BufferedImage: public AbstractImage { template<std::uint8_t dimensions> class BufferedImage: public AbstractImage {
public: public:
const static size_t Dimensions = dimensions; /**< @brief Image dimension count */ const static std::uint8_t Dimensions = dimensions; /**< @brief %Image dimension count */
/** /**
* @brief Constructor * @brief Constructor

4
src/Framebuffer.h

@ -29,8 +29,8 @@
namespace Magnum { namespace Magnum {
template<size_t> class BufferedImage; template<std::uint8_t> class BufferedImage;
template<size_t> class Image; template<std::uint8_t> class Image;
typedef BufferedImage<1> BufferedImage1D; typedef BufferedImage<1> BufferedImage1D;
typedef BufferedImage<2> BufferedImage2D; typedef BufferedImage<2> BufferedImage2D;

2
src/Image.cpp

@ -17,7 +17,7 @@
namespace Magnum { namespace Magnum {
template<size_t dimensions> void Image<dimensions>::setData(const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Components components, ComponentType type, GLvoid* data) { template<std::uint8_t dimensions> void Image<dimensions>::setData(const typename DimensionTraits<Dimensions, GLsizei>::VectorType& size, Components components, ComponentType type, GLvoid* data) {
delete[] _data; delete[] _data;
_components = components; _components = components;
_type = type; _type = type;

4
src/Image.h

@ -34,9 +34,9 @@ ImageWrapper, BufferedImage, which stores image data in GPU memory, or for
example with Trade::ImageData. example with Trade::ImageData.
@see Image1D, Image2D, Image3D @see Image1D, Image2D, Image3D
*/ */
template<size_t dimensions> class Image: public AbstractImage { template<std::uint8_t dimensions> class Image: public AbstractImage {
public: public:
const static size_t Dimensions = dimensions; /**< @brief Image dimension count */ const static std::uint8_t Dimensions = dimensions; /**< @brief %Image dimension count */
/** /**
* @brief Constructor * @brief Constructor

4
src/ImageWrapper.h

@ -40,9 +40,9 @@ to change image properties, only data pointer.
See also Image, BufferedImage and Trade::ImageData. See also Image, BufferedImage and Trade::ImageData.
*/ */
template<size_t dimensions> class ImageWrapper: public AbstractImage { template<std::uint8_t dimensions> class ImageWrapper: public AbstractImage {
public: public:
const static size_t Dimensions = dimensions; /**< @brief Image dimension count */ const static std::uint8_t Dimensions = dimensions; /**< @brief %Image dimension count */
/** /**
* @brief Constructor * @brief Constructor

2
src/Physics/AbstractShape.cpp

@ -17,7 +17,7 @@
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
template<size_t dimensions> bool AbstractShape<dimensions>::collides(const AbstractShape* other) const { template<std::uint8_t 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);

6
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<size_t dimensions> struct ShapeDimensionTraits {}; template<std::uint8_t dimensions> struct ShapeDimensionTraits {};
template<> struct ShapeDimensionTraits<2> { template<> struct ShapeDimensionTraits<2> {
enum class Type { enum class Type {
@ -65,10 +65,10 @@ namespace Implementation {
See @ref collision-detection for brief introduction. See @ref collision-detection for brief introduction.
@see AbstractShape2D, AbstractShape3D @see AbstractShape2D, AbstractShape3D
*/ */
template<size_t dimensions> class PHYSICS_EXPORT AbstractShape { template<std::uint8_t dimensions> class PHYSICS_EXPORT AbstractShape {
public: public:
/** @brief Dimension count */ /** @brief Dimension count */
static const size_t Dimensions = dimensions; static const std::uint8_t Dimensions = dimensions;
/** /**
* @brief Shape type * @brief Shape type

2
src/Physics/AxisAlignedBox.cpp

@ -20,7 +20,7 @@
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
template<size_t dimensions> void AxisAlignedBox<dimensions>::applyTransformation(const typename DimensionTraits<dimensions, GLfloat>::MatrixType& transformation) { template<std::uint8_t dimensions> void AxisAlignedBox<dimensions>::applyTransformation(const typename DimensionTraits<dimensions, GLfloat>::MatrixType& transformation) {
_transformedPosition = (transformation*typename DimensionTraits<dimensions, GLfloat>::PointType(_position)).vector(); _transformedPosition = (transformation*typename DimensionTraits<dimensions, GLfloat>::PointType(_position)).vector();
_transformedSize = transformation.rotationScaling()*_size; _transformedSize = transformation.rotationScaling()*_size;
} }

2
src/Physics/AxisAlignedBox.h

@ -29,7 +29,7 @@ namespace Magnum { namespace Physics {
@see AxisAlignedBox2D, AxisAlignedBox3D @see AxisAlignedBox2D, AxisAlignedBox3D
*/ */
template<size_t dimensions> class PHYSICS_EXPORT AxisAlignedBox: public AbstractShape<dimensions> { template<std::uint8_t dimensions> class PHYSICS_EXPORT AxisAlignedBox: public AbstractShape<dimensions> {
public: public:
/** @brief Constructor */ /** @brief Constructor */
inline AxisAlignedBox(const typename DimensionTraits<dimensions, GLfloat>::VectorType& position, const typename DimensionTraits<dimensions, GLfloat>::VectorType& size): _position(position), _transformedPosition(position), _size(size), _transformedSize(size) {} inline AxisAlignedBox(const typename DimensionTraits<dimensions, GLfloat>::VectorType& position, const typename DimensionTraits<dimensions, GLfloat>::VectorType& size): _position(position), _transformedPosition(position), _size(size), _transformedSize(size) {}

2
src/Physics/Box.cpp

@ -20,7 +20,7 @@
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
template<size_t dimensions> void Box<dimensions>::applyTransformation(const typename DimensionTraits<dimensions, GLfloat>::MatrixType& transformation) { template<std::uint8_t dimensions> void Box<dimensions>::applyTransformation(const typename DimensionTraits<dimensions, GLfloat>::MatrixType& transformation) {
_transformedTransformation = (transformation*_transformation); _transformedTransformation = (transformation*_transformation);
} }

2
src/Physics/Box.h

@ -30,7 +30,7 @@ namespace Magnum { namespace Physics {
@see Box2D, Box3D @see Box2D, Box3D
*/ */
template<size_t dimensions> class PHYSICS_EXPORT Box: public AbstractShape<dimensions> { template<std::uint8_t dimensions> class PHYSICS_EXPORT Box: public AbstractShape<dimensions> {
public: public:
/** @brief Constructor */ /** @brief Constructor */
inline Box(const typename DimensionTraits<dimensions, GLfloat>::MatrixType& transformation): _transformation(transformation), _transformedTransformation(transformation) {} inline Box(const typename DimensionTraits<dimensions, GLfloat>::MatrixType& transformation): _transformation(transformation), _transformedTransformation(transformation) {}

8
src/Physics/Capsule.cpp

@ -27,14 +27,14 @@ using namespace Magnum::Math::Geometry;
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
template<size_t dimensions> void Capsule<dimensions>::applyTransformation(const typename DimensionTraits<dimensions, GLfloat>::MatrixType& transformation) { template<std::uint8_t dimensions> void Capsule<dimensions>::applyTransformation(const typename DimensionTraits<dimensions, GLfloat>::MatrixType& transformation) {
_transformedA = (transformation*typename DimensionTraits<dimensions, GLfloat>::PointType(_a)).vector(); _transformedA = (transformation*typename DimensionTraits<dimensions, GLfloat>::PointType(_a)).vector();
_transformedB = (transformation*typename DimensionTraits<dimensions, GLfloat>::PointType(_b)).vector(); _transformedB = (transformation*typename DimensionTraits<dimensions, GLfloat>::PointType(_b)).vector();
float scaling = (transformation.rotationScaling()*typename DimensionTraits<dimensions, GLfloat>::VectorType(1/Math::Constants<float>::sqrt3())).length(); float scaling = (transformation.rotationScaling()*typename DimensionTraits<dimensions, GLfloat>::VectorType(1/Math::Constants<float>::sqrt3())).length();
_transformedRadius = scaling*_radius; _transformedRadius = scaling*_radius;
} }
template<size_t dimensions> bool Capsule<dimensions>::collides(const AbstractShape<dimensions>* other) const { template<std::uint8_t 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)
@ -43,12 +43,12 @@ template<size_t dimensions> bool Capsule<dimensions>::collides(const AbstractSha
return AbstractShape<dimensions>::collides(other); return AbstractShape<dimensions>::collides(other);
} }
template<size_t dimensions> bool Capsule<dimensions>::operator%(const Point<dimensions>& other) const { template<std::uint8_t 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<size_t dimensions> bool Capsule<dimensions>::operator%(const Sphere<dimensions>& other) const { template<std::uint8_t 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());
} }

10
src/Physics/Capsule.h

@ -24,8 +24,8 @@
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
template<size_t> class Point; template<std::uint8_t> class Point;
template<size_t> class Sphere; template<std::uint8_t> class Sphere;
/** /**
@brief %Capsule defined by cylinder start and end point and radius @brief %Capsule defined by cylinder start and end point and radius
@ -34,7 +34,7 @@ Unlike other elements the capsule doesn't support asymmetric scaling. When
applying transformation, the scale factor is averaged from all axes. applying transformation, the scale factor is averaged from all axes.
@see Capsule2D, Capsule3D @see Capsule2D, Capsule3D
*/ */
template<size_t dimensions> class PHYSICS_EXPORT Capsule: public AbstractShape<dimensions> { template<std::uint8_t dimensions> class PHYSICS_EXPORT Capsule: public AbstractShape<dimensions> {
public: public:
/** @brief Constructor */ /** @brief Constructor */
inline Capsule(const typename DimensionTraits<dimensions, GLfloat>::VectorType& a, const typename DimensionTraits<dimensions, GLfloat>::VectorType& b, float radius): _a(a), _transformedA(a), _b(b), _transformedB(b), _radius(radius), _transformedRadius(radius) {} inline Capsule(const typename DimensionTraits<dimensions, GLfloat>::VectorType& a, const typename DimensionTraits<dimensions, GLfloat>::VectorType& b, float radius): _a(a), _transformedA(a), _b(b), _transformedB(b), _radius(radius), _transformedRadius(radius) {}
@ -113,10 +113,10 @@ typedef Capsule<2> Capsule2D;
typedef Capsule<3> Capsule3D; typedef Capsule<3> Capsule3D;
/** @collisionoperator{Point,Capsule} */ /** @collisionoperator{Point,Capsule} */
template<size_t dimensions> inline bool operator%(const Point<dimensions>& a, const Capsule<dimensions>& b) { return b % a; } template<std::uint8_t dimensions> inline bool operator%(const Point<dimensions>& a, const Capsule<dimensions>& b) { return b % a; }
/** @collisionoperator{Sphere,Capsule} */ /** @collisionoperator{Sphere,Capsule} */
template<size_t dimensions> inline bool operator%(const Sphere<dimensions>& a, const Capsule<dimensions>& b) { return b % a; } template<std::uint8_t 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<size_t dimensions> void Line<dimensions>::applyTransformation(const typename DimensionTraits<dimensions, GLfloat>::MatrixType& transformation) { template<std::uint8_t dimensions> void Line<dimensions>::applyTransformation(const typename DimensionTraits<dimensions, GLfloat>::MatrixType& transformation) {
_transformedA = (transformation*typename DimensionTraits<dimensions, GLfloat>::PointType(_a)).vector(); _transformedA = (transformation*typename DimensionTraits<dimensions, GLfloat>::PointType(_a)).vector();
_transformedB = (transformation*typename DimensionTraits<dimensions, GLfloat>::PointType(_b)).vector(); _transformedB = (transformation*typename DimensionTraits<dimensions, GLfloat>::PointType(_b)).vector();
} }

2
src/Physics/Line.h

@ -30,7 +30,7 @@ namespace Magnum { namespace Physics {
@see Line2D, Line3D @see Line2D, Line3D
@todo collision detection of two Line2D @todo collision detection of two Line2D
*/ */
template<size_t dimensions> class PHYSICS_EXPORT Line: public AbstractShape<dimensions> { template<std::uint8_t dimensions> class PHYSICS_EXPORT Line: public AbstractShape<dimensions> {
public: public:
/** @brief Constructor */ /** @brief Constructor */
inline Line(const typename DimensionTraits<dimensions, GLfloat>::VectorType& a, const typename DimensionTraits<dimensions, GLfloat>::VectorType& b): _a(a), _transformedA(a), _b(b), _transformedB(b) {} inline Line(const typename DimensionTraits<dimensions, GLfloat>::VectorType& a, const typename DimensionTraits<dimensions, GLfloat>::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<size_t dimensions> class LineSegment: public Line<dimensions> { template<std::uint8_t dimensions> class LineSegment: public Line<dimensions> {
public: public:
/** @brief Constructor */ /** @brief Constructor */
inline LineSegment(const typename DimensionTraits<dimensions, GLfloat>::VectorType& a, const typename DimensionTraits<dimensions, GLfloat>::VectorType& b): Line<dimensions>(a, b) {} inline LineSegment(const typename DimensionTraits<dimensions, GLfloat>::VectorType& a, const typename DimensionTraits<dimensions, GLfloat>::VectorType& b): Line<dimensions>(a, b) {}

4
src/Physics/Plane.h

@ -24,9 +24,9 @@
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
template<size_t> class Line; template<std::uint8_t> class Line;
typedef Line<3> Line3D; typedef Line<3> Line3D;
template<size_t> class LineSegment; template<std::uint8_t> class LineSegment;
typedef LineSegment<3> LineSegment3D; typedef LineSegment<3> LineSegment3D;
/** @brief Infinite plane, defined by position and normal (3D only) */ /** @brief Infinite plane, defined by position and normal (3D only) */

2
src/Physics/Point.cpp

@ -20,7 +20,7 @@
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
template<size_t dimensions> void Point<dimensions>::applyTransformation(const typename DimensionTraits<dimensions, GLfloat>::MatrixType& transformation) { template<std::uint8_t dimensions> void Point<dimensions>::applyTransformation(const typename DimensionTraits<dimensions, GLfloat>::MatrixType& transformation) {
_transformedPosition = (transformation*typename DimensionTraits<dimensions, GLfloat>::PointType(_position)).vector(); _transformedPosition = (transformation*typename DimensionTraits<dimensions, GLfloat>::PointType(_position)).vector();
} }

2
src/Physics/Point.h

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

10
src/Physics/ShapeGroup.cpp

@ -17,18 +17,18 @@
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
template<size_t dimensions> ShapeGroup<dimensions>::ShapeGroup(ShapeGroup<dimensions>&& other): operation(other.operation), a(other.a), b(other.b) { template<std::uint8_t 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<size_t dimensions> ShapeGroup<dimensions>::~ShapeGroup() { template<std::uint8_t 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<size_t dimensions> ShapeGroup<dimensions>& ShapeGroup<dimensions>::operator=(ShapeGroup<dimensions>&& other) { template<std::uint8_t 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<size_t dimensions> ShapeGroup<dimensions>& ShapeGroup<dimensions>::oper
return *this; return *this;
} }
template<size_t dimensions> void ShapeGroup<dimensions>::applyTransformation(const typename DimensionTraits<dimensions, GLfloat>::MatrixType& transformation) { template<std::uint8_t dimensions> void ShapeGroup<dimensions>::applyTransformation(const typename DimensionTraits<dimensions, GLfloat>::MatrixType& transformation) {
if(a) a->applyTransformation(transformation); if(a) a->applyTransformation(transformation);
if(b) b->applyTransformation(transformation); if(b) b->applyTransformation(transformation);
} }
template<size_t dimensions> bool ShapeGroup<dimensions>::collides(const AbstractShape<dimensions>* other) const { template<std::uint8_t 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

@ -55,7 +55,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<size_t dimensions> class PHYSICS_EXPORT ShapeGroup: public AbstractShape<dimensions> { template<std::uint8_t dimensions> class 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;
@ -173,7 +173,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<size_t dimensions, class T, class U> inline constexpr ShapeGroup<dimensions> operator&&(T a, U b); template<std::uint8_t 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
@ -182,7 +182,7 @@ template<size_t dimensions, class T, class U> inline constexpr ShapeGroup<dimens
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<size_t dimensions, class T, class U> inline constexpr ShapeGroup<dimensions> operator||(T a, U b); template<std::uint8_t 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 { \

8
src/Physics/ShapedObject.cpp

@ -27,22 +27,22 @@ using namespace std;
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
template<size_t dimensions> ShapedObject<dimensions>::ShapedObject(ShapedObjectGroup<dimensions>* group, typename SceneGraph::AbstractObject<dimensions>::ObjectType* parent): SceneGraph::AbstractObject<dimensions>::ObjectType(parent), group(group), _shape(nullptr) { template<uint8_t dimensions> ShapedObject<dimensions>::ShapedObject(ShapedObjectGroup<dimensions>* group, typename SceneGraph::AbstractObject<dimensions>::ObjectType* parent): SceneGraph::AbstractObject<dimensions>::ObjectType(parent), group(group), _shape(nullptr) {
group->objects.push_back(this); group->objects.push_back(this);
} }
template<size_t dimensions> ShapedObject<dimensions>::~ShapedObject() { template<uint8_t dimensions> ShapedObject<dimensions>::~ShapedObject() {
group->objects.erase(find(group->objects.begin(), group->objects.end(), this)); group->objects.erase(find(group->objects.begin(), group->objects.end(), this));
delete _shape; delete _shape;
} }
template<size_t dimensions> void ShapedObject<dimensions>::setDirty() { template<uint8_t dimensions> void ShapedObject<dimensions>::setDirty() {
SceneGraph::AbstractObject<dimensions>::ObjectType::setDirty(); SceneGraph::AbstractObject<dimensions>::ObjectType::setDirty();
group->setDirty(); group->setDirty();
} }
template<size_t dimensions> void ShapedObject<dimensions>::clean(const typename DimensionTraits<dimensions, GLfloat>::MatrixType& absoluteTransformation) { template<uint8_t dimensions> void ShapedObject<dimensions>::clean(const typename DimensionTraits<dimensions, GLfloat>::MatrixType& absoluteTransformation) {
SceneGraph::AbstractObject<dimensions>::ObjectType::clean(absoluteTransformation); SceneGraph::AbstractObject<dimensions>::ObjectType::clean(absoluteTransformation);
if(_shape) _shape->applyTransformation(absoluteTransformation); if(_shape) _shape->applyTransformation(absoluteTransformation);

6
src/Physics/ShapedObject.h

@ -25,15 +25,15 @@
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
template<size_t> class ShapedObjectGroup; template<std::uint8_t> class ShapedObjectGroup;
template<size_t> class AbstractShape; template<std::uint8_t> class AbstractShape;
/** /**
@brief Object with assigned shape @brief Object with assigned shape
@see ShapedObject2D, ShapedObject3D @see ShapedObject2D, ShapedObject3D
*/ */
template<size_t dimensions> class PHYSICS_EXPORT ShapedObject: public SceneGraph::AbstractObject<dimensions>::ObjectType { template<std::uint8_t dimensions> class PHYSICS_EXPORT ShapedObject: public SceneGraph::AbstractObject<dimensions>::ObjectType {
public: public:
/** /**
* @brief Constructor * @brief Constructor

2
src/Physics/ShapedObjectGroup.cpp

@ -19,7 +19,7 @@
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
template<size_t dimensions> void ShapedObjectGroup<dimensions>::setClean() { template<std::uint8_t dimensions> void ShapedObjectGroup<dimensions>::setClean() {
for(ShapedObject<dimensions>* object: objects) for(ShapedObject<dimensions>* object: objects)
if(object->isDirty()) object->setClean(); if(object->isDirty()) object->setClean();

5
src/Physics/ShapedObjectGroup.h

@ -20,6 +20,7 @@
*/ */
#include <cstddef> #include <cstddef>
#include <cstdint>
#include <vector> #include <vector>
#include "magnumPhysicsVisibility.h" #include "magnumPhysicsVisibility.h"
@ -31,7 +32,7 @@ template<class T, class U> class Resource;
namespace Physics { namespace Physics {
template<size_t> class ShapedObject; template<std::uint8_t> class ShapedObject;
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
namespace Implementation { namespace Implementation {
@ -51,7 +52,7 @@ specifying it in the constructor. When the group is deleted, all objects
belogning to it are deleted too. belogning to it are deleted too.
@see ShapedObjectGroup2D, ShapedObjectGroup3D @see ShapedObjectGroup2D, ShapedObjectGroup3D
*/ */
template<size_t dimensions> class PHYSICS_EXPORT ShapedObjectGroup { template<std::uint8_t dimensions> class PHYSICS_EXPORT ShapedObjectGroup {
friend class ShapedObject<dimensions>; friend class ShapedObject<dimensions>;
public: public:

14
src/Physics/Sphere.cpp

@ -28,7 +28,7 @@ using namespace Magnum::Math::Geometry;
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
namespace { namespace {
template<size_t dimensions> static typename DimensionTraits<dimensions, GLfloat>::VectorType unitVector(); template<std::uint8_t dimensions> static typename DimensionTraits<dimensions, GLfloat>::VectorType unitVector();
template<> inline Vector2 unitVector<2>() { template<> inline Vector2 unitVector<2>() {
return Vector2(1/Math::Constants<float>::sqrt2()); return Vector2(1/Math::Constants<float>::sqrt2());
@ -39,13 +39,13 @@ namespace {
} }
} }
template<size_t dimensions> void Sphere<dimensions>::applyTransformation(const typename DimensionTraits<dimensions, GLfloat>::MatrixType& transformation) { template<std::uint8_t dimensions> void Sphere<dimensions>::applyTransformation(const typename DimensionTraits<dimensions, GLfloat>::MatrixType& transformation) {
_transformedPosition = (transformation*typename DimensionTraits<dimensions, GLfloat>::PointType(_position)).vector(); _transformedPosition = (transformation*typename DimensionTraits<dimensions, GLfloat>::PointType(_position)).vector();
float scaling = (transformation.rotationScaling()*unitVector<dimensions>()).length(); float scaling = (transformation.rotationScaling()*unitVector<dimensions>()).length();
_transformedRadius = scaling*_radius; _transformedRadius = scaling*_radius;
} }
template<size_t dimensions> bool Sphere<dimensions>::collides(const AbstractShape<dimensions>* other) const { template<std::uint8_t 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)
@ -58,22 +58,22 @@ template<size_t dimensions> bool Sphere<dimensions>::collides(const AbstractShap
return AbstractShape<dimensions>::collides(other); return AbstractShape<dimensions>::collides(other);
} }
template<size_t dimensions> bool Sphere<dimensions>::operator%(const Point<dimensions>& other) const { template<std::uint8_t 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<size_t dimensions> bool Sphere<dimensions>::operator%(const Line<dimensions>& other) const { template<std::uint8_t 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<size_t dimensions> bool Sphere<dimensions>::operator%(const LineSegment<dimensions>& other) const { template<std::uint8_t 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<size_t dimensions> bool Sphere<dimensions>::operator%(const Sphere<dimensions>& other) const { template<std::uint8_t 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());
} }

14
src/Physics/Sphere.h

@ -24,9 +24,9 @@
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
template<size_t> class Line; template<std::uint8_t> class Line;
template<size_t> class LineSegment; template<std::uint8_t> class LineSegment;
template<size_t> class Point; template<std::uint8_t> class Point;
/** /**
@brief %Sphere defined by position and radius @brief %Sphere defined by position and radius
@ -35,7 +35,7 @@ Unlike other elements the sphere doesn't support asymmetric scaling. When
applying transformation, the scale factor is averaged from all axes. applying transformation, the scale factor is averaged from all axes.
@see Sphere2D, Sphere3D @see Sphere2D, Sphere3D
*/ */
template<size_t dimensions> class PHYSICS_EXPORT Sphere: public AbstractShape<dimensions> { template<std::uint8_t dimensions> class PHYSICS_EXPORT Sphere: public AbstractShape<dimensions> {
public: public:
/** @brief Constructor */ /** @brief Constructor */
inline Sphere(const typename DimensionTraits<dimensions, GLfloat>::VectorType& position, float radius): _position(position), _transformedPosition(position), _radius(radius), _transformedRadius(radius) {} inline Sphere(const typename DimensionTraits<dimensions, GLfloat>::VectorType& position, float radius): _position(position), _transformedPosition(position), _radius(radius), _transformedRadius(radius) {}
@ -105,13 +105,13 @@ typedef Sphere<2> Sphere2D;
typedef Sphere<3> Sphere3D; typedef Sphere<3> Sphere3D;
/** @collisionoperator{Point,Sphere} */ /** @collisionoperator{Point,Sphere} */
template<size_t dimensions> inline bool operator%(const Point<dimensions>& a, const Sphere<dimensions>& b) { return b % a; } template<std::uint8_t dimensions> inline bool operator%(const Point<dimensions>& a, const Sphere<dimensions>& b) { return b % a; }
/** @collisionoperator{Line,Sphere} */ /** @collisionoperator{Line,Sphere} */
template<size_t dimensions> inline bool operator%(const Line<dimensions>& a, const Sphere<dimensions>& b) { return b % a; } template<std::uint8_t dimensions> inline bool operator%(const Line<dimensions>& a, const Sphere<dimensions>& b) { return b % a; }
/** @collisionoperator{LineSegment,Sphere} */ /** @collisionoperator{LineSegment,Sphere} */
template<size_t dimensions> inline bool operator%(const LineSegment<dimensions>& a, const Sphere<dimensions>& b) { return b % a; } template<std::uint8_t dimensions> inline bool operator%(const LineSegment<dimensions>& a, const Sphere<dimensions>& b) { return b % a; }
}} }}

12
src/SceneGraph/Camera.cpp

@ -45,26 +45,26 @@ template Matrix4 aspectRatioFix<Matrix4>(AspectRatioPolicy, const Vector2&, cons
} }
#endif #endif
template<size_t dimensions> AbstractCamera<dimensions>::AbstractCamera(typename AbstractObject<dimensions>::ObjectType* parent): AbstractObject<dimensions>::ObjectType(parent), _aspectRatioPolicy(AspectRatioPolicy::NotPreserved) {} template<std::uint8_t dimensions> AbstractCamera<dimensions>::AbstractCamera(typename AbstractObject<dimensions>::ObjectType* parent): AbstractObject<dimensions>::ObjectType(parent), _aspectRatioPolicy(AspectRatioPolicy::NotPreserved) {}
template<size_t dimensions> typename AbstractObject<dimensions>::CameraType* AbstractCamera<dimensions>::setAspectRatioPolicy(AspectRatioPolicy policy) { template<std::uint8_t dimensions> typename AbstractObject<dimensions>::CameraType* AbstractCamera<dimensions>::setAspectRatioPolicy(AspectRatioPolicy policy) {
_aspectRatioPolicy = policy; _aspectRatioPolicy = policy;
fixAspectRatio(); fixAspectRatio();
return static_cast<typename AbstractObject<dimensions>::CameraType*>(this); return static_cast<typename AbstractObject<dimensions>::CameraType*>(this);
} }
template<size_t dimensions> void AbstractCamera<dimensions>::setViewport(const Math::Vector2<GLsizei>& size) { template<std::uint8_t dimensions> void AbstractCamera<dimensions>::setViewport(const Math::Vector2<GLsizei>& size) {
_viewport = size; _viewport = size;
fixAspectRatio(); fixAspectRatio();
} }
template<size_t dimensions> void AbstractCamera<dimensions>::clean(const typename DimensionTraits<dimensions, GLfloat>::MatrixType& absoluteTransformation) { template<std::uint8_t dimensions> void AbstractCamera<dimensions>::clean(const typename DimensionTraits<dimensions, GLfloat>::MatrixType& absoluteTransformation) {
AbstractObject<dimensions>::ObjectType::clean(absoluteTransformation); AbstractObject<dimensions>::ObjectType::clean(absoluteTransformation);
_cameraMatrix = absoluteTransformation.inverted(); _cameraMatrix = absoluteTransformation.inverted();
} }
template<size_t dimensions> void AbstractCamera<dimensions>::draw() { template<std::uint8_t dimensions> void AbstractCamera<dimensions>::draw() {
typename AbstractObject<dimensions>::SceneType* s = this->scene(); typename AbstractObject<dimensions>::SceneType* s = this->scene();
CORRADE_ASSERT(s, "Camera: cannot draw without camera attached to scene", ); CORRADE_ASSERT(s, "Camera: cannot draw without camera attached to scene", );
@ -72,7 +72,7 @@ template<size_t dimensions> void AbstractCamera<dimensions>::draw() {
drawChildren(s, cameraMatrix()); drawChildren(s, cameraMatrix());
} }
template<size_t dimensions> void AbstractCamera<dimensions>::drawChildren(typename AbstractObject<dimensions>::ObjectType* object, const typename DimensionTraits<dimensions, GLfloat>::MatrixType& transformationMatrix) { template<std::uint8_t dimensions> void AbstractCamera<dimensions>::drawChildren(typename AbstractObject<dimensions>::ObjectType* object, const typename DimensionTraits<dimensions, GLfloat>::MatrixType& transformationMatrix) {
for(typename AbstractObject<dimensions>::ObjectType* i = object->firstChild(); i; i = i->nextSibling()) { for(typename AbstractObject<dimensions>::ObjectType* i = object->firstChild(); i; i = i->nextSibling()) {
/* Transformation matrix for the object */ /* Transformation matrix for the object */
typename DimensionTraits<dimensions, GLfloat>::MatrixType matrix = transformationMatrix*i->transformation(); typename DimensionTraits<dimensions, GLfloat>::MatrixType matrix = transformationMatrix*i->transformation();

8
src/SceneGraph/Camera.h

@ -36,8 +36,6 @@ namespace Implementation {
NotPreserved, Extend, Clip NotPreserved, Extend, Clip
}; };
template<size_t dimensions> class Camera {};
template<class MatrixType> MatrixType aspectRatioFix(AspectRatioPolicy aspectRatioPolicy, const Vector2& projectionScale, const Math::Vector2<GLsizei>& viewport); template<class MatrixType> MatrixType aspectRatioFix(AspectRatioPolicy aspectRatioPolicy, const Vector2& projectionScale, const Math::Vector2<GLsizei>& viewport);
/* These templates are instantiated in source file */ /* These templates are instantiated in source file */
@ -49,7 +47,7 @@ namespace Implementation {
/** /**
@brief %Camera object @brief %Camera object
*/ */
template<size_t dimensions> class SCENEGRAPH_EXPORT AbstractCamera: public AbstractObject<dimensions>::ObjectType { template<std::uint8_t dimensions> class SCENEGRAPH_EXPORT AbstractCamera: public AbstractObject<dimensions>::ObjectType {
public: public:
/** /**
* @brief Aspect ratio policy * @brief Aspect ratio policy
@ -160,7 +158,7 @@ template<size_t dimensions> class SCENEGRAPH_EXPORT AbstractCamera: public Abstr
Math::Vector2<GLsizei> _viewport; Math::Vector2<GLsizei> _viewport;
}; };
template<size_t dimensions> inline AbstractCamera<dimensions>::~AbstractCamera() {} template<std::uint8_t dimensions> inline AbstractCamera<dimensions>::~AbstractCamera() {}
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
/* These templates are instantiated in source file */ /* These templates are instantiated in source file */
@ -168,6 +166,8 @@ extern template class SCENEGRAPH_EXPORT AbstractCamera<2>;
extern template class SCENEGRAPH_EXPORT AbstractCamera<3>; extern template class SCENEGRAPH_EXPORT AbstractCamera<3>;
namespace Implementation { namespace Implementation {
template<std::uint8_t dimensions> class Camera {};
template<> class Camera<2> { template<> class Camera<2> {
public: public:
inline constexpr static Matrix3 aspectRatioScale(const Vector2& scale) { inline constexpr static Matrix3 aspectRatioScale(const Vector2& scale) {

12
src/SceneGraph/Object.cpp

@ -25,7 +25,7 @@ using namespace Magnum::Math;
namespace Magnum { namespace SceneGraph { namespace Magnum { namespace SceneGraph {
template<size_t dimensions> typename AbstractObject<dimensions>::ObjectType* AbstractObject<dimensions>::setParent(ObjectType* parent) { template<std::uint8_t dimensions> typename AbstractObject<dimensions>::ObjectType* AbstractObject<dimensions>::setParent(ObjectType* parent) {
/* Skip if nothing to do or this is scene */ /* Skip if nothing to do or this is scene */
if(this->parent() == parent || isScene()) return static_cast<ObjectType*>(this); if(this->parent() == parent || isScene()) return static_cast<ObjectType*>(this);
@ -49,7 +49,7 @@ template<size_t dimensions> typename AbstractObject<dimensions>::ObjectType* Abs
return static_cast<ObjectType*>(this); return static_cast<ObjectType*>(this);
} }
template<size_t dimensions> typename DimensionTraits<dimensions, GLfloat>::MatrixType AbstractObject<dimensions>::absoluteTransformation(CameraType* camera) { template<std::uint8_t dimensions> typename DimensionTraits<dimensions, GLfloat>::MatrixType AbstractObject<dimensions>::absoluteTransformation(CameraType* camera) {
/* Shortcut for absolute transformation of camera relative to itself */ /* Shortcut for absolute transformation of camera relative to itself */
if(camera == this) return typename DimensionTraits<dimensions, GLfloat>::MatrixType(); if(camera == this) return typename DimensionTraits<dimensions, GLfloat>::MatrixType();
@ -77,7 +77,7 @@ template<size_t dimensions> typename DimensionTraits<dimensions, GLfloat>::Matri
return t; return t;
} }
template<size_t dimensions> typename AbstractObject<dimensions>::SceneType* AbstractObject<dimensions>::scene() { template<std::uint8_t dimensions> typename AbstractObject<dimensions>::SceneType* AbstractObject<dimensions>::scene() {
/* Goes up the family tree until it finds object which is parent of itself /* Goes up the family tree until it finds object which is parent of itself
(that's the scene) */ (that's the scene) */
ObjectType* p = parent(); ObjectType* p = parent();
@ -89,7 +89,7 @@ template<size_t dimensions> typename AbstractObject<dimensions>::SceneType* Abst
return nullptr; return nullptr;
} }
template<size_t dimensions> typename AbstractObject<dimensions>::ObjectType* AbstractObject<dimensions>::setTransformation(const typename DimensionTraits<dimensions, GLfloat>::MatrixType& transformation) { template<std::uint8_t dimensions> typename AbstractObject<dimensions>::ObjectType* AbstractObject<dimensions>::setTransformation(const typename DimensionTraits<dimensions, GLfloat>::MatrixType& transformation) {
/* Setting transformation is forbidden for the scene */ /* Setting transformation is forbidden for the scene */
/** @todo Assert for this? */ /** @todo Assert for this? */
if(isScene()) return static_cast<ObjectType*>(this); if(isScene()) return static_cast<ObjectType*>(this);
@ -99,7 +99,7 @@ template<size_t dimensions> typename AbstractObject<dimensions>::ObjectType* Abs
return static_cast<ObjectType*>(this); return static_cast<ObjectType*>(this);
} }
template<size_t dimensions> void AbstractObject<dimensions>::setDirty() { template<std::uint8_t dimensions> void AbstractObject<dimensions>::setDirty() {
/* The object (and all its children) are already dirty, nothing to do */ /* The object (and all its children) are already dirty, nothing to do */
if(dirty) return; if(dirty) return;
@ -110,7 +110,7 @@ template<size_t dimensions> void AbstractObject<dimensions>::setDirty() {
i->setDirty(); i->setDirty();
} }
template<size_t dimensions> void AbstractObject<dimensions>::setClean() { template<std::uint8_t dimensions> void AbstractObject<dimensions>::setClean() {
/* The object (and all its parents) are already clean, nothing to do */ /* The object (and all its parents) are already clean, nothing to do */
if(!dirty) return; if(!dirty) return;

14
src/SceneGraph/Object.h

@ -34,13 +34,13 @@ class Camera2D;
class Camera3D; class Camera3D;
class Object2D; class Object2D;
class Object3D; class Object3D;
template<size_t dimensions> class Scene; template<std::uint8_t dimensions> class Scene;
typedef Scene<2> Scene2D; typedef Scene<2> Scene2D;
typedef Scene<3> Scene3D; typedef Scene<3> Scene3D;
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
namespace Implementation { namespace Implementation {
template<size_t dimensions> struct ObjectDimensionTraits {}; template<std::uint8_t dimensions> struct ObjectDimensionTraits {};
template<> struct ObjectDimensionTraits<2> { template<> struct ObjectDimensionTraits<2> {
typedef Object2D ObjectType; typedef Object2D ObjectType;
@ -72,7 +72,7 @@ namespace Implementation {
@todo Transform transformation when changing parent, so the object stays in @todo Transform transformation when changing parent, so the object stays in
place. place.
*/ */
template<size_t dimensions> class SCENEGRAPH_EXPORT AbstractObject: public Corrade::Containers::LinkedList<typename Implementation::ObjectDimensionTraits<dimensions>::ObjectType>, public Corrade::Containers::LinkedListItem<typename Implementation::ObjectDimensionTraits<dimensions>::ObjectType, typename Implementation::ObjectDimensionTraits<dimensions>::ObjectType> { template<std::uint8_t dimensions> class SCENEGRAPH_EXPORT AbstractObject: public Corrade::Containers::LinkedList<typename Implementation::ObjectDimensionTraits<dimensions>::ObjectType>, public Corrade::Containers::LinkedListItem<typename Implementation::ObjectDimensionTraits<dimensions>::ObjectType, typename Implementation::ObjectDimensionTraits<dimensions>::ObjectType> {
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
AbstractObject(const AbstractObject<dimensions>& other) = delete; AbstractObject(const AbstractObject<dimensions>& other) = delete;
AbstractObject(AbstractObject<dimensions>&& other) = delete; AbstractObject(AbstractObject<dimensions>&& other) = delete;
@ -81,7 +81,7 @@ template<size_t dimensions> class SCENEGRAPH_EXPORT AbstractObject: public Corra
#endif #endif
public: public:
static const size_t Dimensions = dimensions; /**< @brief %Object dimension count */ static const std::uint8_t Dimensions = dimensions; /**< @brief %Object dimension count */
/** @brief %Object type for given dimension count */ /** @brief %Object type for given dimension count */
typedef typename Implementation::ObjectDimensionTraits<Dimensions>::ObjectType ObjectType; typedef typename Implementation::ObjectDimensionTraits<Dimensions>::ObjectType ObjectType;
@ -306,11 +306,11 @@ template<size_t dimensions> class SCENEGRAPH_EXPORT AbstractObject: public Corra
bool dirty; bool dirty;
}; };
template<size_t dimensions> inline AbstractObject<dimensions>::~AbstractObject() {} template<std::uint8_t dimensions> inline AbstractObject<dimensions>::~AbstractObject() {}
/* Implementations for inline functions with unused parameters */ /* Implementations for inline functions with unused parameters */
template<size_t dimensions> inline void AbstractObject<dimensions>::draw(const typename DimensionTraits<dimensions, GLfloat>::MatrixType&, CameraType*) {} template<std::uint8_t dimensions> inline void AbstractObject<dimensions>::draw(const typename DimensionTraits<dimensions, GLfloat>::MatrixType&, CameraType*) {}
template<size_t dimensions> inline void AbstractObject<dimensions>::clean(const typename DimensionTraits<dimensions, GLfloat>::MatrixType&) { dirty = false; } template<std::uint8_t dimensions> inline void AbstractObject<dimensions>::clean(const typename DimensionTraits<dimensions, GLfloat>::MatrixType&) { dirty = false; }
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
/* These templates are instantiated in source file */ /* These templates are instantiated in source file */

2
src/SceneGraph/Scene.h

@ -28,7 +28,7 @@ namespace Magnum { namespace SceneGraph {
@see Scene2D, Scene3D @see Scene2D, Scene3D
*/ */
template<size_t dimensions> class SCENEGRAPH_EXPORT Scene: public AbstractObject<dimensions>::ObjectType { template<std::uint8_t dimensions> class SCENEGRAPH_EXPORT Scene: public AbstractObject<dimensions>::ObjectType {
public: public:
/** @copydoc AbstractObject::isScene() */ /** @copydoc AbstractObject::isScene() */
inline bool isScene() const { return true; } inline bool isScene() const { return true; }

4
src/Texture.h

@ -50,9 +50,9 @@ for more information.
@see Texture1D, Texture2D, Texture3D, CubeMapTexture, CubeMapTextureArray @see Texture1D, Texture2D, Texture3D, CubeMapTexture, CubeMapTextureArray
@todo @extension{AMD,sparse_texture} @todo @extension{AMD,sparse_texture}
*/ */
template<size_t dimensions> class Texture: public AbstractTexture { template<std::uint8_t dimensions> class Texture: public AbstractTexture {
public: public:
static const size_t Dimensions = dimensions; /**< @brief %Texture dimension count */ static const std::uint8_t Dimensions = dimensions; /**< @brief %Texture dimension count */
#ifdef DOXYGEN_GENERATING_OUTPUT #ifdef DOXYGEN_GENERATING_OUTPUT
/** /**

4
src/Trade/ImageData.h

@ -32,9 +32,9 @@ namespace Magnum { namespace Trade {
Provides access to image data and additional information about data type and Provides access to image data and additional information about data type and
dimensions. Can be used in the same situations as Image and BufferedImage. dimensions. Can be used in the same situations as Image and BufferedImage.
*/ */
template<size_t dimensions> class ImageData: public AbstractImage { template<std::uint8_t dimensions> class ImageData: public AbstractImage {
public: public:
const static size_t Dimensions = dimensions; /**< @brief %Image dimension count */ const static std::uint8_t Dimensions = dimensions; /**< @brief %Image dimension count */
/** /**
* @brief Constructor * @brief Constructor

Loading…
Cancel
Save