vsg  1.1.0
VulkanSceneGraph library
Intersector.h
1 #pragma once
2 
3 /* <editor-fold desc="MIT License">
4 
5 Copyright(c) 2020 Robert Osfield
6 
7 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:
8 
9 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10 
11 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.
12 
13 </editor-fold> */
14 
15 #include <vsg/nodes/Node.h>
16 #include <vsg/state/ArrayState.h>
17 
18 namespace vsg
19 {
20 
23  class VSG_DECLSPEC Intersector : public Inherit<ConstVisitor, Intersector>
24  {
25  public:
26  using NodePath = std::vector<const Node*>;
27  using ArrayStateStack = std::vector<ref_ptr<ArrayState>>;
28 
29  Intersector(ref_ptr<ArrayState> initialArrayState = {});
30 
31  //
32  // handle traverse of the scene graph
33  //
34  void apply(const Node& node) override;
35  void apply(const StateGroup& stategroup) override;
36  void apply(const Transform& transform) override;
37  void apply(const LOD& lod) override;
38  void apply(const PagedLOD& plod) override;
39  void apply(const CullNode& cn) override;
40  void apply(const CullGroup& cn) override;
41  void apply(const DepthSorted& cn) override;
42 
43  void apply(const VertexDraw& vid) override;
44  void apply(const VertexIndexDraw& vid) override;
45  void apply(const Geometry& geometry) override;
46 
47  void apply(const BindVertexBuffers& bvb) override;
48  void apply(const BindIndexBuffer& bib) override;
49  void apply(const Draw& draw) override;
50  void apply(const DrawIndexed& drawIndexed) override;
51 
52  void apply(const BufferInfo& bufferInfo) override;
53  void apply(const ushortArray& array) override;
54  void apply(const uintArray& array) override;
55 
56  //
57  // provide virtual functions for concrete Intersector implementations to provide handling of intersection with mesh geometries
58  //
59 
61  virtual void pushTransform(const Transform& transform) = 0;
62 
63  virtual void popTransform() = 0;
64 
66  virtual bool intersects(const dsphere& sphere) = 0;
67 
69  virtual bool intersectDraw(uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount) = 0;
70 
72  virtual bool intersectDrawIndexed(uint32_t firstIndex, uint32_t indexCount, uint32_t firstInstance, uint32_t instanceCount) = 0;
73 
75  std::vector<dmat4>& localToWorldStack() { return arrayStateStack.back()->localToWorldStack; }
76 
78  std::vector<dmat4>& worldToLocalStack() { return arrayStateStack.back()->worldToLocalStack; }
79 
80  protected:
81  ArrayStateStack arrayStateStack;
82 
83  ref_ptr<const ushortArray> ushort_indices;
84  ref_ptr<const uintArray> uint_indices;
85 
86  NodePath _nodePath;
87  };
88  VSG_type_name(vsg::Intersector);
89 
90 } // namespace vsg
BindIndexBuffer command encapsulates vkCmdBindIndexBuffer call and associated settings.
Definition: BindIndexBuffer.h:28
BindVertexBuffers command encapsulates vkCmdBindVertexBuffers call and associated settings.
Definition: BindVertexBuffers.h:25
BufferInfo encapsulates the settings that map to VkDescriptorBufferInfo.
Definition: BufferInfo.h:27
CullNode that enables view frustum culling on a list of children.
Definition: CullGroup.h:23
Definition: CullNode.h:25
Definition: DepthSorted.h:27
DrawIndexed command encapsulates vkCmdDrawIndexed call and associated settings.
Definition: DrawIndexed.h:24
Draw command encapsulates vkCmdDraw call and associated settings.
Definition: Draw.h:24
Definition: Geometry.h:30
Definition: Inherit.h:28
Definition: Intersector.h:24
virtual bool intersectDraw(uint32_t firstVertex, uint32_t vertexCount, uint32_t firstInstance, uint32_t instanceCount)=0
intersect with a vkCmdDraw primitive
virtual bool intersects(const dsphere &sphere)=0
check for intersection with sphere
std::vector< dmat4 > & worldToLocalStack()
get the current world to local matrix stack
Definition: Intersector.h:78
virtual bool intersectDrawIndexed(uint32_t firstIndex, uint32_t indexCount, uint32_t firstInstance, uint32_t instanceCount)=0
intersect with a vkCmdDrawIndexed primitive
virtual void pushTransform(const Transform &transform)=0
clone and transform this Intersector to provide a new Intersector in local coordinates
std::vector< dmat4 > & localToWorldStack()
get the current local to world matrix stack
Definition: Intersector.h:75
Definition: LOD.h:33
Definition: Node.h:24
Definition: PagedLOD.h:36
Definition: StateGroup.h:32
Transform node is a pure virtual base class for positioning/scaling/rotating subgraphs.
Definition: Transform.h:22
Definition: VertexDraw.h:25
Definition: VertexIndexDraw.h:25
Definition: ref_ptr.h:22