mirror of https://github.com/mosra/magnum.git
Browse Source
Conflicts: src/Physics/Test/AbstractShapeTest.h src/SceneGraph/AbstractGroupedFeature.h
31 changed files with 744 additions and 392 deletions
@ -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"); |
||||
} |
||||
|
||||
}}} |
||||
@ -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 |
||||
@ -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 |
||||
@ -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 |
||||
@ -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 |
||||
@ -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 |
||||
@ -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 |
||||
Loading…
Reference in new issue