diff --git a/src/Physics/ShapedObject.cpp b/src/Physics/ShapedObject.cpp index f7f31deb9..dd34a52a9 100644 --- a/src/Physics/ShapedObject.cpp +++ b/src/Physics/ShapedObject.cpp @@ -42,7 +42,7 @@ template void ShapedObject::setDirty() { group->setDirty(); } -template void ShapedObject::clean(const typename SceneGraph::AbstractObject::MatrixType& absoluteTransformation) { +template void ShapedObject::clean(const typename DimensionTraits::MatrixType& absoluteTransformation) { SceneGraph::AbstractObject::ObjectType::clean(absoluteTransformation); if(_shape) _shape->applyTransformation(absoluteTransformation); diff --git a/src/Physics/ShapedObject.h b/src/Physics/ShapedObject.h index 4ceeb238e..2c04c962a 100644 --- a/src/Physics/ShapedObject.h +++ b/src/Physics/ShapedObject.h @@ -72,7 +72,7 @@ template class PHYSICS_EXPORT ShapedObject: public SceneGraph * * Applies transformation to associated shape. */ - void clean(const typename SceneGraph::AbstractObject::MatrixType& absoluteTransformation); + void clean(const typename DimensionTraits::MatrixType& absoluteTransformation); private: ShapedObjectGroup* group; diff --git a/src/SceneGraph/Camera.cpp b/src/SceneGraph/Camera.cpp index 892a0a419..81c39d354 100644 --- a/src/SceneGraph/Camera.cpp +++ b/src/SceneGraph/Camera.cpp @@ -58,7 +58,7 @@ template void AbstractCamera::setViewport(const M fixAspectRatio(); } -template void AbstractCamera::clean(const typename AbstractObject::MatrixType& absoluteTransformation) { +template void AbstractCamera::clean(const typename DimensionTraits::MatrixType& absoluteTransformation) { AbstractObject::ObjectType::clean(absoluteTransformation); _cameraMatrix = absoluteTransformation.inverted(); @@ -72,10 +72,10 @@ template void AbstractCamera::draw() { drawChildren(s, cameraMatrix()); } -template void AbstractCamera::drawChildren(typename AbstractObject::ObjectType* object, const typename AbstractObject::MatrixType& transformationMatrix) { +template void AbstractCamera::drawChildren(typename AbstractObject::ObjectType* object, const typename DimensionTraits::MatrixType& transformationMatrix) { for(typename AbstractObject::ObjectType* i = object->firstChild(); i; i = i->nextSibling()) { /* Transformation matrix for the object */ - typename AbstractObject::MatrixType matrix = transformationMatrix*i->transformation(); + typename DimensionTraits::MatrixType matrix = transformationMatrix*i->transformation(); /* Draw the object and its children */ i->draw(matrix, static_cast::CameraType*>(this)); diff --git a/src/SceneGraph/Camera.h b/src/SceneGraph/Camera.h index 18f5c016c..3e473c4a7 100644 --- a/src/SceneGraph/Camera.h +++ b/src/SceneGraph/Camera.h @@ -86,7 +86,7 @@ template class SCENEGRAPH_EXPORT AbstractCamera: public Abstr * Camera matrix describes world position relative to the camera and is * applied as first. */ - inline typename AbstractObject::MatrixType cameraMatrix() { + inline typename DimensionTraits::MatrixType cameraMatrix() { this->setClean(); return _cameraMatrix; } @@ -98,7 +98,7 @@ template class SCENEGRAPH_EXPORT AbstractCamera: public Abstr * as last. * @see projectionSize() */ - inline typename AbstractObject::MatrixType projectionMatrix() const { return _projectionMatrix; } + inline typename DimensionTraits::MatrixType projectionMatrix() const { return _projectionMatrix; } /** * @brief Size of (near) XY plane in current projection @@ -135,27 +135,27 @@ template class SCENEGRAPH_EXPORT AbstractCamera: public Abstr /** * Recalculates camera matrix. */ - void clean(const typename AbstractObject::MatrixType& absoluteTransformation); + void clean(const typename DimensionTraits::MatrixType& absoluteTransformation); /** * @brief Draw object children * * Recursively draws all children of the object. */ - void drawChildren(typename AbstractObject::ObjectType* object, const typename AbstractObject::MatrixType& transformationMatrix); + void drawChildren(typename AbstractObject::ObjectType* object, const typename DimensionTraits::MatrixType& transformationMatrix); #ifndef DOXYGEN_GENERATING_OUTPUT inline void fixAspectRatio() { - _projectionMatrix = Implementation::aspectRatioFix::MatrixType>(_aspectRatioPolicy, {rawProjectionMatrix[0].x(), rawProjectionMatrix[1].y()}, _viewport)*rawProjectionMatrix; + _projectionMatrix = Implementation::aspectRatioFix::MatrixType>(_aspectRatioPolicy, {rawProjectionMatrix[0].x(), rawProjectionMatrix[1].y()}, _viewport)*rawProjectionMatrix; } - typename AbstractObject::MatrixType rawProjectionMatrix; + typename DimensionTraits::MatrixType rawProjectionMatrix; AspectRatioPolicy _aspectRatioPolicy; #endif private: - typename AbstractObject::MatrixType _projectionMatrix; - typename AbstractObject::MatrixType _cameraMatrix; + typename DimensionTraits::MatrixType _projectionMatrix; + typename DimensionTraits::MatrixType _cameraMatrix; Math::Vector2 _viewport; }; diff --git a/src/SceneGraph/Object.cpp b/src/SceneGraph/Object.cpp index a0a02922a..b723a55a5 100644 --- a/src/SceneGraph/Object.cpp +++ b/src/SceneGraph/Object.cpp @@ -49,11 +49,11 @@ template typename AbstractObject::ObjectType* Abs return static_cast(this); } -template typename AbstractObject::MatrixType AbstractObject::absoluteTransformation(CameraType* camera) { +template typename DimensionTraits::MatrixType AbstractObject::absoluteTransformation(CameraType* camera) { /* Shortcut for absolute transformation of camera relative to itself */ - if(camera == this) return MatrixType(); + if(camera == this) return typename DimensionTraits::MatrixType(); - MatrixType t = _transformation; + typename DimensionTraits::MatrixType t = _transformation; ObjectType* p = parent(); while(p != nullptr) { @@ -89,7 +89,7 @@ template typename AbstractObject::SceneType* Abst return nullptr; } -template typename AbstractObject::ObjectType* AbstractObject::setTransformation(const MatrixType& transformation) { +template typename AbstractObject::ObjectType* AbstractObject::setTransformation(const typename DimensionTraits::MatrixType& transformation) { /* Setting transformation is forbidden for the scene */ /** @todo Assert for this? */ if(isScene()) return static_cast(this); @@ -130,7 +130,7 @@ template void AbstractObject::setClean() { /* Call setClean(const Matrix4&) for every parent and also this object */ ObjectType* o = objects.top(); objects.pop(); - MatrixType absoluteTransformation = o->absoluteTransformation(); + typename DimensionTraits::MatrixType absoluteTransformation = o->absoluteTransformation(); o->clean(absoluteTransformation); while(!objects.empty()) { o = objects.top(); diff --git a/src/SceneGraph/Object.h b/src/SceneGraph/Object.h index ddb8f6191..3b2e5dca0 100644 --- a/src/SceneGraph/Object.h +++ b/src/SceneGraph/Object.h @@ -24,6 +24,7 @@ #include "Math/Matrix3.h" #include "Math/Matrix4.h" #include "Magnum.h" +#include "DimensionTraits.h" #include "magnumSceneGraphVisibility.h" @@ -42,18 +43,12 @@ namespace Implementation { template struct ObjectDimensionTraits {}; template<> struct ObjectDimensionTraits<2> { - static const size_t Dimensions = 2; - typedef Vector2 VectorType; - typedef Matrix3 MatrixType; typedef Object2D ObjectType; typedef Camera2D CameraType; typedef Scene2D SceneType; }; template<> struct ObjectDimensionTraits<3> { - static const size_t Dimensions = 3; - typedef Vector3 VectorType; - typedef Matrix4 MatrixType; typedef Object3D ObjectType; typedef Camera3D CameraType; typedef Scene3D SceneType; @@ -88,12 +83,6 @@ template class SCENEGRAPH_EXPORT AbstractObject: public Corra public: static const size_t Dimensions = dimensions; /**< @brief %Object dimension count */ - /** @brief %Vector type for given dimension count */ - typedef typename Implementation::ObjectDimensionTraits::VectorType VectorType; - - /** @brief %Matrix type for given dimension count */ - typedef typename Implementation::ObjectDimensionTraits::MatrixType MatrixType; - /** @brief %Object type for given dimension count */ typedef typename Implementation::ObjectDimensionTraits::ObjectType ObjectType; @@ -174,7 +163,7 @@ template class SCENEGRAPH_EXPORT AbstractObject: public Corra }; /** @brief Transformation */ - inline MatrixType transformation() const { + inline typename DimensionTraits::MatrixType transformation() const { return _transformation; } @@ -189,13 +178,13 @@ template class SCENEGRAPH_EXPORT AbstractObject: public Corra * objects every time it is asked, unless this function is * reimplemented in a different way. */ - virtual MatrixType absoluteTransformation(CameraType* camera = nullptr); + virtual typename DimensionTraits::MatrixType absoluteTransformation(CameraType* camera = nullptr); /** * @brief Set transformation * @return Pointer to self (for method chaining) */ - ObjectType* setTransformation(const MatrixType& transformation); + ObjectType* setTransformation(const typename DimensionTraits::MatrixType& transformation); /** * @brief Multiply transformation @@ -203,7 +192,7 @@ template class SCENEGRAPH_EXPORT AbstractObject: public Corra * @param type Transformation type * @return Pointer to self (for method chaining) */ - inline ObjectType* multiplyTransformation(const MatrixType& transformation, Transformation type = Transformation::Global) { + inline ObjectType* multiplyTransformation(const typename DimensionTraits::MatrixType& transformation, Transformation type = Transformation::Global) { setTransformation(type == Transformation::Global ? transformation*_transformation : _transformation*transformation); return static_cast(this); @@ -220,7 +209,7 @@ template class SCENEGRAPH_EXPORT AbstractObject: public Corra * * Default implementation does nothing. */ - virtual void draw(const MatrixType& transformationMatrix, CameraType* camera); + virtual void draw(const typename DimensionTraits::MatrixType& transformationMatrix, CameraType* camera); /** @{ @name Caching helpers * @@ -295,7 +284,7 @@ template class SCENEGRAPH_EXPORT AbstractObject: public Corra * } * @endcode */ - virtual void clean(const MatrixType& absoluteTransformation); + virtual void clean(const typename DimensionTraits::MatrixType& absoluteTransformation); /*@}*/ @@ -313,15 +302,15 @@ template class SCENEGRAPH_EXPORT AbstractObject: public Corra using Corrade::Containers::LinkedListItem::previous; using Corrade::Containers::LinkedListItem::next; - MatrixType _transformation; + typename DimensionTraits::MatrixType _transformation; bool dirty; }; template inline AbstractObject::~AbstractObject() {} /* Implementations for inline functions with unused parameters */ -template inline void AbstractObject::draw(const MatrixType&, CameraType*) {} -template inline void AbstractObject::clean(const MatrixType&) { dirty = false; } +template inline void AbstractObject::draw(const typename DimensionTraits::MatrixType&, CameraType*) {} +template inline void AbstractObject::clean(const typename DimensionTraits::MatrixType&) { dirty = false; } #ifndef DOXYGEN_GENERATING_OUTPUT /* These templates are instantiated in source file */ diff --git a/src/SceneGraph/Scene.h b/src/SceneGraph/Scene.h index 092f85e73..90d0e2ca7 100644 --- a/src/SceneGraph/Scene.h +++ b/src/SceneGraph/Scene.h @@ -36,15 +36,15 @@ template class SCENEGRAPH_EXPORT Scene: public AbstractObject /** @todo Some deleted functions belong only to Scene2D, some only to Scene3D - what to do? */ #ifndef DOXYGEN_GENERATING_OUTPUT void setParent(typename AbstractObject::ObjectType* parent) = delete; - void setTransformation(const typename AbstractObject::MatrixType& transformation) = delete; - void multiplyTransformation(const typename AbstractObject::MatrixType& transformation, typename AbstractObject::Transformation type = AbstractObject::Transformation::Global) = delete; - void translate(const typename AbstractObject::VectorType& vec, typename AbstractObject::Transformation type = AbstractObject::Transformation::Global) = delete; - void scale(const typename AbstractObject::VectorType& vec, typename AbstractObject::Transformation type = AbstractObject::Transformation::Global) = delete; - void rotate(GLfloat angle, const typename AbstractObject::VectorType& vec, typename AbstractObject::Transformation type = AbstractObject::Transformation::Global) = delete; + void setTransformation(const typename DimensionTraits::MatrixType& transformation) = delete; + void multiplyTransformation(const typename DimensionTraits::MatrixType& transformation, typename AbstractObject::Transformation type = DimensionTraits::Transformation::Global) = delete; + void translate(const typename DimensionTraits::VectorType& vec, typename AbstractObject::Transformation type = AbstractObject::Transformation::Global) = delete; + void scale(const typename DimensionTraits::VectorType& vec, typename AbstractObject::Transformation type = AbstractObject::Transformation::Global) = delete; + void rotate(GLfloat angle, const typename DimensionTraits::VectorType& vec, typename AbstractObject::Transformation type = AbstractObject::Transformation::Global) = delete; #endif private: - inline void draw(const typename AbstractObject::MatrixType&, typename AbstractObject::CameraType*) {} + inline void draw(const typename DimensionTraits::MatrixType&, typename AbstractObject::CameraType*) {} }; /** @brief Two-dimensional scene */