Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
QuadtreeNode.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018 DIVIDE-Studio
3 Copyright (c) 2009 Ionut Cava
4
5 This file is part of DIVIDE Framework.
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software
9 and associated documentation files (the "Software"), to deal in the Software
10 without restriction,
11 including without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so,
15 subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED,
22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27 IN CONNECTION WITH THE SOFTWARE
28 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31
32#pragma once
33#ifndef DVD_QUAD_TREE_NODE
34#define DVD_QUAD_TREE_NODE
35
38
39namespace Divide {
40
41enum class ChildPosition :U32 {
42 CHILD_NW = 0,
43 CHILD_NE = 1,
44 CHILD_SW = 2,
45 CHILD_SE = 3
46};
47
48class Terrain;
49class GFXDevice;
50class SceneState;
51class IMPrimitive;
52class VertexBuffer;
53class ShaderProgram;
54class SceneGraphNode;
55class SceneRenderState;
56
57struct RenderPackage;
58
59class Quadtree;
60class QuadtreeChildren;
61
62FWD_DECLARE_MANAGED_CLASS(TerrainChunk);
63
65 public:
66 QuadtreeNode(Quadtree* parent) noexcept;
68
70 void build(U8 depth,
71 vec2<U16> pos,
72 vec2<U16> HMsize,
73 U32 targetChunkDimension,
74 Terrain* terrain,
75 U32& chunkCount);
76
77 [[nodiscard]] bool computeBoundingBox(BoundingBox& parentBB);
78
79 void drawBBox(GFXDevice& context);
81
82 [[nodiscard]] bool isALeaf() const noexcept { return _children[0] == nullptr; }
83 [[nodiscard]] U8 LoD() const noexcept { return _LoD; }
84
85 [[nodiscard]] const BoundingBox& getBoundingBox() const noexcept { return _boundingBox; }
86 void setBoundingBox(const BoundingBox& bbox) noexcept { _boundingBox = bbox; }
87 [[nodiscard]] TerrainChunk* getChunk() const noexcept { return _terrainChunk.get(); }
88
89 [[nodiscard]] QuadtreeNode& getChild(const ChildPosition pos) const noexcept { return *_children[to_base(pos)]; }
90 [[nodiscard]] QuadtreeNode& getChild(const U32 index) const noexcept { return *_children[index]; }
91
92 PROPERTY_R_IW(U32, targetChunkDimension, 0u);
93
94 private:
97 Quadtree* _parent = nullptr;
98 std::array<QuadtreeNode*, 4> _children = {};
99 TerrainChunk_uptr _terrainChunk;
100 U8 _LoD = 0u;
101 bool _drawBBoxes = false;
102};
103
105
106} // namespace Divide
107
108#endif //DVD_QUAD_TREE_NODE
#define FWD_DECLARE_MANAGED_CLASS(T)
Rough around the edges Adapter pattern abstracting the actual rendering API and access to the GPU.
Definition: GFXDevice.h:215
std::array< QuadtreeNode *, 4 > _children
Node children.
Definition: QuadtreeNode.h:98
void build(U8 depth, vec2< U16 > pos, vec2< U16 > HMsize, U32 targetChunkDimension, Terrain *terrain, U32 &chunkCount)
recursive node building function
void drawBBox(GFXDevice &context)
TerrainChunk_uptr _terrainChunk
Terrain Chunk contained in node.
Definition: QuadtreeNode.h:99
BoundingSphere _boundingSphere
Node BoundingSphere.
Definition: QuadtreeNode.h:96
U8 LoD() const noexcept
Definition: QuadtreeNode.h:83
bool computeBoundingBox(BoundingBox &parentBB)
TerrainChunk * getChunk() const noexcept
Definition: QuadtreeNode.h:87
BoundingBox _boundingBox
Node BoundingBox.
Definition: QuadtreeNode.h:95
QuadtreeNode & getChild(const U32 index) const noexcept
Definition: QuadtreeNode.h:90
QuadtreeNode & getChild(const ChildPosition pos) const noexcept
Definition: QuadtreeNode.h:89
PROPERTY_R_IW(U32, targetChunkDimension, 0u)
bool isALeaf() const noexcept
Definition: QuadtreeNode.h:82
void setBoundingBox(const BoundingBox &bbox) noexcept
Definition: QuadtreeNode.h:86
const BoundingBox & getBoundingBox() const noexcept
Definition: QuadtreeNode.h:85
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
uint8_t U8
Project & parent
Definition: DefaultScene.h:41
uint32_t U32
constexpr auto to_base(const Type value) -> Type