mirror of https://github.com/mosra/magnum.git
10 changed files with 207 additions and 192 deletions
@ -0,0 +1,46 @@ |
|||||||
|
/*
|
||||||
|
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 "ObjectShape.h" |
||||||
|
|
||||||
|
#include <algorithm> |
||||||
|
|
||||||
|
#include "AbstractShape.h" |
||||||
|
#include "ObjectShapeGroup.h" |
||||||
|
|
||||||
|
using namespace std; |
||||||
|
|
||||||
|
namespace Magnum { namespace Physics { |
||||||
|
|
||||||
|
template<uint8_t dimensions> ObjectShape<dimensions>::ObjectShape(SceneGraph::AbstractObject<dimensions>* object, ObjectShapeGroup<dimensions>* group): SceneGraph::AbstractGroupedFeature<dimensions, ObjectShape<dimensions>>(object, group), _shape(nullptr) { |
||||||
|
this->setCachedTransformations(SceneGraph::AbstractFeature<dimensions>::CachedTransformation::Absolute); |
||||||
|
} |
||||||
|
|
||||||
|
template<uint8_t dimensions> ObjectShape<dimensions>::~ObjectShape() { |
||||||
|
delete _shape; |
||||||
|
} |
||||||
|
|
||||||
|
template<uint8_t dimensions> void ObjectShape<dimensions>::markDirty() { |
||||||
|
group()->setDirty(); |
||||||
|
} |
||||||
|
|
||||||
|
template<uint8_t dimensions> void ObjectShape<dimensions>::clean(const typename DimensionTraits<dimensions, GLfloat>::MatrixType& absoluteTransformation) { |
||||||
|
if(_shape) _shape->applyTransformation(absoluteTransformation); |
||||||
|
} |
||||||
|
|
||||||
|
template class ObjectShape<2>; |
||||||
|
template class ObjectShape<3>; |
||||||
|
|
||||||
|
}} |
||||||
@ -0,0 +1,98 @@ |
|||||||
|
#ifndef Magnum_Physics_ObjectShape_h |
||||||
|
#define Magnum_Physics_ObjectShape_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::Physics::ObjectShape |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "SceneGraph/AbstractGroupedFeature.h" |
||||||
|
#include "ObjectShapeGroup.h" |
||||||
|
|
||||||
|
#include "magnumPhysicsVisibility.h" |
||||||
|
|
||||||
|
namespace Magnum { namespace Physics { |
||||||
|
|
||||||
|
template<std::uint8_t> class ObjectShapeGroup; |
||||||
|
template<std::uint8_t> class AbstractShape; |
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Object shape |
||||||
|
|
||||||
|
Adds shape for collision detection to object. |
||||||
|
@see ObjectShape2D, ObjectShape3D |
||||||
|
*/ |
||||||
|
template<std::uint8_t dimensions> class PHYSICS_EXPORT ObjectShape: public SceneGraph::AbstractGroupedFeature<dimensions, ObjectShape<dimensions>> { |
||||||
|
public: |
||||||
|
/**
|
||||||
|
* @brief Constructor |
||||||
|
* @param object Object holding this feature |
||||||
|
* @param group Group this shape belongs to |
||||||
|
* |
||||||
|
* Creates empty object shape. |
||||||
|
* @see setShape() |
||||||
|
*/ |
||||||
|
ObjectShape(SceneGraph::AbstractObject<dimensions>* object, ObjectShapeGroup<dimensions>* group = nullptr); |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Destructor |
||||||
|
* |
||||||
|
* Deletes associated shape. |
||||||
|
*/ |
||||||
|
~ObjectShape(); |
||||||
|
|
||||||
|
/** @brief Shape */ |
||||||
|
inline AbstractShape<dimensions>* shape() { return _shape; } |
||||||
|
inline const AbstractShape<dimensions>* shape() const { return _shape; } /**< @overload */ |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set shape |
||||||
|
* @return Pointer to self (for method chaining) |
||||||
|
*/ |
||||||
|
inline ObjectShape<dimensions>* setShape(AbstractShape<dimensions>* shape) { |
||||||
|
_shape = shape; |
||||||
|
this->object()->setDirty(); |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
inline ObjectShapeGroup<dimensions>* group() { |
||||||
|
return static_cast<ObjectShapeGroup<dimensions>*>(SceneGraph::AbstractGroupedFeature<dimensions, ObjectShape<dimensions>>::group()); |
||||||
|
} |
||||||
|
|
||||||
|
inline const ObjectShapeGroup<dimensions>* group() const { |
||||||
|
return static_cast<const ObjectShapeGroup<dimensions>*>(SceneGraph::AbstractGroupedFeature<dimensions, ObjectShape<dimensions>>::group()); |
||||||
|
} |
||||||
|
|
||||||
|
protected: |
||||||
|
/** Marks also the group as dirty */ |
||||||
|
void markDirty() override; |
||||||
|
|
||||||
|
/** Applies transformation to associated shape. */ |
||||||
|
void clean(const typename DimensionTraits<dimensions>::MatrixType& absoluteTransformation) override; |
||||||
|
|
||||||
|
private: |
||||||
|
AbstractShape<dimensions>* _shape; |
||||||
|
}; |
||||||
|
|
||||||
|
/** @brief Two-dimensional object shape */ |
||||||
|
typedef ObjectShape<2> ObjectShape2D; |
||||||
|
|
||||||
|
/** @brief Three-dimensional object shape */ |
||||||
|
typedef ObjectShape<3> ObjectShape3D; |
||||||
|
|
||||||
|
}} |
||||||
|
|
||||||
|
#endif |
||||||
@ -1,51 +0,0 @@ |
|||||||
/*
|
|
||||||
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 "ShapedObject.h" |
|
||||||
|
|
||||||
#include <algorithm> |
|
||||||
|
|
||||||
#include "AbstractShape.h" |
|
||||||
#include "ShapedObjectGroup.h" |
|
||||||
|
|
||||||
using namespace std; |
|
||||||
|
|
||||||
namespace Magnum { namespace Physics { |
|
||||||
|
|
||||||
template<uint8_t dimensions> ShapedObject<dimensions>::ShapedObject(ShapedObjectGroup<dimensions>* group, typename SceneGraph::AbstractObject<dimensions>::ObjectType* parent): SceneGraph::AbstractObject<dimensions>::ObjectType(parent), group(group), _shape(nullptr) { |
|
||||||
group->objects.push_back(this); |
|
||||||
} |
|
||||||
|
|
||||||
template<uint8_t dimensions> ShapedObject<dimensions>::~ShapedObject() { |
|
||||||
group->objects.erase(find(group->objects.begin(), group->objects.end(), this)); |
|
||||||
delete _shape; |
|
||||||
} |
|
||||||
|
|
||||||
template<uint8_t dimensions> void ShapedObject<dimensions>::setDirty() { |
|
||||||
SceneGraph::AbstractObject<dimensions>::ObjectType::setDirty(); |
|
||||||
|
|
||||||
group->setDirty(); |
|
||||||
} |
|
||||||
|
|
||||||
template<uint8_t dimensions> void ShapedObject<dimensions>::clean(const typename DimensionTraits<dimensions, GLfloat>::MatrixType& absoluteTransformation) { |
|
||||||
SceneGraph::AbstractObject<dimensions>::ObjectType::clean(absoluteTransformation); |
|
||||||
|
|
||||||
if(_shape) _shape->applyTransformation(absoluteTransformation); |
|
||||||
} |
|
||||||
|
|
||||||
template class ShapedObject<2>; |
|
||||||
template class ShapedObject<3>; |
|
||||||
|
|
||||||
}} |
|
||||||
@ -1,97 +0,0 @@ |
|||||||
#ifndef Magnum_Physics_ShapedObject_h |
|
||||||
#define Magnum_Physics_ShapedObject_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::Physics::ShapedObject |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "SceneGraph/Object.h" |
|
||||||
|
|
||||||
#include "magnumPhysicsVisibility.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace Physics { |
|
||||||
|
|
||||||
template<std::uint8_t> class ShapedObjectGroup; |
|
||||||
template<std::uint8_t> class AbstractShape; |
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Object with assigned shape |
|
||||||
|
|
||||||
@see ShapedObject2D, ShapedObject3D |
|
||||||
*/ |
|
||||||
template<std::uint8_t dimensions> class PHYSICS_EXPORT ShapedObject: public SceneGraph::AbstractObject<dimensions>::ObjectType { |
|
||||||
public: |
|
||||||
/**
|
|
||||||
* @brief Constructor |
|
||||||
* @param group Group this shaped object belongs to |
|
||||||
* @param parent Parent object |
|
||||||
* |
|
||||||
* Creates object with no shape. |
|
||||||
* @see setShape() |
|
||||||
*/ |
|
||||||
ShapedObject(ShapedObjectGroup<dimensions>* group, typename SceneGraph::AbstractObject<dimensions>::ObjectType* parent = nullptr); |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Destructor |
|
||||||
* |
|
||||||
* Deletes associated shape. |
|
||||||
*/ |
|
||||||
~ShapedObject(); |
|
||||||
|
|
||||||
/** @brief Object shape */ |
|
||||||
inline AbstractShape<dimensions>* shape() { return _shape; } |
|
||||||
inline const AbstractShape<dimensions>* shape() const { return _shape; } /**< @overload */ |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Set object shape |
|
||||||
* @return Pointer to self (for method chaining) |
|
||||||
*/ |
|
||||||
inline ShapedObject<dimensions>* setShape(AbstractShape<dimensions>* shape) { |
|
||||||
_shape = shape; |
|
||||||
setDirty(); |
|
||||||
return this; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @copybrief SceneGraph::AbstractObject::setDirty() |
|
||||||
* |
|
||||||
* Marks shaped object group as dirty. |
|
||||||
*/ |
|
||||||
void setDirty(); |
|
||||||
|
|
||||||
protected: |
|
||||||
/**
|
|
||||||
* @copybrief SceneGraph::AbstractObject::clean() |
|
||||||
* |
|
||||||
* Applies transformation to associated shape. |
|
||||||
*/ |
|
||||||
void clean(const typename DimensionTraits<dimensions, GLfloat>::MatrixType& absoluteTransformation); |
|
||||||
|
|
||||||
private: |
|
||||||
ShapedObjectGroup<dimensions>* group; |
|
||||||
AbstractShape<dimensions>* _shape; |
|
||||||
}; |
|
||||||
|
|
||||||
/** @brief Two-dimensional shaped object */ |
|
||||||
typedef ShapedObject<2> ShapedObject2D; |
|
||||||
|
|
||||||
/** @brief Three-dimensional shaped object */ |
|
||||||
typedef ShapedObject<3> ShapedObject3D; |
|
||||||
|
|
||||||
}} |
|
||||||
|
|
||||||
#endif |
|
||||||
Loading…
Reference in new issue