mirror of https://github.com/mosra/magnum.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
153 lines
5.5 KiB
153 lines
5.5 KiB
|
13 years ago
|
#ifndef Magnum_Shapes_Shape_h
|
||
|
|
#define Magnum_Shapes_Shape_h
|
||
|
14 years ago
|
/*
|
||
|
|
This file is part of Magnum.
|
||
|
|
|
||
|
13 years ago
|
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz>
|
||
|
|
|
||
|
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||
|
|
copy of this software and associated documentation files (the "Software"),
|
||
|
|
to deal in the Software without restriction, including without limitation
|
||
|
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||
|
|
and/or sell copies of the Software, and to permit persons to whom the
|
||
|
|
Software is furnished to do so, subject to the following conditions:
|
||
|
|
|
||
|
|
The above copyright notice and this permission notice shall be included
|
||
|
|
in all copies or substantial portions of the Software.
|
||
|
|
|
||
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||
|
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||
|
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||
|
|
DEALINGS IN THE SOFTWARE.
|
||
|
14 years ago
|
*/
|
||
|
|
|
||
|
|
/** @file
|
||
|
13 years ago
|
* @brief Class Magnum::Shapes::Shape
|
||
|
14 years ago
|
*/
|
||
|
|
|
||
|
13 years ago
|
#include "Shapes/AbstractShape.h"
|
||
|
|
#include "Shapes/Shapes.h"
|
||
|
14 years ago
|
|
||
|
13 years ago
|
#include "magnumShapesVisibility.h"
|
||
|
14 years ago
|
|
||
|
13 years ago
|
namespace Magnum { namespace Shapes {
|
||
|
14 years ago
|
|
||
|
13 years ago
|
namespace Implementation {
|
||
|
13 years ago
|
template<class> struct ShapeHelper;
|
||
|
13 years ago
|
}
|
||
|
|
|
||
|
14 years ago
|
/**
|
||
|
|
@brief Object shape
|
||
|
|
|
||
|
13 years ago
|
Adds shape for collision detection to object. Each %Shape is part of
|
||
|
|
some ShapeGroup, which essentially maintains a set of objects which can
|
||
|
13 years ago
|
collide with each other.
|
||
|
|
|
||
|
13 years ago
|
@section Shape-usage Usage
|
||
|
13 years ago
|
|
||
|
|
Add the feature to the object and some shape group (you can also use
|
||
|
13 years ago
|
ShapeGroup::add() and ShapeGroup::remove() later) and configure the
|
||
|
13 years ago
|
shape.
|
||
|
13 years ago
|
@code
|
||
|
13 years ago
|
Shapes::ShapeGroup3D shapes;
|
||
|
13 years ago
|
|
||
|
|
Object3D* object;
|
||
|
13 years ago
|
auto shape = new Shapes::Shape<Shapes::Sphere3D>(object, {{}, 0.75f}, &shapes);
|
||
|
13 years ago
|
@endcode
|
||
|
|
|
||
|
13 years ago
|
@see @ref scenegraph, ShapeGroup2D, ShapeGroup3D,
|
||
|
13 years ago
|
DebugTools::ShapeRenderer
|
||
|
14 years ago
|
*/
|
||
|
13 years ago
|
template<class T> class MAGNUM_SHAPES_EXPORT Shape: public AbstractShape<T::Dimensions> {
|
||
|
13 years ago
|
friend struct Implementation::ShapeHelper<T>;
|
||
|
13 years ago
|
|
||
|
14 years ago
|
public:
|
||
|
|
/**
|
||
|
|
* @brief Constructor
|
||
|
|
* @param object Object holding this feature
|
||
|
13 years ago
|
* @param shape Shape
|
||
|
14 years ago
|
* @param group Group this shape belongs to
|
||
|
|
*/
|
||
|
13 years ago
|
template<class ...U> explicit Shape(SceneGraph::AbstractObject<T::Dimensions>* object, const T& shape, ShapeGroup<T::Dimensions>* group = nullptr): AbstractShape<T::Dimensions>(object, group) {
|
||
|
|
Implementation::ShapeHelper<T>::set(*this, shape);
|
||
|
13 years ago
|
}
|
||
|
14 years ago
|
|
||
|
13 years ago
|
/** @overload */
|
||
|
13 years ago
|
template<class ...U> explicit Shape(SceneGraph::AbstractObject<T::Dimensions>* object, T&& shape, ShapeGroup<T::Dimensions>* group = nullptr): AbstractShape<T::Dimensions>(object, group) {
|
||
|
|
Implementation::ShapeHelper<T>::set(*this, std::move(shape));
|
||
|
13 years ago
|
}
|
||
|
14 years ago
|
|
||
|
13 years ago
|
/** @overload */
|
||
|
13 years ago
|
template<class ...U> explicit Shape(SceneGraph::AbstractObject<T::Dimensions>* object, ShapeGroup<T::Dimensions>* group = nullptr): AbstractShape<T::Dimensions>(object, group) {}
|
||
|
14 years ago
|
|
||
|
13 years ago
|
/** @brief Shape */
|
||
|
|
inline const T& shape() const { return _shape.shape; }
|
||
|
14 years ago
|
|
||
|
13 years ago
|
/**
|
||
|
|
* @brief Set shape
|
||
|
|
* @return Pointer to self (for method chaining)
|
||
|
|
*
|
||
|
13 years ago
|
* Marks the feature as dirty.
|
||
|
13 years ago
|
*/
|
||
|
13 years ago
|
Shape<T>* setShape(const T& shape);
|
||
|
13 years ago
|
|
||
|
13 years ago
|
/**
|
||
|
13 years ago
|
* @brief Transformed shape
|
||
|
13 years ago
|
*
|
||
|
13 years ago
|
* Cleans the feature before returning the shape.
|
||
|
13 years ago
|
*/
|
||
|
13 years ago
|
const T& transformedShape();
|
||
|
14 years ago
|
|
||
|
|
protected:
|
||
|
|
/** Applies transformation to associated shape. */
|
||
|
13 years ago
|
void clean(const typename DimensionTraits<T::Dimensions>::MatrixType& absoluteTransformationMatrix) override;
|
||
|
14 years ago
|
|
||
|
|
private:
|
||
|
13 years ago
|
const Implementation::AbstractShape<T::Dimensions>* abstractTransformedShape() const override {
|
||
|
|
return &_transformedShape;
|
||
|
|
}
|
||
|
|
|
||
|
|
Implementation::Shape<T> _shape, _transformedShape;
|
||
|
14 years ago
|
};
|
||
|
|
|
||
|
13 years ago
|
template<class T> inline Shape<T>* Shape<T>::setShape(const T& shape) {
|
||
|
|
Implementation::ShapeHelper<T>::set(*this, shape);
|
||
|
13 years ago
|
this->object()->setDirty();
|
||
|
|
return this;
|
||
|
|
}
|
||
|
|
|
||
|
13 years ago
|
template<class T> inline const T& Shape<T>::transformedShape() {
|
||
|
13 years ago
|
this->object()->setClean();
|
||
|
|
return _transformedShape.shape;
|
||
|
|
}
|
||
|
|
|
||
|
13 years ago
|
template<class T> void Shape<T>::clean(const typename DimensionTraits<T::Dimensions>::MatrixType& absoluteTransformationMatrix) {
|
||
|
|
Implementation::ShapeHelper<T>::transform(*this, absoluteTransformationMatrix);
|
||
|
13 years ago
|
}
|
||
|
|
|
||
|
|
namespace Implementation {
|
||
|
13 years ago
|
template<class T> struct ShapeHelper {
|
||
|
13 years ago
|
inline static void set(Shapes::Shape<T>& shape, const T& s) {
|
||
|
13 years ago
|
shape._shape.shape = s;
|
||
|
13 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
inline static void transform(Shapes::Shape<T>& shape, const typename DimensionTraits<T::Dimensions>::MatrixType& absoluteTransformationMatrix) {
|
||
|
13 years ago
|
shape._transformedShape.shape = shape._shape.shape.transformed(absoluteTransformationMatrix);
|
||
|
13 years ago
|
}
|
||
|
|
};
|
||
|
|
|
||
|
13 years ago
|
template<UnsignedInt dimensions> struct MAGNUM_SHAPES_EXPORT ShapeHelper<Composition<dimensions>> {
|
||
|
|
static void set(Shapes::Shape<Composition<dimensions>>& shape, const Composition<dimensions>& composition);
|
||
|
|
static void set(Shapes::Shape<Composition<dimensions>>& shape, Composition<dimensions>&& composition);
|
||
|
14 years ago
|
|
||
|
13 years ago
|
static void transform(Shapes::Shape<Composition<dimensions>>& shape, const typename DimensionTraits<dimensions>::MatrixType& absoluteTransformationMatrix);
|
||
|
13 years ago
|
};
|
||
|
|
}
|
||
|
14 years ago
|
|
||
|
|
}}
|
||
|
|
|
||
|
|
#endif
|