From 9d9517c824780016aaca62e333f4cf85019cfeb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 11 Nov 2012 01:04:27 +0100 Subject: [PATCH 01/14] Vector::angle(): reflect normalization requirement in parameter names. Will be more intuitive when IDE autocompletion kicks in. --- src/Math/Vector.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 5beb7e22c..57f2509d6 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -61,10 +61,10 @@ template class Vector: public RectangularMatrix<1, si * @attention Assertion fails on non-normalized vectors and NaN is * returned. */ - inline static T angle(const Vector& a, const Vector& b) { - CORRADE_ASSERT(MathTypeTraits::equals(a.dot(), T(1)) && MathTypeTraits::equals(b.dot(), T(1)), + inline static T angle(const Vector& normalizedA, const Vector& normalizedB) { + CORRADE_ASSERT(MathTypeTraits::equals(normalizedA.dot(), T(1)) && MathTypeTraits::equals(normalizedB.dot(), T(1)), "Math::Vector::angle(): vectors must be normalized", std::numeric_limits::quiet_NaN()); - return std::acos(dot(a, b)); + return std::acos(dot(normalizedA, normalizedB)); } /** @brief Default constructor */ From e508da2b6a2ac6c2cdd1b616b68433e9ad45a3b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 11 Nov 2012 01:14:40 +0100 Subject: [PATCH 02/14] Moved AspectRatioPolicy enum out of Camera class. It was pain to type it with all the template parameters (`typename AbstractCamera::AspectRatioPolicy`, `Camera3D<>::AspectRatioPolicy::Extend`...) and it looked like it is different for each camera template (which internally wasn't). --- src/SceneGraph/Camera.h | 36 +++++++++++------------------- src/SceneGraph/Test/CameraTest.cpp | 22 +++++++++--------- 2 files changed, 24 insertions(+), 34 deletions(-) diff --git a/src/SceneGraph/Camera.h b/src/SceneGraph/Camera.h index 37d0bed94..e9637fb70 100644 --- a/src/SceneGraph/Camera.h +++ b/src/SceneGraph/Camera.h @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::SceneGraph::AbstractCamera, Magnum::SceneGraph::Camera2D, Magnum::SceneGraph::Camera3D, alias Magnum::SceneGraph::AbstractCamera2D, Magnum::SceneGraph::AbstractCamera3D + * @brief Class Magnum::SceneGraph::AbstractCamera, Magnum::SceneGraph::Camera2D, Magnum::SceneGraph::Camera3D, enum AspectRatioPolicy, alias Magnum::SceneGraph::AbstractCamera2D, Magnum::SceneGraph::AbstractCamera3D */ #include "Math/Matrix3.h" @@ -40,14 +40,19 @@ template using DrawableGroup = Featu template class DrawableGroup; #endif -/** @todo Export implementation symbols only for tests */ +/** @relates AbstractCamera +@brief Camera aspect ratio policy + +@see AbstractCamera::setAspectRatioPolicy() +*/ +enum class AspectRatioPolicy { + NotPreserved, /**< Don't preserve aspect ratio (default) */ + Extend, /**< Extend on larger side of view */ + Clip /**< Clip on smaller side of view */ +}; #ifndef DOXYGEN_GENERATING_OUTPUT namespace Implementation { - enum class AspectRatioPolicy { - NotPreserved, Extend, Clip - }; - template typename DimensionTraits::MatrixType aspectRatioFix(AspectRatioPolicy aspectRatioPolicy, const Math::Vector2& projectionScale, const Math::Vector2& viewport); } #endif @@ -71,21 +76,6 @@ avoid linker errors. See @ref compilation-speedup-hpp for more information. */ template class SCENEGRAPH_EXPORT AbstractCamera: public AbstractFeature { public: - /** - * @brief Aspect ratio policy - * - * @see aspectRatioPolicy(), setAspectRatioPolicy() - */ - #ifndef DOXYGEN_GENERATING_OUTPUT - typedef Implementation::AspectRatioPolicy AspectRatioPolicy; - #else - enum class AspectRatioPolicy { - NotPreserved, /**< Don't preserve aspect ratio (default) */ - Extend, /**< Extend on larger side of view */ - Clip /**< Clip on smaller side of view */ - }; - #endif - /** * @brief Constructor * @param object Object holding the camera @@ -250,7 +240,7 @@ template class SCENEGRAPH_EXPORT Camera2D: public AbstractCam /* Overloads to remove WTF-factor from method chaining order */ #ifndef DOXYGEN_GENERATING_OUTPUT - inline Camera2D* setAspectRatioPolicy(typename AbstractCamera<2, T>::AspectRatioPolicy policy) { + inline Camera2D* setAspectRatioPolicy(AspectRatioPolicy policy) { AbstractCamera<2, T>::setAspectRatioPolicy(policy); return this; } @@ -314,7 +304,7 @@ template class SCENEGRAPH_EXPORT Camera3D: public AbstractCam /* Overloads to remove WTF-factor from method chaining order */ #ifndef DOXYGEN_GENERATING_OUTPUT - inline Camera3D* setAspectRatioPolicy(typename AbstractCamera<3, T>::AspectRatioPolicy policy) { + inline Camera3D* setAspectRatioPolicy(AspectRatioPolicy policy) { AbstractCamera<3, T>::setAspectRatioPolicy(policy); return this; } diff --git a/src/SceneGraph/Test/CameraTest.cpp b/src/SceneGraph/Test/CameraTest.cpp index 36f901ed0..fa33df768 100644 --- a/src/SceneGraph/Test/CameraTest.cpp +++ b/src/SceneGraph/Test/CameraTest.cpp @@ -52,37 +52,37 @@ void CameraTest::fixAspectRatio() { Vector2 projectionScaleZeroX(0.0f, 0.5f); Math::Vector2 sizeZeroY(400, 0); Math::Vector2 sizeZeroX(0, 300); - CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(Implementation::AspectRatioPolicy::Clip, projectionScaleZeroX, size)), Matrix4()); - CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(Implementation::AspectRatioPolicy::Clip, projectionScaleZeroY, size)), Matrix4()); - CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(Implementation::AspectRatioPolicy::Clip, projectionScale, sizeZeroY)), Matrix4()); - CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(Implementation::AspectRatioPolicy::Extend, projectionScale, sizeZeroX)), Matrix4()); + CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(AspectRatioPolicy::Clip, projectionScaleZeroX, size)), Matrix4()); + CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(AspectRatioPolicy::Clip, projectionScaleZeroY, size)), Matrix4()); + CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(AspectRatioPolicy::Clip, projectionScale, sizeZeroY)), Matrix4()); + CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(AspectRatioPolicy::Extend, projectionScale, sizeZeroX)), Matrix4()); /* Not preserved */ - CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(Implementation::AspectRatioPolicy::NotPreserved, projectionScale, size)), Matrix4()); + CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(AspectRatioPolicy::NotPreserved, projectionScale, size)), Matrix4()); /* Clip */ Matrix4 expectedClip(1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 4.0f/3.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f); - CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(Implementation::AspectRatioPolicy::Clip, Vector2(0.5f), size)), expectedClip); + CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(AspectRatioPolicy::Clip, Vector2(0.5f), size)), expectedClip); Matrix4 expectedClipRectangle(1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f); - CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(Implementation::AspectRatioPolicy::Clip, projectionScale, size)), expectedClipRectangle); + CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(AspectRatioPolicy::Clip, projectionScale, size)), expectedClipRectangle); /* Extend */ Matrix4 expectedExtend(3.0f/4.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f); - CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(Implementation::AspectRatioPolicy::Extend, Vector2(0.5f), size)), expectedExtend); + CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(AspectRatioPolicy::Extend, Vector2(0.5f), size)), expectedExtend); Matrix4 expectedExtendRectangle(0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f); - CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(Implementation::AspectRatioPolicy::Extend, projectionScale, size)), expectedExtendRectangle); + CORRADE_COMPARE((Implementation::aspectRatioFix<3, GLfloat>(AspectRatioPolicy::Extend, projectionScale, size)), expectedExtendRectangle); } void CameraTest::defaultProjection2D() { @@ -159,10 +159,10 @@ void CameraTest::projectionSizeViewport() { camera.setViewport({200, 300}); CORRADE_COMPARE(camera.projectionSize(), Vector2(2.0f, 2.0f)); - camera.setAspectRatioPolicy(Camera3D::AspectRatioPolicy::Extend); + camera.setAspectRatioPolicy(AspectRatioPolicy::Extend); CORRADE_COMPARE(camera.projectionSize(), Vector2(2.0f, 3.0f)); - camera.setAspectRatioPolicy(Camera3D::AspectRatioPolicy::Clip); + camera.setAspectRatioPolicy(AspectRatioPolicy::Clip); CORRADE_COMPARE(camera.projectionSize(), Vector2(4.0f/3.0f, 2.0f)); } From 616c4101cb3d4fef75f0a66e2c8b2d63fdaf935a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 11 Nov 2012 01:43:41 +0100 Subject: [PATCH 03/14] Doc++ --- src/SceneGraph/AbstractGroupedFeature.h | 2 +- src/SceneGraph/AbstractObject.h | 6 +++--- src/SceneGraph/Camera.h | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/SceneGraph/AbstractGroupedFeature.h b/src/SceneGraph/AbstractGroupedFeature.h index a60ba6c55..3a5114dcd 100644 --- a/src/SceneGraph/AbstractGroupedFeature.h +++ b/src/SceneGraph/AbstractGroupedFeature.h @@ -33,7 +33,7 @@ template class FeatureGroup; Used together with FeatureGroup. -@section AbstractGroupedFeature-usage Usage +@section AbstractGroupedFeature-subclassing Subclassing Usage is via subclassing the feature using [CRTP](http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern) and typedef'ing FeatureGroup to accept only given type, e.g.: diff --git a/src/SceneGraph/AbstractObject.h b/src/SceneGraph/AbstractObject.h index 286e56f2b..63d962981 100644 --- a/src/SceneGraph/AbstractObject.h +++ b/src/SceneGraph/AbstractObject.h @@ -33,9 +33,9 @@ template class AbstractFeature; /** @brief Base for objects -Provides minimal interface for features, not depending on object -transformation implementation. See Object or @ref scenegraph for more -information. +Provides minimal interface for features, not depending on object transformation +implementation. This class is not directly instantiatable, use Object subclass +instead. See also @ref scenegraph for more information. @see AbstractObject2D, AbstractObject3D */ diff --git a/src/SceneGraph/Camera.h b/src/SceneGraph/Camera.h index e9637fb70..96056e300 100644 --- a/src/SceneGraph/Camera.h +++ b/src/SceneGraph/Camera.h @@ -60,7 +60,8 @@ namespace Implementation { /** @brief Base for cameras -See Drawable documentation for more information. +See Drawable documentation for more information. This class is not directly +instantiatable, use Camera2D or Camera3D subclasses instead. @section AbstractCamera-explicit-specializations Explicit template specializations From 767c9d6166fa5b8215453fe61323643f8ea80540 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 11 Nov 2012 02:12:00 +0100 Subject: [PATCH 04/14] SceneGraph: AbstractCamera, Camera2D, Camera3D are now in separate files. --- src/SceneGraph/{Camera.h => AbstractCamera.h} | 133 ++---------------- .../{Camera.hpp => AbstractCamera.hpp} | 55 +------- src/SceneGraph/CMakeLists.txt | 8 +- src/SceneGraph/Camera.cpp | 5 +- src/SceneGraph/Camera2D.h | 73 ++++++++++ src/SceneGraph/Camera2D.hpp | 39 +++++ src/SceneGraph/Camera3D.h | 100 +++++++++++++ src/SceneGraph/Camera3D.hpp | 67 +++++++++ src/SceneGraph/Test/CameraTest.cpp | 6 +- 9 files changed, 304 insertions(+), 182 deletions(-) rename src/SceneGraph/{Camera.h => AbstractCamera.h} (60%) rename src/SceneGraph/{Camera.hpp => AbstractCamera.hpp} (68%) create mode 100644 src/SceneGraph/Camera2D.h create mode 100644 src/SceneGraph/Camera2D.hpp create mode 100644 src/SceneGraph/Camera3D.h create mode 100644 src/SceneGraph/Camera3D.hpp diff --git a/src/SceneGraph/Camera.h b/src/SceneGraph/AbstractCamera.h similarity index 60% rename from src/SceneGraph/Camera.h rename to src/SceneGraph/AbstractCamera.h index 96056e300..48c7890d2 100644 --- a/src/SceneGraph/Camera.h +++ b/src/SceneGraph/AbstractCamera.h @@ -1,5 +1,5 @@ -#ifndef Magnum_SceneGraph_Camera_h -#define Magnum_SceneGraph_Camera_h +#ifndef Magnum_SceneGraph_AbstractCamera_h +#define Magnum_SceneGraph_AbstractCamera_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::SceneGraph::AbstractCamera, Magnum::SceneGraph::Camera2D, Magnum::SceneGraph::Camera3D, enum AspectRatioPolicy, alias Magnum::SceneGraph::AbstractCamera2D, Magnum::SceneGraph::AbstractCamera3D + * @brief Class Magnum::SceneGraph::AbstractCamera, enum AspectRatioPolicy, alias Magnum::SceneGraph::AbstractCamera2D, Magnum::SceneGraph::AbstractCamera3D */ #include "Math/Matrix3.h" @@ -25,11 +25,6 @@ #include "magnumSceneGraphVisibility.h" -#ifdef WIN32 /* I so HATE windows.h */ -#undef near -#undef far -#endif - namespace Magnum { namespace SceneGraph { template class Drawable; @@ -66,14 +61,16 @@ instantiatable, use Camera2D or Camera3D subclasses instead. @section AbstractCamera-explicit-specializations Explicit template specializations The following specialization are explicitly compiled into SceneGraph library. -For other specializations you have to use Camera.hpp implementation file to -avoid linker errors. See @ref compilation-speedup-hpp for more information. +For other specializations you have to use AbstractCamera.hpp implementation +file to avoid linker errors. See also relevant sections in +@ref Camera2D-explicit-specializations "Camera2D" and +@ref Camera3D-explicit-specializations "Camera3D" class documentation or +@ref compilation-speedup-hpp for more information. - @ref AbstractCamera "AbstractCamera<2>" - @ref AbstractCamera "AbstractCamera<3>" -@see Camera2D, Camera3D, Drawable, DrawableGroup, AbstractCamera2D, - AbstractCamera3D +@see Drawable, DrawableGroup, AbstractCamera2D, AbstractCamera3D */ template class SCENEGRAPH_EXPORT AbstractCamera: public AbstractFeature { public: @@ -203,118 +200,6 @@ template using AbstractCamera3D = AbstractCamera<3, T>; typedef AbstractCamera<3, T = GLfloat> AbstractCamera3D; #endif -/** -@brief Camera for two-dimensional scenes - -See Drawable documentation for more information. - -@section Object-explicit-specializations Explicit template specializations - -The following specialization are explicitly compiled into SceneGraph library. -For other specializations you have to use Camera.hpp implementation file to -avoid linker errors. See @ref compilation-speedup-hpp for more information. - - - @ref Camera2D "Camera2D" - -@see Camera3D, Drawable, DrawableGroup -*/ -template class SCENEGRAPH_EXPORT Camera2D: public AbstractCamera<2, T> { - public: - /** - * @brief Constructor - * @param object %Object holding this feature - * - * Sets orthographic projection to the default OpenGL cube (range @f$ [-1; 1] @f$ in all directions). - * @see setOrthographic() - */ - inline Camera2D(AbstractObject<2, T>* object): AbstractCamera<2, T>(object) {} - - /** - * @brief Set projection - * @param size Size of the view - * @return Pointer to self (for method chaining) - * - * The area of given size will be scaled down to range @f$ [-1; 1] @f$ - * on all directions. - */ - Camera2D* setProjection(const Math::Vector2& size); - - /* Overloads to remove WTF-factor from method chaining order */ - #ifndef DOXYGEN_GENERATING_OUTPUT - inline Camera2D* setAspectRatioPolicy(AspectRatioPolicy policy) { - AbstractCamera<2, T>::setAspectRatioPolicy(policy); - return this; - } - #endif -}; - -/** -@brief Camera for three-dimensional scenes - -See Drawable documentation for more information. - -@section Object-explicit-specializations Explicit template specializations - -The following specialization are explicitly compiled into SceneGraph library. -For other specializations you have to use Camera.hpp implementation file to -avoid linker errors. See @ref compilation-speedup-hpp for more information. - - - @ref Camera3D "Camera3D" - -@see Camera2D, Drawable, DrawableGroup -*/ -template class SCENEGRAPH_EXPORT Camera3D: public AbstractCamera<3, T> { - public: - /** - * @brief Constructor - * @param object %Object holding this feature - * - * Sets orthographic projection to the default OpenGL cube (range @f$ [-1; 1] @f$ in all directions). - * @see setOrthographic(), setPerspective() - */ - inline Camera3D(AbstractObject<3, T>* object): AbstractCamera<3, T>(object), _near(0.0f), _far(0.0f) {} - - /** - * @brief Set orthographic projection - * @param size Size of the view - * @param near Near clipping plane - * @param far Far clipping plane - * @return Pointer to self (for method chaining) - * - * The volume of given size will be scaled down to range @f$ [-1; 1] @f$ - * on all directions. - */ - Camera3D* setOrthographic(const Math::Vector2& size, T near, T far); - - /** - * @brief Set perspective projection - * @param fov Field of view angle - * @param near Near clipping plane - * @param far Far clipping plane - * @return Pointer to self (for method chaining) - * - * @todo Aspect ratio - */ - Camera3D* setPerspective(T fov, T near, T far); - - /** @brief Near clipping plane */ - inline T near() const { return _near; } - - /** @brief Far clipping plane */ - inline T far() const { return _far; } - - /* Overloads to remove WTF-factor from method chaining order */ - #ifndef DOXYGEN_GENERATING_OUTPUT - inline Camera3D* setAspectRatioPolicy(AspectRatioPolicy policy) { - AbstractCamera<3, T>::setAspectRatioPolicy(policy); - return this; - } - #endif - - private: - T _near, _far; -}; - /* Make implementers' life easier */ #ifndef MAGNUM_GCC46_COMPATIBILITY template using DrawableGroup2D = DrawableGroup<2, T>; diff --git a/src/SceneGraph/Camera.hpp b/src/SceneGraph/AbstractCamera.hpp similarity index 68% rename from src/SceneGraph/Camera.hpp rename to src/SceneGraph/AbstractCamera.hpp index 2d1e7a42a..bbd6166e1 100644 --- a/src/SceneGraph/Camera.hpp +++ b/src/SceneGraph/AbstractCamera.hpp @@ -1,5 +1,5 @@ -#ifndef Magnum_SceneGraph_Camera_hpp -#define Magnum_SceneGraph_Camera_hpp +#ifndef Magnum_SceneGraph_AbstractCamera_hpp +#define Magnum_SceneGraph_AbstractCamera_hpp /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -16,15 +16,12 @@ */ /** @file - * @brief @ref compilation-speedup-hpp "Template implementation" for Camera.h + * @brief @ref compilation-speedup-hpp "Template implementation" for AbstractCamera.h */ -#include "Camera.h" - -#include +#include "AbstractCamera.h" #include "Drawable.h" -#include "Scene.h" using namespace std; @@ -96,50 +93,6 @@ template void AbstractCamera::d group[i]->draw(transformations[i], this); } -template Camera2D* Camera2D::setProjection(const Math::Vector2& size) { - /* Scale the volume down so it fits in (-1, 1) in all directions */ - AbstractCamera<2, T>::rawProjectionMatrix = Math::Matrix3::scaling(2.0f/size); - - AbstractCamera<2, T>::fixAspectRatio(); - return this; -} - -template Camera3D* Camera3D::setOrthographic(const Math::Vector2& size, T near, T far) { - _near = near; - _far = far; - - Math::Vector2 xyScale = T(2.0)/size; - T zScale = T(2.0)/(near-far); - - AbstractCamera<3, T>::rawProjectionMatrix = Math::Matrix4( - xyScale.x(), T(0.0), T(0.0), T(0.0), - T(0.0), xyScale.y(), T(0.0), T(0.0), - T(0.0), T(0.0), zScale, T(0.0), - T(0.0), T(0.0), near*zScale-1, T(1.0) - ); - - AbstractCamera<3, T>::fixAspectRatio(); - return this; -} - -template Camera3D* Camera3D::setPerspective(T fov, T near, T far) { - _near = near; - _far = far; - - T xyScale = T(1.0)/tan(fov/2); /* == near/size */ - T zScale = T(1.0)/(near-far); - - AbstractCamera<3, T>::rawProjectionMatrix = Matrix4( - xyScale, T(0.0), T(0.0), T(0.0), - T(0.0), xyScale, T(0.0), T(0.0), - T(0.0), T(0.0), (far+near)*zScale, T(-1.0), - T(0.0), T(0.0), (2*far*near)*zScale, T(0.0) - ); - - AbstractCamera<3, T>::fixAspectRatio(); - return this; -} - }} #endif diff --git a/src/SceneGraph/CMakeLists.txt b/src/SceneGraph/CMakeLists.txt index 2268b0dd5..b9a271d03 100644 --- a/src/SceneGraph/CMakeLists.txt +++ b/src/SceneGraph/CMakeLists.txt @@ -1,6 +1,8 @@ set(MagnumSceneGraph_SRCS Camera.cpp) set(MagnumSceneGraph_HEADERS + AbstractCamera.h + AbstractCamera.hpp AbstractFeature.h AbstractGroupedFeature.h AbstractObject.h @@ -9,8 +11,10 @@ set(MagnumSceneGraph_HEADERS AbstractTranslationRotation3D.h AbstractTranslationRotationScaling2D.h AbstractTranslationRotationScaling3D.h - Camera.h - Camera.hpp + Camera2D.h + Camera2D.hpp + Camera3D.h + Camera3D.hpp Drawable.h MatrixTransformation2D.h MatrixTransformation3D.h diff --git a/src/SceneGraph/Camera.cpp b/src/SceneGraph/Camera.cpp index f76b3a6d1..dbb8e1081 100644 --- a/src/SceneGraph/Camera.cpp +++ b/src/SceneGraph/Camera.cpp @@ -13,9 +13,8 @@ GNU Lesser General Public License version 3 for more details. */ -#include "Camera.h" - -#include "Camera.hpp" +#include "Camera2D.hpp" +#include "Camera3D.hpp" namespace Magnum { namespace SceneGraph { diff --git a/src/SceneGraph/Camera2D.h b/src/SceneGraph/Camera2D.h new file mode 100644 index 000000000..9f9845797 --- /dev/null +++ b/src/SceneGraph/Camera2D.h @@ -0,0 +1,73 @@ +#ifndef Magnum_SceneGraph_Camera2D_h +#define Magnum_SceneGraph_Camera2D_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::SceneGraph::Camera2D + */ + +#include "AbstractCamera.h" + +namespace Magnum { namespace SceneGraph { + +/** +@brief Camera for two-dimensional scenes + +See Drawable documentation for more information. + +@section Camera2D-explicit-specializations Explicit template specializations + +The following specialization are explicitly compiled into SceneGraph library. +For other specializations you have to use Camera2D.hpp implementation file to +avoid linker errors. See @ref compilation-speedup-hpp for more information. + + - @ref Camera2D "Camera2D" + +@see Camera3D, Drawable, DrawableGroup +*/ +template class SCENEGRAPH_EXPORT Camera2D: public AbstractCamera<2, T> { + public: + /** + * @brief Constructor + * @param object %Object holding this feature + * + * Sets orthographic projection to the default OpenGL cube (range @f$ [-1; 1] @f$ in all directions). + * @see setOrthographic() + */ + inline Camera2D(AbstractObject<2, T>* object): AbstractCamera<2, T>(object) {} + + /** + * @brief Set projection + * @param size Size of the view + * @return Pointer to self (for method chaining) + * + * The area of given size will be scaled down to range @f$ [-1; 1] @f$ + * on all directions. + */ + Camera2D* setProjection(const Math::Vector2& size); + + /* Overloads to remove WTF-factor from method chaining order */ + #ifndef DOXYGEN_GENERATING_OUTPUT + inline Camera2D* setAspectRatioPolicy(AspectRatioPolicy policy) { + AbstractCamera<2, T>::setAspectRatioPolicy(policy); + return this; + } + #endif +}; + +}} + +#endif diff --git a/src/SceneGraph/Camera2D.hpp b/src/SceneGraph/Camera2D.hpp new file mode 100644 index 000000000..818e5ea19 --- /dev/null +++ b/src/SceneGraph/Camera2D.hpp @@ -0,0 +1,39 @@ +#ifndef Magnum_SceneGraph_Camera2D_hpp +#define Magnum_SceneGraph_Camera2D_hpp +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief @ref compilation-speedup-hpp "Template implementation" for Camera2D.h + */ + +#include "AbstractCamera.hpp" +#include "Camera2D.h" + +using namespace std; + +namespace Magnum { namespace SceneGraph { + +template Camera2D* Camera2D::setProjection(const Math::Vector2& size) { + /* Scale the volume down so it fits in (-1, 1) in all directions */ + AbstractCamera<2, T>::rawProjectionMatrix = Math::Matrix3::scaling(2.0f/size); + + AbstractCamera<2, T>::fixAspectRatio(); + return this; +} + +}} + +#endif diff --git a/src/SceneGraph/Camera3D.h b/src/SceneGraph/Camera3D.h new file mode 100644 index 000000000..c34e8ecb2 --- /dev/null +++ b/src/SceneGraph/Camera3D.h @@ -0,0 +1,100 @@ +#ifndef Magnum_SceneGraph_Camera3D_h +#define Magnum_SceneGraph_Camera3D_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::SceneGraph::Camera3D + */ + +#include "AbstractCamera.h" + +#ifdef WIN32 /* I so HATE windows.h */ +#undef near +#undef far +#endif + +namespace Magnum { namespace SceneGraph { + +/** +@brief Camera for three-dimensional scenes + +See Drawable documentation for more information. + +@section Camera3D-explicit-specializations Explicit template specializations + +The following specialization are explicitly compiled into SceneGraph library. +For other specializations you have to use Camera3D.hpp implementation file to +avoid linker errors. See @ref compilation-speedup-hpp for more information. + + - @ref Camera3D "Camera3D" + +@see Camera2D, Drawable, DrawableGroup +*/ +template class SCENEGRAPH_EXPORT Camera3D: public AbstractCamera<3, T> { + public: + /** + * @brief Constructor + * @param object %Object holding this feature + * + * Sets orthographic projection to the default OpenGL cube (range @f$ [-1; 1] @f$ in all directions). + * @see setOrthographic(), setPerspective() + */ + inline Camera3D(AbstractObject<3, T>* object): AbstractCamera<3, T>(object), _near(0.0f), _far(0.0f) {} + + /** + * @brief Set orthographic projection + * @param size Size of the view + * @param near Near clipping plane + * @param far Far clipping plane + * @return Pointer to self (for method chaining) + * + * The volume of given size will be scaled down to range @f$ [-1; 1] @f$ + * on all directions. + */ + Camera3D* setOrthographic(const Math::Vector2& size, T near, T far); + + /** + * @brief Set perspective projection + * @param fov Field of view angle + * @param near Near clipping plane + * @param far Far clipping plane + * @return Pointer to self (for method chaining) + * + * @todo Aspect ratio + */ + Camera3D* setPerspective(T fov, T near, T far); + + /** @brief Near clipping plane */ + inline T near() const { return _near; } + + /** @brief Far clipping plane */ + inline T far() const { return _far; } + + /* Overloads to remove WTF-factor from method chaining order */ + #ifndef DOXYGEN_GENERATING_OUTPUT + inline Camera3D* setAspectRatioPolicy(AspectRatioPolicy policy) { + AbstractCamera<3, T>::setAspectRatioPolicy(policy); + return this; + } + #endif + + private: + T _near, _far; +}; + +}} + +#endif diff --git a/src/SceneGraph/Camera3D.hpp b/src/SceneGraph/Camera3D.hpp new file mode 100644 index 000000000..23bee2e44 --- /dev/null +++ b/src/SceneGraph/Camera3D.hpp @@ -0,0 +1,67 @@ +#ifndef Magnum_SceneGraph_Camera3D_hpp +#define Magnum_SceneGraph_Camera3D_hpp +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief @ref compilation-speedup-hpp "Template implementation" for Camera3D.h + */ + +#include "AbstractCamera.hpp" +#include "Camera3D.h" + +using namespace std; + +namespace Magnum { namespace SceneGraph { + +template Camera3D* Camera3D::setOrthographic(const Math::Vector2& size, T near, T far) { + _near = near; + _far = far; + + Math::Vector2 xyScale = T(2.0)/size; + T zScale = T(2.0)/(near-far); + + AbstractCamera<3, T>::rawProjectionMatrix = Math::Matrix4( + xyScale.x(), T(0.0), T(0.0), T(0.0), + T(0.0), xyScale.y(), T(0.0), T(0.0), + T(0.0), T(0.0), zScale, T(0.0), + T(0.0), T(0.0), near*zScale-1, T(1.0) + ); + + AbstractCamera<3, T>::fixAspectRatio(); + return this; +} + +template Camera3D* Camera3D::setPerspective(T fov, T near, T far) { + _near = near; + _far = far; + + T xyScale = T(1.0)/tan(fov/2); /* == near/size */ + T zScale = T(1.0)/(near-far); + + AbstractCamera<3, T>::rawProjectionMatrix = Matrix4( + xyScale, T(0.0), T(0.0), T(0.0), + T(0.0), xyScale, T(0.0), T(0.0), + T(0.0), T(0.0), (far+near)*zScale, T(-1.0), + T(0.0), T(0.0), (2*far*near)*zScale, T(0.0) + ); + + AbstractCamera<3, T>::fixAspectRatio(); + return this; +} + +}} + +#endif diff --git a/src/SceneGraph/Test/CameraTest.cpp b/src/SceneGraph/Test/CameraTest.cpp index fa33df768..c3396e458 100644 --- a/src/SceneGraph/Test/CameraTest.cpp +++ b/src/SceneGraph/Test/CameraTest.cpp @@ -16,11 +16,13 @@ #include "CameraTest.h" #include "Math/Constants.h" -#include "SceneGraph/Camera.h" -#include "SceneGraph/Camera.hpp" /* only for aspectRatioFix(), so it doesn't have to be exported */ +#include "SceneGraph/AbstractCamera.hpp" /* only for aspectRatioFix(), so it doesn't have to be exported */ +#include "SceneGraph/Camera2D.h" +#include "SceneGraph/Camera3D.h" #include "SceneGraph/Drawable.h" #include "SceneGraph/MatrixTransformation2D.h" #include "SceneGraph/MatrixTransformation3D.h" +#include "SceneGraph/Scene.h" CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::CameraTest) From 6efb5607fa4fd2e0fc91c8f0a3f7c44fff777187 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 11 Nov 2012 01:08:16 +0100 Subject: [PATCH 05/14] SceneGraph: renamed multiplyTransformation() to transform(). It is shorter and looks better. --- src/SceneGraph/MatrixTransformation2D.h | 16 +++++++-------- src/SceneGraph/MatrixTransformation3D.h | 26 ++++++++++++------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/SceneGraph/MatrixTransformation2D.h b/src/SceneGraph/MatrixTransformation2D.h index e2e9b783f..b25ea2e1f 100644 --- a/src/SceneGraph/MatrixTransformation2D.h +++ b/src/SceneGraph/MatrixTransformation2D.h @@ -74,12 +74,12 @@ template class MatrixTransformation2D: public AbstractTransla } /** - * @brief Multiply transformation + * @brief Transform object * @param transformation Transformation * @param type Transformation type * @return Pointer to self (for method chaining) */ - inline MatrixTransformation2D* multiplyTransformation(const Math::Matrix3& transformation, TransformationType type = TransformationType::Global) { + inline MatrixTransformation2D* transform(const Math::Matrix3& transformation, TransformationType type = TransformationType::Global) { setTransformation(type == TransformationType::Global ? transformation*_transformation : _transformation*transformation); return this; @@ -87,28 +87,28 @@ template class MatrixTransformation2D: public AbstractTransla /** * @copydoc AbstractTranslationRotationScaling2D::translate() - * Same as calling multiplyTransformation() with Matrix3::translation(). + * Same as calling transform() with Matrix3::translation(). */ inline MatrixTransformation2D* translate(const Math::Vector2& vector, TransformationType type = TransformationType::Global) override { - multiplyTransformation(Math::Matrix3::translation(vector), type); + transform(Math::Matrix3::translation(vector), type); return this; } /** * @copydoc AbstractTranslationRotationScaling2D::rotate() - * Same as calling multiplyTransformation() with Matrix3::rotation(). + * Same as calling transform() with Matrix3::rotation(). */ inline MatrixTransformation2D* rotate(T angle, TransformationType type = TransformationType::Global) override { - multiplyTransformation(Math::Matrix3::rotation(angle), type); + transform(Math::Matrix3::rotation(angle), type); return this; } /** * @copydoc AbstractTranslationRotationScaling2D::scale() - * Same as calling multiplyTransformation() with Matrix3::scaling(). + * Same as calling transform() with Matrix3::scaling(). */ inline MatrixTransformation2D* scale(const Math::Vector2& vector, TransformationType type = TransformationType::Global) override { - multiplyTransformation(Math::Matrix3::scaling(vector), type); + transform(Math::Matrix3::scaling(vector), type); return this; } diff --git a/src/SceneGraph/MatrixTransformation3D.h b/src/SceneGraph/MatrixTransformation3D.h index 973e0bd36..dff09d723 100644 --- a/src/SceneGraph/MatrixTransformation3D.h +++ b/src/SceneGraph/MatrixTransformation3D.h @@ -79,7 +79,7 @@ template class MatrixTransformation3D: public AbstractTransla * @param type Transformation type * @return Pointer to self (for method chaining) */ - inline MatrixTransformation3D* multiplyTransformation(const Math::Matrix4& transformation, TransformationType type = TransformationType::Global) { + inline MatrixTransformation3D* transform(const Math::Matrix4& transformation, TransformationType type = TransformationType::Global) { setTransformation(type == TransformationType::Global ? transformation*_transformation : _transformation*transformation); return this; @@ -87,19 +87,19 @@ template class MatrixTransformation3D: public AbstractTransla /** * @copydoc AbstractTranslationRotationScaling3D::translate() - * Same as calling multiplyTransformation() with Matrix4::translation(). + * Same as calling transform() with Matrix4::translation(). */ inline MatrixTransformation3D* translate(const Math::Vector3& vector, TransformationType type = TransformationType::Global) override { - multiplyTransformation(Math::Matrix4::translation(vector), type); + transform(Math::Matrix4::translation(vector), type); return this; } /** * @copydoc AbstractTranslationRotationScaling3D::rotate() - * Same as calling multiplyTransformation() with Matrix4::rotation(). + * Same as calling transform() with Matrix4::rotation(). */ inline MatrixTransformation3D* rotate(T angle, const Math::Vector3& normalizedAxis, TransformationType type = TransformationType::Global) override { - multiplyTransformation(Math::Matrix4::rotation(angle, normalizedAxis), type); + transform(Math::Matrix4::rotation(angle, normalizedAxis), type); return this; } @@ -109,11 +109,11 @@ template class MatrixTransformation3D: public AbstractTransla * @param type Transformation type * @return Pointer to self (for method chaining) * - * Same as calling multiplyTransformation() with Matrix4::rotationX(). + * Same as calling transform() with Matrix4::rotationX(). * @see deg(), rad() */ inline MatrixTransformation3D* rotateX(T angle, TransformationType type = TransformationType::Global) override { - multiplyTransformation(Math::Matrix4::rotationX(angle), type); + transform(Math::Matrix4::rotationX(angle), type); return this; } @@ -123,11 +123,11 @@ template class MatrixTransformation3D: public AbstractTransla * @param type Transformation type * @return Pointer to self (for method chaining) * - * Same as calling multiplyTransformation() with Matrix4::rotationY(). + * Same as calling transform() with Matrix4::rotationY(). * @see deg(), rad() */ inline MatrixTransformation3D* rotateY(T angle, TransformationType type = TransformationType::Global) override { - multiplyTransformation(Math::Matrix4::rotationY(angle), type); + transform(Math::Matrix4::rotationY(angle), type); return this; } @@ -137,20 +137,20 @@ template class MatrixTransformation3D: public AbstractTransla * @param type Transformation type * @return Pointer to self (for method chaining) * - * Same as calling multiplyTransformation() with Matrix4::rotationZ(). + * Same as calling transform() with Matrix4::rotationZ(). * @see deg(), rad() */ inline MatrixTransformation3D* rotateZ(T angle, TransformationType type = TransformationType::Global) override { - multiplyTransformation(Math::Matrix4::rotationZ(angle), type); + transform(Math::Matrix4::rotationZ(angle), type); return this; } /** * @copydoc AbstractTranslationRotationScaling3D::scale() - * Same as calling multiplyTransformation() with Matrix4::scaling(). + * Same as calling transform() with Matrix4::scaling(). */ inline MatrixTransformation3D* scale(const Math::Vector3& vector, TransformationType type = TransformationType::Global) override { - multiplyTransformation(Math::Matrix4::scaling(vector), type); + transform(Math::Matrix4::scaling(vector), type); return this; } From f7d002d06d4c3ba5b22b28689f07512bbbb3dec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 11 Nov 2012 16:33:46 +0100 Subject: [PATCH 06/14] Debug operator for shape type. --- src/Physics/AbstractShape.cpp | 39 ++++++++++++++++++++++ src/Physics/AbstractShape.h | 8 +++++ src/Physics/Test/AbstractShapeTest.cpp | 41 +++++++++++++++++++++++ src/Physics/Test/AbstractShapeTest.h | 25 +++----------- src/Physics/Test/CMakeLists.txt | 1 + src/Physics/Test/CapsuleTest.h | 4 +-- src/Physics/Test/PlaneTest.h | 4 +-- src/Physics/Test/ShapeTestBase.h | 46 ++++++++++++++++++++++++++ src/Physics/Test/SphereTest.h | 4 +-- 9 files changed, 146 insertions(+), 26 deletions(-) create mode 100644 src/Physics/Test/AbstractShapeTest.cpp create mode 100644 src/Physics/Test/ShapeTestBase.h diff --git a/src/Physics/AbstractShape.cpp b/src/Physics/AbstractShape.cpp index 23a15ec0d..5ce4474bd 100644 --- a/src/Physics/AbstractShape.cpp +++ b/src/Physics/AbstractShape.cpp @@ -15,6 +15,8 @@ #include "AbstractShape.h" +#include + namespace Magnum { namespace Physics { template bool AbstractShape::collides(const AbstractShape* other) const { @@ -28,4 +30,41 @@ template bool AbstractShape::collides(const template class AbstractShape<2>; template class AbstractShape<3>; +#ifndef DOXYGEN_GENERATING_OUTPUT +Debug operator<<(Debug debug, AbstractShape2D::Type value) { + switch(value) { + #define _val(value) case AbstractShape2D::Type::value: return debug << "AbstractShape2D::Type::" #value; + _val(Point) + _val(Line) + _val(LineSegment) + _val(Sphere) + _val(Capsule) + _val(AxisAlignedBox) + _val(Box) + _val(ShapeGroup) + #undef _val + } + + return debug << "AbstractShape2D::Type::(unknown)"; +} + +Debug operator<<(Debug debug, AbstractShape3D::Type value) { + switch(value) { + #define _val(value) case AbstractShape3D::Type::value: return debug << "AbstractShape3D::Type::" #value; + _val(Point) + _val(Line) + _val(LineSegment) + _val(Sphere) + _val(Capsule) + _val(AxisAlignedBox) + _val(Box) + _val(ShapeGroup) + _val(Plane) + #undef _val + } + + return debug << "AbstractShape2D::Type::(unknown)"; +} +#endif + }} diff --git a/src/Physics/AbstractShape.h b/src/Physics/AbstractShape.h index 6ac3bdf25..a8320aa0d 100644 --- a/src/Physics/AbstractShape.h +++ b/src/Physics/AbstractShape.h @@ -124,6 +124,14 @@ typedef AbstractShape<2> AbstractShape2D; /** @brief Abstract three-dimensional shape */ typedef AbstractShape<3> AbstractShape3D; +/** @debugoperator{Magnum::Physics::AbstractShape} */ +#ifndef DOXYGEN_GENERATING_OUTPUT +Debug PHYSICS_EXPORT operator<<(Debug debug, AbstractShape2D::Type value); +Debug PHYSICS_EXPORT operator<<(Debug debug, AbstractShape3D::Type value); +#else +template Debug operator<<(Debug debug, typename AbstractShape::Type value); +#endif + }} #endif diff --git a/src/Physics/Test/AbstractShapeTest.cpp b/src/Physics/Test/AbstractShapeTest.cpp new file mode 100644 index 000000000..a7979c8ae --- /dev/null +++ b/src/Physics/Test/AbstractShapeTest.cpp @@ -0,0 +1,41 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "AbstractShapeTest.h" + +#include +#include + +#include "Physics/AbstractShape.h" + +CORRADE_TEST_MAIN(Magnum::Physics::Test::AbstractShapeTest) + +namespace Magnum { namespace Physics { namespace Test { + +AbstractShapeTest::AbstractShapeTest() { + addTests(&AbstractShapeTest::debug); +} + +void AbstractShapeTest::debug() { + std::ostringstream o; + Debug(&o) << AbstractShape2D::Type::ShapeGroup; + CORRADE_COMPARE(o.str(), "AbstractShape2D::Type::ShapeGroup\n"); + + o.str(""); + Debug(&o) << AbstractShape3D::Type::Plane; + CORRADE_COMPARE(o.str(), "AbstractShape3D::Type::Plane\n"); +} + +}}} diff --git a/src/Physics/Test/AbstractShapeTest.h b/src/Physics/Test/AbstractShapeTest.h index ea8d1ff06..1fa4c4531 100644 --- a/src/Physics/Test/AbstractShapeTest.h +++ b/src/Physics/Test/AbstractShapeTest.h @@ -17,29 +17,14 @@ #include -#include "Math/Matrix4.h" -#include "Magnum.h" - namespace Magnum { namespace Physics { namespace Test { -class AbstractShapeTest { - protected: - template void randomTransformation(T& shape) { - shape.applyTransformation(Matrix4::translation({7.0f, 8.0f, -9.0f})); - } -}; +class AbstractShapeTest: public Corrade::TestSuite::Tester { + public: + AbstractShapeTest(); -#define VERIFY_COLLIDES(a, b) \ - CORRADE_VERIFY(a % b); \ - CORRADE_VERIFY(b % a); \ - CORRADE_VERIFY(a.collides(&b)); \ - CORRADE_VERIFY(b.collides(&a)); - -#define VERIFY_NOT_COLLIDES(a, b) \ - CORRADE_VERIFY(!(a % b)); \ - CORRADE_VERIFY(!(b % a)); \ - CORRADE_VERIFY(!(a.collides(&b))); \ - CORRADE_VERIFY(!(b.collides(&a))); + void debug(); +}; }}} diff --git a/src/Physics/Test/CMakeLists.txt b/src/Physics/Test/CMakeLists.txt index 4f8130a83..5bb96fb4a 100644 --- a/src/Physics/Test/CMakeLists.txt +++ b/src/Physics/Test/CMakeLists.txt @@ -1,3 +1,4 @@ +corrade_add_test2(PhysicsAbstractShapeTest AbstractShapeTest.cpp LIBRARIES MagnumPhysics) corrade_add_test2(PhysicsAxisAlignedBoxTest AxisAlignedBoxTest.cpp LIBRARIES MagnumPhysics) corrade_add_test2(PhysicsBoxTest BoxTest.cpp LIBRARIES MagnumPhysics) corrade_add_test2(PhysicsCapsuleTest CapsuleTest.cpp LIBRARIES MagnumPhysics) diff --git a/src/Physics/Test/CapsuleTest.h b/src/Physics/Test/CapsuleTest.h index 6cc79cfbb..88dec80df 100644 --- a/src/Physics/Test/CapsuleTest.h +++ b/src/Physics/Test/CapsuleTest.h @@ -15,11 +15,11 @@ GNU Lesser General Public License version 3 for more details. */ -#include "AbstractShapeTest.h" +#include "ShapeTestBase.h" namespace Magnum { namespace Physics { namespace Test { -class CapsuleTest: public Corrade::TestSuite::Tester, AbstractShapeTest { +class CapsuleTest: public Corrade::TestSuite::Tester, ShapeTestBase { public: CapsuleTest(); diff --git a/src/Physics/Test/PlaneTest.h b/src/Physics/Test/PlaneTest.h index 72baabe19..4381e3dc6 100644 --- a/src/Physics/Test/PlaneTest.h +++ b/src/Physics/Test/PlaneTest.h @@ -15,11 +15,11 @@ GNU Lesser General Public License version 3 for more details. */ -#include "AbstractShapeTest.h" +#include "ShapeTestBase.h" namespace Magnum { namespace Physics { namespace Test { -class PlaneTest: public Corrade::TestSuite::Tester, AbstractShapeTest { +class PlaneTest: public Corrade::TestSuite::Tester, ShapeTestBase { public: PlaneTest(); diff --git a/src/Physics/Test/ShapeTestBase.h b/src/Physics/Test/ShapeTestBase.h new file mode 100644 index 000000000..d5503bc65 --- /dev/null +++ b/src/Physics/Test/ShapeTestBase.h @@ -0,0 +1,46 @@ +#ifndef Magnum_Physics_Test_ShapeTestBase_h +#define Magnum_Physics_Test_ShapeTestBase_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +#include "Math/Matrix4.h" +#include "Magnum.h" + +namespace Magnum { namespace Physics { namespace Test { + +class ShapeTestBase { + protected: + template void randomTransformation(T& shape) { + shape.applyTransformation(Matrix4::translation({7.0f, 8.0f, -9.0f})); + } +}; + +#define VERIFY_COLLIDES(a, b) \ + CORRADE_VERIFY(a % b); \ + CORRADE_VERIFY(b % a); \ + CORRADE_VERIFY(a.collides(&b)); \ + CORRADE_VERIFY(b.collides(&a)); + +#define VERIFY_NOT_COLLIDES(a, b) \ + CORRADE_VERIFY(!(a % b)); \ + CORRADE_VERIFY(!(b % a)); \ + CORRADE_VERIFY(!(a.collides(&b))); \ + CORRADE_VERIFY(!(b.collides(&a))); + +}}} + +#endif diff --git a/src/Physics/Test/SphereTest.h b/src/Physics/Test/SphereTest.h index 6ff9c7bc9..48a2d2d3c 100644 --- a/src/Physics/Test/SphereTest.h +++ b/src/Physics/Test/SphereTest.h @@ -15,11 +15,11 @@ GNU Lesser General Public License version 3 for more details. */ -#include "AbstractShapeTest.h" +#include "ShapeTestBase.h" namespace Magnum { namespace Physics { namespace Test { -class SphereTest: public Corrade::TestSuite::Tester, AbstractShapeTest { +class SphereTest: public Corrade::TestSuite::Tester, ShapeTestBase { public: SphereTest(); From fc9ac0fe0f69c86dcfe87775f2d888a8a3540c50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 11 Nov 2012 16:34:59 +0100 Subject: [PATCH 07/14] SceneGraph: split FeatureGroup and AbstractGroupedFeature file. --- src/SceneGraph/AbstractGroupedFeature.h | 111 +----------------- src/SceneGraph/CMakeLists.txt | 1 + src/SceneGraph/FeatureGroup.h | 145 ++++++++++++++++++++++++ 3 files changed, 149 insertions(+), 108 deletions(-) create mode 100644 src/SceneGraph/FeatureGroup.h diff --git a/src/SceneGraph/AbstractGroupedFeature.h b/src/SceneGraph/AbstractGroupedFeature.h index 3a5114dcd..8e17a39d2 100644 --- a/src/SceneGraph/AbstractGroupedFeature.h +++ b/src/SceneGraph/AbstractGroupedFeature.h @@ -16,18 +16,17 @@ */ /** @file - * @brief Class Magnum::SceneGraph::AbstractGroupedFeature, Magnum::SceneGraph::FeatureGroup, alias Magnum::SceneGraph::AbstractGroupedFeature2D, Magnum::SceneGraph::AbstractGroupedFeature3D, Magnum::SceneGraph::FeatureGroup2D, Magnum::SceneGraph::FeatureGroup3D + * @brief Class Magnum::SceneGraph::AbstractGroupedFeature, alias Magnum::SceneGraph::AbstractGroupedFeature2D, Magnum::SceneGraph::AbstractGroupedFeature3D */ #include #include #include "AbstractFeature.h" +#include "FeatureGroup.h" namespace Magnum { namespace SceneGraph { -template class FeatureGroup; - /** @brief Base for grouped features @@ -124,115 +123,11 @@ template using AbstractGroupedFeature3D = Abst typedef AbstractGroupedFeature<3, Derived, T = GLfloat> AbstractGroupedFeature3D; #endif -/** -@brief Group of features - -See AbstractGroupedFeature for more information. -@see FeatureGroup2D, FeatureGroup3D -*/ -template class FeatureGroup { - friend class AbstractGroupedFeature; - - public: - /** - * @brief Destructor - * - * Deletes all features belogning to this group. - */ - inline virtual ~FeatureGroup() { - for(auto i: features) { - i->_group = nullptr; - delete i; - } - } - - /** @brief Whether the group is empty */ - inline bool isEmpty() const { return features.empty(); } - - /** @brief Count of features in the group */ - inline std::size_t size() const { return features.size(); } - - /** @brief Feature at given index */ - inline Feature* operator[](std::size_t index) { - return features[index]; - } - - /** @overload */ - inline const Feature* operator[](std::size_t index) const { - return features[index]; - } - - /** - * @brief Add feature to the group - * - * If the features is part of another group, it is removed from it. - */ - void add(Feature* feature) { - /** @todo Assert the same scene for all items? -- can't easily - watch when feature object is removed from hierarchy */ - - /* Remove from previous group */ - if(feature->_group) - feature->_group->remove(feature); - - /* Crossreference the feature and group together */ - features.push_back(feature); - feature->_group = this; - } - - /** - * @brief Remove feature from the group - * - * The feature must be part of the group. - */ - void remove(Feature* feature) { - CORRADE_ASSERT(feature->_group == this, - "SceneGraph::AbstractFeatureGroup::remove(): feature is not part of this group", ); - - /* Remove the feature and reset group pointer */ - features.erase(std::find(features.begin(), features.end(), feature)); - feature->_group = nullptr; - } - - private: - std::vector features; -}; - -/** -@brief Base for two-dimensional object features - -Convenience alternative to %FeatureGroup<2, Feature, T>. See -AbstractGroupedFeature for more information. -@note Not available on GCC < 4.7. Use %FeatureGroup<2, Feature, T> - instead. -@see FeatureGroup3D -@todoc Remove workaround when Doxygen supports alias template -*/ -#ifndef DOXYGEN_GENERATING_OUTPUT +/* Make implementers' life easier */ #ifndef MAGNUM_GCC46_COMPATIBILITY template using FeatureGroup2D = FeatureGroup<2, Feature, T>; -#endif -#else -typedef FeatureGroup<2, Feature, T = GLfloat> FeatureGroup2D; -#endif - -/** -@brief Base for three-dimensional object features - -Convenience alternative to %FeatureGroup<3, Feature, T>. See -AbstractGroupedFeature for more information. -@note Not available on GCC < 4.7. Use %FeatureGroup<3, Feature, T> - instead. -@see FeatureGroup2D -@todoc Remove workaround when Doxygen supports alias template -*/ -#ifndef DOXYGEN_GENERATING_OUTPUT -#ifndef MAGNUM_GCC46_COMPATIBILITY template using FeatureGroup3D = FeatureGroup<3, Feature, T>; #endif -#else -typedef FeatureGroup<3, Feature, T = GLfloat> FeatureGroup3D; -#endif }} diff --git a/src/SceneGraph/CMakeLists.txt b/src/SceneGraph/CMakeLists.txt index b9a271d03..753944943 100644 --- a/src/SceneGraph/CMakeLists.txt +++ b/src/SceneGraph/CMakeLists.txt @@ -16,6 +16,7 @@ set(MagnumSceneGraph_HEADERS Camera3D.h Camera3D.hpp Drawable.h + FeatureGroup.h MatrixTransformation2D.h MatrixTransformation3D.h Object.h diff --git a/src/SceneGraph/FeatureGroup.h b/src/SceneGraph/FeatureGroup.h new file mode 100644 index 000000000..4614d2a19 --- /dev/null +++ b/src/SceneGraph/FeatureGroup.h @@ -0,0 +1,145 @@ +#ifndef Magnum_SceneGraph_FeatureGroup_h +#define Magnum_SceneGraph_FeatureGroup_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::SceneGraph::FeatureGroup, alias Magnum::SceneGraph::FeatureGroup2D, Magnum::SceneGraph::FeatureGroup3D + */ + +#include +#include +#include +#include + +#include "Magnum.h" + +namespace Magnum { namespace SceneGraph { + +template class AbstractGroupedFeature; + +/** +@brief Group of features + +See AbstractGroupedFeature for more information. +@see FeatureGroup2D, FeatureGroup3D +*/ +template class FeatureGroup { + friend class AbstractGroupedFeature; + + public: + /** + * @brief Destructor + * + * Deletes all features belogning to this group. + */ + inline virtual ~FeatureGroup() { + for(auto i: features) { + i->_group = nullptr; + delete i; + } + } + + /** @brief Whether the group is empty */ + inline bool isEmpty() const { return features.empty(); } + + /** @brief Count of features in the group */ + inline std::size_t size() const { return features.size(); } + + /** @brief Feature at given index */ + inline Feature* operator[](std::size_t index) { + return features[index]; + } + + /** @overload */ + inline const Feature* operator[](std::size_t index) const { + return features[index]; + } + + /** + * @brief Add feature to the group + * + * If the features is part of another group, it is removed from it. + */ + void add(Feature* feature) { + /** @todo Assert the same scene for all items? -- can't easily + watch when feature object is removed from hierarchy */ + + /* Remove from previous group */ + if(feature->_group) + feature->_group->remove(feature); + + /* Crossreference the feature and group together */ + features.push_back(feature); + feature->_group = this; + } + + /** + * @brief Remove feature from the group + * + * The feature must be part of the group. + */ + void remove(Feature* feature) { + CORRADE_ASSERT(feature->_group == this, + "SceneGraph::AbstractFeatureGroup::remove(): feature is not part of this group", ); + + /* Remove the feature and reset group pointer */ + features.erase(std::find(features.begin(), features.end(), feature)); + feature->_group = nullptr; + } + + private: + std::vector features; +}; + +/** +@brief Base for two-dimensional object features + +Convenience alternative to %FeatureGroup<2, Feature, T>. See +AbstractGroupedFeature for more information. +@note Not available on GCC < 4.7. Use %FeatureGroup<2, Feature, T> + instead. +@see FeatureGroup3D +@todoc Remove workaround when Doxygen supports alias template +*/ +#ifndef DOXYGEN_GENERATING_OUTPUT +#ifndef MAGNUM_GCC46_COMPATIBILITY +template using FeatureGroup2D = FeatureGroup<2, Feature, T>; +#endif +#else +typedef FeatureGroup<2, Feature, T = GLfloat> FeatureGroup2D; +#endif + +/** +@brief Base for three-dimensional object features + +Convenience alternative to %FeatureGroup<3, Feature, T>. See +AbstractGroupedFeature for more information. +@note Not available on GCC < 4.7. Use %FeatureGroup<3, Feature, T> + instead. +@see FeatureGroup2D +@todoc Remove workaround when Doxygen supports alias template +*/ +#ifndef DOXYGEN_GENERATING_OUTPUT +#ifndef MAGNUM_GCC46_COMPATIBILITY +template using FeatureGroup3D = FeatureGroup<3, Feature, T>; +#endif +#else +typedef FeatureGroup<3, Feature, T = GLfloat> FeatureGroup3D; +#endif + +}} + +#endif From bfe99dcf2319ab0b1d5556051dcb2f5096d86a68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 11 Nov 2012 16:35:59 +0100 Subject: [PATCH 08/14] Default type for DimensionTraits. --- src/DimensionTraits.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/DimensionTraits.h b/src/DimensionTraits.h index fe188f2b3..d3c794950 100644 --- a/src/DimensionTraits.h +++ b/src/DimensionTraits.h @@ -17,6 +17,8 @@ #include +#include "Magnum.h" + /** @file * @brief Class Magnum::DimensionTraits */ @@ -36,7 +38,7 @@ namespace Math { } /** @brief Matrix, point and vector specializations for given dimension count */ -template struct DimensionTraits { +template struct DimensionTraits { #ifdef DOXYGEN_GENERATING_OUTPUT /** * @brief Vector type From 43770ada637eb7eadbc2ffd05af6da99d44f3aa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 11 Nov 2012 16:39:02 +0100 Subject: [PATCH 09/14] Doc++ --- doc/building.dox | 24 ++++++++++++++++-------- src/SceneGraph/Drawable.h | 5 +++-- src/SceneGraph/FeatureGroup.h | 2 ++ 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/doc/building.dox b/doc/building.dox index c4a964b79..53d3e6b24 100644 --- a/doc/building.dox +++ b/doc/building.dox @@ -16,25 +16,28 @@ Minimal set of tools and libraries required for building is: >= 3.1. - **CMake** >= 2.8.8 (needed for `OBJECT` library target) - **GLEW** - OpenGL extension wrangler (only if targeting desktop OpenGL) -- **Corrade** - Plugin management and utility library. You can get it at - http://github.com/mosra/corrade or at http://mosra.cz/blog/corrade.php. +- **Corrade** - Plugin management and utility library. See + @ref building-corrade "Corrade download and installation guide" for more + information. @section building-download Downloading the sources + The source is available on GitHub: https://github.com/mosra/magnum. Clone the repository with your favorite IDE or Git GUI, download currrent snapshot as compressed archive or use the command line: git clone git://github.com/mosra/magnum.git -If you need toolchains for crosscompiling, run also the following commands or, +If you need toolchains for crosscompiling, run also the following commands, or, if you build from source archive, download snapshot of toolchains repository from https://github.com/mosra/toolchains and put them in `toolchains/` -subdirectory: +subdirectory. git submodule init git submodule update @section building-compilation Compilation, installation + The library (for example with support for GLUT applications) can be built and installed using these four commands. See below for more information about optional features. @@ -50,6 +53,7 @@ If you want to build with another compiler (e.g. Clang), pass `-DCMAKE_CXX_COMPILER=clang++` to CMake. @subsection building-optional Enabling or disabling features + By default the engine is built for desktop OpenGL. If you want to target OpenGL ES, set `TARGET_GLES` to `ON` or pass `-DTARGET_GLES=ON` to CMake. Note that some features are available for desktop OpenGL only, see @ref requires-gl. @@ -79,6 +83,7 @@ None of the application libraries is built by default, regardless to - `WITH_SDL2APPLICATION` - SDL2 application. Requires **SDL2** library. @subsection building-tests Building and running unit tests + If you want to build also unit tests (which are not built by default), pass `-DBUILD_TESTS=ON` to CMake. Unit tests use Corrade's @ref Corrade::TestSuite "TestSuite" framework and can be run using @@ -88,6 +93,7 @@ If you want to build also unit tests (which are not built by default), pass in build directory. Everything should pass ;-) @subsection building-doc Building documentation + The documentation (which you are currently reading) is written in **Doxygen** (version 1.8 with Markdown support is used, but older versions should do good job too) and additionally uses **Graphviz** for class diagrams and **TeX** @@ -100,6 +106,7 @@ will be in `build/doc/` directory. You might need to create `build/` directory if it doesn't exist yet. @section building-arch Building ArchLinux packages + In `package/archlinux` directory is currently one PKGBUILD for Git development build. The package is also in AUR under the same name. @@ -117,6 +124,7 @@ Both development PKGBUILDs can detect when Clang is used and remove unsupported CXX flags. @section building-win Crosscompiling for Windows using MinGW + @note This guide is tailored mainly for crosscompiling from ArchLinux. For this system there is also prepared `mingw32-magnum` development package in root, named `PKGBUILD-mingw32`. @@ -131,7 +139,8 @@ Corrade), i.e. these ArchLinux packages: Make sure you have `toolchains` submodule updated, as @ref building-download "explained above". Then create build directory and run -cmake and make: +cmake and make. You may need to modify the `basic-mingw32.cmake` file and +`CMAKE_INSTALL_PREFIX` to suit your distribution filesystem hierarchy. mkdir build-win cd build-win @@ -140,8 +149,7 @@ cmake and make: -DCMAKE_INSTALL_PREFIX=/usr/i486-mingw32 make -You may need to modify the `basic-mingw32.cmake` file and -`CMAKE_INSTALL_PREFIX` to suit your distribution filesystem hierarchy. If -everything goes well, in `build-win/` subdirectories will be the DLLs. +Then you can install the package using `make install` to make it available for +depending projects. */ } diff --git a/src/SceneGraph/Drawable.h b/src/SceneGraph/Drawable.h index 7b93cc061..5493fe819 100644 --- a/src/SceneGraph/Drawable.h +++ b/src/SceneGraph/Drawable.h @@ -48,7 +48,7 @@ typedef SceneGraph::Scene> Scene3D; class DrawableObject: public Object3D, SceneGraph::Drawable3D<> { public: - DrawableObject(Object* parent, SceneGraph::DrawableGroup3D<>* group): Object3D(parent), SceneGraph::Drawable3D<>(this, group) { + DrawableObject(Object* parent = nullptr, SceneGraph::DrawableGroup3D<>* group = nullptr): Object3D(parent), SceneGraph::Drawable3D<>(this, group) { // ... } @@ -59,7 +59,8 @@ class DrawableObject: public Object3D, SceneGraph::Drawable3D<> { @endcode Then you add these objects to your scene and some drawable group and transform -them as you like: +them as you like. You can also use DrawableGroup::add() and +DrawableGroup::remove() for that. @code Scene3D scene; SceneGraph::DrawableGroup3D<> group; diff --git a/src/SceneGraph/FeatureGroup.h b/src/SceneGraph/FeatureGroup.h index 4614d2a19..b18b6220b 100644 --- a/src/SceneGraph/FeatureGroup.h +++ b/src/SceneGraph/FeatureGroup.h @@ -72,6 +72,7 @@ template class Featur * @brief Add feature to the group * * If the features is part of another group, it is removed from it. + * @see remove(), AbstractGroupedFeature::AbstractGroupedFeature() */ void add(Feature* feature) { /** @todo Assert the same scene for all items? -- can't easily @@ -90,6 +91,7 @@ template class Featur * @brief Remove feature from the group * * The feature must be part of the group. + * @see add() */ void remove(Feature* feature) { CORRADE_ASSERT(feature->_group == this, From 4d69874c922f5883a0e03dfe72639ce4e80f890a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 12 Nov 2012 19:15:36 +0100 Subject: [PATCH 10/14] Updated FindCorrade.cmake from Corrade repository. --- modules/FindCorrade.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/FindCorrade.cmake b/modules/FindCorrade.cmake index 6587d01c5..178e3b2ba 100644 --- a/modules/FindCorrade.cmake +++ b/modules/FindCorrade.cmake @@ -109,9 +109,9 @@ find_path(CORRADE_INCLUDE_DIR include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Corrade DEFAULT_MSG - CORRADE_INCLUDE_DIR CORRADE_UTILITY_LIBRARY CORRADE_PLUGINMANAGER_LIBRARY + CORRADE_INCLUDE_DIR CORRADE_RC_EXECUTABLE) if(NOT CORRADE_FOUND) From 3fd6480a1bac9fb6d7050f55e134ad9160d5116e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 12 Nov 2012 19:18:57 +0100 Subject: [PATCH 11/14] FindMagnum.cmake: show library path in FPHSA rather than include dir. Library path will reflect various lib dir suffixes. --- modules/FindMagnum.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index c6b4fce29..951afd188 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -207,7 +207,7 @@ endforeach() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Magnum - REQUIRED_VARS MAGNUM_INCLUDE_DIR MAGNUM_LIBRARY + REQUIRED_VARS MAGNUM_LIBRARY MAGNUM_INCLUDE_DIR HANDLE_COMPONENTS) # Dependent libraries and includes From e3b59b18e3bb529de385078091cd6d64151a9941 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 12 Nov 2012 19:19:54 +0100 Subject: [PATCH 12/14] Updated toolchains submodule. --- toolchains | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toolchains b/toolchains index bbde13017..f84b61f69 160000 --- a/toolchains +++ b/toolchains @@ -1 +1 @@ -Subproject commit bbde1301797c86a87a93617a094d88ab4a0dda0a +Subproject commit f84b61f694295b70b5e3492161709b77342e597b From a74890068b2ab896f60f89e06f34df0f771f685f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 12 Nov 2012 19:19:33 +0100 Subject: [PATCH 13/14] PKGBUILD-nacl: Build both 32b and 64b versions. --- PKGBUILD-nacl | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/PKGBUILD-nacl b/PKGBUILD-nacl index 5f806d805..2f941ee3f 100644 --- a/PKGBUILD-nacl +++ b/PKGBUILD-nacl @@ -3,7 +3,7 @@ pkgname=nacl-magnum pkgver=dev pkgrel=1 pkgdesc="OpenGL 3 graphics engine (NaCl x86-64 version)" -arch=('x86_64') +arch=('any') url="https://github.com/mosra/magnum" license=('LGPLv3') depends=('nacl-corrade') @@ -11,6 +11,20 @@ makedepends=('nacl-sdk' 'cmake') options=(!makeflags !buildflags !strip) build() { + # Build 32bit + mkdir -p "$startdir/build-nacl-x86-32" + cd "$startdir/build-nacl-x86-32" + + cmake .. \ + -DCMAKE_MODULE_PATH="$startdir/toolchains/modules" \ + -DCMAKE_TOOLCHAIN_FILE="$startdir/toolchains/generic/NaCl-glibc-x86-32.cmake" \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=/usr/nacl \ + -DWITH_NACLAPPLICATION=ON \ + -DLIB_SUFFIX=/32 + make + + # Build 64bit mkdir -p "$startdir/build-nacl-x86-64" cd "$startdir/build-nacl-x86-64" @@ -24,6 +38,12 @@ build() { } package() { + # Install 32bit + cd "$startdir/build-nacl-x86-32" + make DESTDIR="$pkgdir/" install + + # Install 64bit (the headers will be overwritten, but they are (and should + # be) the same for both versions cd "$startdir/build-nacl-x86-64" make DESTDIR="$pkgdir/" install } From 8292bd3f6c00ccbbe4006e2bad0f7e0c9c3907cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 12 Nov 2012 19:21:49 +0100 Subject: [PATCH 14/14] Documented building for Google Chrome Native Client. --- doc/building.dox | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/doc/building.dox b/doc/building.dox index 53d3e6b24..8d122190c 100644 --- a/doc/building.dox +++ b/doc/building.dox @@ -5,7 +5,8 @@ namespace Magnum { %Magnum can be downloaded from GitHub and built either @ref building-compilation "manually" or using already prepared packaging files, currently only @ref building-arch "ArchLinux PKGBUILDs". Guide how to -@ref building-win "crosscompile for Windows" is also available. +crosscompile for @ref building-win "Windows" and +@ref building-nacl "Google Chrome Native Client" is also available. @tableofcontents @@ -151,5 +152,49 @@ cmake and make. You may need to modify the `basic-mingw32.cmake` file and Then you can install the package using `make install` to make it available for depending projects. + +@section building-nacl Compiling for Google Chrome Native Client + +You will need [Native Client SDK](https://developers.google.com/native-client/beta/sdk/download). +Tested version is `pepper_22`. + +Make sure you have `toolchains` Git submodule updated, as +@ref building-download "explained above". Don't forget to adapt `NACL_PREFIX +variable in `generic/NaCl-glibc-x86-32.cmake` and `generic/NaCl-glibc-x86-64.cmake` +to path where your SDK is installed. Default is `/usr/nacl`. + +Then create build directories for x86-32 and x86-64 and run cmake and make in +them. The toolchains needs access to its platform file, so be sure to properly +set **absolute** path to `modules/` directory containing `Platform/NaCl.cmake`. +Also adapt `CMAKE_INSTALL_PREFIX` to the same value you entered into toolchain +files above. + + mkdir -p build-nacl-x86-32 + cd build-nacl-x86-32 + cmake .. \ + -DCMAKE_MODULE_PATH="/absolute/path/to/toolchains/modules" \ + -DCMAKE_TOOLCHAIN_FILE="../toolchains/generic/NaCl-glibc-x86-32.cmake" \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=/usr/nacl \ + -DWITH_NACLAPPLICATION=ON \ + -DLIB_SUFFIX=/32 + make + + mkdir -p build-nacl-x86-64 + cd build-nacl-x86-64 + cmake .. \ + -DCMAKE_MODULE_PATH="/absolute/path/to/toolchains/modules" \ + -DCMAKE_TOOLCHAIN_FILE="../toolchains/generic/NaCl-glibc-x86-64.cmake" \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=/usr/nacl \ + -DWITH_NACLAPPLICATION=ON + make + +Then you can install both versions using `make install` to make them available +for depending projects. The headers are shared by both versions. + +For ArchLinux there is also prepared package file in root, named +`PKGBUILD-nacl`. + */ }