Browse Source

Getting rid of <>, part 2: SceneGraph cameras and drawables.

This allows to use those nice aliases even on GCC <= 4.6 without
resorting to verbose full name. Double and other types can be then
typedef'd as e.g. Camera3Dd or Camera3Di.
pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
a0d60bbaa7
  1. 4
      src/DebugTools/ForceRenderer.cpp
  2. 7
      src/DebugTools/ForceRenderer.h
  3. 4
      src/DebugTools/ObjectRenderer.cpp
  4. 7
      src/DebugTools/ObjectRenderer.h
  5. 4
      src/DebugTools/ShapeRenderer.cpp
  6. 6
      src/DebugTools/ShapeRenderer.h
  7. 53
      src/SceneGraph/AbstractCamera.h
  8. 10
      src/SceneGraph/AbstractCamera.hpp
  9. 36
      src/SceneGraph/Camera2D.h
  10. 8
      src/SceneGraph/Camera2D.hpp
  11. 36
      src/SceneGraph/Camera3D.h
  12. 20
      src/SceneGraph/Camera3D.hpp
  13. 99
      src/SceneGraph/Drawable.h
  14. 30
      src/SceneGraph/SceneGraph.h
  15. 10
      src/SceneGraph/Test/CameraTest.cpp
  16. 8
      src/SceneGraph/instantiation.cpp

4
src/DebugTools/ForceRenderer.cpp

