diff --git a/src/SceneGraph/AbstractTranslation.h b/src/SceneGraph/AbstractTranslation.h new file mode 100644 index 000000000..df64b3d58 --- /dev/null +++ b/src/SceneGraph/AbstractTranslation.h @@ -0,0 +1,142 @@ +#ifndef Magnum_SceneGraph_AbstractTranslation_h +#define Magnum_SceneGraph_AbstractTranslation_h +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +/** @file + * @brief Class @ref Magnum::SceneGraph::AbstractTranslation, alias @ref Magnum::SceneGraph::AbstractBasicTranslation2D, @ref Magnum::SceneGraph::AbstractBasicTranslation3D, typedef @ref Magnum::SceneGraph::AbstractTranslation2D, @ref Magnum::SceneGraph::AbstractBasicTranslation3D + */ + +#include "Math/Vector3.h" +#include "DimensionTraits.h" +#include "SceneGraph/AbstractTransformation.h" + +namespace Magnum { namespace SceneGraph { + +/** +@brief Base transformation for two-dimensional scenes supporting translation + +By default the translation is stored with the same underlying type as resulting +transformation matrix, but it's possible to store translation in e.g. integral +coordinates while having floating-point transformation matrix. + +@see @ref AbstractBasicTranslation2D, @ref AbstractBasicTranslation3D, + @ref AbstractTranslation2D, @ref AbstractTranslation3D, @ref scenegraph +*/ +#ifdef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +class AbstractTranslation: public AbstractTransformation { + public: + explicit AbstractTranslation() = default; + + /** + * @brief Translate object + * @param vector Translation vector + * @param type Transformation type + * @return Reference to self (for method chaining) + * + * @see @ref Vector2::xAxis(), @ref Vector2::yAxis(), @ref Vector3::xAxis(), + * @ref Vector3::yAxis(), @ref Vector3::zAxis() + */ + AbstractTranslation& translate(const typename DimensionTraits::VectorType& vector, TransformationType type = TransformationType::Global) { + doTranslate(vector, type); + return *this; + } + + protected: + ~AbstractTranslation() = default; + + #ifdef DOXYGEN_GENERATING_OUTPUT + protected: + #else + private: + #endif + /** @brief Polymorphic implementation for translate() */ + virtual void doTranslate(const typename DimensionTraits::VectorType& vector, TransformationType type) = 0; +}; + +#ifndef CORRADE_GCC46_COMPATIBILITY +/** +@brief Base transformation for two-dimensional scenes supporting translation + +Convenience alternative to %AbstractTranslation<2, T, TranslationType>. +See @ref AbstractTranslation for more information. +@note Not available on GCC < 4.7. Use %AbstractTranslation<2, T, TranslationType> + instead. +@see @ref AbstractTranslation2D, @ref AbstractBasicTranslation3D +*/ +#ifdef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +using AbstractBasicTranslation2D = AbstractTranslation<2, T, TranslationType>; +#endif + +/** +@brief Base transformation for two-dimensional float scenes supporting translation + +@see @ref AbstractTranslation3D +*/ +#ifndef CORRADE_GCC46_COMPATIBILITY +typedef AbstractBasicTranslation2D AbstractTranslation2D; +#else +typedef AbstractTranslation<2, Float> AbstractTranslation2D; +#endif + +#ifndef CORRADE_GCC46_COMPATIBILITY +/** +@brief Base transformation for three-dimensional scenes supporting translation + +Convenience alternative to %AbstractTranslation<3, T, TranslationType>. +See @ref AbstractTranslation for more information. +@note Not available on GCC < 4.7. Use %AbstractTranslation<3, T, TranslationType> + instead. +@see @ref AbstractTranslation3D, @ref AbstractBasicTranslation2D +*/ +#ifdef DOXYGEN_GENERATING_OUTPUT +template +#else +template +#endif +using AbstractBasicTranslation3D = AbstractTranslation<3, T, TranslationType>; +#endif + +/** +@brief Base transformation for three-dimensional float scenes supporting translation + +@see @ref AbstractTranslation2D +*/ +#ifndef CORRADE_GCC46_COMPATIBILITY +typedef AbstractBasicTranslation3D AbstractTranslation3D; +#else +typedef AbstractTranslation<3, Float> AbstractTranslation3D; +#endif + +}} + +#endif diff --git a/src/SceneGraph/AbstractTranslationRotation2D.h b/src/SceneGraph/AbstractTranslationRotation2D.h index 025b1ce1e..71587264e 100644 --- a/src/SceneGraph/AbstractTranslationRotation2D.h +++ b/src/SceneGraph/AbstractTranslationRotation2D.h @@ -28,8 +28,7 @@ * @brief Class Magnum::SceneGraph::AbstractBasicTranslationRotation2D, typedef Magnum::SceneGraph::AbstractTranslationRotation2D */ -#include "Math/Vector2.h" -#include "AbstractTransformation.h" +#include "SceneGraph/AbstractTranslation.h" namespace Magnum { namespace SceneGraph { @@ -39,23 +38,10 @@ namespace Magnum { namespace SceneGraph { @see @ref AbstractTranslationRotation2D, @ref scenegraph, @ref AbstractBasicTranslationRotation3D @todo Use AbstractBasicTransformation2D when support for GCC 4.6 is dropped */ -template class AbstractBasicTranslationRotation2D: public AbstractTransformation<2, T> { +template class AbstractBasicTranslationRotation2D: public AbstractTranslation<2, T> { public: explicit AbstractBasicTranslationRotation2D() = default; - /** - * @brief Translate object - * @param vector Translation vector - * @param type Transformation type - * @return Reference to self (for method chaining) - * - * @see Vector2::xAxis(), Vector2::yAxis() - */ - AbstractBasicTranslationRotation2D& translate(const Math::Vector2& vector, TransformationType type = TransformationType::Global) { - doTranslate(vector, type); - return *this; - } - /** * @brief Rotate object * @param angle Angle (counterclockwise) @@ -83,9 +69,6 @@ template class AbstractBasicTranslationRotation2D: public AbstractTrans #else private: #endif - /** @brief Polymorphic implementation for translate() */ - virtual void doTranslate(const Math::Vector2& vector, TransformationType type) = 0; - /** @brief Polymorphic implementation for rotate() */ virtual void doRotate(Math::Rad angle, TransformationType type) = 0; }; diff --git a/src/SceneGraph/AbstractTranslationRotation3D.h b/src/SceneGraph/AbstractTranslationRotation3D.h index 2c6d8cee3..e4cfd11d6 100644 --- a/src/SceneGraph/AbstractTranslationRotation3D.h +++ b/src/SceneGraph/AbstractTranslationRotation3D.h @@ -28,8 +28,7 @@ * @brief Class Magnum::SceneGraph::AbstractBasicTranslationRotation3D, typedef Magnum::SceneGraph::AbstractTranslationRotation3D */ -#include "AbstractTransformation.h" -#include "Math/Vector3.h" +#include "SceneGraph/AbstractTranslation.h" namespace Magnum { namespace SceneGraph { @@ -39,23 +38,10 @@ namespace Magnum { namespace SceneGraph { @see @ref AbstractTranslationRotation3D @ref scenegraph, @ref AbstractBasicTranslationRotation2D @todo Use AbstractBasicTransformation3D when support for GCC 4.6 is dropped */ -template class AbstractBasicTranslationRotation3D: public AbstractTransformation<3, T> { +template class AbstractBasicTranslationRotation3D: public AbstractTranslation<3, T> { public: explicit AbstractBasicTranslationRotation3D() = default; - /** - * @brief Translate object - * @param vector Translation vector - * @param type Transformation type - * @return Reference to self (for method chaining) - * - * @see Vector3::xAxis(), Vector3::yAxis(), Vector3::zAxis() - */ - AbstractBasicTranslationRotation3D& translate(const Math::Vector3& vector, TransformationType type = TransformationType::Global) { - doTranslate(vector, type); - return *this; - } - /** * @brief Rotate object * @param angle Angle (counterclockwise) @@ -129,9 +115,6 @@ template class AbstractBasicTranslationRotation3D: public AbstractTrans #else private: #endif - /** @brief Polymorphic implementation for translate() */ - virtual void doTranslate(const Math::Vector3& vector, TransformationType type) = 0; - /** @brief Polymorphic implementation for rotate() */ virtual void doRotate(Math::Rad angle, const Math::Vector3& normalizedAxis, TransformationType type) = 0; diff --git a/src/SceneGraph/CMakeLists.txt b/src/SceneGraph/CMakeLists.txt index 4bd6bf0c7..56b097090 100644 --- a/src/SceneGraph/CMakeLists.txt +++ b/src/SceneGraph/CMakeLists.txt @@ -38,6 +38,7 @@ set(MagnumSceneGraph_HEADERS AbstractGroupedFeature.h AbstractObject.h AbstractTransformation.h + AbstractTranslation.h AbstractTranslationRotation2D.h AbstractTranslationRotation3D.h AbstractTranslationRotationScaling2D.h diff --git a/src/SceneGraph/SceneGraph.h b/src/SceneGraph/SceneGraph.h index c824a4023..2dd49f622 100644 --- a/src/SceneGraph/SceneGraph.h +++ b/src/SceneGraph/SceneGraph.h @@ -94,6 +94,17 @@ typedef AbstractTransformation<2, Float> AbstractTransformation2D; typedef AbstractTransformation<3, Float> AbstractTransformation3D; #endif +template class AbstractTranslation; +#ifndef CORRADE_GCC46_COMPATIBILITY +template using AbstractBasicTranslation2D = AbstractTranslation<2, T, TranslationType>; +template using AbstractBasicTranslation3D = AbstractTranslation<3, T, TranslationType>; +typedef AbstractBasicTranslation2D AbstractTranslation2D; +typedef AbstractBasicTranslation3D AbstractTranslation3D; +#else +typedef AbstractTranslation<2, Float> AbstractTranslation2D; +typedef AbstractTranslation<3, Float> AbstractTranslation3D; +#endif + template class AbstractBasicTranslationRotation2D; template class AbstractBasicTranslationRotation3D; typedef AbstractBasicTranslationRotation2D AbstractTranslationRotation2D;