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

vsg 1.1.3 VulkanSceneGraph library

Loading...
Searching...
No Matches
LoadPagedLOD.h
1#pragma once
2
3/* <editor-fold desc="MIT License">
4
5Copyright(c) 2020 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/core/Visitor.h>
17#include <vsg/maths/transform.h>
18
19#include <stack>
20
21namespace 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
vsg::CullNode
Definition CullNode.h:25
vsg::LOD
Definition LOD.h:33
vsg::LoadPagedLOD
Definition LoadPagedLOD.h:25
vsg::Node
Definition Node.h:24
vsg::PagedLOD
Definition PagedLOD.h:36
vsg::Transform
Transform node is a pure virtual base class for positioning/scaling/rotating subgraphs.
Definition Transform.h:22
vsg::Visitor
Definition Visitor.h:172
vsg::allocator_affinity_nodes
std container adapter for allocating with MEMORY_AFFINITY_NODES
Definition Allocator.h:138
vsg::t_plane
Definition plane.h:33
vsg::t_sphere< double >