mirror of https://github.com/mosra/magnum.git
127 changed files with 27 additions and 8176 deletions
@ -1,185 +0,0 @@ |
|||||||
/* |
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
namespace Magnum { |
|
||||||
/** @page shapes Collision detection |
|
||||||
@brief Collection of simple shapes for high performance collision detection. |
|
||||||
|
|
||||||
@tableofcontents |
|
||||||
@m_footernavigation |
|
||||||
|
|
||||||
@deprecated This library is a failed design experiment and is scheduled for |
|
||||||
removal in a future release. Related geometry algorithms were moved to |
|
||||||
@ref Magnum::Math::Distance "Math::Distance" and |
|
||||||
@ref Magnum::Math::Intersection "Math::Intersection"; if you need a |
|
||||||
full-fledged physics library, please have look at |
|
||||||
[Bullet](https://bulletphysics.org), which has Magnum integration in |
|
||||||
@ref Magnum::BulletIntegration "BulletIntegration" or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example" |
|
||||||
as well. |
|
||||||
|
|
||||||
The essential thing in collision detection is to define a complex object with |
|
||||||
collection of simple shapes, for which it is easy to detect collisions. The |
|
||||||
library is contained in @ref Shapes namespace, see its documentation for more |
|
||||||
information about building and usage with CMake. |
|
||||||
|
|
||||||
These shapes can be either one-, two- or three-dimensional and they can be |
|
||||||
grouped together using various operations. |
|
||||||
|
|
||||||
@section shapes-collection Available shapes |
|
||||||
|
|
||||||
Magnum provides a set of simple shapes for collision detection, similarly to |
|
||||||
what is found in many other collision detection libraries. Additionally some |
|
||||||
shapes are provided in inverted form --- e.g. inverted box detects collisions on |
|
||||||
outside instead of inside, which might be useful for example to create bounds |
|
||||||
around platformer game level. |
|
||||||
|
|
||||||
@subsection shapes-1D One-dimensional shapes |
|
||||||
|
|
||||||
- @ref Shapes::Point "Shapes::Point*D" --- @copybrief Shapes::Point |
|
||||||
- @ref Shapes::Line "Shapes::Line*D" --- @copybrief Shapes::Line |
|
||||||
- @ref Shapes::LineSegment "Shapes::LineSegment*D" --- @copybrief Shapes::LineSegment |
|
||||||
|
|
||||||
Because of numerical instability it's not possible to detect collisions of |
|
||||||
line and point. Collision of two lines can be detected only in 2D. |
|
||||||
|
|
||||||
@subsection shapes-2D Two-dimensional shapes |
|
||||||
|
|
||||||
- @ref Shapes::Plane --- @copybrief Shapes::Plane |
|
||||||
|
|
||||||
@subsection shapes-3D Three-dimensional shapes |
|
||||||
|
|
||||||
- @ref Shapes::Sphere "Shapes::Sphere*D" --- @copybrief Shapes::Sphere |
|
||||||
- @ref Shapes::InvertedSphere "Shapes::InvertedSphere*D" --- @copybrief Shapes::InvertedSphere |
|
||||||
- @ref Shapes::Cylinder "Shapes::Cylinder*D" --- @copybrief Shapes::Cylinder |
|
||||||
- @ref Shapes::Capsule "Shapes::Capsule*D" --- @copybrief Shapes::Capsule |
|
||||||
- @ref Shapes::AxisAlignedBox "Shapes::AxisAlignedBox*D" --- @copybrief Shapes::AxisAlignedBox |
|
||||||
- @ref Shapes::Box "Shapes::Box*D" --- @copybrief Shapes::Box |
|
||||||
|
|
||||||
The easiest (and most efficient) shape combination for detecting collisions |
|
||||||
is point and sphere, followed by two spheres. Computing collision of two boxes |
|
||||||
is least efficient. |
|
||||||
|
|
||||||
@section shapes-composition Creating shape compositions |
|
||||||
|
|
||||||
Shapes can be composed together using one of three available logical |
|
||||||
operations: AND, OR and NOT. These operations are mapped to @cpp && @ce, @cpp || @ce |
|
||||||
and @cpp ! @ce operators, so for example creating negation of logical OR of |
|
||||||
line segment and point is simple as this: |
|
||||||
|
|
||||||
@code{.cpp} |
|
||||||
Shapes::LineSegment3D segment; |
|
||||||
Shapes::Point3D point; |
|
||||||
|
|
||||||
Shapes::Composition3D composition = !(segment || point); |
|
||||||
@endcode |
|
||||||
|
|
||||||
@note Logical operations are not the same as set operations --- intersection of |
|
||||||
two spheres will not generate any collision if they are disjoint, but |
|
||||||
logical AND will if the object collides with both of them. |
|
||||||
|
|
||||||
@subsection shapes-simplification Providing simplified version of shape for better performance |
|
||||||
|
|
||||||
If there are many shapes composed together, it might hurt performance of |
|
||||||
collision detection, because it might be testing collision with more shapes |
|
||||||
than necessary. It's then good to specify simplified version of such shape, |
|
||||||
so the collision detection is done on the complex one if and only if collision |
|
||||||
was detected with the simplified shape. It is in fact logical AND using the |
|
||||||
@cpp && @ce operator --- the collision is initially detected on first |
|
||||||
(simplified) shape and then on the other: |
|
||||||
|
|
||||||
@code{.cpp} |
|
||||||
Shapes::Sphere3D sphere; |
|
||||||
Shapes::Box3D box; |
|
||||||
Shapes::AxisAlignedBox3D simplified; |
|
||||||
|
|
||||||
Shapes::Composition3D composition = simplified && (sphere || box); |
|
||||||
@endcode |
|
||||||
|
|
||||||
@section shapes-collisions Detecting shape collisions |
|
||||||
|
|
||||||
Shape pairs which have collision occurence detection implemented can be tested |
|
||||||
for collision using the @cpp % @ce operator. The operator returns boolean |
|
||||||
describing whether the collision happened or not. Example: |
|
||||||
|
|
||||||
@code{.cpp} |
|
||||||
Shapes::Point3D point; |
|
||||||
Shapes::Sphere3D sphere; |
|
||||||
|
|
||||||
bool collide = point % sphere; |
|
||||||
@endcode |
|
||||||
|
|
||||||
As this is useful for e.g. menu handling and simple particle systems, for |
|
||||||
serious physics you often need more information like contact point, separation |
|
||||||
normal and penetration depth. For shape pairs which have implemented this |
|
||||||
detailed collision detection you can use the `/` operator, which returns |
|
||||||
@ref Shapes::Collision object. Note that unlike with the `%` operator mentioned |
|
||||||
above, this operation is not commutative. See @ref Shapes::Collision class |
|
||||||
documentation for more information about the returned data. Example: |
|
||||||
|
|
||||||
@code{.cpp} |
|
||||||
const Shapes::Collision3D c = point/sphere; |
|
||||||
if(c) { |
|
||||||
Vector3 translation = c.separationNormal()*c.separationDistance(); |
|
||||||
// translate point by translation... |
|
||||||
} |
|
||||||
@endcode |
|
||||||
|
|
||||||
@section shapes-scenegraph Integration with scene graph |
|
||||||
|
|
||||||
Shape can be attached to object in the scene using @ref Shapes::Shape feature. |
|
||||||
In conjunction with @ref Shapes::ShapeGroup you can use |
|
||||||
@ref Shapes::Shape::collides() and @ref Shapes::Shape::collision() similarly to |
|
||||||
the @cpp % @ce and @cpp / @ce operators above. Please note that the shape group |
|
||||||
caches the absolute transformations of all shapes and thus you need to |
|
||||||
explicitly call @ref Shapes::ShapeGroup::setClean() before computing the |
|
||||||
collisions if you did any modifications to the objects in the scene. |
|
||||||
|
|
||||||
Scenegraph-flavored equivalent to the above code: |
|
||||||
|
|
||||||
@code{.cpp} |
|
||||||
Shapes::ShapeGroup3D shapes; |
|
||||||
Object3D& a; |
|
||||||
auto aShape = new Shapes::Shape<Shapes::Sphere3D>(a, {{}, 23.0f}, &shapes); |
|
||||||
|
|
||||||
Object3D& b; |
|
||||||
auto bShape = new Shapes::Shape<Shapes::Point3D>(b, {{1.0f, 0.2f, 3.0f}}, &shapes); |
|
||||||
|
|
||||||
// Translate point so the objects no longer collide |
|
||||||
shapes.setClean(); |
|
||||||
if(aShape->collides(*bShape)) { |
|
||||||
const Shapes::Collision3D c = aShape->collision(*bShape); |
|
||||||
b.translate(c.separationNormal()*c.separationDistance()); |
|
||||||
} |
|
||||||
@endcode |
|
||||||
|
|
||||||
There is also @ref Shapes::ShapeGroup::firstCollision() function which returns |
|
||||||
arbitrary first collision for given shape in whole group (or @cpp nullptr @ce, |
|
||||||
if there isn't any collision). |
|
||||||
|
|
||||||
You can also use @ref DebugTools::ShapeRenderer to visualize the shapes for |
|
||||||
debugging purposes. See also @ref scenegraph for introduction. |
|
||||||
*/ |
|
||||||
} |
|
||||||
@ -1,48 +0,0 @@ |
|||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#define _MAGNUM_DO_NOT_WARN_DEPRECATED_SHAPES |
|
||||||
|
|
||||||
#include "AbstractBoxRenderer.h" |
|
||||||
|
|
||||||
#include "Magnum/GL/Mesh.h" |
|
||||||
#include "Magnum/Primitives/Cube.h" |
|
||||||
#include "Magnum/Primitives/Square.h" |
|
||||||
#include "Magnum/Trade/MeshData2D.h" |
|
||||||
#include "Magnum/Trade/MeshData3D.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
AbstractBoxRenderer<2>::AbstractBoxRenderer(): AbstractShapeRenderer<2>("box2d", "box2d-vertices", {}) { |
|
||||||
if(!wireframeMesh) AbstractShapeRenderer<2>::createResources(Primitives::squareWireframe()); |
|
||||||
} |
|
||||||
|
|
||||||
AbstractBoxRenderer<3>::AbstractBoxRenderer(): AbstractShapeRenderer<3>("box3d", "box3d-vertices", "box3d-indices") { |
|
||||||
if(!wireframeMesh) AbstractShapeRenderer<3>::createResources(Primitives::cubeWireframe()); |
|
||||||
} |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}}} |
|
||||||
@ -1,51 +0,0 @@ |
|||||||
#ifndef Magnum_DebugTools_Implementation_AbstractBoxRenderer_h |
|
||||||
#define Magnum_DebugTools_Implementation_AbstractBoxRenderer_h |
|
||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "AbstractShapeRenderer.h" |
|
||||||
|
|
||||||
#include "Magnum/Resource.h" |
|
||||||
#include "Magnum/Shaders/Shaders.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
template<UnsignedInt dimensions> class AbstractBoxRenderer; |
|
||||||
|
|
||||||
template<> class AbstractBoxRenderer<2>: public AbstractShapeRenderer<2> { |
|
||||||
public: |
|
||||||
AbstractBoxRenderer(); |
|
||||||
}; |
|
||||||
|
|
||||||
template<> class AbstractBoxRenderer<3>: public AbstractShapeRenderer<3> { |
|
||||||
public: |
|
||||||
AbstractBoxRenderer(); |
|
||||||
}; |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}}} |
|
||||||
|
|
||||||
#endif |
|
||||||
@ -1,138 +0,0 @@ |
|||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#define _MAGNUM_DO_NOT_WARN_DEPRECATED_SHAPES |
|
||||||
|
|
||||||
#include "AbstractShapeRenderer.h" |
|
||||||
|
|
||||||
#include <Corrade/Containers/Array.h> |
|
||||||
|
|
||||||
#include "Magnum/DebugTools/ResourceManager.h" |
|
||||||
#include "Magnum/GL/AbstractShaderProgram.h" |
|
||||||
#include "Magnum/GL/Buffer.h" |
|
||||||
#include "Magnum/GL/Mesh.h" |
|
||||||
#include "Magnum/MeshTools/CompressIndices.h" |
|
||||||
#include "Magnum/Shaders/Flat.h" |
|
||||||
#include "Magnum/Trade/MeshData2D.h" |
|
||||||
#include "Magnum/Trade/MeshData3D.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
namespace { |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> ResourceKey shaderKey(); |
|
||||||
template<> inline ResourceKey shaderKey<2>() { return ResourceKey("FlatShader2D"); } |
|
||||||
template<> inline ResourceKey shaderKey<3>() { return ResourceKey("FlatShader3D"); } |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> void create(typename MeshData<dimensions>::Type&, Resource<GL::Mesh>&, Resource<GL::Buffer>&, Resource<GL::Buffer>&); |
|
||||||
|
|
||||||
template<> void create<2>(Trade::MeshData2D& data, Resource<GL::Mesh>& meshResource, Resource<GL::Buffer>& vertexBufferResource, Resource<GL::Buffer>& indexBufferResource) { |
|
||||||
/* Vertex buffer */ |
|
||||||
GL::Buffer* buffer = new GL::Buffer{GL::Buffer::TargetHint::Array}; |
|
||||||
buffer->setData(data.positions(0), GL::BufferUsage::StaticDraw); |
|
||||||
ResourceManager::instance().set(vertexBufferResource.key(), buffer, ResourceDataState::Final, ResourcePolicy::Manual); |
|
||||||
|
|
||||||
/* Mesh configuration */ |
|
||||||
GL::Mesh* mesh = new GL::Mesh; |
|
||||||
mesh->setPrimitive(data.primitive()) |
|
||||||
.addVertexBuffer(*buffer, 0, Shaders::Flat2D::Position()); |
|
||||||
ResourceManager::instance().set(meshResource.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); |
|
||||||
|
|
||||||
/* Index buffer, if needed, if not, resource key doesn't have to be set */ |
|
||||||
if(data.isIndexed()) { |
|
||||||
CORRADE_INTERNAL_ASSERT(indexBufferResource.key() != ResourceKey()); |
|
||||||
|
|
||||||
Containers::Array<char> indexData; |
|
||||||
MeshIndexType indexType; |
|
||||||
UnsignedInt indexStart, indexEnd; |
|
||||||
std::tie(indexData, indexType, indexStart, indexEnd) = MeshTools::compressIndices(data.indices()); |
|
||||||
|
|
||||||
GL::Buffer* indexBuffer = new GL::Buffer{GL::Buffer::TargetHint::ElementArray}; |
|
||||||
indexBuffer->setData(indexData, GL::BufferUsage::StaticDraw); |
|
||||||
mesh->setCount(data.indices().size()) |
|
||||||
.setIndexBuffer(*indexBuffer, 0, indexType, indexStart, indexEnd); |
|
||||||
|
|
||||||
ResourceManager::instance().set(indexBufferResource.key(), indexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); |
|
||||||
|
|
||||||
/* The mesh is not indexed, set proper vertex count */ |
|
||||||
} else mesh->setCount(data.positions(0).size()); |
|
||||||
} |
|
||||||
|
|
||||||
template<> void create<3>(Trade::MeshData3D& data, Resource<GL::Mesh>& meshResource, Resource<GL::Buffer>& vertexBufferResource, Resource<GL::Buffer>& indexBufferResource) { |
|
||||||
/* Vertex buffer */ |
|
||||||
GL::Buffer* vertexBuffer = new GL::Buffer{GL::Buffer::TargetHint::Array}; |
|
||||||
vertexBuffer->setData(data.positions(0), GL::BufferUsage::StaticDraw); |
|
||||||
ResourceManager::instance().set(vertexBufferResource.key(), vertexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); |
|
||||||
|
|
||||||
/* Mesh configuration */ |
|
||||||
GL::Mesh* mesh = new GL::Mesh; |
|
||||||
mesh->setPrimitive(data.primitive()) |
|
||||||
.addVertexBuffer(*vertexBuffer, 0, Shaders::Flat3D::Position()); |
|
||||||
ResourceManager::instance().set(meshResource.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); |
|
||||||
|
|
||||||
/* Index buffer, if needed, if not, resource key doesn't have to be set */ |
|
||||||
if(data.isIndexed()) { |
|
||||||
CORRADE_INTERNAL_ASSERT(indexBufferResource.key() != ResourceKey()); |
|
||||||
|
|
||||||
Containers::Array<char> indexData; |
|
||||||
MeshIndexType indexType; |
|
||||||
UnsignedInt indexStart, indexEnd; |
|
||||||
std::tie(indexData, indexType, indexStart, indexEnd) = MeshTools::compressIndices(data.indices()); |
|
||||||
|
|
||||||
GL::Buffer* indexBuffer = new GL::Buffer{GL::Buffer::TargetHint::ElementArray}; |
|
||||||
indexBuffer->setData(indexData, GL::BufferUsage::StaticDraw); |
|
||||||
mesh->setCount(data.indices().size()) |
|
||||||
.setIndexBuffer(*indexBuffer, 0, indexType, indexStart, indexEnd); |
|
||||||
|
|
||||||
ResourceManager::instance().set(indexBufferResource.key(), indexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); |
|
||||||
|
|
||||||
/* The mesh is not indexed, set proper vertex count */ |
|
||||||
} else mesh->setCount(data.positions(0).size()); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> AbstractShapeRenderer<dimensions>::AbstractShapeRenderer(ResourceKey meshKey, ResourceKey vertexBufferKey, ResourceKey indexBufferKey) { |
|
||||||
wireframeShader = ResourceManager::instance().get<GL::AbstractShaderProgram, Shaders::Flat<dimensions>>(shaderKey<dimensions>()); |
|
||||||
wireframeMesh = ResourceManager::instance().get<GL::Mesh>(meshKey); |
|
||||||
vertexBuffer = ResourceManager::instance().get<GL::Buffer>(vertexBufferKey); |
|
||||||
indexBuffer = ResourceManager::instance().get<GL::Buffer>(indexBufferKey); |
|
||||||
|
|
||||||
if(!wireframeShader) ResourceManager::instance().set<GL::AbstractShaderProgram>(shaderKey<dimensions>(), |
|
||||||
new Shaders::Flat<dimensions>, ResourceDataState::Final, ResourcePolicy::Resident); |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> AbstractShapeRenderer<dimensions>::~AbstractShapeRenderer() = default; |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> void AbstractShapeRenderer<dimensions>::createResources(typename MeshData<dimensions>::Type data) { |
|
||||||
create<dimensions>(data, wireframeMesh, vertexBuffer, indexBuffer); |
|
||||||
} |
|
||||||
|
|
||||||
template class AbstractShapeRenderer<2>; |
|
||||||
template class AbstractShapeRenderer<3>; |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}}} |
|
||||||
@ -1,73 +0,0 @@ |
|||||||
#ifndef Magnum_DebugTools_Implementation_AbstractShapeRenderer_h |
|
||||||
#define Magnum_DebugTools_Implementation_AbstractShapeRenderer_h |
|
||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Magnum/DimensionTraits.h" |
|
||||||
#include "Magnum/Resource.h" |
|
||||||
#include "Magnum/DebugTools/DebugTools.h" |
|
||||||
#include "Magnum/GL/GL.h" |
|
||||||
#include "Magnum/SceneGraph/SceneGraph.h" |
|
||||||
#include "Magnum/Shaders/Shaders.h" |
|
||||||
#include "Magnum/Trade/Trade.h" |
|
||||||
|
|
||||||
namespace Magnum { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
namespace Shapes { namespace Implementation { |
|
||||||
template<UnsignedInt> struct AbstractShape; |
|
||||||
}} |
|
||||||
|
|
||||||
namespace DebugTools { namespace Implementation { |
|
||||||
|
|
||||||
template<UnsignedInt> struct MeshData; |
|
||||||
|
|
||||||
template<> struct MeshData<2> { typedef Trade::MeshData2D Type; }; |
|
||||||
template<> struct MeshData<3> { typedef Trade::MeshData3D Type; }; |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> class AbstractShapeRenderer { |
|
||||||
public: |
|
||||||
AbstractShapeRenderer(ResourceKey mesh, ResourceKey vertexBuffer, ResourceKey indexBuffer); |
|
||||||
virtual ~AbstractShapeRenderer(); |
|
||||||
|
|
||||||
virtual void draw(Resource<ShapeRendererOptions>& options, const MatrixTypeFor<dimensions, Float>& projectionMatrix) = 0; |
|
||||||
|
|
||||||
protected: |
|
||||||
/* Call only if the mesh resource isn't already present */ |
|
||||||
void createResources(typename MeshData<dimensions>::Type data); |
|
||||||
|
|
||||||
Resource<GL::AbstractShaderProgram, Shaders::Flat<dimensions>> wireframeShader; |
|
||||||
Resource<GL::Mesh> wireframeMesh; |
|
||||||
|
|
||||||
private: |
|
||||||
Resource<GL::Buffer> indexBuffer, vertexBuffer; |
|
||||||
}; |
|
||||||
|
|
||||||
}} |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
#endif |
|
||||||
@ -1,52 +0,0 @@ |
|||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#define _MAGNUM_DO_NOT_WARN_DEPRECATED_SHAPES |
|
||||||
|
|
||||||
#include "AxisAlignedBoxRenderer.h" |
|
||||||
|
|
||||||
#include "Magnum/GL/Mesh.h" |
|
||||||
#include "Magnum/DebugTools/ShapeRenderer.h" |
|
||||||
#include "Magnum/Shapes/AxisAlignedBox.h" |
|
||||||
#include "Magnum/Shaders/Flat.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
template<UnsignedInt dimensions> AxisAlignedBoxRenderer<dimensions>::AxisAlignedBoxRenderer(const Shapes::Implementation::AbstractShape<dimensions>& axisAlignedBox): axisAlignedBox(static_cast<const Shapes::Implementation::Shape<Shapes::AxisAlignedBox<dimensions>>&>(axisAlignedBox).shape) {} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> void AxisAlignedBoxRenderer<dimensions>::draw(Resource<ShapeRendererOptions>& options, const MatrixTypeFor<dimensions, Float>& projectionMatrix) { |
|
||||||
AbstractBoxRenderer<dimensions>::wireframeShader->setTransformationProjectionMatrix(projectionMatrix* |
|
||||||
MatrixTypeFor<dimensions, Float>::translation((axisAlignedBox.min()+axisAlignedBox.max())/2)* |
|
||||||
MatrixTypeFor<dimensions, Float>::scaling(axisAlignedBox.max()-axisAlignedBox.min())) |
|
||||||
.setColor(options->color()); |
|
||||||
AbstractBoxRenderer<dimensions>::wireframeMesh->draw(*AbstractBoxRenderer<dimensions>::wireframeShader); |
|
||||||
} |
|
||||||
|
|
||||||
template class AxisAlignedBoxRenderer<2>; |
|
||||||
template class AxisAlignedBoxRenderer<3>; |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}}} |
|
||||||
@ -1,49 +0,0 @@ |
|||||||
#ifndef Magnum_DebugTools_Implementation_AxisAlignedBoxRenderer_h |
|
||||||
#define Magnum_DebugTools_Implementation_AxisAlignedBoxRenderer_h |
|
||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Magnum/Shapes/Shapes.h" |
|
||||||
|
|
||||||
#include "Magnum/DebugTools/Implementation/AbstractBoxRenderer.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
template<UnsignedInt dimensions> class AxisAlignedBoxRenderer: public AbstractBoxRenderer<dimensions> { |
|
||||||
public: |
|
||||||
explicit AxisAlignedBoxRenderer(const Shapes::Implementation::AbstractShape<dimensions>& axisAlignedBox); |
|
||||||
AxisAlignedBoxRenderer(Shapes::Implementation::AbstractShape<dimensions>&&) = delete; |
|
||||||
|
|
||||||
void draw(Resource<ShapeRendererOptions>& options, const MatrixTypeFor<dimensions, Float>& projectionMatrix) override; |
|
||||||
|
|
||||||
private: |
|
||||||
const Shapes::AxisAlignedBox<dimensions>& axisAlignedBox; |
|
||||||
}; |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}}} |
|
||||||
|
|
||||||
#endif |
|
||||||
@ -1,50 +0,0 @@ |
|||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#define _MAGNUM_DO_NOT_WARN_DEPRECATED_SHAPES |
|
||||||
|
|
||||||
#include "BoxRenderer.h" |
|
||||||
|
|
||||||
#include "Magnum/GL/Mesh.h" |
|
||||||
#include "Magnum/DebugTools/ShapeRenderer.h" |
|
||||||
#include "Magnum/Shapes/Box.h" |
|
||||||
#include "Magnum/Shaders/Flat.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
template<UnsignedInt dimensions> BoxRenderer<dimensions>::BoxRenderer(const Shapes::Implementation::AbstractShape<dimensions>& box): box(static_cast<const Shapes::Implementation::Shape<Shapes::Box<dimensions>>&>(box).shape) {} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> void BoxRenderer<dimensions>::draw(Resource<ShapeRendererOptions>& options, const MatrixTypeFor<dimensions, Float>& projectionMatrix) { |
|
||||||
AbstractBoxRenderer<dimensions>::wireframeShader->setTransformationProjectionMatrix(projectionMatrix*box.transformation()) |
|
||||||
.setColor(options->color()); |
|
||||||
AbstractBoxRenderer<dimensions>::wireframeMesh->draw(*AbstractBoxRenderer<dimensions>::wireframeShader); |
|
||||||
} |
|
||||||
|
|
||||||
template class BoxRenderer<2>; |
|
||||||
template class BoxRenderer<3>; |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}}} |
|
||||||
@ -1,49 +0,0 @@ |
|||||||
#ifndef Magnum_DebugTools_Implementation_BoxRenderer_h |
|
||||||
#define Magnum_DebugTools_Implementation_BoxRenderer_h |
|
||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Magnum/Shapes/Shapes.h" |
|
||||||
|
|
||||||
#include "Magnum/DebugTools/Implementation/AbstractBoxRenderer.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
template<UnsignedInt dimensions> class BoxRenderer: public AbstractBoxRenderer<dimensions> { |
|
||||||
public: |
|
||||||
explicit BoxRenderer(const Shapes::Implementation::AbstractShape<dimensions>& box); |
|
||||||
BoxRenderer(const Shapes::Implementation::AbstractShape<dimensions>&&) = delete; |
|
||||||
|
|
||||||
void draw(Resource<ShapeRendererOptions>& options, const MatrixTypeFor<dimensions, Float>& projectionMatrix) override; |
|
||||||
|
|
||||||
private: |
|
||||||
const Shapes::Box<dimensions>& box; |
|
||||||
}; |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}}} |
|
||||||
|
|
||||||
#endif |
|
||||||
@ -1,131 +0,0 @@ |
|||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#define _MAGNUM_DO_NOT_WARN_DEPRECATED_SHAPES |
|
||||||
|
|
||||||
#include "CapsuleRenderer.h" |
|
||||||
|
|
||||||
#include "Magnum/DebugTools/ResourceManager.h" |
|
||||||
#include "Magnum/DebugTools/ShapeRenderer.h" |
|
||||||
#include "Magnum/GL/Mesh.h" |
|
||||||
#include "Magnum/GL/MeshView.h" |
|
||||||
#include "Magnum/Primitives/Capsule.h" |
|
||||||
#include "Magnum/Shapes/Capsule.h" |
|
||||||
#include "Magnum/Shaders/Flat.h" |
|
||||||
#include "Magnum/Trade/MeshData2D.h" |
|
||||||
#include "Magnum/Trade/MeshData3D.h" |
|
||||||
|
|
||||||
#include "Magnum/DebugTools/Implementation/CapsuleRendererTransformation.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
AbstractCapsuleRenderer<2>::AbstractCapsuleRenderer(): AbstractShapeRenderer<2>("capsule2d", "capsule2d-vertices", "capsule2d-indices") { |
|
||||||
constexpr UnsignedInt rings = 10; |
|
||||||
if(!wireframeMesh) createResources(Primitives::capsule2DWireframe(rings, 1, 1.0f)); |
|
||||||
|
|
||||||
/* Bottom hemisphere */ |
|
||||||
if(!(bottom = ResourceManager::instance().get<GL::MeshView>("capsule2d-bottom"))) { |
|
||||||
auto view = new GL::MeshView(*wireframeMesh); |
|
||||||
view->setCount(rings*4) |
|
||||||
.setIndexRange(0, 0, rings*2+1); |
|
||||||
ResourceManager::instance().set(bottom.key(), view, ResourceDataState::Final, ResourcePolicy::Manual); |
|
||||||
} |
|
||||||
|
|
||||||
/* Cylinder */ |
|
||||||
if(!(cylinder = ResourceManager::instance().get<GL::MeshView>("capsule2d-cylinder"))) { |
|
||||||
auto view = new GL::MeshView(*wireframeMesh); |
|
||||||
view->setCount(4) |
|
||||||
.setIndexRange(rings*4, rings*2+1, rings*2+3); |
|
||||||
ResourceManager::instance().set(cylinder.key(), view, ResourceDataState::Final, ResourcePolicy::Manual); |
|
||||||
} |
|
||||||
|
|
||||||
/* Top hemisphere */ |
|
||||||
if(!(top = ResourceManager::instance().get<GL::MeshView>("capsule2d-top"))) { |
|
||||||
auto view = new GL::MeshView(*wireframeMesh); |
|
||||||
view->setCount(rings*4) |
|
||||||
.setIndexRange(rings*4+4, rings*2+3, rings*4+4); |
|
||||||
ResourceManager::instance().set(top.key(), view, ResourceDataState::Final, ResourcePolicy::Manual); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
AbstractCapsuleRenderer<3>::AbstractCapsuleRenderer(): AbstractShapeRenderer<3>("capsule3d", "capsule3d-vertices", "capsule3d-indices") { |
|
||||||
constexpr UnsignedInt rings = 10; |
|
||||||
constexpr UnsignedInt segments = 40; |
|
||||||
if(!wireframeMesh) createResources(Primitives::capsule3DWireframe(rings, 1, segments, 1.0f)); |
|
||||||
|
|
||||||
/* Bottom hemisphere */ |
|
||||||
if(!(bottom = ResourceManager::instance().get<GL::MeshView>("capsule3d-bottom"))) { |
|
||||||
auto view = new GL::MeshView(*wireframeMesh); |
|
||||||
view->setCount(rings*8) |
|
||||||
.setIndexRange(0, 0, rings*4+1); |
|
||||||
ResourceManager::instance().set(bottom.key(), view, ResourceDataState::Final, ResourcePolicy::Manual); |
|
||||||
} |
|
||||||
|
|
||||||
/* Cylinder */ |
|
||||||
if(!(cylinder = ResourceManager::instance().get<GL::MeshView>("capsule3d-cylinder"))) { |
|
||||||
auto view = new GL::MeshView(*wireframeMesh); |
|
||||||
view->setCount(segments*4+8) |
|
||||||
.setIndexRange(rings*8, rings*4+1, rings*4+segments*2+5); |
|
||||||
ResourceManager::instance().set(cylinder.key(), view, ResourceDataState::Final, ResourcePolicy::Manual); |
|
||||||
} |
|
||||||
|
|
||||||
/* Top */ |
|
||||||
if(!(top = ResourceManager::instance().get<GL::MeshView>("capsule3d-top"))) { |
|
||||||
auto view = new GL::MeshView(*wireframeMesh); |
|
||||||
view->setCount(rings*8) |
|
||||||
.setIndexRange(rings*8+segments*4+8, rings*4+segments*2+5, rings*8+segments*2+6); |
|
||||||
ResourceManager::instance().set(top.key(), view, ResourceDataState::Final, ResourcePolicy::Manual); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
AbstractCapsuleRenderer<2>::~AbstractCapsuleRenderer() = default; |
|
||||||
|
|
||||||
AbstractCapsuleRenderer<3>::~AbstractCapsuleRenderer() = default; |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> CapsuleRenderer<dimensions>::CapsuleRenderer(const Shapes::Implementation::AbstractShape<dimensions>& capsule): capsule(static_cast<const Shapes::Implementation::Shape<Shapes::Capsule<dimensions>>&>(capsule).shape) {} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> void CapsuleRenderer<dimensions>::draw(Resource<ShapeRendererOptions>& options, const MatrixTypeFor<dimensions, Float>& projectionMatrix) { |
|
||||||
std::array<MatrixTypeFor<dimensions, Float>, 3> transformations = Implementation::capsuleRendererTransformation<dimensions>(capsule.a(), capsule.b(), capsule.radius()); |
|
||||||
AbstractShapeRenderer<dimensions>::wireframeShader->setColor(options->color()); |
|
||||||
|
|
||||||
/* Bottom */ |
|
||||||
AbstractShapeRenderer<dimensions>::wireframeShader->setTransformationProjectionMatrix(projectionMatrix*transformations[0]); |
|
||||||
AbstractCapsuleRenderer<dimensions>::bottom->draw(*AbstractShapeRenderer<dimensions>::wireframeShader); |
|
||||||
|
|
||||||
/* Cylinder */ |
|
||||||
AbstractShapeRenderer<dimensions>::wireframeShader->setTransformationProjectionMatrix(projectionMatrix*transformations[1]); |
|
||||||
AbstractCapsuleRenderer<dimensions>::cylinder->draw(*AbstractShapeRenderer<dimensions>::wireframeShader); |
|
||||||
|
|
||||||
/* Top */ |
|
||||||
AbstractShapeRenderer<dimensions>::wireframeShader->setTransformationProjectionMatrix(projectionMatrix*transformations[2]); |
|
||||||
AbstractCapsuleRenderer<dimensions>::top->draw(*AbstractShapeRenderer<dimensions>::wireframeShader); |
|
||||||
} |
|
||||||
|
|
||||||
template class CapsuleRenderer<2>; |
|
||||||
template class CapsuleRenderer<3>; |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}}} |
|
||||||
@ -1,69 +0,0 @@ |
|||||||
#ifndef Magnum_DebugTools_Implementation_CapsuleRenderer_h |
|
||||||
#define Magnum_DebugTools_Implementation_CapsuleRenderer_h |
|
||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Magnum/Shapes/Shapes.h" |
|
||||||
|
|
||||||
#include "Magnum/DebugTools/Implementation/AbstractShapeRenderer.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
template<UnsignedInt dimensions> class AbstractCapsuleRenderer; |
|
||||||
|
|
||||||
template<> class AbstractCapsuleRenderer<2>: public AbstractShapeRenderer<2> { |
|
||||||
public: |
|
||||||
explicit AbstractCapsuleRenderer(); |
|
||||||
~AbstractCapsuleRenderer(); |
|
||||||
|
|
||||||
protected: |
|
||||||
Resource<GL::MeshView> bottom, cylinder, top; |
|
||||||
}; |
|
||||||
|
|
||||||
template<> class AbstractCapsuleRenderer<3>: public AbstractShapeRenderer<3> { |
|
||||||
public: |
|
||||||
explicit AbstractCapsuleRenderer(); |
|
||||||
~AbstractCapsuleRenderer(); |
|
||||||
|
|
||||||
protected: |
|
||||||
Resource<GL::MeshView> bottom, cylinder, top; |
|
||||||
}; |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> class CapsuleRenderer: public AbstractCapsuleRenderer<dimensions> { |
|
||||||
public: |
|
||||||
explicit CapsuleRenderer(const Shapes::Implementation::AbstractShape<dimensions>& capsule); |
|
||||||
CapsuleRenderer(const Shapes::Implementation::AbstractShape<dimensions>&&) = delete; |
|
||||||
|
|
||||||
void draw(Resource<ShapeRendererOptions>& options, const MatrixTypeFor<dimensions, Float>& projectionMatrix) override; |
|
||||||
|
|
||||||
private: |
|
||||||
const Shapes::Capsule<dimensions>& capsule; |
|
||||||
}; |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}}} |
|
||||||
|
|
||||||
#endif |
|
||||||
@ -1,109 +0,0 @@ |
|||||||
#ifndef Magnum_DebugTools_Implementation_ForceRendererTransformation_h |
|
||||||
#define Magnum_DebugTools_Implementation_ForceRendererTransformation_h |
|
||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include <array> |
|
||||||
|
|
||||||
#include "Magnum/DimensionTraits.h" |
|
||||||
#include "Magnum/Magnum.h" |
|
||||||
#include "Magnum/Math/Functions.h" |
|
||||||
#include "Magnum/Math/Matrix3.h" |
|
||||||
#include "Magnum/Math/Matrix4.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
template<UnsignedInt dimensions> std::array<MatrixTypeFor<dimensions, Float>, 3> capsuleRendererTransformation(const VectorTypeFor<dimensions, Float>& a, const VectorTypeFor<dimensions, Float>& b, Float radius); |
|
||||||
|
|
||||||
template<> std::array<Matrix3, 3> capsuleRendererTransformation<2>(const Vector2& a, const Vector2& b, const Float radius) { |
|
||||||
/* Vector from capsule center to top hemisphere center */ |
|
||||||
const Vector2 direction = 0.5f*(b - a); |
|
||||||
const Float length = direction.length(); |
|
||||||
|
|
||||||
/* Capsule rotation and distance to caps after they are scaled to proper
|
|
||||||
radius (if nonzero cylinder length) */ |
|
||||||
Matrix3 rotation; |
|
||||||
Vector2 capDistance; |
|
||||||
if(length >= Math::TypeTraits<Float>::epsilon()) { |
|
||||||
rotation.up() = direction/length; |
|
||||||
rotation.right() = rotation.up().perpendicular(); |
|
||||||
CORRADE_INTERNAL_ASSERT(rotation.right().isNormalized()); |
|
||||||
|
|
||||||
capDistance = direction*(radius/length); |
|
||||||
} |
|
||||||
|
|
||||||
/* Scaling and translation of all parts */ |
|
||||||
const auto rotationScaling = rotation*Matrix3::scaling(Vector2(radius)); |
|
||||||
return {{ |
|
||||||
Matrix3::translation(a+capDistance)*rotationScaling, |
|
||||||
Matrix3::translation(0.5f*(a + b))*rotation*Matrix3::scaling({radius, length}), |
|
||||||
Matrix3::translation(b-capDistance)*rotationScaling |
|
||||||
}}; |
|
||||||
} |
|
||||||
|
|
||||||
template<> std::array<Matrix4, 3> capsuleRendererTransformation<3>(const Vector3& a, const Vector3& b, const Float radius) { |
|
||||||
/* Vector from capsule center to top hemisphere center */ |
|
||||||
const Vector3 direction = 0.5f*(b - a); |
|
||||||
const Float length = direction.length(); |
|
||||||
|
|
||||||
/* Capsule rotation and distance to caps after they are scaled to proper
|
|
||||||
radius (if nonzero cylinder length) */ |
|
||||||
Matrix4 rotation; |
|
||||||
Vector3 capDistance; |
|
||||||
if(length >= Math::TypeTraits<Float>::epsilon()) { |
|
||||||
const Vector3 directionNormalized = direction/length; |
|
||||||
const Float dot = Math::dot(directionNormalized, Vector3::zAxis()); |
|
||||||
|
|
||||||
/* Direction is parallel to Z axis, special rotation case */ |
|
||||||
if(Math::abs(dot) > 1.0f - Math::TypeTraits<Float>::epsilon()) { |
|
||||||
rotation.up() = dot*Vector3::zAxis(); |
|
||||||
rotation.right() = Vector3::xAxis(); |
|
||||||
rotation.backward() = -dot*Vector3::yAxis(); |
|
||||||
|
|
||||||
/* Common case */ |
|
||||||
} else { |
|
||||||
rotation.up() = directionNormalized; |
|
||||||
rotation.right() = Math::cross(rotation.up(), Vector3::zAxis()).normalized(); |
|
||||||
rotation.backward() = Math::cross(rotation.right(), rotation.up()); |
|
||||||
CORRADE_INTERNAL_ASSERT(rotation.up().isNormalized() && rotation.backward().isNormalized()); |
|
||||||
} |
|
||||||
|
|
||||||
capDistance = directionNormalized*radius; |
|
||||||
} |
|
||||||
|
|
||||||
/* Scaling and translation of all parts */ |
|
||||||
const auto rotationScaling = rotation*Matrix4::scaling(Vector3(radius)); |
|
||||||
return {{ |
|
||||||
Matrix4::translation(a+capDistance)*rotationScaling, |
|
||||||
Matrix4::translation(0.5f*(a + b))*rotation*Matrix4::scaling({radius, length, radius}), |
|
||||||
Matrix4::translation(b-capDistance)*rotationScaling |
|
||||||
}}; |
|
||||||
} |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}}} |
|
||||||
|
|
||||||
#endif |
|
||||||
@ -1,65 +0,0 @@ |
|||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#define _MAGNUM_DO_NOT_WARN_DEPRECATED_SHAPES |
|
||||||
|
|
||||||
#include "CylinderRenderer.h" |
|
||||||
|
|
||||||
#include "Magnum/DebugTools/ShapeRenderer.h" |
|
||||||
#include "Magnum/GL/Mesh.h" |
|
||||||
#include "Magnum/Shapes/Cylinder.h" |
|
||||||
#include "Magnum/Primitives/Cylinder.h" |
|
||||||
#include "Magnum/Primitives/Square.h" |
|
||||||
#include "Magnum/Shaders/Flat.h" |
|
||||||
#include "Magnum/Trade/MeshData2D.h" |
|
||||||
#include "Magnum/Trade/MeshData3D.h" |
|
||||||
|
|
||||||
#include "CylinderRendererTransformation.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
AbstractCylinderRenderer<2>::AbstractCylinderRenderer(): AbstractShapeRenderer<2>("cylinder2d", "cylinder2d-vertices", {}) { |
|
||||||
if(!wireframeMesh) createResources(Primitives::squareWireframe()); |
|
||||||
} |
|
||||||
|
|
||||||
AbstractCylinderRenderer<3>::AbstractCylinderRenderer(): AbstractShapeRenderer<3>("cylinder3d", "cylinder3d-vertices", "cylinder3d-indices") { |
|
||||||
if(!wireframeMesh) createResources(Primitives::cylinderWireframe(1, 40, 1.0f)); |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> CylinderRenderer<dimensions>::CylinderRenderer(const Shapes::Implementation::AbstractShape<dimensions>& cylinder): cylinder(static_cast<const Shapes::Implementation::Shape<Shapes::Cylinder<dimensions>>&>(cylinder).shape) {} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> void CylinderRenderer<dimensions>::draw(Resource<ShapeRendererOptions>& options, const MatrixTypeFor<dimensions, Float>& projectionMatrix) { |
|
||||||
AbstractShapeRenderer<dimensions>::wireframeShader->setTransformationProjectionMatrix(projectionMatrix* |
|
||||||
Implementation::cylinderRendererTransformation<dimensions>(cylinder.a(), cylinder.b(), cylinder.radius())) |
|
||||||
.setColor(options->color()); |
|
||||||
AbstractShapeRenderer<dimensions>::wireframeMesh->draw(*AbstractShapeRenderer<dimensions>::wireframeShader); |
|
||||||
} |
|
||||||
|
|
||||||
template class CylinderRenderer<2>; |
|
||||||
template class CylinderRenderer<3>; |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}}} |
|
||||||
@ -1,61 +0,0 @@ |
|||||||
#ifndef Magnum_DebugTools_Implementation_CylinderRenderer_h |
|
||||||
#define Magnum_DebugTools_Implementation_CylinderRenderer_h |
|
||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Magnum/Shapes/Shapes.h" |
|
||||||
|
|
||||||
#include "AbstractShapeRenderer.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
template<UnsignedInt dimensions> class AbstractCylinderRenderer; |
|
||||||
|
|
||||||
template<> class AbstractCylinderRenderer<2>: public AbstractShapeRenderer<2> { |
|
||||||
public: |
|
||||||
explicit AbstractCylinderRenderer(); |
|
||||||
}; |
|
||||||
|
|
||||||
template<> class AbstractCylinderRenderer<3>: public AbstractShapeRenderer<3> { |
|
||||||
public: |
|
||||||
explicit AbstractCylinderRenderer(); |
|
||||||
}; |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> class CylinderRenderer: public AbstractCylinderRenderer<dimensions> { |
|
||||||
public: |
|
||||||
explicit CylinderRenderer(const Shapes::Implementation::AbstractShape<dimensions>& cylinder); |
|
||||||
CylinderRenderer(const Shapes::Implementation::AbstractShape<dimensions>&&) = delete; |
|
||||||
|
|
||||||
void draw(Resource<ShapeRendererOptions>& options, const MatrixTypeFor<dimensions, Float>& projectionMatrix) override; |
|
||||||
|
|
||||||
private: |
|
||||||
const Shapes::Cylinder<dimensions>& cylinder; |
|
||||||
}; |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}}} |
|
||||||
|
|
||||||
#endif |
|
||||||
@ -1,91 +0,0 @@ |
|||||||
#ifndef Magnum_DebugTools_Implementation_ForceRendererTransformation_h |
|
||||||
#define Magnum_DebugTools_Implementation_ForceRendererTransformation_h |
|
||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Magnum/DimensionTraits.h" |
|
||||||
#include "Magnum/Magnum.h" |
|
||||||
#include "Magnum/Math/Functions.h" |
|
||||||
#include "Magnum/Math/Matrix3.h" |
|
||||||
#include "Magnum/Math/Matrix4.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
template<UnsignedInt dimensions> MatrixTypeFor<dimensions, Float> cylinderRendererTransformation(const VectorTypeFor<dimensions, Float>& a, const VectorTypeFor<dimensions, Float>& b, Float radius); |
|
||||||
|
|
||||||
template<> Matrix3 cylinderRendererTransformation<2>(const Vector2& a, const Vector2& b, const Float radius) { |
|
||||||
/* Vector from cylinder center to top hemisphere center */ |
|
||||||
const Vector2 direction = 0.5f*(b - a); |
|
||||||
const Float length = direction.length(); |
|
||||||
|
|
||||||
/* Capsule rotation and distance to caps after they are scaled to proper
|
|
||||||
radius (if nonzero cylinder length) */ |
|
||||||
Matrix3 rotation; |
|
||||||
if(length >= Math::TypeTraits<Float>::epsilon()) { |
|
||||||
rotation.up() = direction/length; |
|
||||||
rotation.right() = rotation.up().perpendicular(); |
|
||||||
CORRADE_INTERNAL_ASSERT(rotation.right().isNormalized()); |
|
||||||
} |
|
||||||
|
|
||||||
/* Scaling and translation */ |
|
||||||
return Matrix3::translation(0.5f*(a + b))*rotation*Matrix3::scaling({radius, length}); |
|
||||||
} |
|
||||||
|
|
||||||
template<> Matrix4 cylinderRendererTransformation<3>(const Vector3& a, const Vector3& b, const Float radius) { |
|
||||||
/* Vector from cylinder center to top hemisphere center */ |
|
||||||
const Vector3 direction = 0.5f*(b - a); |
|
||||||
const Float length = direction.length(); |
|
||||||
|
|
||||||
/* Capsule rotation and distance to caps after they are scaled to proper
|
|
||||||
radius (if nonzero cylinder length) */ |
|
||||||
Matrix4 rotation; |
|
||||||
if(length >= Math::TypeTraits<Float>::epsilon()) { |
|
||||||
const Vector3 directionNormalized = direction/length; |
|
||||||
const Float dot = Math::dot(directionNormalized, Vector3::zAxis()); |
|
||||||
|
|
||||||
/* Direction is parallel to Z axis, special rotation case */ |
|
||||||
if(Math::abs(dot) > 1.0f - Math::TypeTraits<Float>::epsilon()) { |
|
||||||
rotation.up() = dot*Vector3::zAxis(); |
|
||||||
rotation.right() = Vector3::xAxis(); |
|
||||||
rotation.backward() = -dot*Vector3::yAxis(); |
|
||||||
|
|
||||||
/* Common case */ |
|
||||||
} else { |
|
||||||
rotation.up() = directionNormalized; |
|
||||||
rotation.right() = Math::cross(rotation.up(), Vector3::zAxis()).normalized(); |
|
||||||
rotation.backward() = Math::cross(rotation.right(), rotation.up()); |
|
||||||
CORRADE_INTERNAL_ASSERT(rotation.up().isNormalized() && rotation.backward().isNormalized()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/* Scaling and translation */ |
|
||||||
return Matrix4::translation(0.5f*(a + b))*rotation*Matrix4::scaling({radius, length, radius}); |
|
||||||
} |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}}} |
|
||||||
|
|
||||||
#endif |
|
||||||
@ -1,72 +0,0 @@ |
|||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#define _MAGNUM_DO_NOT_WARN_DEPRECATED_SHAPES |
|
||||||
|
|
||||||
#include "LineSegmentRenderer.h" |
|
||||||
|
|
||||||
#include "Magnum/DebugTools/ShapeRenderer.h" |
|
||||||
#include "Magnum/GL/Mesh.h" |
|
||||||
#include "Magnum/Shapes/LineSegment.h" |
|
||||||
#include "Magnum/Primitives/Line.h" |
|
||||||
#include "Magnum/Shaders/Flat.h" |
|
||||||
#include "Magnum/Trade/MeshData2D.h" |
|
||||||
#include "Magnum/Trade/MeshData3D.h" |
|
||||||
|
|
||||||
#include "Magnum/DebugTools/Implementation/LineSegmentRendererTransformation.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
namespace { |
|
||||||
template<UnsignedInt dimensions> ResourceKey meshKey(); |
|
||||||
template<> inline ResourceKey meshKey<2>() { return ResourceKey("line2d"); } |
|
||||||
template<> inline ResourceKey meshKey<3>() { return ResourceKey("line3d"); } |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> ResourceKey vertexBufferKey(); |
|
||||||
template<> inline ResourceKey vertexBufferKey<2>() { return ResourceKey("line2d-vertices"); } |
|
||||||
template<> inline ResourceKey vertexBufferKey<3>() { return ResourceKey("line3d-vertices"); } |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> typename MeshData<dimensions>::Type meshData(); |
|
||||||
template<> inline Trade::MeshData2D meshData<2>() { return Primitives::line2D(); } |
|
||||||
template<> inline Trade::MeshData3D meshData<3>() { return Primitives::line3D(); } |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> LineSegmentRenderer<dimensions>::LineSegmentRenderer(const Shapes::Implementation::AbstractShape<dimensions>& line): AbstractShapeRenderer<dimensions>(meshKey<dimensions>(), vertexBufferKey<dimensions>(), {}), line(static_cast<const Shapes::Implementation::Shape<Shapes::LineSegment<dimensions>>&>(line).shape) { |
|
||||||
if(!AbstractShapeRenderer<dimensions>::wireframeMesh) AbstractShapeRenderer<dimensions>::createResources(meshData<dimensions>()); |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> void LineSegmentRenderer<dimensions>::draw(Resource<ShapeRendererOptions>& options, const MatrixTypeFor<dimensions, Float>& projectionMatrix) { |
|
||||||
AbstractShapeRenderer<dimensions>::wireframeShader->setTransformationProjectionMatrix(projectionMatrix* |
|
||||||
Implementation::lineSegmentRendererTransformation<dimensions>(line.a(), line.b())) |
|
||||||
.setColor(options->color()); |
|
||||||
AbstractShapeRenderer<dimensions>::wireframeMesh->draw(*AbstractShapeRenderer<dimensions>::wireframeShader); |
|
||||||
} |
|
||||||
|
|
||||||
template class LineSegmentRenderer<2>; |
|
||||||
template class LineSegmentRenderer<3>; |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}}} |
|
||||||
@ -1,49 +0,0 @@ |
|||||||
#ifndef Magnum_DebugTools_Implementation_LineSegmentRenderer_h |
|
||||||
#define Magnum_DebugTools_Implementation_LineSegmentRenderer_h |
|
||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Magnum/Shapes/Shapes.h" |
|
||||||
|
|
||||||
#include "Magnum/DebugTools/Implementation/AbstractShapeRenderer.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
template<UnsignedInt dimensions> class LineSegmentRenderer: public AbstractShapeRenderer<dimensions> { |
|
||||||
public: |
|
||||||
explicit LineSegmentRenderer(const Shapes::Implementation::AbstractShape<dimensions>& line); |
|
||||||
LineSegmentRenderer(const Shapes::Implementation::AbstractShape<dimensions>&&) = delete; |
|
||||||
|
|
||||||
void draw(Resource<ShapeRendererOptions>& options, const MatrixTypeFor<dimensions, Float>& projectionMatrix) override; |
|
||||||
|
|
||||||
private: |
|
||||||
const Shapes::LineSegment<dimensions>& line; |
|
||||||
}; |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}}} |
|
||||||
|
|
||||||
#endif |
|
||||||
@ -1,42 +0,0 @@ |
|||||||
#ifndef Magnum_DebugTools_Implementation_LineSegmentRendererTransformation_h |
|
||||||
#define Magnum_DebugTools_Implementation_LineSegmentRendererTransformation_h |
|
||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Magnum/DimensionTraits.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
template<UnsignedInt dimensions> MatrixTypeFor<dimensions, Float> lineSegmentRendererTransformation(const VectorTypeFor<dimensions, Float>& a, const VectorTypeFor<dimensions, Float>& b) { |
|
||||||
auto transformation = MatrixTypeFor<dimensions, Float>::translation(a); |
|
||||||
transformation.right() = b - a; |
|
||||||
return transformation; |
|
||||||
} |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}}} |
|
||||||
|
|
||||||
#endif |
|
||||||
@ -1,72 +0,0 @@ |
|||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#define _MAGNUM_DO_NOT_WARN_DEPRECATED_SHAPES |
|
||||||
|
|
||||||
#include "PointRenderer.h" |
|
||||||
|
|
||||||
#include "Magnum/DebugTools/ShapeRenderer.h" |
|
||||||
#include "Magnum/GL/Mesh.h" |
|
||||||
#include "Magnum/Shapes/Point.h" |
|
||||||
#include "Magnum/Primitives/Crosshair.h" |
|
||||||
#include "Magnum/Shaders/Flat.h" |
|
||||||
#include "Magnum/Trade/MeshData2D.h" |
|
||||||
#include "Magnum/Trade/MeshData3D.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
namespace { |
|
||||||
template<UnsignedInt dimensions> ResourceKey meshKey(); |
|
||||||
template<> inline ResourceKey meshKey<2>() { return ResourceKey("point2d"); } |
|
||||||
template<> inline ResourceKey meshKey<3>() { return ResourceKey("point3d"); } |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> ResourceKey vertexBufferKey(); |
|
||||||
template<> inline ResourceKey vertexBufferKey<2>() { return ResourceKey("point2d-vertices"); } |
|
||||||
template<> inline ResourceKey vertexBufferKey<3>() { return ResourceKey("point3d-vertices"); } |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> typename MeshData<dimensions>::Type meshData(); |
|
||||||
template<> inline Trade::MeshData2D meshData<2>() { return Primitives::crosshair2D(); } |
|
||||||
template<> inline Trade::MeshData3D meshData<3>() { return Primitives::crosshair3D(); } |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> PointRenderer<dimensions>::PointRenderer(const Shapes::Implementation::AbstractShape<dimensions>& point): AbstractShapeRenderer<dimensions>(meshKey<dimensions>(), vertexBufferKey<dimensions>(), {}), point(static_cast<const Shapes::Implementation::Shape<Shapes::Point<dimensions>>&>(point).shape) { |
|
||||||
if(!AbstractShapeRenderer<dimensions>::wireframeMesh) AbstractShapeRenderer<dimensions>::createResources(meshData<dimensions>()); |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> void PointRenderer<dimensions>::draw(Resource<ShapeRendererOptions>& options, const MatrixTypeFor<dimensions, Float>& projectionMatrix) { |
|
||||||
/* Half scale, because the point is 2x2(x2) */ |
|
||||||
AbstractShapeRenderer<dimensions>::wireframeShader->setTransformationProjectionMatrix(projectionMatrix* |
|
||||||
MatrixTypeFor<dimensions, Float>::translation(point.position())* |
|
||||||
MatrixTypeFor<dimensions, Float>::scaling(VectorTypeFor<dimensions, Float>{options->pointSize()/2})) |
|
||||||
.setColor(options->color()); |
|
||||||
AbstractShapeRenderer<dimensions>::wireframeMesh->draw(*AbstractShapeRenderer<dimensions>::wireframeShader); |
|
||||||
} |
|
||||||
|
|
||||||
template class PointRenderer<2>; |
|
||||||
template class PointRenderer<3>; |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}}} |
|
||||||
@ -1,49 +0,0 @@ |
|||||||
#ifndef Magnum_DebugTools_Implementation_PointRenderer_h |
|
||||||
#define Magnum_DebugTools_Implementation_PointRenderer_h |
|
||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Magnum/Shapes/Shapes.h" |
|
||||||
|
|
||||||
#include "Magnum/DebugTools/Implementation/AbstractShapeRenderer.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
template<UnsignedInt dimensions> class PointRenderer: public AbstractShapeRenderer<dimensions> { |
|
||||||
public: |
|
||||||
explicit PointRenderer(const Shapes::Implementation::AbstractShape<dimensions>& point); |
|
||||||
PointRenderer(Shapes::Implementation::AbstractShape<dimensions>&&) = delete; |
|
||||||
|
|
||||||
void draw(Resource<ShapeRendererOptions>& options, const MatrixTypeFor<dimensions, Float>& projectionMatrix) override; |
|
||||||
|
|
||||||
private: |
|
||||||
const Shapes::Point<dimensions>& point; |
|
||||||
}; |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}}} |
|
||||||
|
|
||||||
#endif |
|
||||||
@ -1,64 +0,0 @@ |
|||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#define _MAGNUM_DO_NOT_WARN_DEPRECATED_SHAPES |
|
||||||
|
|
||||||
#include "SphereRenderer.h" |
|
||||||
|
|
||||||
#include "Magnum/DebugTools/ShapeRenderer.h" |
|
||||||
#include "Magnum/GL/Mesh.h" |
|
||||||
#include "Magnum/Primitives/Circle.h" |
|
||||||
#include "Magnum/Primitives/UVSphere.h" |
|
||||||
#include "Magnum/Shaders/Flat.h" |
|
||||||
#include "Magnum/Shapes/Sphere.h" |
|
||||||
#include "Magnum/Trade/MeshData2D.h" |
|
||||||
#include "Magnum/Trade/MeshData3D.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
AbstractSphereRenderer<2>::AbstractSphereRenderer(): AbstractShapeRenderer<2>("sphere2d", "sphere2d-vertices", {}) { |
|
||||||
if(!wireframeMesh) createResources(Primitives::circle2DWireframe(40)); |
|
||||||
} |
|
||||||
|
|
||||||
AbstractSphereRenderer<3>::AbstractSphereRenderer(): AbstractShapeRenderer<3>("sphere3d", "sphere3d-vertices", "sphere3d-indices") { |
|
||||||
if(!wireframeMesh) createResources(Primitives::uvSphereWireframe(20, 40)); |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> SphereRenderer<dimensions>::SphereRenderer(const Shapes::Implementation::AbstractShape<dimensions>& sphere): sphere(static_cast<const Shapes::Implementation::Shape<Shapes::Sphere<dimensions>>&>(sphere).shape) {} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> void SphereRenderer<dimensions>::draw(Resource<ShapeRendererOptions>& options, const MatrixTypeFor<dimensions, Float>& projectionMatrix) { |
|
||||||
AbstractShapeRenderer<dimensions>::wireframeShader->setTransformationProjectionMatrix(projectionMatrix* |
|
||||||
MatrixTypeFor<dimensions, Float>::translation(sphere.position())* |
|
||||||
MatrixTypeFor<dimensions, Float>::scaling(VectorTypeFor<dimensions, Float>{sphere.radius()})) |
|
||||||
.setColor(options->color()); |
|
||||||
AbstractShapeRenderer<dimensions>::wireframeMesh->draw(*AbstractShapeRenderer<dimensions>::wireframeShader); |
|
||||||
} |
|
||||||
|
|
||||||
template class SphereRenderer<2>; |
|
||||||
template class SphereRenderer<3>; |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}}} |
|
||||||
@ -1,61 +0,0 @@ |
|||||||
#ifndef Magnum_DebugTools_Implementation_SphereRenderer_h |
|
||||||
#define Magnum_DebugTools_Implementation_SphereRenderer_h |
|
||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Magnum/Shapes/Shapes.h" |
|
||||||
|
|
||||||
#include "Magnum/DebugTools/Implementation/AbstractShapeRenderer.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace DebugTools { namespace Implementation { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
template<UnsignedInt dimensions> class AbstractSphereRenderer; |
|
||||||
|
|
||||||
template<> class AbstractSphereRenderer<2>: public AbstractShapeRenderer<2> { |
|
||||||
public: |
|
||||||
explicit AbstractSphereRenderer(); |
|
||||||
}; |
|
||||||
|
|
||||||
template<> class AbstractSphereRenderer<3>: public AbstractShapeRenderer<3> { |
|
||||||
public: |
|
||||||
explicit AbstractSphereRenderer(); |
|
||||||
}; |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> class SphereRenderer: public AbstractSphereRenderer<dimensions> { |
|
||||||
public: |
|
||||||
explicit SphereRenderer(const Shapes::Implementation::AbstractShape<dimensions>& sphere); |
|
||||||
SphereRenderer(const Shapes::Implementation::AbstractShape<dimensions>&&) = delete; |
|
||||||
|
|
||||||
void draw(Resource<ShapeRendererOptions>& options, const MatrixTypeFor<dimensions, Float>& projectionMatrix) override; |
|
||||||
|
|
||||||
private: |
|
||||||
const Shapes::Sphere<dimensions>& sphere; |
|
||||||
}; |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}}} |
|
||||||
|
|
||||||
#endif |
|
||||||
@ -1,137 +0,0 @@ |
|||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#define _MAGNUM_DO_NOT_WARN_DEPRECATED_SHAPES |
|
||||||
|
|
||||||
#include "ShapeRenderer.h" |
|
||||||
|
|
||||||
#include "Magnum/DebugTools/ResourceManager.h" |
|
||||||
#include "Magnum/Shapes/Composition.h" |
|
||||||
#include "Magnum/Shapes/Shape.h" |
|
||||||
#include "Magnum/SceneGraph/Camera.h" |
|
||||||
|
|
||||||
#include "Magnum/DebugTools/Implementation/AxisAlignedBoxRenderer.h" |
|
||||||
#include "Magnum/DebugTools/Implementation/BoxRenderer.h" |
|
||||||
#include "Magnum/DebugTools/Implementation/CapsuleRenderer.h" |
|
||||||
#include "Magnum/DebugTools/Implementation/CylinderRenderer.h" |
|
||||||
#include "Magnum/DebugTools/Implementation/LineSegmentRenderer.h" |
|
||||||
#include "Magnum/DebugTools/Implementation/PointRenderer.h" |
|
||||||
#include "Magnum/DebugTools/Implementation/SphereRenderer.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace DebugTools { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
namespace Implementation { |
|
||||||
|
|
||||||
template<> void createDebugMesh(ShapeRenderer<2>& renderer, const Shapes::Implementation::AbstractShape<2>& shape) { |
|
||||||
switch(shape.type()) { |
|
||||||
case Shapes::AbstractShape2D::Type::AxisAlignedBox: |
|
||||||
renderer._renderers.push_back(new Implementation::AxisAlignedBoxRenderer<2>(shape)); |
|
||||||
break; |
|
||||||
case Shapes::AbstractShape2D::Type::Box: |
|
||||||
renderer._renderers.push_back(new Implementation::BoxRenderer<2>(shape)); |
|
||||||
break; |
|
||||||
case Shapes::AbstractShape2D::Type::LineSegment: |
|
||||||
renderer._renderers.push_back(new Implementation::LineSegmentRenderer<2>(shape)); |
|
||||||
break; |
|
||||||
case Shapes::AbstractShape2D::Type::Point: |
|
||||||
renderer._renderers.push_back(new Implementation::PointRenderer<2>(shape)); |
|
||||||
break; |
|
||||||
case Shapes::AbstractShape2D::Type::Sphere: |
|
||||||
case Shapes::AbstractShape2D::Type::InvertedSphere: /* Isn't publicly subclassed, but shouldn't matter */ |
|
||||||
renderer._renderers.push_back(new Implementation::SphereRenderer<2>(shape)); |
|
||||||
break; |
|
||||||
case Shapes::AbstractShape2D::Type::Capsule: |
|
||||||
renderer._renderers.push_back(new Implementation::CapsuleRenderer<2>(shape)); |
|
||||||
break; |
|
||||||
case Shapes::AbstractShape2D::Type::Cylinder: |
|
||||||
renderer._renderers.push_back(new Implementation::CylinderRenderer<2>(shape)); |
|
||||||
break; |
|
||||||
case Shapes::AbstractShape2D::Type::Composition: { |
|
||||||
const Shapes::Composition2D& composition = |
|
||||||
static_cast<const Shapes::Implementation::Shape<Shapes::Composition2D>&>(shape).shape; |
|
||||||
for(std::size_t i = 0; i != composition.size(); ++i) |
|
||||||
createDebugMesh(renderer, Shapes::Implementation::getAbstractShape(composition, i)); |
|
||||||
} break; |
|
||||||
default: |
|
||||||
Warning() << "DebugTools::ShapeRenderer2D::createShapeRenderer(): type" << shape.type() << "not implemented"; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
template<> void createDebugMesh(ShapeRenderer<3>& renderer, const Shapes::Implementation::AbstractShape<3>& shape) { |
|
||||||
switch(shape.type()) { |
|
||||||
case Shapes::AbstractShape3D::Type::AxisAlignedBox: |
|
||||||
renderer._renderers.push_back(new Implementation::AxisAlignedBoxRenderer<3>(shape)); |
|
||||||
break; |
|
||||||
case Shapes::AbstractShape3D::Type::Box: |
|
||||||
renderer._renderers.push_back(new Implementation::BoxRenderer<3>(shape)); |
|
||||||
break; |
|
||||||
case Shapes::AbstractShape3D::Type::LineSegment: |
|
||||||
renderer._renderers.push_back(new Implementation::LineSegmentRenderer<3>(shape)); |
|
||||||
break; |
|
||||||
case Shapes::AbstractShape3D::Type::Point: |
|
||||||
renderer._renderers.push_back(new Implementation::PointRenderer<3>(shape)); |
|
||||||
break; |
|
||||||
case Shapes::AbstractShape3D::Type::Sphere: |
|
||||||
case Shapes::AbstractShape3D::Type::InvertedSphere: /* Isn't publicly subclassed, but shouldn't matter */ |
|
||||||
renderer._renderers.push_back(new Implementation::SphereRenderer<3>(shape)); |
|
||||||
break; |
|
||||||
case Shapes::AbstractShape3D::Type::Capsule: |
|
||||||
renderer._renderers.push_back(new Implementation::CapsuleRenderer<3>(shape)); |
|
||||||
break; |
|
||||||
case Shapes::AbstractShape3D::Type::Cylinder: |
|
||||||
renderer._renderers.push_back(new Implementation::CylinderRenderer<3>(shape)); |
|
||||||
break; |
|
||||||
case Shapes::AbstractShape3D::Type::Composition: { |
|
||||||
const Shapes::Composition3D& composition = |
|
||||||
static_cast<const Shapes::Implementation::Shape<Shapes::Composition3D>&>(shape).shape; |
|
||||||
for(std::size_t i = 0; i != composition.size(); ++i) |
|
||||||
createDebugMesh(renderer, Shapes::Implementation::getAbstractShape(composition, i)); |
|
||||||
} break; |
|
||||||
default: |
|
||||||
Warning() << "DebugTools::ShapeRenderer3D::createShapeRenderer(): type" << shape.type() << "not implemented"; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> ShapeRenderer<dimensions>::ShapeRenderer(Shapes::AbstractShape<dimensions>& shape, ResourceKey options, SceneGraph::DrawableGroup<dimensions, Float>* drawables): SceneGraph::Drawable<dimensions, Float>(shape.object(), drawables), _options(ResourceManager::instance().get<ShapeRendererOptions>(options)) { |
|
||||||
Implementation::createDebugMesh(*this, Shapes::Implementation::getAbstractShape(shape)); |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> ShapeRenderer<dimensions>::~ShapeRenderer() { |
|
||||||
for(auto i: _renderers) delete i; |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> void ShapeRenderer<dimensions>::draw(const MatrixTypeFor<dimensions, Float>&, SceneGraph::Camera<dimensions, Float>& camera) { |
|
||||||
const MatrixTypeFor<dimensions, Float> projectionMatrix = camera.projectionMatrix()*camera.cameraMatrix(); |
|
||||||
for(auto i: _renderers) i->draw(_options, projectionMatrix); |
|
||||||
} |
|
||||||
|
|
||||||
template class ShapeRenderer<2>; |
|
||||||
template class ShapeRenderer<3>; |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}} |
|
||||||
@ -1,250 +0,0 @@ |
|||||||
#ifndef Magnum_DebugTools_ShapeRenderer_h |
|
||||||
#define Magnum_DebugTools_ShapeRenderer_h |
|
||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#ifdef MAGNUM_TARGET_GL |
|
||||||
/** @file
|
|
||||||
@brief Class @ref Magnum::DebugTools::ShapeRenderer, @ref Magnum::DebugTools::ShapeRendererOptions, typedef @ref Magnum::DebugTools::ShapeRenderer2D, @ref Magnum::DebugTools::ShapeRenderer3D |
|
||||||
|
|
||||||
@deprecated The @ref Magnum::Shapes library is a failed design experiment and |
|
||||||
is scheduled for removal in a future release. Related geometry algorithms |
|
||||||
were moved to @ref Magnum::Math::Distance and @ref Magnum::Math::Intersection; |
|
||||||
if you need a full-fledged physics library, please have look at |
|
||||||
[Bullet](https://bulletphysics.org), which has Magnum integration in
|
|
||||||
@ref Magnum::BulletIntegration, or at [Box2D](https://box2d.org/), which
|
|
||||||
has a @ref examples-box2d "Magnum example" as well. |
|
||||||
*/ |
|
||||||
#endif |
|
||||||
|
|
||||||
#include "Magnum/Resource.h" |
|
||||||
#include "Magnum/Math/Color.h" |
|
||||||
#include "Magnum/SceneGraph/Drawable.h" |
|
||||||
#include "Magnum/Shapes/Shapes.h" |
|
||||||
#include "Magnum/Shapes/shapeImplementation.h" |
|
||||||
#include "Magnum/DebugTools/DebugTools.h" |
|
||||||
#include "Magnum/DebugTools/visibility.h" |
|
||||||
|
|
||||||
#ifndef MAGNUM_BUILD_DEPRECATED |
|
||||||
#error the Shapes library is scheduled for removal, see the docs for alternatives |
|
||||||
#endif |
|
||||||
|
|
||||||
/* I still have a test for this class and it shouldn't pollute the log there */ |
|
||||||
#ifndef _MAGNUM_DO_NOT_WARN_DEPRECATED_SHAPES |
|
||||||
CORRADE_DEPRECATED_FILE("the Shapes library is scheduled for removal, see the docs for alternatives") |
|
||||||
#endif |
|
||||||
|
|
||||||
#ifdef MAGNUM_TARGET_GL |
|
||||||
namespace Magnum { namespace DebugTools { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
template<UnsignedInt> class ShapeRenderer; |
|
||||||
|
|
||||||
namespace Implementation { |
|
||||||
template<UnsignedInt> class AbstractShapeRenderer; |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> void createDebugMesh(ShapeRenderer<dimensions>& renderer, const Shapes::Implementation::AbstractShape<dimensions>& shape); |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Shape renderer options |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
|
|
||||||
See @ref ShapeRenderer documentation for more information. |
|
||||||
|
|
||||||
@note This class is available only if Magnum is compiled with |
|
||||||
@ref MAGNUM_TARGET_GL "TARGET_GL" enabled (done by default) and |
|
||||||
`WITH_SHAPES` enabled (disabled by default). See @ref building-features for |
|
||||||
more information. |
|
||||||
*/ |
|
||||||
class CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") ShapeRendererOptions { |
|
||||||
public: |
|
||||||
/**
|
|
||||||
* @brief Shape rendering mode |
|
||||||
* |
|
||||||
* @see @ref setRenderMode() |
|
||||||
*/ |
|
||||||
enum class RenderMode: UnsignedByte { |
|
||||||
Wireframe, /**< Wireframe rendering */ |
|
||||||
Solid /**< Solid rendering */ |
|
||||||
}; |
|
||||||
|
|
||||||
constexpr ShapeRendererOptions(): _color(1.0f), _pointSize(0.25f), _renderMode(RenderMode::Wireframe) {} |
|
||||||
|
|
||||||
/** @brief Shape rendering mode */ |
|
||||||
constexpr RenderMode renderMode() const { return _renderMode; } |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Set shape rendering mode |
|
||||||
* @return Reference to self (for method chaining) |
|
||||||
* |
|
||||||
* Default is @ref RenderMode::Wireframe. |
|
||||||
*/ |
|
||||||
ShapeRendererOptions& setRenderMode(RenderMode mode) { |
|
||||||
_renderMode = mode; |
|
||||||
return *this; |
|
||||||
} |
|
||||||
|
|
||||||
/** @brief Color of rendered shape */ |
|
||||||
constexpr Color4 color() const { return _color; } |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Set color of rendered shape |
|
||||||
* @return Reference to self (for method chaining) |
|
||||||
* |
|
||||||
* Default is @cpp 0xffffffff_rgbaf @ce. |
|
||||||
*/ |
|
||||||
ShapeRendererOptions& setColor(const Color4& color) { |
|
||||||
_color = color; |
|
||||||
return *this; |
|
||||||
} |
|
||||||
|
|
||||||
/** @brief Point size */ |
|
||||||
constexpr Float pointSize() const { return _pointSize; } |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Set point size |
|
||||||
* @return Reference to self (for method chaining) |
|
||||||
* |
|
||||||
* Size of rendered crosshairs, representing @ref Shapes::Point shapes. |
|
||||||
* Default is @cpp 0.25f @ce. |
|
||||||
*/ |
|
||||||
ShapeRendererOptions& setPointSize(Float size) { |
|
||||||
_pointSize = size; |
|
||||||
return *this; |
|
||||||
} |
|
||||||
|
|
||||||
private: |
|
||||||
Color4 _color; |
|
||||||
Float _pointSize; |
|
||||||
RenderMode _renderMode; |
|
||||||
}; |
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Shape renderer |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
|
|
||||||
Visualizes collision shapes using wireframe primitives. See |
|
||||||
@ref debug-tools-renderers for more information. |
|
||||||
|
|
||||||
@section DebugTools-ShapeRenderer-usage Basic usage |
|
||||||
|
|
||||||
Example code: |
|
||||||
|
|
||||||
@code{.cpp} |
|
||||||
// Create some options
|
|
||||||
DebugTools::ResourceManager::instance().set("red", |
|
||||||
DebugTools::ShapeRendererOptions().setColor({1.0f, 0.0f, 0.0f})); |
|
||||||
|
|
||||||
// Create debug renderer for given shape, use "red" options for it
|
|
||||||
Shapes::AbstractShape2D* shape; |
|
||||||
new DebugTools::ShapeRenderer2D(shape, "red", debugDrawables); |
|
||||||
@endcode |
|
||||||
|
|
||||||
@note This class is available only if Magnum is compiled with |
|
||||||
@ref MAGNUM_TARGET_GL "TARGET_GL" enabled (done by default) and |
|
||||||
`WITH_SHAPES` enabled (disabled by default). See @ref building-features for |
|
||||||
more information. |
|
||||||
|
|
||||||
@see @ref ShapeRenderer2D, @ref ShapeRenderer3D, @ref ShapeRendererOptions |
|
||||||
|
|
||||||
@todo Different drawing style for inverted shapes? (marking the "inside" somehow) |
|
||||||
*/ |
|
||||||
template<UnsignedInt dimensions> class CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") MAGNUM_DEBUGTOOLS_EXPORT ShapeRenderer: public SceneGraph::Drawable<dimensions, Float> { |
|
||||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
|
||||||
friend void Implementation::createDebugMesh<>(ShapeRenderer<dimensions>&, const Shapes::Implementation::AbstractShape<dimensions>&); |
|
||||||
#endif |
|
||||||
|
|
||||||
public: |
|
||||||
/**
|
|
||||||
* @brief Constructor |
|
||||||
* @param shape Shape for which to create debug renderer |
|
||||||
* @param options Options resource key. See |
|
||||||
* @ref DebugTools-ShapeRenderer-usage "class documentation" for |
|
||||||
* more information. |
|
||||||
* @param drawables Drawable group |
|
||||||
* |
|
||||||
* The renderer is automatically added to shape's object features, |
|
||||||
* @p shape must be available for the whole lifetime of the renderer |
|
||||||
* and if it is group, it must not change its internal structure. |
|
||||||
*/ |
|
||||||
explicit ShapeRenderer(Shapes::AbstractShape<dimensions>& shape, ResourceKey options = ResourceKey(), SceneGraph::DrawableGroup<dimensions, Float>* drawables = nullptr); |
|
||||||
|
|
||||||
~ShapeRenderer(); |
|
||||||
|
|
||||||
private: |
|
||||||
void draw(const MatrixTypeFor<dimensions, Float>& transformationMatrix, SceneGraph::Camera<dimensions, Float>& camera) override; |
|
||||||
|
|
||||||
Resource<ShapeRendererOptions> _options; |
|
||||||
std::vector<Implementation::AbstractShapeRenderer<dimensions>*> _renderers; |
|
||||||
}; |
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Two-dimensional shape renderer |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
*/ |
|
||||||
typedef CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") ShapeRenderer<2> ShapeRenderer2D; |
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Three-dimensional shape renderer |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
*/ |
|
||||||
typedef CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") ShapeRenderer<3> ShapeRenderer3D; |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}} |
|
||||||
#else |
|
||||||
#error this header is available only in the OpenGL build |
|
||||||
#endif |
|
||||||
|
|
||||||
#endif |
|
||||||
@ -1,179 +0,0 @@ |
|||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include <Corrade/TestSuite/Tester.h> |
|
||||||
|
|
||||||
#include "Magnum/DebugTools/Implementation/CapsuleRendererTransformation.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace DebugTools { namespace Test { namespace { |
|
||||||
|
|
||||||
struct CapsuleRendererTest: TestSuite::Tester { |
|
||||||
explicit CapsuleRendererTest(); |
|
||||||
|
|
||||||
void zeroLength2D(); |
|
||||||
void common2D(); |
|
||||||
|
|
||||||
void zeroLength3D(); |
|
||||||
void parallel3D(); |
|
||||||
void antiParallel3D(); |
|
||||||
void common3D(); |
|
||||||
}; |
|
||||||
|
|
||||||
CapsuleRendererTest::CapsuleRendererTest() { |
|
||||||
addTests({&CapsuleRendererTest::zeroLength2D, |
|
||||||
&CapsuleRendererTest::common2D, |
|
||||||
|
|
||||||
&CapsuleRendererTest::zeroLength3D, |
|
||||||
&CapsuleRendererTest::parallel3D, |
|
||||||
&CapsuleRendererTest::antiParallel3D, |
|
||||||
&CapsuleRendererTest::common3D}); |
|
||||||
} |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
void CapsuleRendererTest::zeroLength2D() { |
|
||||||
const Vector2 a(0.5f, 3.0f); |
|
||||||
std::array<Matrix3, 3> transformation = Implementation::capsuleRendererTransformation<2>(a, a, 3.5f); |
|
||||||
|
|
||||||
const auto scaling = Matrix2x2::fromDiagonal(Vector2(3.5f)); |
|
||||||
CORRADE_COMPARE(transformation[0].rotationScaling(), scaling); |
|
||||||
CORRADE_COMPARE(transformation[1].rotationScaling(), Matrix2x2::fromDiagonal({3.5f, 0.0f})); |
|
||||||
CORRADE_COMPARE(transformation[2].rotationScaling(), scaling); |
|
||||||
|
|
||||||
CORRADE_COMPARE(transformation[0].translation(), a); |
|
||||||
CORRADE_COMPARE(transformation[1].translation(), a); |
|
||||||
CORRADE_COMPARE(transformation[2].translation(), a); |
|
||||||
} |
|
||||||
|
|
||||||
void CapsuleRendererTest::common2D() { |
|
||||||
const Vector2 a(0.5f, 3.0f); |
|
||||||
const Vector2 b(7.5f, -1.0f); |
|
||||||
std::array<Matrix3, 3> transformation = Implementation::capsuleRendererTransformation<2>(a, b, 3.5f); |
|
||||||
|
|
||||||
/* Vector from capsule center to top hemisphere center */ |
|
||||||
const Vector2 up(3.5f, -2.0f); |
|
||||||
CORRADE_COMPARE(transformation[0].up(), up.resized(3.5f)); |
|
||||||
CORRADE_COMPARE(transformation[1].up(), up); |
|
||||||
CORRADE_COMPARE(transformation[2].up(), up.resized(3.5f)); |
|
||||||
|
|
||||||
const auto right = Vector2(4.0f, 7.0f).resized(3.5f); |
|
||||||
CORRADE_COMPARE(transformation[0].right(), right); |
|
||||||
CORRADE_COMPARE(transformation[1].right(), right); |
|
||||||
CORRADE_COMPARE(transformation[2].right(), right); |
|
||||||
|
|
||||||
/* Orthogonality */ |
|
||||||
CORRADE_COMPARE(Math::dot(transformation[0].up(), transformation[0].right()), 0.0f); |
|
||||||
|
|
||||||
const Vector2 capDistance = up.resized(3.5f); |
|
||||||
CORRADE_COMPARE(transformation[0].translation(), a+capDistance); |
|
||||||
CORRADE_COMPARE(transformation[1].translation(), 0.5f*(a + b)); |
|
||||||
CORRADE_COMPARE(transformation[2].translation(), b-capDistance); |
|
||||||
} |
|
||||||
|
|
||||||
void CapsuleRendererTest::zeroLength3D() { |
|
||||||
const Vector3 a(0.5f, 3.0f, 7.0f); |
|
||||||
std::array<Matrix4, 3> transformation = Implementation::capsuleRendererTransformation<3>(a, a, 3.5f); |
|
||||||
|
|
||||||
const auto scaling = Matrix3x3::fromDiagonal(Vector3(3.5f)); |
|
||||||
CORRADE_COMPARE(transformation[0].rotationScaling(), scaling); |
|
||||||
CORRADE_COMPARE(transformation[1].rotationScaling(), Matrix3x3::fromDiagonal({3.5f, 0.0f, 3.5f})); |
|
||||||
CORRADE_COMPARE(transformation[2].rotationScaling(), scaling); |
|
||||||
|
|
||||||
CORRADE_COMPARE(transformation[0].translation(), a); |
|
||||||
CORRADE_COMPARE(transformation[1].translation(), a); |
|
||||||
CORRADE_COMPARE(transformation[2].translation(), a); |
|
||||||
} |
|
||||||
|
|
||||||
void CapsuleRendererTest::parallel3D() { |
|
||||||
const Vector3 a(0.5f, 3.0f, 7.0f); |
|
||||||
const Vector3 b(0.5f, 3.0f, 11.0f); |
|
||||||
std::array<Matrix4, 3> transformation = Implementation::capsuleRendererTransformation<3>(a, b, 3.5f); |
|
||||||
|
|
||||||
const auto rotation = Matrix4::rotationX(Deg(90.0f)); |
|
||||||
const auto scaling = (rotation*Matrix4::scaling(Vector3(3.5f))).rotationScaling(); |
|
||||||
CORRADE_COMPARE(transformation[0].rotationScaling(), scaling); |
|
||||||
CORRADE_COMPARE(transformation[1].rotationScaling(), |
|
||||||
(rotation*Matrix4::scaling({3.5f, 2.0f, 3.5f})).rotationScaling()); |
|
||||||
CORRADE_COMPARE(transformation[2].rotationScaling(), scaling); |
|
||||||
|
|
||||||
const auto capDistance = Vector3::zAxis(3.5f); |
|
||||||
CORRADE_COMPARE(transformation[0].translation(), a+capDistance); |
|
||||||
CORRADE_COMPARE(transformation[1].translation(), a+Vector3::zAxis(2.0f)); |
|
||||||
CORRADE_COMPARE(transformation[2].translation(), b-capDistance); |
|
||||||
} |
|
||||||
|
|
||||||
void CapsuleRendererTest::antiParallel3D() { |
|
||||||
const Vector3 a(0.5f, 3.0f, 7.0f); |
|
||||||
const Vector3 b(0.5f, 3.0f, 3.0f); |
|
||||||
std::array<Matrix4, 3> transformation = Implementation::capsuleRendererTransformation<3>(a, b, 3.5f); |
|
||||||
|
|
||||||
const auto rotation = Matrix4::rotationX(-Deg(90.0f)); |
|
||||||
const auto rotationScaling = (rotation*Matrix4::scaling(Vector3(3.5f))).rotationScaling(); |
|
||||||
CORRADE_COMPARE(transformation[0].rotationScaling(), rotationScaling); |
|
||||||
CORRADE_COMPARE(transformation[1].rotationScaling(), |
|
||||||
(rotation*Matrix4::scaling({3.5f, 2.0f, 3.5f})).rotationScaling()); |
|
||||||
CORRADE_COMPARE(transformation[2].rotationScaling(), rotationScaling); |
|
||||||
|
|
||||||
const auto capDistance = Vector3::zAxis(-3.5f); |
|
||||||
CORRADE_COMPARE(transformation[0].translation(), a+capDistance); |
|
||||||
CORRADE_COMPARE(transformation[1].translation(), a+Vector3::zAxis(-2.0f)); |
|
||||||
CORRADE_COMPARE(transformation[2].translation(), b-capDistance); |
|
||||||
} |
|
||||||
|
|
||||||
void CapsuleRendererTest::common3D() { |
|
||||||
const Vector3 a(0.5f, 3.0f, 7.0f); |
|
||||||
const Vector3 b(7.5f, -1.0f, 1.5f); |
|
||||||
std::array<Matrix4, 3> transformation = Implementation::capsuleRendererTransformation<3>(a, b, 3.5f); |
|
||||||
|
|
||||||
/* Vector from capsule center to top hemisphere center */ |
|
||||||
const Vector3 up(3.5f, -2.0f, -2.75f); |
|
||||||
CORRADE_COMPARE(transformation[0].up(), up.resized(3.5f)); |
|
||||||
CORRADE_COMPARE(transformation[1].up(), up); |
|
||||||
CORRADE_COMPARE(transformation[2].up(), up.resized(3.5f)); |
|
||||||
|
|
||||||
const auto right = Vector3(-2.0f, -3.5f, 0.0f).resized(3.5f); |
|
||||||
CORRADE_COMPARE(transformation[0].right(), right); |
|
||||||
CORRADE_COMPARE(transformation[1].right(), right); |
|
||||||
CORRADE_COMPARE(transformation[2].right(), right); |
|
||||||
|
|
||||||
const auto backward = Vector3(9.625f, -5.5f, 16.25f).resized(3.5f); |
|
||||||
CORRADE_COMPARE(transformation[0].backward(), backward); |
|
||||||
CORRADE_COMPARE(transformation[1].backward(), backward); |
|
||||||
CORRADE_COMPARE(transformation[2].backward(), backward); |
|
||||||
|
|
||||||
/* Orthogonality */ |
|
||||||
CORRADE_COMPARE(Math::dot(transformation[0].up(), transformation[0].right()), 0.0f); |
|
||||||
CORRADE_COMPARE(Math::dot(transformation[0].up(), transformation[0].backward()), 0.0f); |
|
||||||
CORRADE_COMPARE(Math::dot(transformation[0].right(), transformation[0].backward()), 0.0f); |
|
||||||
|
|
||||||
const Vector3 capDistance = up.resized(3.5f); |
|
||||||
CORRADE_COMPARE(transformation[0].translation(), a+capDistance); |
|
||||||
CORRADE_COMPARE(transformation[1].translation(), 0.5f*(a + b)); |
|
||||||
CORRADE_COMPARE(transformation[2].translation(), b-capDistance); |
|
||||||
} |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}}}} |
|
||||||
|
|
||||||
CORRADE_TEST_MAIN(Magnum::DebugTools::Test::CapsuleRendererTest) |
|
||||||
@ -1,127 +0,0 @@ |
|||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include <Corrade/TestSuite/Tester.h> |
|
||||||
|
|
||||||
#include "Magnum/DebugTools/Implementation/CylinderRendererTransformation.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace DebugTools { namespace Test { namespace { |
|
||||||
|
|
||||||
struct CylinderRendererTest: TestSuite::Tester { |
|
||||||
explicit CylinderRendererTest(); |
|
||||||
|
|
||||||
void zeroLength2D(); |
|
||||||
void common2D(); |
|
||||||
|
|
||||||
void zeroLength3D(); |
|
||||||
void parallel3D(); |
|
||||||
void antiParallel3D(); |
|
||||||
void common3D(); |
|
||||||
}; |
|
||||||
|
|
||||||
CylinderRendererTest::CylinderRendererTest() { |
|
||||||
addTests({&CylinderRendererTest::zeroLength2D, |
|
||||||
&CylinderRendererTest::common2D, |
|
||||||
|
|
||||||
&CylinderRendererTest::zeroLength3D, |
|
||||||
&CylinderRendererTest::parallel3D, |
|
||||||
&CylinderRendererTest::antiParallel3D, |
|
||||||
&CylinderRendererTest::common3D}); |
|
||||||
} |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
void CylinderRendererTest::zeroLength2D() { |
|
||||||
const Vector2 a(0.5f, 3.0f); |
|
||||||
const Matrix3 transformation = Implementation::cylinderRendererTransformation<2>(a, a, 3.5f); |
|
||||||
|
|
||||||
CORRADE_COMPARE(transformation.rotationScaling(), Matrix2x2::fromDiagonal({3.5f, 0.0f})); |
|
||||||
CORRADE_COMPARE(transformation.translation(), a); |
|
||||||
} |
|
||||||
|
|
||||||
void CylinderRendererTest::common2D() { |
|
||||||
const Vector2 a(0.5f, 3.0f); |
|
||||||
const Vector2 b(7.5f, -1.0f); |
|
||||||
const Matrix3 transformation = Implementation::cylinderRendererTransformation<2>(a, b, 3.5f); |
|
||||||
|
|
||||||
/* Rotation + scaling, test orthogonality */ |
|
||||||
CORRADE_COMPARE(transformation.up(), Vector2(3.5f, -2.0f)); |
|
||||||
CORRADE_COMPARE(transformation.right(), Vector2(4.0f, 7.0f).resized(3.5f)); |
|
||||||
CORRADE_COMPARE(Math::dot(transformation.up(), transformation.right()), 0.0f); |
|
||||||
|
|
||||||
CORRADE_COMPARE(transformation.translation(), 0.5f*(a + b)); |
|
||||||
} |
|
||||||
|
|
||||||
void CylinderRendererTest::zeroLength3D() { |
|
||||||
const Vector3 a(0.5f, 3.0f, 7.0f); |
|
||||||
const Matrix4 transformation = Implementation::cylinderRendererTransformation<3>(a, a, 3.5f); |
|
||||||
|
|
||||||
CORRADE_COMPARE(transformation.rotationScaling(), Matrix3x3::fromDiagonal({3.5f, 0.0f, 3.5f})); |
|
||||||
CORRADE_COMPARE(transformation.translation(), a); |
|
||||||
} |
|
||||||
|
|
||||||
void CylinderRendererTest::parallel3D() { |
|
||||||
const Vector3 a(0.5f, 3.0f, 7.0f); |
|
||||||
const Vector3 b(0.5f, 3.0f, 11.0f); |
|
||||||
const Matrix4 transformation = Implementation::cylinderRendererTransformation<3>(a, b, 3.5f); |
|
||||||
|
|
||||||
CORRADE_COMPARE(transformation.rotationScaling(), |
|
||||||
(Matrix4::rotationX(Deg(90.0f))*Matrix4::scaling({3.5f, 2.0f, 3.5f})).rotationScaling()); |
|
||||||
|
|
||||||
CORRADE_COMPARE(transformation.translation(), a+Vector3::zAxis(2.0f)); |
|
||||||
} |
|
||||||
|
|
||||||
void CylinderRendererTest::antiParallel3D() { |
|
||||||
const Vector3 a(0.5f, 3.0f, 7.0f); |
|
||||||
const Vector3 b(0.5f, 3.0f, 3.0f); |
|
||||||
const Matrix4 transformation = Implementation::cylinderRendererTransformation<3>(a, b, 3.5f); |
|
||||||
|
|
||||||
CORRADE_COMPARE(transformation.rotationScaling(), |
|
||||||
(Matrix4::rotationX(-Deg(90.0f))*Matrix4::scaling({3.5f, 2.0f, 3.5f})).rotationScaling()); |
|
||||||
|
|
||||||
CORRADE_COMPARE(transformation.translation(), a+Vector3::zAxis(-2.0f)); |
|
||||||
} |
|
||||||
|
|
||||||
void CylinderRendererTest::common3D() { |
|
||||||
const Vector3 a(0.5f, 3.0f, 7.0f); |
|
||||||
const Vector3 b(7.5f, -1.0f, 1.5f); |
|
||||||
const Matrix4 transformation = Implementation::cylinderRendererTransformation<3>(a, b, 3.5f); |
|
||||||
|
|
||||||
/* Rotation + scaling */ |
|
||||||
CORRADE_COMPARE(transformation.up(), Vector3(3.5f, -2.0f, -2.75f)); |
|
||||||
CORRADE_COMPARE(transformation.right(), Vector3(-2.0f, -3.5f, 0.0f).resized(3.5f)); |
|
||||||
CORRADE_COMPARE(transformation.backward(), Vector3(9.625f, -5.5f, 16.25f).resized(3.5f)); |
|
||||||
|
|
||||||
/* Orthogonality */ |
|
||||||
CORRADE_COMPARE(Math::dot(transformation.up(), transformation.right()), 0.0f); |
|
||||||
CORRADE_COMPARE(Math::dot(transformation.up(), transformation.backward()), 0.0f); |
|
||||||
CORRADE_COMPARE(Math::dot(transformation.right(), transformation.backward()), 0.0f); |
|
||||||
|
|
||||||
CORRADE_COMPARE(transformation.translation(), 0.5f*(a + b)); |
|
||||||
} |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}}}} |
|
||||||
|
|
||||||
CORRADE_TEST_MAIN(Magnum::DebugTools::Test::CylinderRendererTest) |
|
||||||
@ -1,70 +0,0 @@ |
|||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include <Corrade/TestSuite/Tester.h> |
|
||||||
|
|
||||||
#include "Magnum/Magnum.h" |
|
||||||
#include "Magnum/Math/Matrix3.h" |
|
||||||
#include "Magnum/Math/Matrix4.h" |
|
||||||
|
|
||||||
#include "Magnum/DebugTools/Implementation/LineSegmentRendererTransformation.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace DebugTools { namespace Test { namespace { |
|
||||||
|
|
||||||
struct LineSegmentRendererTest: TestSuite::Tester { |
|
||||||
explicit LineSegmentRendererTest(); |
|
||||||
|
|
||||||
void line2D(); |
|
||||||
void line3D(); |
|
||||||
}; |
|
||||||
|
|
||||||
LineSegmentRendererTest::LineSegmentRendererTest() { |
|
||||||
addTests({&LineSegmentRendererTest::line2D, |
|
||||||
&LineSegmentRendererTest::line3D}); |
|
||||||
} |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
void LineSegmentRendererTest::line2D() { |
|
||||||
const Vector2 a(-2.0f, 3.0f); |
|
||||||
const Vector2 b(3.4f, -1.5f); |
|
||||||
const Matrix3 matrix = Implementation::lineSegmentRendererTransformation<2>(a, b); |
|
||||||
|
|
||||||
CORRADE_COMPARE(matrix.transformPoint({0.0f, 0.0f}), a); |
|
||||||
CORRADE_COMPARE(matrix.transformPoint({1.0f, 0.0f}), b); |
|
||||||
} |
|
||||||
|
|
||||||
void LineSegmentRendererTest::line3D() { |
|
||||||
const Vector3 a(-2.0f, 3.0f, 1.5f); |
|
||||||
const Vector3 b(3.4f, -1.5f, 0.5f); |
|
||||||
const Matrix4 matrix = Implementation::lineSegmentRendererTransformation<3>(a, b); |
|
||||||
|
|
||||||
CORRADE_COMPARE(matrix.transformPoint({0.0f, 0.0f, 0.0f}), a); |
|
||||||
CORRADE_COMPARE(matrix.transformPoint({1.0f, 0.0f, 0.0f}), b); |
|
||||||
} |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}}}} |
|
||||||
|
|
||||||
CORRADE_TEST_MAIN(Magnum::DebugTools::Test::LineSegmentRendererTest) |
|
||||||
@ -1,73 +0,0 @@ |
|||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#define _MAGNUM_DO_NOT_WARN_DEPRECATED_SHAPES |
|
||||||
|
|
||||||
#include "AbstractShape.h" |
|
||||||
|
|
||||||
#include <Corrade/Utility/Debug.h> |
|
||||||
|
|
||||||
#include "Magnum/Shapes/Collision.h" |
|
||||||
#include "Magnum/Shapes/ShapeGroup.h" |
|
||||||
#include "Magnum/Shapes/Implementation/CollisionDispatch.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace Shapes { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
template<UnsignedInt dimensions> AbstractShape<dimensions>::AbstractShape(SceneGraph::AbstractObject<dimensions, Float>& object, ShapeGroup<dimensions>* group): SceneGraph::AbstractGroupedFeature<dimensions, AbstractShape<dimensions>, Float>(object, group) { |
|
||||||
SceneGraph::AbstractFeature<dimensions, Float>::setCachedTransformations(SceneGraph::CachedTransformation::Absolute); |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> ShapeGroup<dimensions>* AbstractShape<dimensions>::group() { |
|
||||||
return static_cast<ShapeGroup<dimensions>*>(SceneGraph::AbstractGroupedFeature<dimensions, AbstractShape<dimensions>, Float>::group()); |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> const ShapeGroup<dimensions>* AbstractShape<dimensions>::group() const { |
|
||||||
return static_cast<const ShapeGroup<dimensions>*>(SceneGraph::AbstractGroupedFeature<dimensions, AbstractShape<dimensions>, Float>::group()); |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> auto AbstractShape<dimensions>::type() const -> Type { |
|
||||||
return abstractTransformedShape().type(); |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> bool AbstractShape<dimensions>::collides(const AbstractShape<dimensions>& other) const { |
|
||||||
return Implementation::collides(abstractTransformedShape(), other.abstractTransformedShape()); |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> Collision<dimensions> AbstractShape<dimensions>::collision(const AbstractShape<dimensions>& other) const { |
|
||||||
return Implementation::collision(abstractTransformedShape(), other.abstractTransformedShape()); |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> void AbstractShape<dimensions>::markDirty() { |
|
||||||
if(group()) group()->setDirty(); |
|
||||||
} |
|
||||||
|
|
||||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
|
||||||
template class MAGNUM_SHAPES_EXPORT AbstractShape<2>; |
|
||||||
template class MAGNUM_SHAPES_EXPORT AbstractShape<3>; |
|
||||||
#endif |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}} |
|
||||||
@ -1,172 +0,0 @@ |
|||||||
#ifndef Magnum_Shapes_AbstractShape_h |
|
||||||
#define Magnum_Shapes_AbstractShape_h |
|
||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @file
|
|
||||||
@brief Class @ref Magnum::Shapes::AbstractShape, typedef @ref Magnum::Shapes::AbstractShape2D, @ref Magnum::Shapes::AbstractShape3D |
|
||||||
|
|
||||||
@deprecated The @ref Magnum::Shapes library is a failed design experiment and |
|
||||||
is scheduled for removal in a future release. Related geometry algorithms |
|
||||||
were moved to @ref Magnum::Math::Distance and @ref Magnum::Math::Intersection; |
|
||||||
if you need a full-fledged physics library, please have look at |
|
||||||
[Bullet](https://bulletphysics.org), which has Magnum integration in
|
|
||||||
@ref Magnum::BulletIntegration, or at [Box2D](https://box2d.org/), which
|
|
||||||
has a @ref examples-box2d "Magnum example" as well. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Magnum/Magnum.h" |
|
||||||
#include "Magnum/DimensionTraits.h" |
|
||||||
#include "Magnum/SceneGraph/AbstractGroupedFeature.h" |
|
||||||
#include "Magnum/Shapes/shapeImplementation.h" |
|
||||||
#include "Magnum/Shapes/Shapes.h" |
|
||||||
#include "Magnum/Shapes/visibility.h" |
|
||||||
|
|
||||||
/* File-level deprecation warning issued from Shapes.h */ |
|
||||||
|
|
||||||
namespace Magnum { namespace Shapes { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
namespace Implementation { |
|
||||||
template<UnsignedInt dimensions> inline const AbstractShape<dimensions>& getAbstractShape(const Shapes::AbstractShape<dimensions>& shape) { |
|
||||||
return shape.abstractTransformedShape(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Base class for object shapes |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
|
|
||||||
This class is not directly instantiable, use @ref Shape instead. See |
|
||||||
@ref shapes for brief introduction. |
|
||||||
@see @ref AbstractShape2D, @ref AbstractShape3D |
|
||||||
*/ |
|
||||||
template<UnsignedInt dimensions> class CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") MAGNUM_SHAPES_EXPORT AbstractShape: public SceneGraph::AbstractGroupedFeature<dimensions, AbstractShape<dimensions>, Float> { |
|
||||||
#ifndef CORRADE_MSVC2017_COMPATIBILITY |
|
||||||
friend const Implementation::AbstractShape<dimensions>& Implementation::getAbstractShape<>(const AbstractShape<dimensions>&); |
|
||||||
#else |
|
||||||
/* Otherwise it complains that this is not a function */ |
|
||||||
template<UnsignedInt dimensions_> friend const Implementation::AbstractShape<dimensions_>& Implementation::getAbstractShape(const Shapes::AbstractShape<dimensions_>&); |
|
||||||
#endif |
|
||||||
|
|
||||||
public: |
|
||||||
enum: UnsignedInt { |
|
||||||
Dimensions = dimensions /**< Dimension count */ |
|
||||||
}; |
|
||||||
|
|
||||||
/** @brief Shape type */ |
|
||||||
#ifdef DOXYGEN_GENERATING_OUTPUT |
|
||||||
enum class Type { |
|
||||||
Point, /**< @ref Point */ |
|
||||||
Line, /**< @ref Line */ |
|
||||||
LineSegment, /**< @ref LineSegment "Line segment" */ |
|
||||||
Sphere, /**< @ref Sphere */ |
|
||||||
Capsule, /**< @ref Capsule */ |
|
||||||
AxisAlignedBox, /**< @ref AxisAlignedBox "Axis aligned box" */ |
|
||||||
Box, /**< @ref Box */ |
|
||||||
Composition, /**< @ref Composition "Shape group" */ |
|
||||||
Plane /**< @ref Plane (3D only) */ |
|
||||||
}; |
|
||||||
#else |
|
||||||
typedef typename Implementation::ShapeDimensionTraits<dimensions>::Type Type; |
|
||||||
#endif |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Constructor |
|
||||||
* @param object Object holding this feature |
|
||||||
* @param group Group this shape belongs to |
|
||||||
*/ |
|
||||||
explicit AbstractShape(SceneGraph::AbstractObject<dimensions, Float>& object, ShapeGroup<dimensions>* group = nullptr); |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Shape group containing this shape |
|
||||||
* |
|
||||||
* If the shape doesn't belong to any group, returns @cpp nullptr @ce. |
|
||||||
*/ |
|
||||||
ShapeGroup<dimensions>* group(); |
|
||||||
const ShapeGroup<dimensions>* group() const; /**< @overload */ |
|
||||||
|
|
||||||
/** @brief Shape type */ |
|
||||||
Type type() const; |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Detect collision with other shape |
|
||||||
* |
|
||||||
* Default implementation returns false. |
|
||||||
*/ |
|
||||||
bool collides(const AbstractShape<dimensions>& other) const; |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Collision with other shape |
|
||||||
* |
|
||||||
* Default implementation returns empty collision. |
|
||||||
*/ |
|
||||||
Collision<dimensions> collision(const AbstractShape<dimensions>& other) const; |
|
||||||
|
|
||||||
protected: |
|
||||||
/** Marks also the group as dirty */ |
|
||||||
void markDirty() override; |
|
||||||
|
|
||||||
private: |
|
||||||
virtual const Implementation::AbstractShape<dimensions> MAGNUM_SHAPES_LOCAL & abstractTransformedShape() const = 0; |
|
||||||
}; |
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Base class for two-dimensional object shapes |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
*/ |
|
||||||
typedef CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") AbstractShape<2> AbstractShape2D; |
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Base class for three-dimensional object shapes |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
*/ |
|
||||||
typedef CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") AbstractShape<3> AbstractShape3D; |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}} |
|
||||||
|
|
||||||
#endif |
|
||||||
@ -1,53 +0,0 @@ |
|||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#define _MAGNUM_DO_NOT_WARN_DEPRECATED_SHAPES |
|
||||||
|
|
||||||
#include "AxisAlignedBox.h" |
|
||||||
|
|
||||||
#include "Magnum/Math/Matrix3.h" |
|
||||||
#include "Magnum/Math/Matrix4.h" |
|
||||||
#include "Magnum/Shapes/Point.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace Shapes { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
template<UnsignedInt dimensions> AxisAlignedBox<dimensions> AxisAlignedBox<dimensions>::transformed(const MatrixTypeFor<dimensions, Float>& matrix) const { |
|
||||||
return AxisAlignedBox<dimensions>(matrix.transformPoint(_min), |
|
||||||
matrix.transformPoint(_max)); |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> bool AxisAlignedBox<dimensions>::operator%(const Point<dimensions>& other) const { |
|
||||||
return (other.position() >= _min).all() && |
|
||||||
(other.position() < _max).all(); |
|
||||||
} |
|
||||||
|
|
||||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
|
||||||
template class MAGNUM_SHAPES_EXPORT AxisAlignedBox<2>; |
|
||||||
template class MAGNUM_SHAPES_EXPORT AxisAlignedBox<3>; |
|
||||||
#endif |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}} |
|
||||||
@ -1,153 +0,0 @@ |
|||||||
#ifndef Magnum_Shapes_AxisAlignedBox_h |
|
||||||
#define Magnum_Shapes_AxisAlignedBox_h |
|
||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @file
|
|
||||||
@brief Class @ref Magnum::Shapes::AxisAlignedBox, typedef @ref Magnum::Shapes::AxisAlignedBox2D, @ref Magnum::Shapes::AxisAlignedBox3D |
|
||||||
|
|
||||||
@deprecated The @ref Magnum::Shapes library is a failed design experiment and |
|
||||||
is scheduled for removal in a future release. Related geometry algorithms |
|
||||||
were moved to @ref Magnum::Math::Distance and @ref Magnum::Math::Intersection; |
|
||||||
if you need a full-fledged physics library, please have look at |
|
||||||
[Bullet](https://bulletphysics.org), which has Magnum integration in
|
|
||||||
@ref Magnum::BulletIntegration, or at [Box2D](https://box2d.org/), which
|
|
||||||
has a @ref examples-box2d "Magnum example" as well. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Magnum/DimensionTraits.h" |
|
||||||
#include "Magnum/Math/Vector3.h" |
|
||||||
#include "Magnum/Shapes/Shapes.h" |
|
||||||
#include "Magnum/Shapes/visibility.h" |
|
||||||
|
|
||||||
/* File-level deprecation warning issued from Shapes.h */ |
|
||||||
|
|
||||||
namespace Magnum { namespace Shapes { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
/**
|
|
||||||
@brief Axis-aligned box |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
|
|
||||||
See @ref shapes for brief introduction. |
|
||||||
@see @ref AxisAlignedBox2D, @ref AxisAlignedBox3D |
|
||||||
@todo Assert for rotation |
|
||||||
*/ |
|
||||||
template<UnsignedInt dimensions> class CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") MAGNUM_SHAPES_EXPORT AxisAlignedBox { |
|
||||||
public: |
|
||||||
enum: UnsignedInt { |
|
||||||
Dimensions = dimensions /**< Dimension count */ |
|
||||||
}; |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Default constructor |
|
||||||
* |
|
||||||
* Creates zero sized box positioned at origin. |
|
||||||
*/ |
|
||||||
constexpr /*implicit*/ AxisAlignedBox() {} |
|
||||||
|
|
||||||
/** @brief Constructor */ |
|
||||||
constexpr /*implicit*/ AxisAlignedBox(const VectorTypeFor<dimensions, Float>& min, const typename DimensionTraits<dimensions, Float>::VectorType& max): _min(min), _max(max) {} |
|
||||||
|
|
||||||
/** @brief Transformed shape */ |
|
||||||
AxisAlignedBox<dimensions> transformed(const MatrixTypeFor<dimensions, Float>& matrix) const; |
|
||||||
|
|
||||||
/** @brief Minimal coordinates */ |
|
||||||
constexpr VectorTypeFor<dimensions, Float> min() const { |
|
||||||
return _min; |
|
||||||
} |
|
||||||
|
|
||||||
/** @brief Set minimal coordinates */ |
|
||||||
void setMin(const VectorTypeFor<dimensions, Float>& min) { |
|
||||||
_min = min; |
|
||||||
} |
|
||||||
|
|
||||||
/** @brief Maximal coordinates */ |
|
||||||
constexpr VectorTypeFor<dimensions, Float> max() const { |
|
||||||
return _max; |
|
||||||
} |
|
||||||
|
|
||||||
/** @brief Set maximal coordinates */ |
|
||||||
void setMax(const VectorTypeFor<dimensions, Float>& max) { |
|
||||||
_max = max; |
|
||||||
} |
|
||||||
|
|
||||||
/** @brief Collision occurence with point */ |
|
||||||
bool operator%(const Point<dimensions>& other) const; |
|
||||||
|
|
||||||
private: |
|
||||||
VectorTypeFor<dimensions, Float> _min, _max; |
|
||||||
}; |
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Two-dimensional axis-aligned box |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
*/ |
|
||||||
typedef CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") AxisAlignedBox<2> AxisAlignedBox2D; |
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Three-dimensional axis-aligned box |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
*/ |
|
||||||
typedef CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") AxisAlignedBox<3> AxisAlignedBox3D; |
|
||||||
|
|
||||||
/**
|
|
||||||
@collisionoccurenceoperator{Point,AxisAlignedBox} |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
*/ |
|
||||||
template<UnsignedInt dimensions> inline CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") bool operator%(const Point<dimensions>& a, const AxisAlignedBox<dimensions>& b) { return b % a; } |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}} |
|
||||||
|
|
||||||
#endif |
|
||||||
@ -1,43 +0,0 @@ |
|||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#define _MAGNUM_DO_NOT_WARN_DEPRECATED_SHAPES |
|
||||||
|
|
||||||
#include "Box.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace Shapes { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
template<UnsignedInt dimensions> Box<dimensions> Box<dimensions>::transformed(const MatrixTypeFor<dimensions, Float>& matrix) const { |
|
||||||
return Box<dimensions>(matrix*_transformation); |
|
||||||
} |
|
||||||
|
|
||||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
|
||||||
template class MAGNUM_SHAPES_EXPORT Box<2>; |
|
||||||
template class MAGNUM_SHAPES_EXPORT Box<3>; |
|
||||||
#endif |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}} |
|
||||||
@ -1,130 +0,0 @@ |
|||||||
#ifndef Magnum_Shapes_Box_h |
|
||||||
#define Magnum_Shapes_Box_h |
|
||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @file
|
|
||||||
@brief Class @ref Magnum::Shapes::Box, typedef @ref Magnum::Shapes::Box2D, @ref Magnum::Shapes::Box3D |
|
||||||
|
|
||||||
@deprecated The @ref Magnum::Shapes library is a failed design experiment and |
|
||||||
is scheduled for removal in a future release. Related geometry algorithms |
|
||||||
were moved to @ref Magnum::Math::Distance and @ref Magnum::Math::Intersection; |
|
||||||
if you need a full-fledged physics library, please have look at |
|
||||||
[Bullet](https://bulletphysics.org), which has Magnum integration in
|
|
||||||
@ref Magnum::BulletIntegration, or at [Box2D](https://box2d.org/), which
|
|
||||||
has a @ref examples-box2d "Magnum example" as well. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Magnum/DimensionTraits.h" |
|
||||||
#include "Magnum/Math/Matrix3.h" |
|
||||||
#include "Magnum/Math/Matrix4.h" |
|
||||||
#include "Magnum/Shapes/Shapes.h" |
|
||||||
#include "Magnum/Shapes/visibility.h" |
|
||||||
|
|
||||||
/* File-level deprecation warning issued from Shapes.h */ |
|
||||||
|
|
||||||
namespace Magnum { namespace Shapes { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
/**
|
|
||||||
@brief Unit-size box with assigned transformation matrix |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
|
|
||||||
Unit-size means that half extents are equal to 1, equivalent to e.g. sphere |
|
||||||
radius. See @ref shapes for brief introduction. |
|
||||||
@see @ref Box2D, @ref Box3D |
|
||||||
@todo Use quat + position + size instead? |
|
||||||
@todo Assert for skew |
|
||||||
*/ |
|
||||||
template<UnsignedInt dimensions> class CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") MAGNUM_SHAPES_EXPORT Box { |
|
||||||
public: |
|
||||||
enum: UnsignedInt { |
|
||||||
Dimensions = dimensions /**< Dimension count */ |
|
||||||
}; |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Default constructor |
|
||||||
* |
|
||||||
* Creates zero-sized box positioned at origin. |
|
||||||
*/ |
|
||||||
constexpr /*implicit*/ Box(): _transformation{Math::ZeroInit} {} |
|
||||||
|
|
||||||
/** @brief Constructor */ |
|
||||||
constexpr /*implicit*/ Box(const MatrixTypeFor<dimensions, Float>& transformation): _transformation(transformation) {} |
|
||||||
|
|
||||||
/** @brief Transformed shape */ |
|
||||||
Box<dimensions> transformed(const MatrixTypeFor<dimensions, Float>& matrix) const; |
|
||||||
|
|
||||||
/** @brief Transformation */ |
|
||||||
constexpr MatrixTypeFor<dimensions, Float> transformation() const { |
|
||||||
return _transformation; |
|
||||||
} |
|
||||||
|
|
||||||
/** @brief Set transformation */ |
|
||||||
void setTransformation(const MatrixTypeFor<dimensions, Float>& transformation) { |
|
||||||
_transformation = transformation; |
|
||||||
} |
|
||||||
|
|
||||||
private: |
|
||||||
MatrixTypeFor<dimensions, Float> _transformation; |
|
||||||
}; |
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Two-dimensional box |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
*/ |
|
||||||
typedef CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") Box<2> Box2D; |
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Three-dimensional box |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
*/ |
|
||||||
typedef CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") Box<3> Box3D; |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}} |
|
||||||
|
|
||||||
#endif |
|
||||||
@ -1,97 +0,0 @@ |
|||||||
# |
|
||||||
# This file is part of Magnum. |
|
||||||
# |
|
||||||
# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
# 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. |
|
||||||
# |
|
||||||
|
|
||||||
if(NOT MAGNUM_BUILD_DEPRECATED) |
|
||||||
message(FATAL_ERROR "Shapes are scheduled for removal and not available if BUILD_DEPRECATED is disabled. See the docs for alternatives.") |
|
||||||
endif() |
|
||||||
|
|
||||||
set(MagnumShapes_SRCS |
|
||||||
AbstractShape.cpp |
|
||||||
AxisAlignedBox.cpp |
|
||||||
Box.cpp |
|
||||||
Capsule.cpp |
|
||||||
Cylinder.cpp |
|
||||||
Composition.cpp |
|
||||||
Line.cpp |
|
||||||
Plane.cpp |
|
||||||
Point.cpp |
|
||||||
Shape.cpp |
|
||||||
ShapeGroup.cpp |
|
||||||
Sphere.cpp |
|
||||||
|
|
||||||
shapeImplementation.cpp |
|
||||||
|
|
||||||
Implementation/CollisionDispatch.cpp) |
|
||||||
|
|
||||||
set(MagnumShapes_HEADERS |
|
||||||
AbstractShape.h |
|
||||||
AxisAlignedBox.h |
|
||||||
Box.h |
|
||||||
Capsule.h |
|
||||||
Cylinder.h |
|
||||||
Collision.h |
|
||||||
Composition.h |
|
||||||
Line.h |
|
||||||
LineSegment.h |
|
||||||
Shape.h |
|
||||||
ShapeGroup.h |
|
||||||
Shapes.h |
|
||||||
Plane.h |
|
||||||
Point.h |
|
||||||
Sphere.h |
|
||||||
|
|
||||||
shapeImplementation.h |
|
||||||
visibility.h) |
|
||||||
|
|
||||||
# Header files to display in project view of IDEs only |
|
||||||
set(MagnumShapes_PRIVATE_HEADERS Implementation/CollisionDispatch.h) |
|
||||||
|
|
||||||
# Shapes library |
|
||||||
add_library(MagnumShapes ${SHARED_OR_STATIC} |
|
||||||
${MagnumShapes_SRCS} |
|
||||||
${MagnumShapes_HEADERS} |
|
||||||
${MagnumShapes_PRIVATE_HEADERS}) |
|
||||||
set_target_properties(MagnumShapes PROPERTIES |
|
||||||
DEBUG_POSTFIX "-d" |
|
||||||
FOLDER "Magnum/Shapes") |
|
||||||
if(NOT BUILD_STATIC) |
|
||||||
set_target_properties(MagnumShapes PROPERTIES VERSION ${MAGNUM_LIBRARY_VERSION} SOVERSION ${MAGNUM_LIBRARY_SOVERSION}) |
|
||||||
elseif(BUILD_STATIC_PIC) |
|
||||||
set_target_properties(MagnumShapes PROPERTIES POSITION_INDEPENDENT_CODE ON) |
|
||||||
endif() |
|
||||||
target_link_libraries(MagnumShapes PUBLIC Magnum MagnumSceneGraph) |
|
||||||
|
|
||||||
install(TARGETS MagnumShapes |
|
||||||
RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} |
|
||||||
LIBRARY DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR} |
|
||||||
ARCHIVE DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) |
|
||||||
install(FILES ${MagnumShapes_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Shapes) |
|
||||||
|
|
||||||
if(BUILD_TESTS) |
|
||||||
add_subdirectory(Test) |
|
||||||
endif() |
|
||||||
|
|
||||||
# Magnum Shapes target alias for superprojects |
|
||||||
add_library(Magnum::Shapes ALIAS MagnumShapes) |
|
||||||
@ -1,61 +0,0 @@ |
|||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#define _MAGNUM_DO_NOT_WARN_DEPRECATED_SHAPES |
|
||||||
|
|
||||||
#include "Capsule.h" |
|
||||||
|
|
||||||
#include "Magnum/Magnum.h" |
|
||||||
#include "Magnum/Math/Distance.h" |
|
||||||
#include "Magnum/Math/Functions.h" |
|
||||||
#include "Magnum/Math/Matrix3.h" |
|
||||||
#include "Magnum/Math/Matrix4.h" |
|
||||||
#include "Magnum/Shapes/Point.h" |
|
||||||
#include "Magnum/Shapes/Sphere.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace Shapes { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
template<UnsignedInt dimensions> Capsule<dimensions> Capsule<dimensions>::transformed(const MatrixTypeFor<dimensions, Float>& matrix) const { |
|
||||||
return Capsule<dimensions>(matrix.transformPoint(_a), matrix.transformPoint(_b), matrix.uniformScaling()*_radius); |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> bool Capsule<dimensions>::operator%(const Point<dimensions>& other) const { |
|
||||||
return Math::Distance::lineSegmentPointSquared(_a, _b, other.position()) < |
|
||||||
Math::pow<2>(_radius); |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> bool Capsule<dimensions>::operator%(const Sphere<dimensions>& other) const { |
|
||||||
return Math::Distance::lineSegmentPointSquared(_a, _b, other.position()) < |
|
||||||
Math::pow<2>(_radius+other.radius()); |
|
||||||
} |
|
||||||
|
|
||||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
|
||||||
template class MAGNUM_SHAPES_EXPORT Capsule<2>; |
|
||||||
template class MAGNUM_SHAPES_EXPORT Capsule<3>; |
|
||||||
#endif |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}} |
|
||||||
@ -1,178 +0,0 @@ |
|||||||
#ifndef Magnum_Shapes_Capsule_h |
|
||||||
#define Magnum_Shapes_Capsule_h |
|
||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @file
|
|
||||||
@brief Class @ref Magnum::Shapes::Capsule, typedef @ref Magnum::Shapes::Capsule2D, @ref Magnum::Shapes::Capsule3D |
|
||||||
|
|
||||||
@deprecated The @ref Magnum::Shapes library is a failed design experiment and |
|
||||||
is scheduled for removal in a future release. Related geometry algorithms |
|
||||||
were moved to @ref Magnum::Math::Distance and @ref Magnum::Math::Intersection; |
|
||||||
if you need a full-fledged physics library, please have look at |
|
||||||
[Bullet](https://bulletphysics.org), which has Magnum integration in
|
|
||||||
@ref Magnum::BulletIntegration, or at [Box2D](https://box2d.org/), which
|
|
||||||
has a @ref examples-box2d "Magnum example" as well. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Magnum/DimensionTraits.h" |
|
||||||
#include "Magnum/Math/Vector3.h" |
|
||||||
#include "Magnum/Shapes/Shapes.h" |
|
||||||
#include "Magnum/Shapes/visibility.h" |
|
||||||
|
|
||||||
/* File-level deprecation warning issued from Shapes.h */ |
|
||||||
|
|
||||||
namespace Magnum { namespace Shapes { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
/**
|
|
||||||
@brief Capsule defined by cylinder start and end point and radius |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
|
|
||||||
Unlike other elements the capsule expects uniform scaling. See @ref shapes for |
|
||||||
brief introduction. |
|
||||||
@see @ref Capsule2D, @ref Capsule3D, @ref Cylinder |
|
||||||
@todo Store the radius as squared value to avoid sqrt/pow? Will complicate |
|
||||||
collision detection with sphere. |
|
||||||
*/ |
|
||||||
template<UnsignedInt dimensions> class CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") MAGNUM_SHAPES_EXPORT Capsule { |
|
||||||
public: |
|
||||||
enum: UnsignedInt { |
|
||||||
Dimensions = dimensions /**< Dimension count */ |
|
||||||
}; |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Constructor |
|
||||||
* |
|
||||||
* Creates zero-sized capsule at origin. |
|
||||||
*/ |
|
||||||
constexpr /*implicit*/ Capsule(): _radius(0.0f) {} |
|
||||||
|
|
||||||
/** @brief Constructor */ |
|
||||||
constexpr /*implicit*/ Capsule(const VectorTypeFor<dimensions, Float>& a, const VectorTypeFor<dimensions, Float>& b, Float radius): _a(a), _b(b), _radius(radius) {} |
|
||||||
|
|
||||||
/** @brief Transformed shape */ |
|
||||||
Capsule<dimensions> transformed(const MatrixTypeFor<dimensions, Float>& matrix) const; |
|
||||||
|
|
||||||
/** @brief Start point */ |
|
||||||
constexpr VectorTypeFor<dimensions, Float> a() const { |
|
||||||
return _a; |
|
||||||
} |
|
||||||
|
|
||||||
/** @brief Set start point */ |
|
||||||
void setA(const VectorTypeFor<dimensions, Float>& a) { |
|
||||||
_a = a; |
|
||||||
} |
|
||||||
|
|
||||||
/** @brief End point */ |
|
||||||
constexpr VectorTypeFor<dimensions, Float> b() const { |
|
||||||
return _b; |
|
||||||
} |
|
||||||
|
|
||||||
/** @brief Set end point */ |
|
||||||
void setB(const VectorTypeFor<dimensions, Float>& b) { |
|
||||||
_b = b; |
|
||||||
} |
|
||||||
|
|
||||||
/** @brief Radius */ |
|
||||||
constexpr Float radius() const { return _radius; } |
|
||||||
|
|
||||||
/** @brief Set radius */ |
|
||||||
void setRadius(Float radius) { _radius = radius; } |
|
||||||
|
|
||||||
/** @brief Collision occurence with point */ |
|
||||||
bool operator%(const Point<dimensions>& other) const; |
|
||||||
|
|
||||||
/** @brief Collision occurence with sphere */ |
|
||||||
bool operator%(const Sphere<dimensions>& other) const; |
|
||||||
|
|
||||||
private: |
|
||||||
VectorTypeFor<dimensions, Float> _a, _b; |
|
||||||
Float _radius; |
|
||||||
}; |
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Two-dimensional capsule |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
*/ |
|
||||||
typedef CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") Capsule<2> Capsule2D; |
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Three-dimensional capsule |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
*/ |
|
||||||
typedef CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") Capsule<3> Capsule3D; |
|
||||||
|
|
||||||
/**
|
|
||||||
@collisionoccurenceoperator{Point,Capsule} |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
*/ |
|
||||||
template<UnsignedInt dimensions> inline CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") bool operator%(const Point<dimensions>& a, const Capsule<dimensions>& b) { return b % a; } |
|
||||||
|
|
||||||
/**
|
|
||||||
@collisionoccurenceoperator{Sphere,Capsule} |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
*/ |
|
||||||
template<UnsignedInt dimensions> inline CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") bool operator%(const Sphere<dimensions>& a, const Capsule<dimensions>& b) { return b % a; } |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}} |
|
||||||
|
|
||||||
#endif |
|
||||||
@ -1,173 +0,0 @@ |
|||||||
#ifndef Magnum_Shapes_Collision_h |
|
||||||
#define Magnum_Shapes_Collision_h |
|
||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @file
|
|
||||||
@brief Class @ref Magnum::Shapes::Collision, typedef @ref Magnum::Shapes::Collision2D, @ref Magnum::Shapes::Collision3D |
|
||||||
|
|
||||||
@deprecated The @ref Magnum::Shapes library is a failed design experiment and |
|
||||||
is scheduled for removal in a future release. Related geometry algorithms |
|
||||||
were moved to @ref Magnum::Math::Distance and @ref Magnum::Math::Intersection; |
|
||||||
if you need a full-fledged physics library, please have look at |
|
||||||
[Bullet](https://bulletphysics.org), which has Magnum integration in
|
|
||||||
@ref Magnum::BulletIntegration, or at [Box2D](https://box2d.org/), which
|
|
||||||
has a @ref examples-box2d "Magnum example" as well. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Magnum/DimensionTraits.h" |
|
||||||
#include "Magnum/Math/Vector2.h" |
|
||||||
#include "Magnum/Math/Vector3.h" |
|
||||||
#include "Magnum/Shapes/Shapes.h" |
|
||||||
|
|
||||||
/* File-level deprecation warning issued from Shapes.h */ |
|
||||||
|
|
||||||
namespace Magnum { namespace Shapes { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
/**
|
|
||||||
@brief Collision data |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
|
|
||||||
Contains information about collision between objects A and B, described by |
|
||||||
contact position, separation normal and separation distance. |
|
||||||
|
|
||||||
If the collision occured, contact position is on object B surface, separation |
|
||||||
normal is *normalized* vector in which direction should object A be moved to |
|
||||||
separate the bodies, separation distance is positive and describes minimal |
|
||||||
movement of object A in direction of separation normal after which the contact |
|
||||||
position will no longer be colliding with object A. |
|
||||||
|
|
||||||
If the collision not occured, contact position and separation normal is |
|
||||||
undefined (i.e., *not* normalized) and separation distance is negative or zero. |
|
||||||
@see @ref Collision2D, @ref Collision3D |
|
||||||
*/ |
|
||||||
template<UnsignedInt dimensions> class CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") Collision { |
|
||||||
public: |
|
||||||
/**
|
|
||||||
* @brief Default constructor |
|
||||||
* |
|
||||||
* Sets position, normal and separation distance to zero, as if no |
|
||||||
* collision happened. |
|
||||||
*/ |
|
||||||
/*implicit*/ Collision(): _separationDistance(0.0f) {} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Constructor |
|
||||||
* |
|
||||||
* If separation distance is positive, the separation normal is |
|
||||||
* expected to be normalized. |
|
||||||
*/ |
|
||||||
explicit Collision(const VectorTypeFor<dimensions, Float>& position, const VectorTypeFor<dimensions, Float>& separationNormal, Float separationDistance) noexcept: _position(position), _separationNormal(separationNormal), _separationDistance(separationDistance) { |
|
||||||
CORRADE_ASSERT(_separationDistance < Math::TypeTraits<Float>::epsilon() || separationNormal.isNormalized(), "Shapes::Collision::Collision: separation normal is not normalized", ); |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Whether the collision happened |
|
||||||
* |
|
||||||
* Negative or zero separation distance means that no collision |
|
||||||
* happened. |
|
||||||
* @see @ref separationDistance() |
|
||||||
*/ |
|
||||||
operator bool() const { return _separationDistance > 0.0f; } |
|
||||||
|
|
||||||
/** @brief Collision position */ |
|
||||||
VectorTypeFor<dimensions, Float> position() const { |
|
||||||
return _position; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Separation normal |
|
||||||
* |
|
||||||
* @see @ref separationDistance(), @ref flipped() |
|
||||||
*/ |
|
||||||
VectorTypeFor<dimensions, Float> separationNormal() const { |
|
||||||
return _separationNormal; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Separation distance |
|
||||||
* |
|
||||||
* @see @ref separationNormal(), @ref operator bool() |
|
||||||
*/ |
|
||||||
Float separationDistance() const { |
|
||||||
return _separationDistance; |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Flipped collision |
|
||||||
* |
|
||||||
* Returns new collision object as if the collision occured between |
|
||||||
* flipped pair of objects, i.e. with flipped separation normal and |
|
||||||
* contact position on surface of object A. |
|
||||||
* @see @ref position(), @ref separationNormal() |
|
||||||
*/ |
|
||||||
Collision<dimensions> flipped() const { |
|
||||||
return Collision<dimensions>(_position - _separationDistance*_separationNormal, -_separationNormal, _separationDistance); |
|
||||||
} |
|
||||||
|
|
||||||
private: |
|
||||||
VectorTypeFor<dimensions, Float> _position; |
|
||||||
VectorTypeFor<dimensions, Float> _separationNormal; |
|
||||||
Float _separationDistance; |
|
||||||
}; |
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Two-dimensional collision data |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
*/ |
|
||||||
typedef CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") Collision<2> Collision2D; |
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Three-dimensional collision data |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
*/ |
|
||||||
typedef CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") Collision<3> Collision3D; |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}} |
|
||||||
|
|
||||||
#endif |
|
||||||
@ -1,160 +0,0 @@ |
|||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#define _MAGNUM_DO_NOT_WARN_DEPRECATED_SHAPES |
|
||||||
|
|
||||||
#include "Composition.h" |
|
||||||
|
|
||||||
#include <algorithm> |
|
||||||
#include <Corrade/Utility/Assert.h> |
|
||||||
|
|
||||||
#include "Magnum/Shapes/Implementation/CollisionDispatch.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace Shapes { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
/*
|
|
||||||
Hierarchy implementation notes: |
|
||||||
|
|
||||||
The hierarchy is stored in flat array to provide easy access for the user and |
|
||||||
to save some allocations. Each node has zero, one or two subnodes. Value of |
|
||||||
`Node::rightNode` describes which child nodes exist: |
|
||||||
|
|
||||||
* 0 - no child subnodes |
|
||||||
* 1 - only left subnode exists |
|
||||||
* 2 - only right subnode exists |
|
||||||
* >2 - both child nodes exist |
|
||||||
|
|
||||||
If left node exists, it is right next to current one. If right node exists, it |
|
||||||
is at position `Node::rightNode-1` relative to current one (this applies also |
|
||||||
when `rightNode` is equal to 2, right node is right next to current one, |
|
||||||
because there are no left nodes). |
|
||||||
|
|
||||||
The node also specifies which shapes belong to it. Root node owns whole shape |
|
||||||
array and `Node::rightShape` marks first shape belonging to the right child |
|
||||||
node, relatively to begin. This recurses into child nodes, thus left child node |
|
||||||
has shapes from parent's begin to parent's `rightShape`. |
|
||||||
|
|
||||||
Shapes are merged together by concatenating its node and shape list and adding |
|
||||||
new node at the beginning with properly set `rightNode` and `rightShape`. |
|
||||||
Because these values are relative to parent, they don't need to be modified |
|
||||||
when concatenating. |
|
||||||
*/ |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> Composition<dimensions>::Composition(const Composition<dimensions>& other): _shapes(other._shapes.size()), _nodes(other._nodes.size()) { |
|
||||||
copyShapes(0, other); |
|
||||||
copyNodes(0, other); |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> Composition<dimensions>::Composition(Composition<dimensions>&& other): _shapes(std::move(other._shapes)), _nodes(std::move(other._nodes)) { |
|
||||||
other._shapes = nullptr; |
|
||||||
other._nodes = nullptr; |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> Composition<dimensions>::~Composition() { |
|
||||||
for(std::size_t i = 0; i != _shapes.size(); ++i) |
|
||||||
delete _shapes[i]; |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> Composition<dimensions>& Composition<dimensions>::operator=(const Composition<dimensions>& other) { |
|
||||||
for(std::size_t i = 0; i != _shapes.size(); ++i) |
|
||||||
delete _shapes[i]; |
|
||||||
|
|
||||||
if(_shapes.size() != other._shapes.size()) |
|
||||||
_shapes = Containers::Array<Implementation::AbstractShape<dimensions>*>(other._shapes.size()); |
|
||||||
|
|
||||||
if(_nodes.size() != other._nodes.size()) |
|
||||||
_nodes = Containers::Array<Node>(other._nodes.size()); |
|
||||||
|
|
||||||
copyShapes(0, other); |
|
||||||
copyNodes(0, other); |
|
||||||
return *this; |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> Composition<dimensions>& Composition<dimensions>::operator=(Composition<dimensions>&& other) { |
|
||||||
using std::swap; |
|
||||||
swap(other._shapes, _shapes); |
|
||||||
swap(other._nodes, _nodes); |
|
||||||
return *this; |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> void Composition<dimensions>::copyShapes(const std::size_t offset, Composition<dimensions>&& other) { |
|
||||||
CORRADE_INTERNAL_ASSERT(_shapes.size() >= other._shapes.size()+offset); |
|
||||||
std::move(other._shapes.begin(), other._shapes.end(), _shapes.begin()+offset); |
|
||||||
other._shapes = nullptr; |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> void Composition<dimensions>::copyShapes(const std::size_t offset, const Composition<dimensions>& other) { |
|
||||||
CORRADE_INTERNAL_ASSERT(_shapes.size() >= other._shapes.size()+offset); |
|
||||||
for(Implementation::AbstractShape<dimensions> * const* i = other._shapes.begin(), ** o = _shapes.begin()+offset; i != other._shapes.end(); ++i, ++o) |
|
||||||
*o = (*i)->clone(); |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> void Composition<dimensions>::copyNodes(std::size_t offset, const Composition<dimensions>& other) { |
|
||||||
CORRADE_INTERNAL_ASSERT(_nodes.size() >= other._nodes.size()+offset); |
|
||||||
std::copy(other._nodes.begin(), other._nodes.end(), _nodes.begin()+offset); |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> Composition<dimensions> Composition<dimensions>::transformed(const MatrixTypeFor<dimensions, Float>& matrix) const { |
|
||||||
Composition<dimensions> out(*this); |
|
||||||
for(Implementation::AbstractShape<dimensions> * const* i = _shapes.begin(), * const* o = out._shapes.begin(); i != _shapes.end(); ++i, ++o) |
|
||||||
(*i)->transform(matrix, *o); |
|
||||||
return out; |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> bool Composition<dimensions>::collides(const Implementation::AbstractShape<dimensions>& a, const std::size_t node, const std::size_t shapeBegin, const std::size_t shapeEnd) const { |
|
||||||
/* Empty group */ |
|
||||||
if(shapeBegin == shapeEnd) return false; |
|
||||||
|
|
||||||
CORRADE_INTERNAL_ASSERT(node < _nodes.size() && shapeBegin < shapeEnd); |
|
||||||
|
|
||||||
/* Collision on the left child. If the node is leaf one (no left child
|
|
||||||
exists), do it directly, recurse instead. */ |
|
||||||
const bool collidesLeft = (_nodes[node].rightNode == 0 || _nodes[node].rightNode == 2) ? |
|
||||||
Implementation::collides(a, *_shapes[shapeBegin]) : |
|
||||||
collides(a, node+1, shapeBegin, shapeBegin+_nodes[node].rightShape); |
|
||||||
|
|
||||||
/* NOT operation */ |
|
||||||
if(_nodes[node].operation == CompositionOperation::Not) |
|
||||||
return !collidesLeft; |
|
||||||
|
|
||||||
/* Short-circuit evaluation for AND/OR */ |
|
||||||
if((_nodes[node].operation == CompositionOperation::Or) == collidesLeft) |
|
||||||
return collidesLeft; |
|
||||||
|
|
||||||
/* Now the collision result depends only on the right child. Similar to
|
|
||||||
collision on the left child. */ |
|
||||||
return (_nodes[node].rightNode < 2) ? |
|
||||||
Implementation::collides(a, *_shapes[shapeBegin+_nodes[node].rightShape]) : |
|
||||||
collides(a, node+_nodes[node].rightNode-1, shapeBegin+_nodes[node].rightShape, shapeEnd); |
|
||||||
} |
|
||||||
|
|
||||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
|
||||||
template class MAGNUM_SHAPES_EXPORT Composition<2>; |
|
||||||
template class MAGNUM_SHAPES_EXPORT Composition<3>; |
|
||||||
#endif |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}} |
|
||||||
@ -1,395 +0,0 @@ |
|||||||
#ifndef Magnum_Shapes_Composition_h |
|
||||||
#define Magnum_Shapes_Composition_h |
|
||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @file
|
|
||||||
@brief Class @ref Magnum::Shapes::Composition, typedef @ref Magnum::Shapes::Composition2D, @ref Magnum::Shapes::Composition3D, enum @ref Magnum::Shapes::CompositionOperation |
|
||||||
|
|
||||||
@deprecated The @ref Magnum::Shapes library is a failed design experiment and |
|
||||||
is scheduled for removal in a future release. Related geometry algorithms |
|
||||||
were moved to @ref Magnum::Math::Distance and @ref Magnum::Math::Intersection; |
|
||||||
if you need a full-fledged physics library, please have look at |
|
||||||
[Bullet](https://bulletphysics.org), which has Magnum integration in
|
|
||||||
@ref Magnum::BulletIntegration, or at [Box2D](https://box2d.org/), which
|
|
||||||
has a @ref examples-box2d "Magnum example" as well. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include <type_traits> |
|
||||||
#include <utility> |
|
||||||
#include <Corrade/Containers/Array.h> |
|
||||||
#include <Corrade/Utility/Assert.h> |
|
||||||
|
|
||||||
#include "Magnum/DimensionTraits.h" |
|
||||||
#include "Magnum/Shapes/Shapes.h" |
|
||||||
#include "Magnum/Shapes/shapeImplementation.h" |
|
||||||
#include "Magnum/Shapes/visibility.h" |
|
||||||
|
|
||||||
/* File-level deprecation warning issued from Shapes.h */ |
|
||||||
|
|
||||||
namespace Magnum { namespace Shapes { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
namespace Implementation { |
|
||||||
template<class> struct ShapeHelper; |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> inline AbstractShape<dimensions>& getAbstractShape(Composition<dimensions>& group, std::size_t i) { |
|
||||||
return *group._shapes[i]; |
|
||||||
} |
|
||||||
template<UnsignedInt dimensions> inline const AbstractShape<dimensions>& getAbstractShape(const Composition<dimensions>& group, std::size_t i) { |
|
||||||
return *group._shapes[i]; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Shape operation |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
*/ |
|
||||||
enum class CORRADE_DEPRECATED_ENUM("scheduled for removal, see the docs for alternatives") CompositionOperation: UnsignedByte { |
|
||||||
Not, /**< Boolean NOT */ |
|
||||||
And, /**< Boolean AND */ |
|
||||||
Or /**< Boolean OR */ |
|
||||||
}; |
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Composition of shapes |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
|
|
||||||
Result of logical operations on shapes. See @ref shapes for brief introduction. |
|
||||||
*/ |
|
||||||
template<UnsignedInt dimensions> class CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") MAGNUM_SHAPES_EXPORT Composition { |
|
||||||
friend Implementation::AbstractShape<dimensions>& Implementation::getAbstractShape<>(Composition<dimensions>&, std::size_t); |
|
||||||
friend const Implementation::AbstractShape<dimensions>& Implementation::getAbstractShape<>(const Composition<dimensions>&, std::size_t); |
|
||||||
friend Implementation::ShapeHelper<Composition<dimensions>>; |
|
||||||
|
|
||||||
public: |
|
||||||
enum: UnsignedInt { |
|
||||||
Dimensions = dimensions /**< Dimension count */ |
|
||||||
}; |
|
||||||
|
|
||||||
/** @brief Shape type */ |
|
||||||
#ifdef DOXYGEN_GENERATING_OUTPUT |
|
||||||
enum class Type { |
|
||||||
Point, /**< @ref Point */ |
|
||||||
Line, /**< @ref Line */ |
|
||||||
LineSegment, /**< @ref LineSegment "Line segment" */ |
|
||||||
Sphere, /**< @ref Sphere */ |
|
||||||
InvertedSphere, /**< @ref InvertedSphere "Inverted sphere" */ |
|
||||||
Cylinder, /**< @ref Cylinder */ |
|
||||||
Capsule, /**< @ref Capsule */ |
|
||||||
AxisAlignedBox, /**< @ref AxisAlignedBox "Axis aligned box" */ |
|
||||||
Box, /**< @ref Box */ |
|
||||||
Plane /**< @ref Plane (3D only) */ |
|
||||||
}; |
|
||||||
#else |
|
||||||
typedef typename Implementation::ShapeDimensionTraits<dimensions>::Type Type; |
|
||||||
#endif |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Default constructor |
|
||||||
* |
|
||||||
* Creates empty composition. |
|
||||||
*/ |
|
||||||
explicit Composition() {} |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Unary operation constructor |
|
||||||
* @param operation Unary operation |
|
||||||
* @param a Operand |
|
||||||
*/ |
|
||||||
template<class T> explicit Composition(CompositionOperation operation, T&& a); |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Binary operation constructor |
|
||||||
* @param operation Binary operation |
|
||||||
* @param a Left operand |
|
||||||
* @param b Right operand |
|
||||||
*/ |
|
||||||
template<class T, class U> explicit Composition(CompositionOperation operation, T&& a, U&& b); |
|
||||||
|
|
||||||
/** @brief Copy constructor */ |
|
||||||
Composition(const Composition<dimensions>& other); |
|
||||||
|
|
||||||
/** @brief Move constructor */ |
|
||||||
Composition(Composition<dimensions>&& other); |
|
||||||
|
|
||||||
~Composition(); |
|
||||||
|
|
||||||
/** @brief Assigment operator */ |
|
||||||
Composition<dimensions>& operator=(const Composition<dimensions>& other); |
|
||||||
|
|
||||||
/** @brief Move assignment operator */ |
|
||||||
Composition<dimensions>& operator=(Composition<dimensions>&& other); |
|
||||||
|
|
||||||
/** @brief Transformed shape */ |
|
||||||
Composition<dimensions> transformed(const MatrixTypeFor<dimensions, Float>& matrix) const; |
|
||||||
|
|
||||||
/** @brief Count of shapes in the hierarchy */ |
|
||||||
std::size_t size() const { return _shapes.size(); } |
|
||||||
|
|
||||||
/** @brief Type of shape at given position */ |
|
||||||
Type type(std::size_t i) const { return _shapes[i]->type(); } |
|
||||||
|
|
||||||
/** @brief Shape at given position */ |
|
||||||
template<class T> const T& get(std::size_t i) const; |
|
||||||
|
|
||||||
/** @brief Collision with another shape */ |
|
||||||
#ifdef DOXYGEN_GENERATING_OUTPUT |
|
||||||
template<class T> bool operator%(const T& other) const { |
|
||||||
#else |
|
||||||
template<class T> auto operator%(const T& other) const -> typename std::enable_if<std::is_same<decltype(Implementation::TypeOf<T>::type()), typename Implementation::ShapeDimensionTraits<dimensions>::Type>::value, bool>::type { |
|
||||||
#endif |
|
||||||
return collides(Implementation::Shape<T>(other)); |
|
||||||
} |
|
||||||
|
|
||||||
private: |
|
||||||
struct Node { |
|
||||||
std::size_t rightNode, rightShape; |
|
||||||
CompositionOperation operation; |
|
||||||
}; |
|
||||||
|
|
||||||
bool collides(const Implementation::AbstractShape<dimensions>& a) const { |
|
||||||
return collides(a, 0, 0, _shapes.size()); |
|
||||||
} |
|
||||||
|
|
||||||
bool collides(const Implementation::AbstractShape<dimensions>& a, std::size_t node, std::size_t shapeBegin, std::size_t shapeEnd) const; |
|
||||||
|
|
||||||
template<class T> constexpr static std::size_t shapeCount(const T&) { |
|
||||||
return 1; |
|
||||||
} |
|
||||||
constexpr static std::size_t shapeCount(const Composition<dimensions>& hierarchy) { |
|
||||||
return hierarchy._shapes.size(); |
|
||||||
} |
|
||||||
template<class T> constexpr static std::size_t nodeCount(const T&) { |
|
||||||
return 0; |
|
||||||
} |
|
||||||
constexpr static std::size_t nodeCount(const Composition<dimensions>& hierarchy) { |
|
||||||
return hierarchy._nodes.size(); |
|
||||||
} |
|
||||||
|
|
||||||
template<class T> void copyShapes(std::size_t offset, const T& shape) { |
|
||||||
_shapes[offset] = new Implementation::Shape<T>(shape); |
|
||||||
} |
|
||||||
void copyShapes(std::size_t offset, Composition<dimensions>&& other); |
|
||||||
void copyShapes(std::size_t offset, const Composition<dimensions>& other); |
|
||||||
|
|
||||||
template<class T> void copyNodes(std::size_t, const T&) {} |
|
||||||
void copyNodes(std::size_t offset, const Composition<dimensions>& other); |
|
||||||
|
|
||||||
Containers::Array<Implementation::AbstractShape<dimensions>*> _shapes; |
|
||||||
Containers::Array<Node> _nodes; |
|
||||||
}; |
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Two-dimensional shape composition |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
*/ |
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH /* Otherwise GCC warns on the typedef :/ */ |
|
||||||
typedef CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") Composition<2> Composition2D; |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Three-dimensional shape composition |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
*/ |
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH /* Otherwise GCC warns on the typedef :/ */ |
|
||||||
typedef CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") Composition<3> Composition3D; |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
#ifdef DOXYGEN_GENERATING_OUTPUT |
|
||||||
/**
|
|
||||||
@debugoperatorclassenum{Composition,Composition::Type} |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
*/ |
|
||||||
template<UnsignedInt dimensions> Debug& operator<<(Debug& debug, typename Composition<dimensions>::Type value); |
|
||||||
#endif |
|
||||||
|
|
||||||
/** @relates Composition
|
|
||||||
@brief Collision occurence of shape with Composition |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
*/ |
|
||||||
#ifdef DOXYGEN_GENERATING_OUTPUT |
|
||||||
template<UnsignedInt dimensions, class T> inline bool operator%(const T& a, const Composition<dimensions>& b) { |
|
||||||
#else |
|
||||||
template<UnsignedInt dimensions, class T> inline CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") auto operator%(const T& a, const Composition<dimensions>& b) -> typename std::enable_if<std::is_same<decltype(Implementation::TypeOf<T>::type()), typename Implementation::ShapeDimensionTraits<dimensions>::Type>::value, bool>::type { |
|
||||||
#endif |
|
||||||
return b % a; |
|
||||||
} |
|
||||||
|
|
||||||
#ifdef DOXYGEN_GENERATING_OUTPUT |
|
||||||
/** @relates Composition
|
|
||||||
@brief Logical NOT of shape |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
*/ |
|
||||||
template<class T> inline CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") Composition<T::Dimensions> operator!(T a); |
|
||||||
|
|
||||||
/** @relates Composition
|
|
||||||
@brief Logical AND of two shapes |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
|
|
||||||
[Short-circuit evaluation](http://en.wikipedia.org/wiki/Short-circuit_evaluation)
|
|
||||||
is used here, so this operation can be used for providing simplified shape |
|
||||||
version, because collision with @p b is computed only if @p a collides. |
|
||||||
See @ref shapes-simplification for an example. |
|
||||||
*/ |
|
||||||
template<class T> inline CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") Composition<T::Dimensions> operator&&(T a, T b); |
|
||||||
|
|
||||||
/** @relates Composition
|
|
||||||
@brief Logical OR of two shapes |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
|
|
||||||
[Short-circuit evaluation](http://en.wikipedia.org/wiki/Short-circuit_evaluation)
|
|
||||||
is used, so if collision with @p a is detected, collision with @p b is not |
|
||||||
computed. |
|
||||||
*/ |
|
||||||
template<class T> inline CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") Composition<T::Dimensions> operator||(T a, T b); |
|
||||||
#endif |
|
||||||
|
|
||||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
|
||||||
#define enableIfIsShapeType typename std::enable_if< \ |
|
||||||
std::is_same<decltype(Implementation::TypeOf<T>::type()), typename Implementation::ShapeDimensionTraits<T::Dimensions>::Type>::value, \
|
|
||||||
Composition<T::Dimensions>>::type |
|
||||||
#define enableIfAreShapeType typename std::enable_if< \ |
|
||||||
std::is_same<decltype(Implementation::TypeOf<T>::type()), typename Implementation::ShapeDimensionTraits<T::Dimensions>::Type>::value && \
|
|
||||||
std::is_same<decltype(Implementation::TypeOf<U>::type()), typename Implementation::ShapeDimensionTraits<T::Dimensions>::Type>::value, \
|
|
||||||
Composition<T::Dimensions>>::type |
|
||||||
template<class T> inline CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") auto operator!(T&& a) -> enableIfIsShapeType { |
|
||||||
return Composition<T::Dimensions>(CompositionOperation::Not, std::forward<T>(a)); |
|
||||||
} |
|
||||||
template<class T, class U> inline CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") auto operator&&(T&& a, U&& b) -> enableIfAreShapeType { |
|
||||||
return Composition<T::Dimensions>(CompositionOperation::And, std::forward<T>(a), std::forward<U>(b)); |
|
||||||
} |
|
||||||
template<class T, class U> inline CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") auto operator||(T&& a, U&& b) -> enableIfAreShapeType { |
|
||||||
return Composition<T::Dimensions>(CompositionOperation::Or, std::forward<T>(a), std::forward<U>(b)); |
|
||||||
} |
|
||||||
#undef enableIfIsShapeType |
|
||||||
#undef enableIfAreShapeType |
|
||||||
#endif |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> template<class T> Composition<dimensions>::Composition(CompositionOperation operation, T&& a): _shapes(shapeCount(a)), _nodes(nodeCount(a)+1) { |
|
||||||
CORRADE_ASSERT(operation == CompositionOperation::Not, |
|
||||||
"Shapes::Composition::Composition(): unary operation expected", ); |
|
||||||
_nodes[0].operation = operation; |
|
||||||
|
|
||||||
/* 0 = no children, 1 = left child only */ |
|
||||||
_nodes[0].rightNode = (nodeCount(a) == 0 ? 0 : 1); |
|
||||||
_nodes[0].rightShape = shapeCount(a); |
|
||||||
copyNodes(1, a); |
|
||||||
copyShapes(0, std::forward<T>(a)); |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> template<class T, class U> Composition<dimensions>::Composition(CompositionOperation operation, T&& a, U&& b): _shapes(shapeCount(a) + shapeCount(b)), _nodes(nodeCount(a) + nodeCount(b) + 1) { |
|
||||||
CORRADE_ASSERT(operation != CompositionOperation::Not, |
|
||||||
"Shapes::Composition::Composition(): binary operation expected", ); |
|
||||||
_nodes[0].operation = operation; |
|
||||||
|
|
||||||
/* 0 = no children, 1 = left child only, 2 = right child only, >2 = both */ |
|
||||||
if(nodeCount(a) == 0 && nodeCount(b) == 0) |
|
||||||
_nodes[0].rightNode = 0; |
|
||||||
else if(nodeCount(b) == 0) |
|
||||||
_nodes[0].rightNode = 1; |
|
||||||
else _nodes[0].rightNode = nodeCount(a) + 2; |
|
||||||
|
|
||||||
_nodes[0].rightShape = shapeCount(a); |
|
||||||
copyNodes(1, a); |
|
||||||
copyNodes(nodeCount(a) + 1, b); |
|
||||||
copyShapes(shapeCount(a), std::forward<U>(b)); |
|
||||||
copyShapes(0, std::forward<T>(a)); |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> template<class T> inline const T& Composition<dimensions>::get(std::size_t i) const { |
|
||||||
CORRADE_ASSERT(_shapes[i]->type() == Implementation::TypeOf<T>::type(), |
|
||||||
"Shapes::Composition::get(): given shape is not of type" << Implementation::TypeOf<T>::type() << |
|
||||||
"but" << _shapes[i]->type(), *static_cast<T*>(nullptr)); |
|
||||||
return static_cast<Implementation::Shape<T>*>(_shapes[i])->shape; |
|
||||||
} |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}} |
|
||||||
|
|
||||||
#endif |
|
||||||
@ -1,61 +0,0 @@ |
|||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#define _MAGNUM_DO_NOT_WARN_DEPRECATED_SHAPES |
|
||||||
|
|
||||||
#include "Cylinder.h" |
|
||||||
|
|
||||||
#include "Magnum/Magnum.h" |
|
||||||
#include "Magnum/Math/Distance.h" |
|
||||||
#include "Magnum/Math/Functions.h" |
|
||||||
#include "Magnum/Math/Matrix3.h" |
|
||||||
#include "Magnum/Math/Matrix4.h" |
|
||||||
#include "Magnum/Shapes/Point.h" |
|
||||||
#include "Magnum/Shapes/Sphere.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace Shapes { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
template<UnsignedInt dimensions> Cylinder<dimensions> Cylinder<dimensions>::transformed(const MatrixTypeFor<dimensions, Float>& matrix) const { |
|
||||||
return Cylinder<dimensions>(matrix.transformPoint(_a), matrix.transformPoint(_b), matrix.uniformScaling()*_radius); |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> bool Cylinder<dimensions>::operator%(const Point<dimensions>& other) const { |
|
||||||
return Math::Distance::linePointSquared(_a, _b, other.position()) < |
|
||||||
Math::pow<2>(_radius); |
|
||||||
} |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> bool Cylinder<dimensions>::operator%(const Sphere<dimensions>& other) const { |
|
||||||
return Math::Distance::linePointSquared(_a, _b, other.position()) < |
|
||||||
Math::pow<2>(_radius+other.radius()); |
|
||||||
} |
|
||||||
|
|
||||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
|
||||||
template class MAGNUM_SHAPES_EXPORT Cylinder<2>; |
|
||||||
template class MAGNUM_SHAPES_EXPORT Cylinder<3>; |
|
||||||
#endif |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}} |
|
||||||
@ -1,178 +0,0 @@ |
|||||||
#ifndef Magnum_Shapes_Cylinder_h |
|
||||||
#define Magnum_Shapes_Cylinder_h |
|
||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @file
|
|
||||||
@brief Class @ref Magnum::Shapes::Cylinder, typedef @ref Magnum::Shapes::Cylinder2D, @ref Magnum::Shapes::Cylinder3D |
|
||||||
|
|
||||||
@deprecated The @ref Magnum::Shapes library is a failed design experiment and |
|
||||||
is scheduled for removal in a future release. Related geometry algorithms |
|
||||||
were moved to @ref Magnum::Math::Distance and @ref Magnum::Math::Intersection; |
|
||||||
if you need a full-fledged physics library, please have look at |
|
||||||
[Bullet](https://bulletphysics.org), which has Magnum integration in
|
|
||||||
@ref Magnum::BulletIntegration, or at [Box2D](https://box2d.org/), which
|
|
||||||
has a @ref examples-box2d "Magnum example" as well. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Magnum/DimensionTraits.h" |
|
||||||
#include "Magnum/Math/Vector3.h" |
|
||||||
#include "Magnum/Shapes/Shapes.h" |
|
||||||
#include "Magnum/Shapes/visibility.h" |
|
||||||
|
|
||||||
/* File-level deprecation warning issued from Shapes.h */ |
|
||||||
|
|
||||||
namespace Magnum { namespace Shapes { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
/**
|
|
||||||
@brief Infinite cylinder defined by line and radius |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
|
|
||||||
Unlike other elements the cylinder expects uniform scaling. See @ref shapes for |
|
||||||
brief introduction. |
|
||||||
@see @ref Cylinder2D, @ref Cylinder3D, @ref Capsule |
|
||||||
@todo Store the radius as squared value to avoid sqrt/pow? Will complicate |
|
||||||
collision detection with sphere. |
|
||||||
*/ |
|
||||||
template<UnsignedInt dimensions> class CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") MAGNUM_SHAPES_EXPORT Cylinder { |
|
||||||
public: |
|
||||||
enum: UnsignedInt { |
|
||||||
Dimensions = dimensions /**< Dimension count */ |
|
||||||
}; |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Constructor |
|
||||||
* |
|
||||||
* Creates zero-sized cylinder at origin. |
|
||||||
*/ |
|
||||||
constexpr /*implicit*/ Cylinder(): _radius(0.0f) {} |
|
||||||
|
|
||||||
/** @brief Constructor */ |
|
||||||
constexpr /*implicit*/ Cylinder(const VectorTypeFor<dimensions, Float>& a, const VectorTypeFor<dimensions, Float>& b, Float radius): _a(a), _b(b), _radius(radius) {} |
|
||||||
|
|
||||||
/** @brief Transformed shape */ |
|
||||||
Cylinder<dimensions> transformed(const MatrixTypeFor<dimensions, Float>& matrix) const; |
|
||||||
|
|
||||||
/** @brief First point */ |
|
||||||
constexpr VectorTypeFor<dimensions, Float> a() const { |
|
||||||
return _a; |
|
||||||
} |
|
||||||
|
|
||||||
/** @brief Set first point */ |
|
||||||
void setA(const VectorTypeFor<dimensions, Float>& a) { |
|
||||||
_a = a; |
|
||||||
} |
|
||||||
|
|
||||||
/** @brief Second point */ |
|
||||||
constexpr VectorTypeFor<dimensions, Float> b() const { |
|
||||||
return _b; |
|
||||||
} |
|
||||||
|
|
||||||
/** @brief Set second point */ |
|
||||||
void setB(const VectorTypeFor<dimensions, Float>& b) { |
|
||||||
_b = b; |
|
||||||
} |
|
||||||
|
|
||||||
/** @brief Radius */ |
|
||||||
constexpr Float radius() const { return _radius; } |
|
||||||
|
|
||||||
/** @brief Set radius */ |
|
||||||
void setRadius(Float radius) { _radius = radius; } |
|
||||||
|
|
||||||
/** @brief Collision occurence with point */ |
|
||||||
bool operator%(const Point<dimensions>& other) const; |
|
||||||
|
|
||||||
/** @brief Collision occurence with sphere */ |
|
||||||
bool operator%(const Sphere<dimensions>& other) const; |
|
||||||
|
|
||||||
private: |
|
||||||
VectorTypeFor<dimensions, Float> _a, _b; |
|
||||||
Float _radius; |
|
||||||
}; |
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Infinite two-dimensional cylinder |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
*/ |
|
||||||
typedef CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") Cylinder<2> Cylinder2D; |
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Infinite three-dimensional cylinder |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
*/ |
|
||||||
typedef CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") Cylinder<3> Cylinder3D; |
|
||||||
|
|
||||||
/**
|
|
||||||
@collisionoccurenceoperator{Point,Cylinder} |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
*/ |
|
||||||
template<UnsignedInt dimensions> inline CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") bool operator%(const Point<dimensions>& a, const Cylinder<dimensions>& b) { return b % a; } |
|
||||||
|
|
||||||
/**
|
|
||||||
@collisionoccurenceoperator{Sphere,Cylinder} |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
*/ |
|
||||||
template<UnsignedInt dimensions> inline CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") bool operator%(const Sphere<dimensions>& a, const Cylinder<dimensions>& b) { return b % a; } |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}} |
|
||||||
|
|
||||||
#endif |
|
||||||
@ -1,133 +0,0 @@ |
|||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#define _MAGNUM_DO_NOT_WARN_DEPRECATED_SHAPES |
|
||||||
|
|
||||||
#include "CollisionDispatch.h" |
|
||||||
|
|
||||||
#include "Magnum/Shapes/AxisAlignedBox.h" |
|
||||||
#include "Magnum/Shapes/Box.h" |
|
||||||
#include "Magnum/Shapes/Capsule.h" |
|
||||||
#include "Magnum/Shapes/Cylinder.h" |
|
||||||
#include "Magnum/Shapes/LineSegment.h" |
|
||||||
#include "Magnum/Shapes/Plane.h" |
|
||||||
#include "Magnum/Shapes/Point.h" |
|
||||||
#include "Magnum/Shapes/Sphere.h" |
|
||||||
#include "Magnum/Shapes/shapeImplementation.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace Shapes { namespace Implementation { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
template<> bool collides(const AbstractShape<2>& a, const AbstractShape<2>& b) { |
|
||||||
if(a.type() < b.type()) return collides(b, a); |
|
||||||
|
|
||||||
switch(UnsignedInt(a.type())*UnsignedInt(b.type())) { |
|
||||||
#define _c(aType, aClass, bType, bClass) \ |
|
||||||
case UnsignedInt(ShapeDimensionTraits<2>::Type::aType)*UnsignedInt(ShapeDimensionTraits<2>::Type::bType): \
|
|
||||||
return static_cast<const Shape<aClass>&>(a).shape % static_cast<const Shape<bClass>&>(b).shape; |
|
||||||
_c(Sphere, Sphere2D, Point, Point2D) |
|
||||||
_c(Sphere, Sphere2D, Line, Line2D) |
|
||||||
_c(Sphere, Sphere2D, LineSegment, LineSegment2D) |
|
||||||
_c(Sphere, Sphere2D, Sphere, Sphere2D) |
|
||||||
|
|
||||||
_c(InvertedSphere, InvertedSphere2D, Point, Point2D) |
|
||||||
_c(InvertedSphere, InvertedSphere2D, Sphere, Sphere2D) |
|
||||||
|
|
||||||
_c(Cylinder, Cylinder2D, Point, Point2D) |
|
||||||
_c(Cylinder, Cylinder2D, Sphere, Sphere2D) |
|
||||||
|
|
||||||
_c(Capsule, Capsule2D, Point, Point2D) |
|
||||||
_c(Capsule, Capsule2D, Sphere, Sphere2D) |
|
||||||
|
|
||||||
_c(AxisAlignedBox, AxisAlignedBox2D, Point, Point2D) |
|
||||||
#undef _c |
|
||||||
} |
|
||||||
|
|
||||||
return false; |
|
||||||
} |
|
||||||
|
|
||||||
template<> Collision<2> collision(const AbstractShape<2>& a, const AbstractShape<2>& b) { |
|
||||||
if(a.type() < b.type()) return collision(b, a); |
|
||||||
|
|
||||||
switch(UnsignedInt(a.type())*UnsignedInt(b.type())) { |
|
||||||
#define _c(aType, aClass, bType, bClass) \ |
|
||||||
case UnsignedInt(ShapeDimensionTraits<2>::Type::aType)*UnsignedInt(ShapeDimensionTraits<2>::Type::bType): \
|
|
||||||
return static_cast<const Shape<aClass>&>(a).shape / static_cast<const Shape<bClass>&>(b).shape; |
|
||||||
_c(Sphere, Sphere2D, Point, Point2D) |
|
||||||
_c(Sphere, Sphere2D, Sphere, Sphere2D) |
|
||||||
#undef _c |
|
||||||
} |
|
||||||
|
|
||||||
return {}; |
|
||||||
} |
|
||||||
|
|
||||||
template<> bool collides(const AbstractShape<3>& a, const AbstractShape<3>& b) { |
|
||||||
if(a.type() < b.type()) return collides(b, a); |
|
||||||
|
|
||||||
switch(UnsignedInt(a.type())*UnsignedInt(b.type())) { |
|
||||||
#define _c(aType, aClass, bType, bClass) \ |
|
||||||
case UnsignedInt(ShapeDimensionTraits<3>::Type::aType)*UnsignedInt(ShapeDimensionTraits<3>::Type::bType): \
|
|
||||||
return static_cast<const Shape<aClass>&>(a).shape % static_cast<const Shape<bClass>&>(b).shape; |
|
||||||
_c(Sphere, Sphere3D, Point, Point3D) |
|
||||||
_c(Sphere, Sphere3D, Line, Line3D) |
|
||||||
_c(Sphere, Sphere3D, LineSegment, LineSegment3D) |
|
||||||
_c(Sphere, Sphere3D, Sphere, Sphere3D) |
|
||||||
|
|
||||||
_c(InvertedSphere, InvertedSphere3D, Point, Point3D) |
|
||||||
_c(InvertedSphere, InvertedSphere3D, Sphere, Sphere3D) |
|
||||||
|
|
||||||
_c(Cylinder, Cylinder3D, Point, Point3D) |
|
||||||
_c(Cylinder, Cylinder3D, Sphere, Sphere3D) |
|
||||||
|
|
||||||
_c(Capsule, Capsule3D, Point, Point3D) |
|
||||||
_c(Capsule, Capsule3D, Sphere, Sphere3D) |
|
||||||
|
|
||||||
_c(AxisAlignedBox, AxisAlignedBox3D, Point, Point3D) |
|
||||||
|
|
||||||
_c(Plane, Plane, Line, Line3D) |
|
||||||
_c(Plane, Plane, LineSegment, LineSegment3D) |
|
||||||
#undef _c |
|
||||||
} |
|
||||||
|
|
||||||
return false; |
|
||||||
} |
|
||||||
|
|
||||||
template<> Collision<3> collision(const AbstractShape<3>& a, const AbstractShape<3>& b) { |
|
||||||
if(a.type() < b.type()) return collision(b, a); |
|
||||||
|
|
||||||
switch(UnsignedInt(a.type())*UnsignedInt(b.type())) { |
|
||||||
#define _c(aType, aClass, bType, bClass) \ |
|
||||||
case UnsignedInt(ShapeDimensionTraits<3>::Type::aType)*UnsignedInt(ShapeDimensionTraits<3>::Type::bType): \
|
|
||||||
return static_cast<const Shape<aClass>&>(a).shape / static_cast<const Shape<bClass>&>(b).shape; |
|
||||||
_c(Sphere, Sphere3D, Point, Point3D) |
|
||||||
_c(Sphere, Sphere3D, Sphere, Sphere3D) |
|
||||||
#undef _c |
|
||||||
} |
|
||||||
|
|
||||||
return {}; |
|
||||||
} |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}}} |
|
||||||
@ -1,53 +0,0 @@ |
|||||||
#ifndef Magnum_Shapes_Implementation_CollisionDispatch_h |
|
||||||
#define Magnum_Shapes_Implementation_CollisionDispatch_h |
|
||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Magnum/Types.h" |
|
||||||
#include "Magnum/Shapes/Shapes.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace Shapes { namespace Implementation { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
template<UnsignedInt> struct AbstractShape; |
|
||||||
|
|
||||||
/*
|
|
||||||
Shape collision double-dispatch: |
|
||||||
|
|
||||||
The collision is symmetric, i.e. it doesn't matter if we test Point vs. Sphere |
|
||||||
or Sphere vs. Point. Each type is specified by unique prime number. Then we |
|
||||||
multiply the two numbers together and switch() on the result. Because of |
|
||||||
multiplying two prime numbers, there is no ambiguity (the result is unique for |
|
||||||
each combination). |
|
||||||
*/ |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> bool collides(const AbstractShape<dimensions>& a, const AbstractShape<dimensions>& b); |
|
||||||
|
|
||||||
template<UnsignedInt dimensions> Collision<dimensions> collision(const AbstractShape<dimensions>& a, const AbstractShape<dimensions>& b); |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}}} |
|
||||||
|
|
||||||
#endif |
|
||||||
@ -1,48 +0,0 @@ |
|||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#define _MAGNUM_DO_NOT_WARN_DEPRECATED_SHAPES |
|
||||||
|
|
||||||
#include "Line.h" |
|
||||||
|
|
||||||
#include "Magnum/Math/Matrix3.h" |
|
||||||
#include "Magnum/Math/Matrix4.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace Shapes { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
template<UnsignedInt dimensions> Line<dimensions> Line<dimensions>::transformed(const MatrixTypeFor<dimensions, Float>& matrix) const { |
|
||||||
return Line<dimensions>(matrix.transformPoint(_a), |
|
||||||
matrix.transformPoint(_b)); |
|
||||||
} |
|
||||||
|
|
||||||
/* Explicitly instantiate the templates */ |
|
||||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
|
||||||
template class MAGNUM_SHAPES_EXPORT Line<2>; |
|
||||||
template class MAGNUM_SHAPES_EXPORT Line<3>; |
|
||||||
#endif |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}} |
|
||||||
@ -1,138 +0,0 @@ |
|||||||
#ifndef Magnum_Shapes_Line_h |
|
||||||
#define Magnum_Shapes_Line_h |
|
||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @file
|
|
||||||
@brief Class @ref Magnum::Shapes::Line, typedef @ref Magnum::Shapes::Line2D, @ref Magnum::Shapes::Line3D |
|
||||||
|
|
||||||
@deprecated The @ref Magnum::Shapes library is a failed design experiment and |
|
||||||
is scheduled for removal in a future release. Related geometry algorithms |
|
||||||
were moved to @ref Magnum::Math::Distance and @ref Magnum::Math::Intersection; |
|
||||||
if you need a full-fledged physics library, please have look at |
|
||||||
[Bullet](https://bulletphysics.org), which has Magnum integration in
|
|
||||||
@ref Magnum::BulletIntegration, or at [Box2D](https://box2d.org/), which
|
|
||||||
has a @ref examples-box2d "Magnum example" as well. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Magnum/DimensionTraits.h" |
|
||||||
#include "Magnum/Math/Vector3.h" |
|
||||||
#include "Magnum/Shapes/Shapes.h" |
|
||||||
#include "Magnum/Shapes/visibility.h" |
|
||||||
|
|
||||||
/* File-level deprecation warning issued from Shapes.h */ |
|
||||||
|
|
||||||
namespace Magnum { namespace Shapes { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
/**
|
|
||||||
@brief Infinite line, defined by two points |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
|
|
||||||
See @ref shapes for brief introduction. |
|
||||||
@see @ref Line2D, @ref Line3D |
|
||||||
@todo collision detection of two Line2D |
|
||||||
*/ |
|
||||||
template<UnsignedInt dimensions> class CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") MAGNUM_SHAPES_EXPORT Line { |
|
||||||
public: |
|
||||||
enum: UnsignedInt { |
|
||||||
Dimensions = dimensions /**< Dimension count */ |
|
||||||
}; |
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Default constructor |
|
||||||
* |
|
||||||
* Creates line with both points at origin. |
|
||||||
*/ |
|
||||||
constexpr /*implicit*/ Line() {} |
|
||||||
|
|
||||||
/** @brief Constructor */ |
|
||||||
constexpr /*implicit*/ Line(const VectorTypeFor<dimensions, Float>& a, const typename DimensionTraits<dimensions, Float>::VectorType& b): _a(a), _b(b) {} |
|
||||||
|
|
||||||
/** @brief Transformed shape */ |
|
||||||
Line<dimensions> transformed(const MatrixTypeFor<dimensions, Float>& matrix) const; |
|
||||||
|
|
||||||
/** @brief First point */ |
|
||||||
constexpr VectorTypeFor<dimensions, Float> a() const { |
|
||||||
return _a; |
|
||||||
} |
|
||||||
|
|
||||||
/** @brief Set first point */ |
|
||||||
void setA(const VectorTypeFor<dimensions, Float>& a) { |
|
||||||
_a = a; |
|
||||||
} |
|
||||||
|
|
||||||
/** @brief Second point */ |
|
||||||
constexpr VectorTypeFor<dimensions, Float> b() const { |
|
||||||
return _b; |
|
||||||
} |
|
||||||
|
|
||||||
/** @brief Set second point */ |
|
||||||
void setB(const VectorTypeFor<dimensions, Float>& b) { |
|
||||||
_b = b; |
|
||||||
} |
|
||||||
|
|
||||||
private: |
|
||||||
VectorTypeFor<dimensions, Float> _a, _b; |
|
||||||
}; |
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Infinite two-dimensional line |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
*/ |
|
||||||
typedef CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") Line<2> Line2D; |
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Infinite three-dimensional line |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
*/ |
|
||||||
|
|
||||||
typedef CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") Line<3> Line3D; |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}} |
|
||||||
|
|
||||||
#endif |
|
||||||
@ -1,111 +0,0 @@ |
|||||||
#ifndef Magnum_Shapes_LineSegment_h |
|
||||||
#define Magnum_Shapes_LineSegment_h |
|
||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
/** @file
|
|
||||||
@brief Class @ref Magnum::Shapes::LineSegment, typedef @ref Magnum::Shapes::LineSegment2D, @ref Magnum::Shapes::LineSegment3D |
|
||||||
|
|
||||||
@deprecated The @ref Magnum::Shapes library is a failed design experiment and |
|
||||||
is scheduled for removal in a future release. Related geometry algorithms |
|
||||||
were moved to @ref Magnum::Math::Distance and @ref Magnum::Math::Intersection; |
|
||||||
if you need a full-fledged physics library, please have look at |
|
||||||
[Bullet](https://bulletphysics.org), which has Magnum integration in
|
|
||||||
@ref Magnum::BulletIntegration, or at [Box2D](https://box2d.org/), which
|
|
||||||
has a @ref examples-box2d "Magnum example" as well. |
|
||||||
*/ |
|
||||||
|
|
||||||
#include "Magnum/Shapes/Line.h" |
|
||||||
|
|
||||||
/* File-level deprecation warning issued from Shapes.h */ |
|
||||||
|
|
||||||
namespace Magnum { namespace Shapes { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
/**
|
|
||||||
@brief Line segment, defined by starting and ending point |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
|
|
||||||
See @ref shapes for brief introduction. |
|
||||||
@see @ref LineSegment2D, @ref LineSegment3D |
|
||||||
*/ |
|
||||||
template<UnsignedInt dimensions> class CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") LineSegment: public Line<dimensions> { |
|
||||||
public: |
|
||||||
/**
|
|
||||||
* @brief Default constructor |
|
||||||
* |
|
||||||
* Creates line segment with both points at origin. |
|
||||||
*/ |
|
||||||
constexpr /*implicit*/ LineSegment() {} |
|
||||||
|
|
||||||
/** @brief Constructor */ |
|
||||||
constexpr /*implicit*/ LineSegment(const VectorTypeFor<dimensions, Float>& a, const VectorTypeFor<dimensions, Float>& b): Line<dimensions>(a, b) {} |
|
||||||
|
|
||||||
/** @brief Transformed shape */ |
|
||||||
LineSegment<dimensions> transformed(const MatrixTypeFor<dimensions, Float>& matrix) const { |
|
||||||
return Line<dimensions>::transformed(matrix); |
|
||||||
} |
|
||||||
|
|
||||||
private: |
|
||||||
constexpr LineSegment(const Line<dimensions>& line): Line<dimensions>(line) {} |
|
||||||
}; |
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Two-dimensional line segment |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
*/ |
|
||||||
typedef CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") LineSegment<2> LineSegment2D; |
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Three-dimensional line segment |
|
||||||
|
|
||||||
@deprecated The @ref Shapes library is a failed design experiment and is |
|
||||||
scheduled for removal in a future release. Related geometry algorithms were |
|
||||||
moved to @ref Math::Distance and @ref Math::Intersection; if you need a |
|
||||||
full-fledged physics library, please have look at [Bullet](https://bulletphysics.org),
|
|
||||||
which has Magnum integration in @ref BulletIntegration, or at |
|
||||||
[Box2D](https://box2d.org/), which has a @ref examples-box2d "Magnum example"
|
|
||||||
as well. |
|
||||||
*/ |
|
||||||
typedef CORRADE_DEPRECATED("scheduled for removal, see the docs for alternatives") LineSegment<3> LineSegment3D; |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}} |
|
||||||
|
|
||||||
#endif |
|
||||||
@ -1,56 +0,0 @@ |
|||||||
/*
|
|
||||||
This file is part of Magnum. |
|
||||||
|
|
||||||
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 |
|
||||||
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. |
|
||||||
*/ |
|
||||||
|
|
||||||
#define _MAGNUM_DO_NOT_WARN_DEPRECATED_SHAPES |
|
||||||
|
|
||||||
#include "Plane.h" |
|
||||||
|
|
||||||
#include "Magnum/Math/Intersection.h" |
|
||||||
#include "Magnum/Math/Matrix4.h" |
|
||||||
#include "Magnum/Shapes/LineSegment.h" |
|
||||||
|
|
||||||
namespace Magnum { namespace Shapes { |
|
||||||
|
|
||||||
CORRADE_IGNORE_DEPRECATED_PUSH |
|
||||||
Plane Plane::transformed(const Matrix4& matrix) const { |
|
||||||
/* Using matrix.rotation() would result in two more normalizations (slow),
|
|
||||||
using .normalized() instead of matrix.uniformScaling() would not check |
|
||||||
uniform scaling */ |
|
||||||
return Plane(matrix.transformPoint(_position), |
|
||||||
matrix.rotationScaling()*_normal/matrix.uniformScaling()); |
|
||||||
} |
|
||||||
|
|
||||||
bool Plane::operator%(const Line3D& other) const { |
|
||||||
Float t = Math::Intersection::planeLine(Math::planeEquation(_normal, _position), other.a(), other.b()-other.a()); |
|
||||||
return t != t || (t != Constants::inf() && t != -Constants::inf()); |
|
||||||
} |
|
||||||
|
|
||||||
bool Plane::operator%(const LineSegment3D& other) const { |
|
||||||
Float t = Math::Intersection::planeLine(Math::planeEquation(_normal, _position), other.a(), other.b()-other.a()); |
|
||||||
return t > 0.0f && t < 1.0f; |
|
||||||
} |
|
||||||
CORRADE_IGNORE_DEPRECATED_POP |
|
||||||
|
|
||||||
}} |
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue