From 0c0089f736edd925c8e58c065092683d88c78304 Mon Sep 17 00:00:00 2001 From: samcake Date: Mon, 15 Feb 2016 11:08:12 -0800 Subject: [PATCH] REnamed Octree.h/cpp to SpatialTree and fixing some coding guidelines --- interface/src/Application.h | 2 +- libraries/render/src/render/Scene.cpp | 4 +- libraries/render/src/render/Scene.h | 4 +- .../render/{Octree.cpp => SpatialTree.cpp} | 4 +- .../src/render/{Octree.h => SpatialTree.h} | 43 +++++++++++-------- 5 files changed, 34 insertions(+), 23 deletions(-) rename libraries/render/src/render/{Octree.cpp => SpatialTree.cpp} (99%) rename libraries/render/src/render/{Octree.h => SpatialTree.h} (93%) diff --git a/interface/src/Application.h b/interface/src/Application.h index 3880263aee..d5b677302a 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -479,7 +479,7 @@ private: quint64 _lastFaceTrackerUpdate; - render::ScenePointer _main3DScene{ new render::Scene() }; + render::ScenePointer _main3DScene{ new render::Scene(glm::vec3(-0.5f * (float)TREE_SCALE), (float)TREE_SCALE) }; render::EnginePointer _renderEngine{ new render::Engine() }; gpu::ContextPointer _gpuContext; // initialized during window creation diff --git a/libraries/render/src/render/Scene.cpp b/libraries/render/src/render/Scene.cpp index 43187feb66..c9e83f07aa 100644 --- a/libraries/render/src/render/Scene.cpp +++ b/libraries/render/src/render/Scene.cpp @@ -79,7 +79,9 @@ void PendingChanges::merge(PendingChanges& changes) { _updateFunctors.insert(_updateFunctors.end(), changes._updateFunctors.begin(), changes._updateFunctors.end()); } -Scene::Scene() { +Scene::Scene(glm::vec3 origin, float size) : + _masterSpatialTree(origin, size) +{ _items.push_back(Item()); // add the itemID #0 to nothing _masterBucketMap.allocateStandardOpaqueTranparentBuckets(); } diff --git a/libraries/render/src/render/Scene.h b/libraries/render/src/render/Scene.h index d3d5a6865c..7972507979 100644 --- a/libraries/render/src/render/Scene.h +++ b/libraries/render/src/render/Scene.h @@ -13,7 +13,7 @@ #define hifi_render_Scene_h #include "Item.h" -#include "Octree.h" +#include "SpatialTree.h" namespace render { @@ -68,7 +68,7 @@ typedef std::queue PendingChangesQueue; // Items are notified accordingly on any update message happening class Scene { public: - Scene(); + Scene(glm::vec3 origin, float size); ~Scene() {} /// This call is thread safe, can be called from anywhere to allocate a new ID diff --git a/libraries/render/src/render/Octree.cpp b/libraries/render/src/render/SpatialTree.cpp similarity index 99% rename from libraries/render/src/render/Octree.cpp rename to libraries/render/src/render/SpatialTree.cpp index 9e655b6719..b09b6f4778 100644 --- a/libraries/render/src/render/Octree.cpp +++ b/libraries/render/src/render/SpatialTree.cpp @@ -1,5 +1,5 @@ // -// Octree.h +// SpatialTree.h // render/src/render // // Created by Sam Gateau on 1/25/16. @@ -8,7 +8,7 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "Octree.h" +#include "SpatialTree.h" #include diff --git a/libraries/render/src/render/Octree.h b/libraries/render/src/render/SpatialTree.h similarity index 93% rename from libraries/render/src/render/Octree.h rename to libraries/render/src/render/SpatialTree.h index f283f5b3e2..a5dbb29544 100644 --- a/libraries/render/src/render/Octree.h +++ b/libraries/render/src/render/SpatialTree.h @@ -1,5 +1,5 @@ // -// Octree.h +// SpatialTree.h // render/src/render // // Created by Sam Gateau on 1/25/16. @@ -89,9 +89,9 @@ namespace render { // Max depth is 15 => 32Km root down to 1m cells using Depth = int8_t; - static const Depth ROOT_DEPTH{ 0 }; - static const Depth MAX_DEPTH{ 15 }; - static const Depth METRIC_COORD_DEPTH{ 15 }; + static const Depth ROOT_DEPTH { 0 }; + static const Depth MAX_DEPTH { 15 }; + static const Depth METRIC_COORD_DEPTH { 15 }; static const float INV_DEPTH_DIM[Octree::MAX_DEPTH + 1]; static int getDepthDimension(Depth depth) { return 1 << depth; } @@ -109,12 +109,12 @@ namespace render { static Coord depthBitmask(Depth depth) { return Coord(1 << (MAX_DEPTH - depth)); } static Depth coordToDepth(Coord length) { - Depth d = MAX_DEPTH; + Depth depth = MAX_DEPTH; while (length) { length >>= 1; - d--; + depth--; } - return d; + return depth; } @@ -130,16 +130,16 @@ namespace render { Location(const Coord3& xyz, Depth d) : pos(xyz), depth(d) { assertValid(); } Location(Depth d) : pos(0), depth(d) { assertValid(); } - Coord3 pos{ 0 }; - uint8_t spare{ 0 }; - Depth depth{ ROOT_DEPTH }; + Coord3 pos { 0 }; + uint8_t spare { 0 }; + Depth depth { ROOT_DEPTH }; Coord3f getCenter() const { Coord3f center = (Coord3f(pos) + Coord3f(0.5f)) * Coord3f(Octree::getInvDepthDimension(depth)); return center; } - bool operator== (const Location& right) const { return pos == right.pos && depth == right.depth; } + bool operator== (const Location& other) const { return pos == other.pos && depth == other.depth; } // Eval the octant of this cell relative to its parent Octant octant() const { return Octant((pos.x & 1) | ((pos.y & 1) << 1) | ((pos.z & 1) << 2)); } @@ -316,9 +316,11 @@ namespace render { float angle; float squareTanAlpha; + const float MAX_LOD_ANGLE = glm::radians(45.0f); + const float MIN_LOD_ANGLE = glm::radians(1.0f / 60.0f); + void setAngle(float a) { - angle = std::min(glm::radians(45.0f), a); // no worse than 45 degrees - angle = std::max(glm::radians(1.0f/60.0f), a); // no better than 1 minute of degree + angle = std::max(MIN_LOD_ANGLE, std::min(MAX_LOD_ANGLE, a)); auto tanAlpha = tan(angle); squareTanAlpha = (float)(tanAlpha * tanAlpha); } @@ -365,11 +367,18 @@ namespace render { // An octree of Items organizing them efficiently for culling // The octree only cares about the bound & the key of an item to store it a the right cell location class ItemSpatialTree : public Octree { - float _size{ 32768.0f }; - float _invSize{ 1.0f / _size }; - glm::vec3 _origin{ -16384.0f }; + float _size { 32768.0f }; + float _invSize { 1.0f / _size }; + glm::vec3 _origin { -16384.0f }; + + void init(glm::vec3 origin, float size) { + _size = size; + _invSize = 1.0f / _size; + _origin = origin; + } public: - ItemSpatialTree() {} + // THe overall size and origin of the tree are defined at creation + ItemSpatialTree(glm::vec3 origin, float size) { init(origin, size); } float getSize() const { return _size; } const glm::vec3& getOrigin() const { return _origin; }