Browse Source

Merge branch 'master' into compatibility

Conflicts:
	src/Physics/Test/AbstractShapeTest.h
	src/SceneGraph/AbstractGroupedFeature.h
Vladimír Vondruš 14 years ago
parent
commit
35f549f137
  1. 22
      PKGBUILD-nacl
  2. 71
      doc/building.dox
  3. 2
      modules/FindCorrade.cmake
  4. 2
      modules/FindMagnum.cmake
  5. 4
      src/DimensionTraits.h
  6. 6
      src/Math/Vector.h
  7. 39
      src/Physics/AbstractShape.cpp
  8. 8
      src/Physics/AbstractShape.h
  9. 41
      src/Physics/Test/AbstractShapeTest.cpp
  10. 25
      src/Physics/Test/AbstractShapeTest.h
  11. 1
      src/Physics/Test/CMakeLists.txt
  12. 4
      src/Physics/Test/CapsuleTest.h
  13. 4
      src/Physics/Test/PlaneTest.h
  14. 46
      src/Physics/Test/ShapeTestBase.h
  15. 4
      src/Physics/Test/SphereTest.h
  16. 166
      src/SceneGraph/AbstractCamera.h
  17. 55
      src/SceneGraph/AbstractCamera.hpp
  18. 113
      src/SceneGraph/AbstractGroupedFeature.h
  19. 6
      src/SceneGraph/AbstractObject.h
  20. 9
      src/SceneGraph/CMakeLists.txt
  21. 5
      src/SceneGraph/Camera.cpp
  22. 73
      src/SceneGraph/Camera2D.h
  23. 39
      src/SceneGraph/Camera2D.hpp
  24. 100
      src/SceneGraph/Camera3D.h
  25. 67
      src/SceneGraph/Camera3D.hpp
  26. 5
      src/SceneGraph/Drawable.h
  27. 147
      src/SceneGraph/FeatureGroup.h
  28. 16
      src/SceneGraph/MatrixTransformation2D.h
  29. 26
      src/SceneGraph/MatrixTransformation3D.h
  30. 28
      src/SceneGraph/Test/CameraTest.cpp
  31. 2
      toolchains

22
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
}

