Browse Source

SceneGraph: new AbstractTranslation transformation interface.

Supports also integer coordinates.
pull/23/head
Vladimír Vondruš 13 years ago
parent
commit
732d7e057e
  1. 142
      src/SceneGraph/AbstractTranslation.h
  2. 21
      src/SceneGraph/AbstractTranslationRotation2D.h
  3. 21
      src/SceneGraph/AbstractTranslationRotation3D.h
  4. 1
      src/SceneGraph/CMakeLists.txt
  5. 11
      src/SceneGraph/SceneGraph.h

142
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š <mosra@centrum.cz>
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<UnsignedInt dimensions, class T, class TranslationType = T>
#else
template<UnsignedInt dimensions, class T, class TranslationType>
#endif
class AbstractTranslation: public AbstractTransformation<dimensions, T> {
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<dimensions, T>& translate(const typename DimensionTraits<dimensions, TranslationType>::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<dimensions, TranslationType>::VectorType& vector, TransformationType type) = 0;
};
#ifndef CORRADE_GCC46_COMPATIBILITY
/**
@brief Base transformation for two-dimensional scenes supporting translation
Convenience alternative to <tt>%AbstractTranslation<2, T, TranslationType></tt>.
See @ref AbstractTranslation for more information.
@note Not available on GCC < 4.7. Use <tt>%AbstractTranslation<2, T, TranslationType></tt>
instead.
@see @ref AbstractTranslation2D, @ref AbstractBasicTranslation3D
*/
#ifdef DOXYGEN_GENERATING_OUTPUT
template<class T, class TranslationType = T>
#else
template<class T, class TranslationType>
#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<Float> AbstractTranslation2D;
#else
typedef AbstractTranslation<2, Float> AbstractTranslation2D;
#endif
#ifndef CORRADE_GCC46_COMPATIBILITY
/**
@brief Base transformation for three-dimensional scenes supporting translation
Convenience alternative to <tt>%AbstractTranslation<3, T, TranslationType></tt>.
See @ref AbstractTranslation for more information.
@note Not available on GCC < 4.7. Use <tt>%AbstractTranslation<3, T, TranslationType></tt>
instead.
@see @ref AbstractTranslation3D, @ref AbstractBasicTranslation2D
*/
#ifdef DOXYGEN_GENERATING_OUTPUT
template<class T, class TranslationType = T>
#else
template<class T, class TranslationType>
#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<Float> AbstractTranslation3D;
#else
typedef AbstractTranslation<3, Float> AbstractTranslation3D;
#endif
}}
#endif

21
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<T> when support for GCC 4.6 is dropped
*/
template<class T> class AbstractBasicTranslationRotation2D: public AbstractTransformation<2, T> {
template<class T> 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<T>& translate(const Math::Vector2<T>& vector, TransformationType type = TransformationType::Global) {
doTranslate(vector, type);
return *this;
}
/**
* @brief Rotate object
* @param angle Angle (counterclockwise)
@ -83,9 +69,6 @@ template<class T> class AbstractBasicTranslationRotation2D: public AbstractTrans
#else
private:
#endif
/** @brief Polymorphic implementation for translate() */
virtual void doTranslate(const Math::Vector2<T>& vector, TransformationType type) = 0;
/** @brief Polymorphic implementation for rotate() */
virtual void doRotate(Math::Rad<T> angle, TransformationType type) = 0;
};

21
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<T> when support for GCC 4.6 is dropped
*/
template<class T> class AbstractBasicTranslationRotation3D: public AbstractTransformation<3, T> {
template<class T> 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<T>& translate(const Math::Vector3<T>& vector, TransformationType type = TransformationType::Global) {
doTranslate(vector, type);
return *this;
}
/**
* @brief Rotate object
* @param angle Angle (counterclockwise)
@ -129,9 +115,6 @@ template<class T> class AbstractBasicTranslationRotation3D: public AbstractTrans
#else
private:
#endif
/** @brief Polymorphic implementation for translate() */
virtual void doTranslate(const Math::Vector3<T>& vector, TransformationType type) = 0;
/** @brief Polymorphic implementation for rotate() */
virtual void doRotate(Math::Rad<T> angle, const Math::Vector3<T>& normalizedAxis, TransformationType type) = 0;

1
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

11
src/SceneGraph/SceneGraph.h

@ -94,6 +94,17 @@ typedef AbstractTransformation<2, Float> AbstractTransformation2D;
typedef AbstractTransformation<3, Float> AbstractTransformation3D;
#endif
template<UnsignedInt, class T, class = T> class AbstractTranslation;
#ifndef CORRADE_GCC46_COMPATIBILITY
template<class T, class TranslationType = T> using AbstractBasicTranslation2D = AbstractTranslation<2, T, TranslationType>;
template<class T, class TranslationType = T> using AbstractBasicTranslation3D = AbstractTranslation<3, T, TranslationType>;
typedef AbstractBasicTranslation2D<Float> AbstractTranslation2D;
typedef AbstractBasicTranslation3D<Float> AbstractTranslation3D;
#else
typedef AbstractTranslation<2, Float> AbstractTranslation2D;
typedef AbstractTranslation<3, Float> AbstractTranslation3D;
#endif
template<class> class AbstractBasicTranslationRotation2D;
template<class> class AbstractBasicTranslationRotation3D;
typedef AbstractBasicTranslationRotation2D<Float> AbstractTranslationRotation2D;

Loading…
Cancel
Save