vsg: include/vsg/utils/PolytopeIntersector.h Source File

vsg 1.1.9 VulkanSceneGraph library |

Loading...
Searching...
No Matches
PolytopeIntersector.h
1#pragma once
2
3/* <editor-fold desc="MIT License">
4
5Copyright(c) 2024 Robert Osfield
6
7Permission 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:
8
9The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
11THE 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.
12
13</editor-fold> */
14
15#include <vsg/app/Camera.h>
16#include <vsg/maths/plane.h>
17#include <vsg/utils/Intersector.h>
18#include <vsg/utils/LineSegmentIntersector.h>
19
20namespace vsg
21{
22
23 using Polytope = std::vector<dplane>;
24
26 class VSG_DECLSPEC PolytopeIntersector : public Inherit<Intersector, PolytopeIntersector>
27 {
28 public:
30 explicit PolytopeIntersector(const Polytope& in_polytope, ref_ptr<ArrayState> initialArrayData = {});
31
33 PolytopeIntersector(const Camera& camera, double xMin, double yMin, double xMax, double yMax, ref_ptr<ArrayState> initialArrayData = {});
34
35 class VSG_DECLSPEC Intersection : public Inherit<Object, Intersection>
36 {
37 public:
38 Intersection() {}
39 Intersection(const dvec3& in_localIntersection, const dvec3& in_worldIntersection, const dmat4& in_localToWorld, const NodePath& in_nodePath, const DataList& in_arrays, const std::vector<uint32_t>& in_indexRatios, uint32_t in_instanceIndex);
40
41 dvec3 localIntersection;
42 dvec3 worldIntersection;
43
44 dmat4 localToWorld;
45 NodePath nodePath;
46 DataList arrays;
47 std::vector<uint32_t> indices;
48 uint32_t instanceIndex = 0;
49
50 // return true if Intersection is valid
51 operator bool() const { return !nodePath.empty(); }
52 };
53
54 using Intersections = std::vector<ref_ptr<Intersection>>;
55 Intersections intersections;
56
57 ref_ptr<Intersection> add(const dvec3& coord, const std::vector<uint32_t>& indices, uint32_t instanceIndex);
58
59 void pushTransform(const Transform& transform) override;
60 void popTransform() override;
61
63 bool intersects(const dsphere& bs) override;
64
65 bool intersectDraw(uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount) override;
66 bool intersectDrawIndexed(uint32_t firstIndex, uint32_t indexCount, uint32_t firstInstance, uint32_t instanceCount) override;
67
68 protected:
69 std::vector<Polytope> _polytopeStack;
70 };
71 VSG_type_name(vsg::PolytopeIntersector);
72
73} // namespace vsg
vsg::Camera
Definition Camera.h:27
vsg::PolytopeIntersector
PolytopeIntersector is an Intersector subclass that provides support for computing intersections betw...
Definition PolytopeIntersector.h:27
vsg::PolytopeIntersector::pushTransform
void pushTransform(const Transform &transform) override
clone and transform this Intersector to provide a new Intersector in local coordinates
vsg::PolytopeIntersector::intersectDrawIndexed
bool intersectDrawIndexed(uint32_t firstIndex, uint32_t indexCount, uint32_t firstInstance, uint32_t instanceCount) override
intersect with a vkCmdDrawIndexed primitive
vsg::PolytopeIntersector::intersectDraw
bool intersectDraw(uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount) override
intersect with a vkCmdDraw primitive
vsg::PolytopeIntersector::intersects
bool intersects(const dsphere &bs) override
check for intersection with sphere
vsg::PolytopeIntersector::PolytopeIntersector
PolytopeIntersector(const Polytope &in_polytope, ref_ptr< ArrayState > initialArrayData={})
create intersector for specified polytope.
vsg::PolytopeIntersector::PolytopeIntersector
PolytopeIntersector(const Camera &camera, double xMin, double yMin, double xMax, double yMax, ref_ptr< ArrayState > initialArrayData={})
create intersector for a polytope with window space dimensions, projected into world coords using the...
vsg::Transform
Transform node is a pure virtual base class for positioning/scaling/rotating subgraphs.
Definition Transform.h:22
vsg::ref_ptr
Definition ref_ptr.h:22