vsg  1.1.0
VulkanSceneGraph library
LoadPagedLOD.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/app/Camera.h>
16 #include <vsg/core/Visitor.h>
17 #include <vsg/maths/transform.h>
18 
19 #include <stack>
20 
21 namespace vsg
22 {
23  // Traverse the scene graph loading any PLOD that are required for a camera view.
24  class VSG_DECLSPEC LoadPagedLOD : public vsg::Visitor
25  {
26  public:
27  explicit LoadPagedLOD(ref_ptr<Camera> in_camera, int in_loadLevels = 30);
28 
29  void apply(Node& node) override;
30  void apply(CullNode& node) override;
31  void apply(Transform& transform) override;
32  void apply(LOD& lod) override;
33  void apply(PagedLOD& plod) override;
34 
35  ref_ptr<Camera> camera;
36  int loadLevels = 0;
37  int level = 0;
38  unsigned int numTiles = 0;
39 
40  protected:
41  using Plane = dplane;
42  using Polytope = std::array<Plane, 4>;
43  using MatrixStack = std::stack<dmat4>;
44  using PolytopeStack = std::stack<Polytope>;
45 
46  MatrixStack projectionMatrixStack;
47  MatrixStack modelviewMatrixStack;
48 
49  Polytope _frustumUnit;
50  Polytope _frustumProjected;
51  PolytopeStack _frustumStack;
52  Paths _pathStack;
53 
54  inline std::pair<double, double> computeDistanceAndRF(const dsphere& bs) const
55  {
56  const auto& proj = projectionMatrixStack.top();
57  const auto& mv = modelviewMatrixStack.top();
58  auto f = -proj[1][1];
59 
60  auto dist = std::abs(mv[0][2] * bs.x + mv[1][2] * bs.y + mv[2][2] * bs.z + mv[3][2]);
61  auto rf = bs.r * f;
62  return {dist, rf};
63  }
64 
65  void pushFrustum();
66  };
67  VSG_type_name(vsg::LoadPagedLOD);
68 
69 } // namespace vsg
Definition: CullNode.h:25
Definition: LOD.h:33
Definition: LoadPagedLOD.h:25
Definition: Node.h:24
Definition: PagedLOD.h:36
Transform node is a pure virtual base class for positioning/scaling/rotating subgraphs.
Definition: Transform.h:22
Definition: Visitor.h:147
Definition: ref_ptr.h:22
Definition: plane.h:33