@ -64,7 +64,7 @@ const std::array<UnsignedByte, 6> indices{{
}
template<UnsignedInt dimensions> ForceRenderer<dimensions>::ForceRenderer(SceneGraph::AbstractObject<dimensions>* object, const typename DimensionTraits<dimensions, Float>::VectorType& forcePosition, const typename DimensionTraits<dimensions, Float>::VectorType* force, ResourceKey options, SceneGraph::DrawableGroup<dimensions>* drawables): SceneGraph::Drawable<dimensions>(object, drawables), forcePosition(forcePosition), force(force), options(ResourceManager::instance()->get<ForceRendererOptions>(options)) {
template<UnsignedInt dimensions> ForceRenderer<dimensions>::ForceRenderer(SceneGraph::AbstractObject<dimensions>* object, const typename DimensionTraits<dimensions, Float>::VectorType& forcePosition, const typename DimensionTraits<dimensions, Float>::VectorType* force, ResourceKey options, SceneGraph::BasicDrawableGroup<dimensions, Float>* drawables): SceneGraph::BasicDrawable<dimensions, Float>(object, drawables), forcePosition(forcePosition), force(force), options(ResourceManager::instance()->get<ForceRendererOptions>(options)) {
/* Shader */
shader = ResourceManager::instance()->get<AbstractShaderProgram, Shaders::Flat<dimensions>>(shaderKey<dimensions>());
if(!shader) ResourceManager::instance()->set<AbstractShaderProgram>(shader.key(), new Shaders::Flat<dimensions>);
@ -94,7 +94,7 @@ template<UnsignedInt dimensions> ForceRenderer<dimensions>::ForceRenderer(SceneG
ResourceManager::instance()->set<Mesh>(this->mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual);
}
template<UnsignedInt dimensions> void ForceRenderer<dimensions>::draw(const typename DimensionTraits<dimensions>::MatrixType& transformationMatrix, SceneGraph::AbstractCamera<dimensions>* camera) {
template<UnsignedInt dimensions> void ForceRenderer<dimensions>::draw(const typename DimensionTraits<dimensions>::MatrixType& transformationMatrix, SceneGraph::AbstractBasicCamera<dimensions, Float>* camera) {
shader->setTransformationProjectionMatrix(camera->projectionMatrix()*Implementation::forceRendererTransformation<dimensions>(transformationMatrix.transformPoint(forcePosition), *force)*DimensionTraits<dimensions>::MatrixType::scaling(typename DimensionTraits<dimensions>::VectorType(options->scale())))
->setColor(options->color())
->use();

7
src/DebugTools/ForceRenderer.h

@ -101,7 +101,7 @@ new DebugTools::ForceRenderer2D(object, {0.3f, 1.5f, -0.7f}, &force, "my", debug
@see ForceRenderer2D, ForceRenderer3D
*/
template<UnsignedInt dimensions> class MAGNUM_DEBUGTOOLS_EXPORT ForceRenderer: public SceneGraph::Drawable<dimensions> {
template<UnsignedInt dimensions> class MAGNUM_DEBUGTOOLS_EXPORT ForceRenderer: public SceneGraph::BasicDrawable<dimensions, Float> {
public:
/**
* @brief Constructor
@ -117,11 +117,10 @@ template<UnsignedInt dimensions> class MAGNUM_DEBUGTOOLS_EXPORT ForceRenderer: p
* saved as reference to original vector and thus it must be available
* for the whole lifetime of the renderer.
*/
explicit ForceRenderer(SceneGraph::AbstractObject<dimensions>* object, const typename DimensionTraits<dimensions, Float>::VectorType& forcePosition, const typename DimensionTraits<dimensions, Float>::VectorType* force, ResourceKey options = ResourceKey(), SceneGraph::DrawableGroup<dimensions>* drawables = nullptr);
explicit ForceRenderer(SceneGraph::AbstractObject<dimensions>* object, const typename DimensionTraits<dimensions, Float>::VectorType& forcePosition, const typename DimensionTraits<dimensions, Float>::VectorType* force, ResourceKey options = ResourceKey(), SceneGraph::BasicDrawableGroup<dimensions, Float>* drawables = nullptr);
protected:
/** @todoc Remove Float when Doxygen properly treats this as override */
void draw(const typename DimensionTraits<dimensions, Float>::MatrixType& transformationMatrix, SceneGraph::AbstractCamera<dimensions, Float>* camera) override;
void draw(const typename DimensionTraits<dimensions, Float>::MatrixType& transformationMatrix, SceneGraph::AbstractBasicCamera<dimensions, Float>* camera) override;
private:
const typename DimensionTraits<dimensions, Float>::VectorType forcePosition;

4
src/DebugTools/ObjectRenderer.cpp

@ -142,7 +142,7 @@ const std::array<UnsignedByte, 18> Renderer<3>::indices{{
}
template<UnsignedInt dimensions> ObjectRenderer<dimensions>::ObjectRenderer(SceneGraph::AbstractObject<dimensions>* object, ResourceKey options, SceneGraph::DrawableGroup<dimensions>* drawables): SceneGraph::Drawable<dimensions>(object, drawables), options(ResourceManager::instance()->get<ObjectRendererOptions>(options)) {
template<UnsignedInt dimensions> ObjectRenderer<dimensions>::ObjectRenderer(SceneGraph::AbstractObject<dimensions>* object, ResourceKey options, SceneGraph::BasicDrawableGroup<dimensions, Float>* drawables): SceneGraph::BasicDrawable<dimensions, Float>(object, drawables), options(ResourceManager::instance()->get<ObjectRendererOptions>(options)) {
/* Shader */
shader = ResourceManager::instance()->get<AbstractShaderProgram, Shaders::VertexColor<dimensions>>(Renderer<dimensions>::shader());
if(!shader) ResourceManager::instance()->set<AbstractShaderProgram>(shader.key(), new Shaders::VertexColor<dimensions>);
@ -173,7 +173,7 @@ template<UnsignedInt dimensions> ObjectRenderer<dimensions>::ObjectRenderer(Scen
ResourceManager::instance()->set<Mesh>(this->mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual);
}
template<UnsignedInt dimensions> void ObjectRenderer<dimensions>::draw(const typename DimensionTraits<dimensions>::MatrixType& transformationMatrix, SceneGraph::AbstractCamera<dimensions>* camera) {
template<UnsignedInt dimensions> void ObjectRenderer<dimensions>::draw(const typename DimensionTraits<dimensions>::MatrixType& transformationMatrix, SceneGraph::AbstractBasicCamera<dimensions, Float>* camera) {
shader->setTransformationProjectionMatrix(camera->projectionMatrix()*transformationMatrix*DimensionTraits<dimensions>::MatrixType::scaling(typename DimensionTraits<dimensions>::VectorType(options->size())))
->use();

7
src/DebugTools/ObjectRenderer.h

@ -84,7 +84,7 @@ new DebugTools::ObjectRenderer2D(object, "my", debugDrawables);
@see ObjectRenderer2D, ObjectRenderer3D
*/
template<UnsignedInt dimensions> class MAGNUM_DEBUGTOOLS_EXPORT ObjectRenderer: public SceneGraph::Drawable<dimensions> {
template<UnsignedInt dimensions> class MAGNUM_DEBUGTOOLS_EXPORT ObjectRenderer: public SceneGraph::BasicDrawable<dimensions, Float> {
public:
/**
* @brief Constructor
@ -96,11 +96,10 @@ template<UnsignedInt dimensions> class MAGNUM_DEBUGTOOLS_EXPORT ObjectRenderer:
*
* The renderer is automatically added to object's features.
*/
explicit ObjectRenderer(SceneGraph::AbstractObject<dimensions>* object, ResourceKey options = ResourceKey(), SceneGraph::DrawableGroup<dimensions>* drawables = nullptr);
explicit ObjectRenderer(SceneGraph::AbstractObject<dimensions>* object, ResourceKey options = ResourceKey(), SceneGraph::BasicDrawableGroup<dimensions, Float>* drawables = nullptr);
protected:
/** @todoc Remove Float when Doxygen properly treats this as override */
void draw(const typename DimensionTraits<dimensions, Float>::MatrixType& transformationMatrix, SceneGraph::AbstractCamera<dimensions, Float>* camera) override;
void draw(const typename DimensionTraits<dimensions, Float>::MatrixType& transformationMatrix, SceneGraph::AbstractBasicCamera<dimensions, Float>* camera) override;
private:
Resource<ObjectRendererOptions> options;

4
src/DebugTools/ShapeRenderer.cpp

@ -94,7 +94,7 @@ template<> void createDebugMesh(ShapeRenderer<3>* renderer, const Shapes::Implem
}
template<UnsignedInt dimensions> ShapeRenderer<dimensions>::ShapeRenderer(Shapes::AbstractShape<dimensions>* shape, ResourceKey options, SceneGraph::DrawableGroup<dimensions>* drawables): SceneGraph::Drawable<dimensions>(shape->object(), drawables), options(ResourceManager::instance()->get<ShapeRendererOptions>(options)) {
template<UnsignedInt dimensions> ShapeRenderer<dimensions>::ShapeRenderer(Shapes::AbstractShape<dimensions>* shape, ResourceKey options, SceneGraph::BasicDrawableGroup<dimensions, Float>* drawables): SceneGraph::BasicDrawable<dimensions, Float>(shape->object(), drawables), options(ResourceManager::instance()->get<ShapeRendererOptions>(options)) {
Implementation::createDebugMesh(this, Shapes::Implementation::getAbstractShape(shape));
}
@ -102,7 +102,7 @@ template<UnsignedInt dimensions> ShapeRenderer<dimensions>::~ShapeRenderer() {
for(auto i: renderers) delete i;
}
template<UnsignedInt dimensions> void ShapeRenderer<dimensions>::draw(const typename DimensionTraits<dimensions>::MatrixType&, SceneGraph::AbstractCamera<dimensions>* camera) {
template<UnsignedInt dimensions> void ShapeRenderer<dimensions>::draw(const typename DimensionTraits<dimensions>::MatrixType&, SceneGraph::AbstractBasicCamera<dimensions, Float>* camera) {
typename DimensionTraits<dimensions>::MatrixType projectionMatrix = camera->projectionMatrix()*camera->cameraMatrix();
for(auto i: renderers) i->draw(options, projectionMatrix);
}

6
src/DebugTools/ShapeRenderer.h

@ -138,7 +138,7 @@ new DebugTools::ShapeRenderer2D(shape, "red", debugDrawables);
@see ShapeRenderer2D, ShapeRenderer3D
*/
template<UnsignedInt dimensions> class MAGNUM_DEBUGTOOLS_EXPORT ShapeRenderer: public SceneGraph::Drawable<dimensions> {
template<UnsignedInt dimensions> class MAGNUM_DEBUGTOOLS_EXPORT ShapeRenderer: public SceneGraph::BasicDrawable<dimensions, Float> {
friend void Implementation::createDebugMesh<>(ShapeRenderer<dimensions>*, const Shapes::Implementation::AbstractShape<dimensions>*);
public:
@ -154,13 +154,13 @@ template<UnsignedInt dimensions> class MAGNUM_DEBUGTOOLS_EXPORT ShapeRenderer: p
* @p shape must be available for the whole lifetime of the renderer
* and if it is group, it must not change its internal structure.
*/
explicit ShapeRenderer(Shapes::AbstractShape<dimensions>* shape, ResourceKey options = ResourceKey(), SceneGraph::DrawableGroup<dimensions>* drawables = nullptr);
explicit ShapeRenderer(Shapes::AbstractShape<dimensions>* shape, ResourceKey options = ResourceKey(), SceneGraph::BasicDrawableGroup<dimensions, Float>* drawables = nullptr);
~ShapeRenderer();
protected:
/** @todoc Remove Float when Doxygen properly treats this as override */
void draw(const typename DimensionTraits<dimensions, Float>::MatrixType& transformationMatrix, SceneGraph::AbstractCamera<dimensions, Float>* camera) override;
void draw(const typename DimensionTraits<dimensions, Float>::MatrixType& transformationMatrix, SceneGraph::AbstractBasicCamera<dimensions, Float>* camera) override;
private:
Resource<ShapeRendererOptions> options;

53
src/SceneGraph/AbstractCamera.h

@ -25,7 +25,7 @@
*/
/** @file
* @brief Class Magnum::SceneGraph::AbstractCamera, enum Magnum::SceneGraph::AspectRatioPolicy, alias Magnum::SceneGraph::AbstractCamera2D, Magnum::SceneGraph::AbstractCamera3D
* @brief Class Magnum::SceneGraph::AbstractBasicCamera, enum Magnum::SceneGraph::AspectRatioPolicy, typedef Magnum::SceneGraph::AbstractCamera2D, Magnum::SceneGraph::AbstractCamera3D
*/
#include "Math/Matrix3.h"
@ -39,7 +39,7 @@ namespace Magnum { namespace SceneGraph {
/**
@brief Camera aspect ratio policy
@see AbstractCamera::setAspectRatioPolicy()
@see AbstractBasicCamera::setAspectRatioPolicy()
*/
enum class AspectRatioPolicy: UnsignedByte {
NotPreserved, /**< Don't preserve aspect ratio (default) */
@ -67,25 +67,20 @@ relevant sections in
@ref Camera3D-explicit-specializations "Camera3D" class documentation or
@ref compilation-speedup-hpp for more information.
- @ref AbstractCamera "AbstractCamera<2, Float>"
- @ref AbstractCamera "AbstractCamera<3, Float>"
- @ref AbstractBasicCamera "AbstractBasicCamera<2, Float>"
- @ref AbstractBasicCamera "AbstractBasicCamera<3, Float>"
@see @ref scenegraph, Drawable, DrawableGroup, AbstractCamera2D, AbstractCamera3D
@see AbstractCamera2D, AbstractCamera3D, @ref scenegraph, Drawable, DrawableGroup
*/
#ifndef DOXYGEN_GENERATING_OUTPUT
template<UnsignedInt dimensions, class T>
#else
template<UnsignedInt dimensions, class T = Float>
#endif
class MAGNUM_SCENEGRAPH_EXPORT AbstractCamera: public AbstractFeature<dimensions, T> {
template<UnsignedInt dimensions, class T> class MAGNUM_SCENEGRAPH_EXPORT AbstractBasicCamera: public AbstractFeature<dimensions, T> {
public:
/**
* @brief Constructor
* @param object Object holding the camera
*/
explicit AbstractCamera(AbstractObject<dimensions, T>* object);
explicit AbstractBasicCamera(AbstractObject<dimensions, T>* object);
virtual ~AbstractCamera() = 0;
virtual ~AbstractBasicCamera() = 0;
/** @brief Aspect ratio policy */
AspectRatioPolicy aspectRatioPolicy() const { return _aspectRatioPolicy; }
@ -94,7 +89,7 @@ class MAGNUM_SCENEGRAPH_EXPORT AbstractCamera: public AbstractFeature<dimensions
* @brief Set aspect ratio policy
* @return Pointer to self (for method chaining)
*/
AbstractCamera<dimensions, T>* setAspectRatioPolicy(AspectRatioPolicy policy);
AbstractBasicCamera<dimensions, T>* setAspectRatioPolicy(AspectRatioPolicy policy);
/**
* @brief Camera matrix
@ -143,7 +138,7 @@ class MAGNUM_SCENEGRAPH_EXPORT AbstractCamera: public AbstractFeature<dimensions
*
* Draws given group of drawables.
*/
virtual void draw(DrawableGroup<dimensions, T>& group);
virtual void draw(BasicDrawableGroup<dimensions, T>& group);
protected:
/** Recalculates camera matrix */
@ -167,37 +162,19 @@ class MAGNUM_SCENEGRAPH_EXPORT AbstractCamera: public AbstractFeature<dimensions
Vector2i _viewport;
};
#ifndef CORRADE_GCC46_COMPATIBILITY
/**
@brief Base for two-dimensional cameras
@brief Base camera for two-dimensional float scenes
Convenience alternative to <tt>%AbstractCamera<2, T></tt>. See AbstractCamera
for more information.
@note Not available on GCC < 4.7. Use <tt>%AbstractCamera<2, T></tt> instead.
@see AbstractCamera3D
*/
#ifdef DOXYGEN_GENERATING_OUTPUT
template<class T = Float>
#else
template<class T>
#endif
using AbstractCamera2D = AbstractCamera<2, T>;
typedef AbstractBasicCamera<2, Float> AbstractCamera2D;
/**
@brief Base for three-dimensional cameras
@brief Base camera for three-dimensional float scenes
Convenience alternative to <tt>%AbstractCamera<3, T></tt>. See AbstractCamera
for more information.
@note Not available on GCC < 4.7. Use <tt>%AbstractCamera<3, T></tt> instead.
@see AbstractCamera2D
@see AbstractBasicCamera2D
*/
#ifdef DOXYGEN_GENERATING_OUTPUT
template<class T = Float>
#else
template<class T>
#endif
using AbstractCamera3D = AbstractCamera<3, T>;
#endif
typedef AbstractBasicCamera<3, Float> AbstractCamera3D;
}}

10
src/SceneGraph/AbstractCamera.hpp

@ -70,24 +70,24 @@ template<UnsignedInt dimensions, class T> typename DimensionTraits<dimensions, T
}
template<UnsignedInt dimensions, class T> AbstractCamera<dimensions, T>::AbstractCamera(AbstractObject<dimensions, T>* object): AbstractFeature<dimensions, T>(object), _aspectRatioPolicy(AspectRatioPolicy::NotPreserved) {
template<UnsignedInt dimensions, class T> AbstractBasicCamera<dimensions, T>::AbstractBasicCamera(AbstractObject<dimensions, T>* object): AbstractFeature<dimensions, T>(object), _aspectRatioPolicy(AspectRatioPolicy::NotPreserved) {
AbstractFeature<dimensions, T>::setCachedTransformations(CachedTransformation::InvertedAbsolute);
}
template<UnsignedInt dimensions, class T> AbstractCamera<dimensions, T>::~AbstractCamera() {}
template<UnsignedInt dimensions, class T> AbstractBasicCamera<dimensions, T>::~AbstractBasicCamera() {}
template<UnsignedInt dimensions, class T> AbstractCamera<dimensions, T>* AbstractCamera<dimensions, T>::setAspectRatioPolicy(AspectRatioPolicy policy) {
template<UnsignedInt dimensions, class T> AbstractBasicCamera<dimensions, T>* AbstractBasicCamera<dimensions, T>::setAspectRatioPolicy(AspectRatioPolicy policy) {
_aspectRatioPolicy = policy;
fixAspectRatio();
return this;
}
template<UnsignedInt dimensions, class T> void AbstractCamera<dimensions, T>::setViewport(const Vector2i& size) {
template<UnsignedInt dimensions, class T> void AbstractBasicCamera<dimensions, T>::setViewport(const Vector2i& size) {
_viewport = size;
fixAspectRatio();
}
template<UnsignedInt dimensions, class T> void AbstractCamera<dimensions, T>::draw(DrawableGroup<dimensions, T>& group) {
template<UnsignedInt dimensions, class T> void AbstractBasicCamera<dimensions, T>::draw(BasicDrawableGroup<dimensions, T>& group) {
AbstractObject<dimensions, T>* scene = AbstractFeature<dimensions, T>::object()->scene();
CORRADE_ASSERT(scene, "Camera::draw(): cannot draw when camera is not part of any scene", );

36
src/SceneGraph/Camera2D.h

@ -1,5 +1,5 @@
#ifndef Magnum_SceneGraph_Camera2D_h
#define Magnum_SceneGraph_Camera2D_h
#ifndef Magnum_SceneGraph_BasicCamera2D_h
#define Magnum_SceneGraph_BasicCamera2D_h
/*
This file is part of Magnum.
@ -25,7 +25,7 @@
*/
/** @file
* @brief Class Magnum::SceneGraph::Camera2D
* @brief Class Magnum::SceneGraph::BasicCamera2D, typedef Magnum::SceneGraph::Camera2D
*/
#include "AbstractCamera.h"
@ -39,7 +39,7 @@ See Drawable documentation for introduction. The camera by default displays
OpenGL unit cube `[(-1, -1, -1); (1, 1, 1)]` and doesn't do any aspect ratio
correction. Common setup example:
@code
SceneGraph::Camera2D<>* camera = new SceneGraph::Camera2D<>(&cameraObject);
SceneGraph::BasicCamera2D<>* camera = new SceneGraph::BasicCamera2D<>(&cameraObject);
camera->setProjection({4.0f/3.0f, 1.0f})
->setAspectRatioPolicy(SceneGraph::AspectRatioPolicy::Extend);
@endcode
@ -48,19 +48,14 @@ camera->setProjection({4.0f/3.0f, 1.0f})
The following specialization are explicitly compiled into SceneGraph library.
For other specializations (e.g. using Double type) you have to use
Camera2D.hpp implementation file to avoid linker errors. See
BasicCamera2D.hpp implementation file to avoid linker errors. See
@ref compilation-speedup-hpp for more information.
- @ref Camera2D "Camera2D<Float>"
- @ref BasicCamera2D "BasicCamera2D<Float>"
@see @ref scenegraph, Camera3D, Drawable, DrawableGroup
@see @ref Camera2D, @ref scenegraph, @ref BasicCamera3D, @ref BasicDrawable, @ref BasicDrawableGroup
*/
#ifndef DOXYGEN_GENERATING_OUTPUT
template<class T>
#else
template<class T = Float>
#endif
class MAGNUM_SCENEGRAPH_EXPORT Camera2D: public AbstractCamera<2, T> {
template<class T> class MAGNUM_SCENEGRAPH_EXPORT BasicCamera2D: public AbstractBasicCamera<2, T> {
public:
/**
* @brief Constructor
@ -69,7 +64,7 @@ class MAGNUM_SCENEGRAPH_EXPORT Camera2D: public AbstractCamera<2, T> {
* Sets orthographic projection to the default OpenGL cube (range @f$ [-1; 1] @f$ in all directions).
* @see setProjection()
*/
explicit Camera2D(AbstractObject<2, T>* object);
explicit BasicCamera2D(AbstractObject<2, T>* object);
/**
* @brief Set projection
@ -78,17 +73,24 @@ class MAGNUM_SCENEGRAPH_EXPORT Camera2D: public AbstractCamera<2, T> {
*
* @see Matrix3::projection()
*/
Camera2D<T>* setProjection(const Math::Vector2<T>& size);
BasicCamera2D<T>* setProjection(const Math::Vector2<T>& size);
/* Overloads to remove WTF-factor from method chaining order */
#ifndef DOXYGEN_GENERATING_OUTPUT
Camera2D<T>* setAspectRatioPolicy(AspectRatioPolicy policy) {
AbstractCamera<2, T>::setAspectRatioPolicy(policy);
BasicCamera2D<T>* setAspectRatioPolicy(AspectRatioPolicy policy) {
AbstractBasicCamera<2, T>::setAspectRatioPolicy(policy);
return this;
}
#endif
};
/**
@brief Camera for two-dimensional float scenes
@see @ref Camera3D
*/
typedef BasicCamera2D<Float> Camera2D;
}}
#endif

8
src/SceneGraph/Camera2D.hpp

@ -35,12 +35,12 @@ using namespace std;
namespace Magnum { namespace SceneGraph {
template<class T> Camera2D<T>::Camera2D(AbstractObject<2, T>* object): AbstractCamera<2, T>(object) {}
template<class T> BasicCamera2D<T>::BasicCamera2D(AbstractObject<2, T>* object): AbstractBasicCamera<2, T>(object) {}
template<class T> Camera2D<T>* Camera2D<T>::setProjection(const Math::Vector2<T>& size) {
AbstractCamera<2, T>::rawProjectionMatrix = Math::Matrix3<T>::projection(size);
template<class T> BasicCamera2D<T>* BasicCamera2D<T>::setProjection(const Math::Vector2<T>& size) {
AbstractBasicCamera<2, T>::rawProjectionMatrix = Math::Matrix3<T>::projection(size);
AbstractCamera<2, T>::fixAspectRatio();
AbstractBasicCamera<2, T>::fixAspectRatio();
return this;
}

36
src/SceneGraph/Camera3D.h

@ -25,7 +25,7 @@
*/
/** @file
* @brief Class Magnum::SceneGraph::Camera3D
* @brief Class Magnum::SceneGraph::BasicCamera3D, typedef Magnum::SceneGraph::Camera3D
*/
#include "AbstractCamera.h"
@ -44,7 +44,7 @@ See Drawable documentation for introduction. The camera by default displays
OpenGL unit cube `[(-1, -1, -1); (1, 1, 1)]` with orthographic projection and
doesn't do any aspect ratio correction. Common setup example:
@code
SceneGraph::Camera3D<>* camera = new SceneGraph::Camera3D<>(&cameraObject);
SceneGraph::BasicCamera3D<>* camera = new SceneGraph::BasicCamera3D<>(&cameraObject);
camera->setPerspective({}, 0.001f, 100.0f)
->setAspectRatioPolicy(SceneGraph::AspectRatioPolicy::Extend);
@endcode
@ -53,25 +53,20 @@ camera->setPerspective({}, 0.001f, 100.0f)
The following specialization are explicitly compiled into SceneGraph library.
For other specializations (e.g. using Double type) you have to use
Camera3D.hpp implementation file to avoid linker errors. See
BasicCamera3D.hpp implementation file to avoid linker errors. See
@ref compilation-speedup-hpp for more information.
- @ref Camera3D "Camera3D<Float>"
- @ref BasicCamera3D "BasicCamera3D<Float>"
@see @ref scenegraph, Camera2D, Drawable, DrawableGroup
@see @ref Camera3D, @ref scenegraph, @ref BasicCamera2D, @ref BasicDrawable, @ref BasicDrawableGroup
*/
#ifndef DOXYGEN_GENERATING_OUTPUT
template<class T>
#else
template<class T = Float>
#endif
class MAGNUM_SCENEGRAPH_EXPORT Camera3D: public AbstractCamera<3, T> {
template<class T> class MAGNUM_SCENEGRAPH_EXPORT BasicCamera3D: public AbstractBasicCamera<3, T> {
public:
/**
* @brief Constructor
* @param object %Object holding this feature
*/
explicit Camera3D(AbstractObject<3, T>* object);
explicit BasicCamera3D(AbstractObject<3, T>* object);
/**
* @brief Set orthographic projection
@ -82,7 +77,7 @@ class MAGNUM_SCENEGRAPH_EXPORT Camera3D: public AbstractCamera<3, T> {
*
* @see setPerspective(), Matrix4::orthographicProjection()
*/
Camera3D<T>* setOrthographic(const Math::Vector2<T>& size, T near, T far);
BasicCamera3D<T>* setOrthographic(const Math::Vector2<T>& size, T near, T far);
/**
* @brief Set perspective projection
@ -93,7 +88,7 @@ class MAGNUM_SCENEGRAPH_EXPORT Camera3D: public AbstractCamera<3, T> {
*
* @see setOrthographic(), Matrix4::perspectiveProjection()
*/
Camera3D<T>* setPerspective(const Math::Vector2<T>& size, T near, T far);
BasicCamera3D<T>* setPerspective(const Math::Vector2<T>& size, T near, T far);
/**
* @brief Set perspective projection
@ -105,7 +100,7 @@ class MAGNUM_SCENEGRAPH_EXPORT Camera3D: public AbstractCamera<3, T> {
*
* @see setOrthographic(), Matrix4::perspectiveProjection()
*/
Camera3D<T>* setPerspective(Math::Rad<T> fov, T aspectRatio, T near, T far);
BasicCamera3D<T>* setPerspective(Math::Rad<T> fov, T aspectRatio, T near, T far);
/** @brief Near clipping plane */
T near() const { return _near; }
@ -115,8 +110,8 @@ class MAGNUM_SCENEGRAPH_EXPORT Camera3D: public AbstractCamera<3, T> {
/* Overloads to remove WTF-factor from method chaining order */
#ifndef DOXYGEN_GENERATING_OUTPUT
Camera3D<T>* setAspectRatioPolicy(AspectRatioPolicy policy) {
AbstractCamera<3, T>::setAspectRatioPolicy(policy);
BasicCamera3D<T>* setAspectRatioPolicy(AspectRatioPolicy policy) {
AbstractBasicCamera<3, T>::setAspectRatioPolicy(policy);
return this;
}
#endif
@ -125,6 +120,13 @@ class MAGNUM_SCENEGRAPH_EXPORT Camera3D: public AbstractCamera<3, T> {
T _near, _far;
};
/**
@brief Camera for three-dimensional float scenes
@see @ref Camera2D
*/
typedef BasicCamera3D<Float> Camera3D;
}}
#endif

20
src/SceneGraph/Camera3D.hpp

@ -33,35 +33,35 @@
namespace Magnum { namespace SceneGraph {
template<class T> Camera3D<T>::Camera3D(AbstractObject<3, T>* object): AbstractCamera<3, T>(object), _near(T(0)), _far(T(0)) {}
template<class T> BasicCamera3D<T>::BasicCamera3D(AbstractObject<3, T>* object): AbstractBasicCamera<3, T>(object), _near(T(0)), _far(T(0)) {}
template<class T> Camera3D<T>* Camera3D<T>::setOrthographic(const Math::Vector2<T>& size, T near, T far) {
template<class T> BasicCamera3D<T>* BasicCamera3D<T>::setOrthographic(const Math::Vector2<T>& size, T near, T far) {
/** @todo Get near/far from the matrix */
_near = near;
_far = far;
AbstractCamera<3, T>::rawProjectionMatrix = Math::Matrix4<T>::orthographicProjection(size, near, far);
AbstractCamera<3, T>::fixAspectRatio();
AbstractBasicCamera<3, T>::rawProjectionMatrix = Math::Matrix4<T>::orthographicProjection(size, near, far);
AbstractBasicCamera<3, T>::fixAspectRatio();
return this;
}
template<class T> Camera3D<T>* Camera3D<T>::setPerspective(const Math::Vector2<T>& size, T near, T far) {
template<class T> BasicCamera3D<T>* BasicCamera3D<T>::setPerspective(const Math::Vector2<T>& size, T near, T far) {
/** @todo Get near/far from the matrix */
_near = near;
_far = far;
AbstractCamera<3, T>::rawProjectionMatrix = Math::Matrix4<T>::perspectiveProjection(size, near, far);
AbstractCamera<3, T>::fixAspectRatio();
AbstractBasicCamera<3, T>::rawProjectionMatrix = Math::Matrix4<T>::perspectiveProjection(size, near, far);
AbstractBasicCamera<3, T>::fixAspectRatio();
return this;
}
template<class T> Camera3D<T>* Camera3D<T>::setPerspective(Math::Rad<T> fov, T aspectRatio, T near, T far) {
template<class T> BasicCamera3D<T>* BasicCamera3D<T>::setPerspective(Math::Rad<T> fov, T aspectRatio, T near, T far) {
/** @todo Get near/far from the matrix */
_near = near;
_far = far;
AbstractCamera<3, T>::rawProjectionMatrix = Math::Matrix4<T>::perspectiveProjection(fov, aspectRatio, near, far);
AbstractCamera<3, T>::fixAspectRatio();
AbstractBasicCamera<3, T>::rawProjectionMatrix = Math::Matrix4<T>::perspectiveProjection(fov, aspectRatio, near, far);
AbstractBasicCamera<3, T>::fixAspectRatio();
return this;
}

99
src/SceneGraph/Drawable.h

@ -25,7 +25,7 @@
*/
/** @file
* @brief Class Magnum::SceneGraph::Drawable, Magnum::SceneGraph::DrawableGroup, alias Magnum::SceneGraph::Drawable2D, Magnum::SceneGraph::Drawable3D, Magnum::SceneGraph::DrawableGroup2D, Magnum::SceneGraph::DrawableGroup3D
* @brief Class Magnum::SceneGraph::BasicDrawable, Magnum::SceneGraph::BasicDrawableGroup, typedef Magnum::SceneGraph::Drawable2D, Magnum::SceneGraph::Drawable3D, Magnum::SceneGraph::DrawableGroup2D, Magnum::SceneGraph::DrawableGroup3D
*/
#include "AbstractGroupedFeature.h"
@ -35,7 +35,7 @@ namespace Magnum { namespace SceneGraph {
/**
@brief %Drawable
Adds drawing function to the object. Each %Drawable is part of some DrawableGroup
Adds drawing function to the object. Each Drawable is part of some DrawableGroup
and the whole group is drawn with particular camera using AbstractCamera::draw().
@section Drawable-usage Usage
@ -47,24 +47,24 @@ for introduction). Example:
typedef SceneGraph::Object<SceneGraph::MatrixTransformation3D<>> Object3D;
typedef SceneGraph::Scene<SceneGraph::MatrixTransformation3D<>> Scene3D;
class DrawableObject: public Object3D, SceneGraph::Drawable3D<> {
class DrawableObject: public Object3D, SceneGraph::Drawable3D {
public:
DrawableObject(Object* parent = nullptr, SceneGraph::DrawableGroup3D<>* group = nullptr): Object3D(parent), SceneGraph::Drawable3D<>(this, group) {
DrawableObject(Object* parent = nullptr, SceneGraph::DrawableGroup3D* group = nullptr): Object3D(parent), SceneGraph::Drawable3D(this, group) {
// ...
}
void draw(const Matrix4& transformationMatrix, AbstractCamera3D<>* camera) override {
void draw(const Matrix4& transformationMatrix, AbstractCamera3D* camera) override {
// ...
}
}
@endcode
Then you add these objects to your scene and some drawable group and transform
them as you like. You can also use DrawableGroup::add() and
DrawableGroup::remove().
them as you like. You can also use BasicDrawableGroup::add() and
BasicDrawableGroup::remove().
@code
Scene3D scene;
SceneGraph::DrawableGroup3D<> drawables;
SceneGraph::DrawableGroup3D drawables;
(new DrawableObject(&scene, &drawables))
->translate(Vector3::yAxis(-0.3f))
@ -97,7 +97,7 @@ parameters once for whole group instead of setting them again in each draw()
implementation. Example:
@code
Shaders::PhongShader* shader;
SceneGraph::DrawableGroup3D<> phongObjects, transparentObjects;
SceneGraph::DrawableGroup3D phongObjects, transparentObjects;
void MyApplication::drawEvent() {
shader->setProjectionMatrix(camera->projectionMatrix())
@ -114,14 +114,9 @@ void MyApplication::drawEvent() {
}
@endcode
@see @ref scenegraph, Drawable2D, Drawable3D, DrawableGroup2D, DrawableGroup3D
@see Drawable2D, Drawable3D, @ref scenegraph, DrawableGroup2D, DrawableGroup3D
*/
#ifndef DOXYGEN_GENERATING_OUTPUT
template<UnsignedInt dimensions, class T>
#else
template<UnsignedInt dimensions, class T = Float>
#endif
class Drawable: public AbstractGroupedFeature<dimensions, Drawable<dimensions, T>, T> {
template<UnsignedInt dimensions, class T> class BasicDrawable: public AbstractGroupedFeature<dimensions, BasicDrawable<dimensions, T>, T> {
public:
/**
* @brief Constructor
@ -129,9 +124,9 @@ class Drawable: public AbstractGroupedFeature<dimensions, Drawable<dimensions, T
* @param drawables Group this drawable belongs to
*
* Adds the feature to the object and also to the group, if specified.
* Otherwise you can use DrawableGroup::add().
* Otherwise you can use BasicDrawableGroup::add().
*/
explicit Drawable(AbstractObject<dimensions, T>* object, DrawableGroup<dimensions, T>* drawables = nullptr): AbstractGroupedFeature<dimensions, Drawable<dimensions, T>, T>(object, drawables) {}
explicit BasicDrawable(AbstractObject<dimensions, T>* object, BasicDrawableGroup<dimensions, T>* drawables = nullptr): AbstractGroupedFeature<dimensions, BasicDrawable<dimensions, T>, T>(object, drawables) {}
/**
* @brief Draw the object using given camera
@ -141,40 +136,22 @@ class Drawable: public AbstractGroupedFeature<dimensions, Drawable<dimensions, T
*
* Projection matrix can be retrieved from AbstractCamera::projectionMatrix().
*/
virtual void draw(const typename DimensionTraits<dimensions, T>::MatrixType& transformationMatrix, AbstractCamera<dimensions, T>* camera) = 0;
virtual void draw(const typename DimensionTraits<dimensions, T>::MatrixType& transformationMatrix, AbstractBasicCamera<dimensions, T>* camera) = 0;
};
#ifndef CORRADE_GCC46_COMPATIBILITY
/**
@brief Two-dimensional drawable
@brief Two-dimensional drawable for float scenes
Convenience alternative to <tt>%Drawable<2, T></tt>. See Drawable for more
information.
@note Not available on GCC < 4.7. Use <tt>%Drawable<2, T></tt> instead.
@see Drawable3D
*/
#ifdef DOXYGEN_GENERATING_OUTPUT
template<class T = Float>
#else
template<class T>
#endif
using Drawable2D = Drawable<2, T>;
typedef BasicDrawable<2, Float> Drawable2D;
/**
@brief Three-dimensional drawable
@brief Three-dimensional drawable for float scenes
Convenience alternative to <tt>%Drawable<3, T></tt>. See Drawable for more
information.
@note Not available on GCC < 4.7. Use <tt>%Drawable<3, T></tt> instead.
@see Drawable2D
*/
#ifdef DOXYGEN_GENERATING_OUTPUT
template<class T = Float>
#else
template<class T>
#endif
using Drawable3D = Drawable<3, T>;
#endif
typedef BasicDrawable<3, Float> Drawable3D;
/**
@brief Group of drawables
@ -183,52 +160,24 @@ See Drawable for more information.
@see @ref scenegraph, DrawableGroup2D, DrawableGroup3D
*/
#ifndef CORRADE_GCC46_COMPATIBILITY
#ifdef DOXYGEN_GENERATING_OUTPUT
template<UnsignedInt dimensions, class T = Float>
#else
template<UnsignedInt dimensions, class T>
#endif
using DrawableGroup = FeatureGroup<dimensions, Drawable<dimensions, T>, T>;
#else
#ifdef DOXYGEN_GENERATING_OUTPUT
template<UnsignedInt dimensions, class T = Float>
template<UnsignedInt dimensions, class T> using BasicDrawableGroup = FeatureGroup<dimensions, BasicDrawable<dimensions, T>, T>;
#else
template<UnsignedInt dimensions, class T>
#endif
class DrawableGroup: public FeatureGroup<dimensions, Drawable<dimensions, T>, T> {};
template<UnsignedInt dimensions, class T> class BasicDrawableGroup: public FeatureGroup<dimensions, BasicDrawable<dimensions, T>, T> {};
#endif
#ifndef CORRADE_GCC46_COMPATIBILITY
/**
@brief Group of two-dimensional drawables
@brief Group of two-dimensional drawables for float scenes
Convenience alternative to <tt>%DrawableGroup<2, T></tt>. See Drawable for
more information.
@note Not available on GCC < 4.7. Use <tt>%Drawable<2, T></tt> instead.
@see DrawableGroup3D
*/
#ifdef DOXYGEN_GENERATING_OUTPUT
template<class T = Float>
#else
template<class T>
#endif
using DrawableGroup2D = DrawableGroup<2, T>;
typedef BasicDrawableGroup<2, Float> DrawableGroup2D;
/**
@brief Group of three-dimensional drawables
@brief Group of three-dimensional drawables for float scenes
Convenience alternative to <tt>%DrawableGroup<3, T></tt>. See Drawable for
more information.
@note Not available on GCC < 4.7. Use <tt>%Drawable<3, T></tt> instead.
@see DrawableGroup2D
*/
#ifdef DOXYGEN_GENERATING_OUTPUT
template<class T = Float>
#else
template<class T>
#endif
using DrawableGroup3D = DrawableGroup<3, T>;
#endif
typedef BasicDrawableGroup<3, Float> DrawableGroup3D;
}}

30
src/SceneGraph/SceneGraph.h

@ -38,11 +38,9 @@ namespace Magnum { namespace SceneGraph {
#ifndef DOXYGEN_GENERATING_OUTPUT
enum class AspectRatioPolicy: UnsignedByte;
template<UnsignedInt dimensions, class T = Float> class AbstractCamera;
#ifndef CORRADE_GCC46_COMPATIBILITY
template<class T = Float> using AbstractCamera2D = AbstractCamera<2, T>;
template<class T = Float> using AbstractCamera3D = AbstractCamera<3, T>;
#endif
template<UnsignedInt, class> class AbstractBasicCamera;
typedef AbstractBasicCamera<2, Float> AbstractCamera2D;
typedef AbstractBasicCamera<3, Float> AbstractCamera3D;
/* Enum CachedTransformation and CachedTransformations used only directly */
@ -97,14 +95,14 @@ template<class T = Float> using AnimableGroup2D = AnimableGroup<2, T>;
template<class T = Float> using AnimableGroup3D = AnimableGroup<3, T>;
#endif
template<class T = Float> class Camera2D;
template<class T = Float> class Camera3D;
template<class> class BasicCamera2D;
template<class> class BasicCamera3D;
typedef BasicCamera2D<Float> Camera2D;
typedef BasicCamera3D<Float> Camera3D;
template<UnsignedInt dimensions, class T = Float> class Drawable;
#ifndef CORRADE_GCC46_COMPATIBILITY
template<class T = Float> using Drawable2D = Drawable<2, T>;
template<class T = Float> using Drawable3D = Drawable<3, T>;
#endif
template<UnsignedInt, class> class BasicDrawable;
typedef BasicDrawable<2, Float> Drawable2D;
typedef BasicDrawable<3, Float> Drawable3D;
template<class T = Float> class DualComplexTransformation;
template<class T = Float> class DualQuaternionTransformation;
@ -116,12 +114,12 @@ template<class Feature, class T = Float> using FeatureGroup3D = FeatureGroup<3,
#endif
#ifndef CORRADE_GCC46_COMPATIBILITY
template<UnsignedInt dimensions, class T = Float> using DrawableGroup = FeatureGroup<dimensions, Drawable<dimensions, T>, T>;
template<class T = Float> using DrawableGroup2D = DrawableGroup<2, T>;
template<class T = Float> using DrawableGroup3D = DrawableGroup<3, T>;
template<UnsignedInt dimensions, class T> using BasicDrawableGroup = FeatureGroup<dimensions, BasicDrawable<dimensions, T>, T>;
#else
template<UnsignedInt dimensions, class T = Float> class DrawableGroup;
template<UnsignedInt, class> class BasicDrawableGroup;
#endif
typedef BasicDrawableGroup<2, Float> DrawableGroup2D;
typedef BasicDrawableGroup<3, Float> DrawableGroup3D;
template<class T = Float> class MatrixTransformation2D;
template<class T = Float> class MatrixTransformation3D;

10
src/SceneGraph/Test/CameraTest.cpp

@ -51,8 +51,6 @@ class CameraTest: public TestSuite::Tester {
typedef SceneGraph::Object<SceneGraph::MatrixTransformation2D<>> Object2D;
typedef SceneGraph::Object<SceneGraph::MatrixTransformation3D<>> Object3D;
typedef SceneGraph::Scene<SceneGraph::MatrixTransformation3D<>> Scene3D;
typedef SceneGraph::Camera2D<> Camera2D;
typedef SceneGraph::Camera3D<> Camera3D;
CameraTest::CameraTest() {
addTests({&CameraTest::fixAspectRatio,
@ -158,12 +156,12 @@ void CameraTest::projectionSizeViewport() {
}
void CameraTest::draw() {
class Drawable: public SceneGraph::Drawable<3> {
class Drawable: public SceneGraph::Drawable3D {
public:
Drawable(AbstractObject<3>* object, DrawableGroup<3>* group, Matrix4& result): SceneGraph::Drawable<3>(object, group), result(result) {}
Drawable(AbstractObject<3>* object, DrawableGroup3D* group, Matrix4& result): SceneGraph::Drawable3D(object, group), result(result) {}
protected:
void draw(const Matrix4& transformationMatrix, AbstractCamera<3>*) {
void draw(const Matrix4& transformationMatrix, AbstractCamera3D*) {
result = transformationMatrix;
}
@ -171,7 +169,7 @@ void CameraTest::draw() {
Matrix4& result;
};
DrawableGroup<3> group;
DrawableGroup3D group;
Scene3D scene;
Object3D first(&scene);

8
src/SceneGraph/instantiation.cpp

@ -47,10 +47,10 @@ template class MAGNUM_SCENEGRAPH_EXPORT AbstractFeature<3, Float>;
template class AbstractFeatureGroup<2, Float>;
template class AbstractFeatureGroup<3, Float>;
template class AbstractCamera<2, Float>;
template class AbstractCamera<3, Float>;
template class Camera2D<Float>;
template class Camera3D<Float>;
template class AbstractBasicCamera<2, Float>;
template class AbstractBasicCamera<3, Float>;
template class BasicCamera2D<Float>;
template class BasicCamera3D<Float>;
template class MAGNUM_SCENEGRAPH_EXPORT Object<DualComplexTransformation<Float>>;
template class MAGNUM_SCENEGRAPH_EXPORT Object<DualQuaternionTransformation<Float>>;

Loading…
Cancel
Save