71
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
@ -16,25 +17,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 +54,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 +84,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 +94,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 +107,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 +125,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 +140,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 +150,51 @@ 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.
@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`.
*/
}

2
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)

2
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

4
src/DimensionTraits.h

@ -18,6 +18,8 @@
#include <cstddef>
#include <cstdint>
#include "Magnum.h"
/** @file
* @brief Class Magnum::DimensionTraits
*/
@ -37,7 +39,7 @@ namespace Math {
}
/** @brief Matrix, point and vector specializations for given dimension count */
template<std::uint8_t dimensions, class T> struct DimensionTraits {
template<std::uint8_t dimensions, class T = GLfloat> struct DimensionTraits {
#ifdef DOXYGEN_GENERATING_OUTPUT
/**
* @brief Vector type

6
src/Math/Vector.h

@ -61,10 +61,10 @@ template<std::size_t size, class T> class Vector: public RectangularMatrix<1, si
* @attention Assertion fails on non-normalized vectors and NaN is
* returned.
*/
inline static T angle(const Vector<size, T>& a, const Vector<size, T>& b) {
CORRADE_ASSERT(MathTypeTraits<T>::equals(a.dot(), T(1)) && MathTypeTraits<T>::equals(b.dot(), T(1)),
inline static T angle(const Vector<size, T>& normalizedA, const Vector<size, T>& normalizedB) {
CORRADE_ASSERT(MathTypeTraits<T>::equals(normalizedA.dot(), T(1)) && MathTypeTraits<T>::equals(normalizedB.dot(), T(1)),
"Math::Vector::angle(): vectors must be normalized", std::numeric_limits<T>::quiet_NaN());
return std::acos(dot(a, b));
return std::acos(dot(normalizedA, normalizedB));
}
/** @brief Default constructor */

39
src/Physics/AbstractShape.cpp

@ -15,6 +15,8 @@
#include "AbstractShape.h"
#include <Utility/Debug.h>
namespace Magnum { namespace Physics {
template<std::uint8_t dimensions> bool AbstractShape<dimensions>::collides(const AbstractShape* other) const {
@ -28,4 +30,41 @@ template<std::uint8_t dimensions> bool AbstractShape<dimensions>::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
}}

8
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<std::uint8_t dimensions> Debug operator<<(Debug debug, typename AbstractShape<dimensions>::Type value);
#endif
}}
#endif

41
src/Physics/Test/AbstractShapeTest.cpp

@ -0,0 +1,41 @@
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
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 <sstream>
#include <Utility/Debug.h>
#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");
}
}}}

25
src/Physics/Test/AbstractShapeTest.h

@ -17,29 +17,14 @@
#include <TestSuite/Tester.h>
#include "Math/Matrix4.h"
#include "Magnum.h"
namespace Magnum { namespace Physics { namespace Test {
class AbstractShapeTest {
protected:
template<class T> void randomTransformation(T& shape) {
shape.applyTransformation(Matrix4::translation(Vector3(7.0f, 8.0f, -9.0f)));
}
};
class AbstractShapeTest: public Corrade::TestSuite::Tester<AbstractShapeTest> {
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();
};
}}}

1
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)

4
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<CapsuleTest>, AbstractShapeTest {
class CapsuleTest: public Corrade::TestSuite::Tester<CapsuleTest>, ShapeTestBase {
public:
CapsuleTest();

4
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<PlaneTest>, AbstractShapeTest {
class PlaneTest: public Corrade::TestSuite::Tester<PlaneTest>, ShapeTestBase {
public:
PlaneTest();

46
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š <mosra@centrum.cz>
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 <TestSuite/Tester.h>
#include "Math/Matrix4.h"
#include "Magnum.h"
namespace Magnum { namespace Physics { namespace Test {
class ShapeTestBase {
protected:
template<class T> void randomTransformation(T& shape) {
shape.applyTransformation(Matrix4::translation(Vector3(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

4
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<SphereTest>, AbstractShapeTest {
class SphereTest: public Corrade::TestSuite::Tester<SphereTest>, ShapeTestBase {
public:
SphereTest();

166
src/SceneGraph/Camera.h → 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š <mosra@centrum.cz>
@ -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, 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<std::uint8_t, class> class Drawable;
@ -40,14 +35,19 @@ template<std::uint8_t dimensions, class T = GLfloat> using DrawableGroup = Featu
template<std::uint8_t, class> 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<std::uint8_t dimensions, class T> typename DimensionTraits<dimensions, T>::MatrixType aspectRatioFix(AspectRatioPolicy aspectRatioPolicy, const Math::Vector2<T>& projectionScale, const Math::Vector2<GLsizei>& viewport);
}
#endif
@ -55,37 +55,25 @@ 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
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<std::uint8_t dimensions, class T = GLfloat> class SCENEGRAPH_EXPORT AbstractCamera: public AbstractFeature<dimensions, T> {
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
@ -212,118 +200,6 @@ template<class T = GLfloat> 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<GLfloat>"
@see Camera3D, Drawable, DrawableGroup
*/
template<class T = GLfloat> 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<T>* setProjection(const Math::Vector2<T>& size);
/* Overloads to remove WTF-factor from method chaining order */
#ifndef DOXYGEN_GENERATING_OUTPUT
inline Camera2D<T>* setAspectRatioPolicy(typename AbstractCamera<2, T>::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<GLfloat>"
@see Camera2D, Drawable, DrawableGroup
*/
template<class T = GLfloat> 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<T>* setOrthographic(const Math::Vector2<T>& 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<T>* 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<T>* setAspectRatioPolicy(typename AbstractCamera<3, T>::AspectRatioPolicy policy) {
AbstractCamera<3, T>::setAspectRatioPolicy(policy);
return this;
}
#endif
private:
T _near, _far;
};
/* Make implementers' life easier */
#ifndef MAGNUM_GCC46_COMPATIBILITY
template<class T = GLfloat> using DrawableGroup2D = DrawableGroup<2, T>;

55
src/SceneGraph/Camera.hpp → 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š <mosra@centrum.cz>
@ -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 <algorithm>
#include "AbstractCamera.h"
#include "Drawable.h"
#include "Scene.h"
using namespace std;
@ -96,50 +93,6 @@ template<std::uint8_t dimensions, class T> void AbstractCamera<dimensions, T>::d
group[i]->draw(transformations[i], this);
}
template<class T> Camera2D<T>* Camera2D<T>::setProjection(const Math::Vector2<T>& size) {
/* Scale the volume down so it fits in (-1, 1) in all directions */
AbstractCamera<2, T>::rawProjectionMatrix = Math::Matrix3<T>::scaling(2.0f/size);
AbstractCamera<2, T>::fixAspectRatio();
return this;
}
template<class T> Camera3D<T>* Camera3D<T>::setOrthographic(const Math::Vector2<T>& size, T near, T far) {
_near = near;
_far = far;
Math::Vector2<T> xyScale = T(2.0)/size;
T zScale = T(2.0)/(near-far);
AbstractCamera<3, T>::rawProjectionMatrix = Math::Matrix4<T>(
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<class T> Camera3D<T>* Camera3D<T>::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

113
src/SceneGraph/AbstractGroupedFeature.h

@ -16,24 +16,23 @@
*/
/** @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 <algorithm>
#include <vector>
#include "AbstractFeature.h"
#include "FeatureGroup.h"
namespace Magnum { namespace SceneGraph {
template<std::uint8_t, class, class> class FeatureGroup;
/**
@brief Base for grouped features
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.:
@ -124,115 +123,11 @@ template<class Derived, class T = GLfloat> using AbstractGroupedFeature3D = Abst
typedef AbstractGroupedFeature<3, Derived, T = GLfloat> AbstractGroupedFeature3D;
#endif
/**
@brief Group of features
See AbstractGroupedFeature for more information.
@see FeatureGroup2D, FeatureGroup3D
*/
template<std::uint8_t dimensions, class Feature, class T = GLfloat> class FeatureGroup {
friend class AbstractGroupedFeature<dimensions, Feature, T>;
public:
/**
* @brief Destructor
*
* Deletes all features belogning to this group.
*/
inline virtual ~FeatureGroup() {
for(auto it = features.begin(); it != features.end(); ++it) {
(*it)->_group = nullptr;
delete *it;
}
}
/** @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<Feature*> features;
};
/**
@brief Base for two-dimensional object features
Convenience alternative to <tt>%FeatureGroup<2, Feature, T></tt>. See
AbstractGroupedFeature for more information.
@note Not available on GCC < 4.7. Use <tt>%FeatureGroup<2, Feature, T></tt>
instead.
@see FeatureGroup3D
@todoc Remove workaround when Doxygen supports alias template
*/
#ifndef DOXYGEN_GENERATING_OUTPUT
/* Make implementers' life easier */
#ifndef MAGNUM_GCC46_COMPATIBILITY
template<class Feature, class T = GLfloat> 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 <tt>%FeatureGroup<3, Feature, T></tt>. See
AbstractGroupedFeature for more information.
@note Not available on GCC < 4.7. Use <tt>%FeatureGroup<3, Feature, T></tt>
instead.
@see FeatureGroup2D
@todoc Remove workaround when Doxygen supports alias template
*/
#ifndef DOXYGEN_GENERATING_OUTPUT
#ifndef MAGNUM_GCC46_COMPATIBILITY
template<class Feature, class T = GLfloat> using FeatureGroup3D = FeatureGroup<3, Feature, T>;
#endif
#else
typedef FeatureGroup<3, Feature, T = GLfloat> FeatureGroup3D;
#endif
}}

6
src/SceneGraph/AbstractObject.h

@ -33,9 +33,9 @@ template<std::uint8_t, class> 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
*/

9
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,9 +11,12 @@ set(MagnumSceneGraph_HEADERS
AbstractTranslationRotation3D.h
AbstractTranslationRotationScaling2D.h
AbstractTranslationRotationScaling3D.h
Camera.h
Camera.hpp
Camera2D.h
Camera2D.hpp
Camera3D.h
Camera3D.hpp
Drawable.h
FeatureGroup.h
MatrixTransformation2D.h
MatrixTransformation3D.h
Object.h

5
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 {

73
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š <mosra@centrum.cz>
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<GLfloat>"
@see Camera3D, Drawable, DrawableGroup
*/
template<class T = GLfloat> 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<T>* setProjection(const Math::Vector2<T>& size);
/* Overloads to remove WTF-factor from method chaining order */
#ifndef DOXYGEN_GENERATING_OUTPUT
inline Camera2D<T>* setAspectRatioPolicy(AspectRatioPolicy policy) {
AbstractCamera<2, T>::setAspectRatioPolicy(policy);
return this;
}
#endif
};
}}
#endif

39
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š <mosra@centrum.cz>
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<class T> Camera2D<T>* Camera2D<T>::setProjection(const Math::Vector2<T>& size) {
/* Scale the volume down so it fits in (-1, 1) in all directions */
AbstractCamera<2, T>::rawProjectionMatrix = Math::Matrix3<T>::scaling(2.0f/size);
AbstractCamera<2, T>::fixAspectRatio();
return this;
}
}}
#endif

100
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š <mosra@centrum.cz>
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<GLfloat>"
@see Camera2D, Drawable, DrawableGroup
*/
template<class T = GLfloat> 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<T>* setOrthographic(const Math::Vector2<T>& 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<T>* 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<T>* setAspectRatioPolicy(AspectRatioPolicy policy) {
AbstractCamera<3, T>::setAspectRatioPolicy(policy);
return this;
}
#endif
private:
T _near, _far;
};
}}
#endif

67
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š <mosra@centrum.cz>
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<class T> Camera3D<T>* Camera3D<T>::setOrthographic(const Math::Vector2<T>& size, T near, T far) {
_near = near;
_far = far;
Math::Vector2<T> xyScale = T(2.0)/size;
T zScale = T(2.0)/(near-far);
AbstractCamera<3, T>::rawProjectionMatrix = Math::Matrix4<T>(
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<class T> Camera3D<T>* Camera3D<T>::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

5
src/SceneGraph/Drawable.h

@ -48,7 +48,7 @@ typedef SceneGraph::Scene<SceneGraph::MatrixTransformation3D<>> 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;

147
src/SceneGraph/FeatureGroup.h

@ -0,0 +1,147 @@
#ifndef Magnum_SceneGraph_FeatureGroup_h
#define Magnum_SceneGraph_FeatureGroup_h
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
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 <cstdint>
#include <algorithm>
#include <vector>
#include <Utility/Debug.h>
#include "Magnum.h"
namespace Magnum { namespace SceneGraph {
template<std::uint8_t, class, class T> class AbstractGroupedFeature;
/**
@brief Group of features
See AbstractGroupedFeature for more information.
@see FeatureGroup2D, FeatureGroup3D
*/
template<std::uint8_t dimensions, class Feature, class T = GLfloat> class FeatureGroup {
friend class AbstractGroupedFeature<dimensions, Feature, T>;
public:
/**
* @brief Destructor
*
* Deletes all features belogning to this group.
*/
inline virtual ~FeatureGroup() {
for(auto it = features.begin(); it != features.end(); ++it) {
(*it)->_group = nullptr;
delete *it;
}
}
/** @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.
* @see remove(), AbstractGroupedFeature::AbstractGroupedFeature()
*/
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.
* @see add()
*/
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<Feature*> features;
};
/**
@brief Base for two-dimensional object features
Convenience alternative to <tt>%FeatureGroup<2, Feature, T></tt>. See
AbstractGroupedFeature for more information.
@note Not available on GCC < 4.7. Use <tt>%FeatureGroup<2, Feature, T></tt>
instead.
@see FeatureGroup3D
@todoc Remove workaround when Doxygen supports alias template
*/
#ifndef DOXYGEN_GENERATING_OUTPUT
#ifndef MAGNUM_GCC46_COMPATIBILITY
template<class Feature, class T = GLfloat> 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 <tt>%FeatureGroup<3, Feature, T></tt>. See
AbstractGroupedFeature for more information.
@note Not available on GCC < 4.7. Use <tt>%FeatureGroup<3, Feature, T></tt>
instead.
@see FeatureGroup2D
@todoc Remove workaround when Doxygen supports alias template
*/
#ifndef DOXYGEN_GENERATING_OUTPUT
#ifndef MAGNUM_GCC46_COMPATIBILITY
template<class Feature, class T = GLfloat> using FeatureGroup3D = FeatureGroup<3, Feature, T>;
#endif
#else
typedef FeatureGroup<3, Feature, T = GLfloat> FeatureGroup3D;
#endif
}}
#endif

16
src/SceneGraph/MatrixTransformation2D.h

@ -74,12 +74,12 @@ template<class T = GLfloat> 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<T>* multiplyTransformation(const Math::Matrix3<T>& transformation, TransformationType type = TransformationType::Global) {
inline MatrixTransformation2D<T>* transform(const Math::Matrix3<T>& transformation, TransformationType type = TransformationType::Global) {
setTransformation(type == TransformationType::Global ?
transformation*_transformation : _transformation*transformation);
return this;
@ -87,28 +87,28 @@ template<class T = GLfloat> class MatrixTransformation2D: public AbstractTransla
/**
* @copydoc AbstractTranslationRotationScaling2D::translate()
* Same as calling multiplyTransformation() with Matrix3::translation().
* Same as calling transform() with Matrix3::translation().
*/
inline MatrixTransformation2D<T>* translate(const Math::Vector2<T>& vector, TransformationType type = TransformationType::Global) override {
multiplyTransformation(Math::Matrix3<T>::translation(vector), type);
transform(Math::Matrix3<T>::translation(vector), type);
return this;
}
/**
* @copydoc AbstractTranslationRotationScaling2D::rotate()
* Same as calling multiplyTransformation() with Matrix3::rotation().
* Same as calling transform() with Matrix3::rotation().
*/
inline MatrixTransformation2D<T>* rotate(T angle, TransformationType type = TransformationType::Global) override {
multiplyTransformation(Math::Matrix3<T>::rotation(angle), type);
transform(Math::Matrix3<T>::rotation(angle), type);
return this;
}
/**
* @copydoc AbstractTranslationRotationScaling2D::scale()
* Same as calling multiplyTransformation() with Matrix3::scaling().
* Same as calling transform() with Matrix3::scaling().
*/
inline MatrixTransformation2D<T>* scale(const Math::Vector2<T>& vector, TransformationType type = TransformationType::Global) override {
multiplyTransformation(Math::Matrix3<T>::scaling(vector), type);
transform(Math::Matrix3<T>::scaling(vector), type);
return this;
}

26
src/SceneGraph/MatrixTransformation3D.h

@ -79,7 +79,7 @@ template<class T = GLfloat> class MatrixTransformation3D: public AbstractTransla
* @param type Transformation type
* @return Pointer to self (for method chaining)
*/
inline MatrixTransformation3D<T>* multiplyTransformation(const Math::Matrix4<T>& transformation, TransformationType type = TransformationType::Global) {
inline MatrixTransformation3D<T>* transform(const Math::Matrix4<T>& transformation, TransformationType type = TransformationType::Global) {
setTransformation(type == TransformationType::Global ?
transformation*_transformation : _transformation*transformation);
return this;
@ -87,19 +87,19 @@ template<class T = GLfloat> class MatrixTransformation3D: public AbstractTransla
/**
* @copydoc AbstractTranslationRotationScaling3D::translate()
* Same as calling multiplyTransformation() with Matrix4::translation().
* Same as calling transform() with Matrix4::translation().
*/
inline MatrixTransformation3D<T>* translate(const Math::Vector3<T>& vector, TransformationType type = TransformationType::Global) override {
multiplyTransformation(Math::Matrix4<T>::translation(vector), type);
transform(Math::Matrix4<T>::translation(vector), type);
return this;
}
/**
* @copydoc AbstractTranslationRotationScaling3D::rotate()
* Same as calling multiplyTransformation() with Matrix4::rotation().
* Same as calling transform() with Matrix4::rotation().
*/
inline MatrixTransformation3D<T>* rotate(T angle, const Math::Vector3<T>& normalizedAxis, TransformationType type = TransformationType::Global) override {
multiplyTransformation(Math::Matrix4<T>::rotation(angle, normalizedAxis), type);
transform(Math::Matrix4<T>::rotation(angle, normalizedAxis), type);
return this;
}
@ -109,11 +109,11 @@ template<class T = GLfloat> 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<T>* rotateX(T angle, TransformationType type = TransformationType::Global) override {
multiplyTransformation(Math::Matrix4<T>::rotationX(angle), type);
transform(Math::Matrix4<T>::rotationX(angle), type);
return this;
}
@ -123,11 +123,11 @@ template<class T = GLfloat> 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<T>* rotateY(T angle, TransformationType type = TransformationType::Global) override {
multiplyTransformation(Math::Matrix4<T>::rotationY(angle), type);
transform(Math::Matrix4<T>::rotationY(angle), type);
return this;
}
@ -137,20 +137,20 @@ template<class T = GLfloat> 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<T>* rotateZ(T angle, TransformationType type = TransformationType::Global) override {
multiplyTransformation(Math::Matrix4<T>::rotationZ(angle), type);
transform(Math::Matrix4<T>::rotationZ(angle), type);
return this;
}
/**
* @copydoc AbstractTranslationRotationScaling3D::scale()
* Same as calling multiplyTransformation() with Matrix4::scaling().
* Same as calling transform() with Matrix4::scaling().
*/
inline MatrixTransformation3D<T>* scale(const Math::Vector3<T>& vector, TransformationType type = TransformationType::Global) override {
multiplyTransformation(Math::Matrix4<T>::scaling(vector), type);
transform(Math::Matrix4<T>::scaling(vector), type);
return this;
}

28
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)
@ -52,37 +54,37 @@ void CameraTest::fixAspectRatio() {
Vector2 projectionScaleZeroX(0.0f, 0.5f);
Math::Vector2<GLsizei> sizeZeroY(400, 0);
Math::Vector2<GLsizei> 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 +161,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));
}

2
toolchains

@ -1 +1 @@
Subproject commit bbde1301797c86a87a93617a094d88ab4a0dda0a
Subproject commit f84b61f694295b70b5e3492161709b77342e597b
Loading…
Cancel
Save