Panagiotis Christopoulos Charitos 13 anos atrás
pai
commit
ede439c478

+ 3 - 3
include/anki/renderer/Drawer.h

@@ -168,7 +168,7 @@ public:
 
 	void draw(SceneNode& node);
 
-	virtual void draw(Octree& octree) const;
+	virtual void draw(const Octree& octree) const;
 
 	void setViewProjectionMatrix(const Mat4& m)
 	{
@@ -182,8 +182,8 @@ private:
 
 	virtual void draw(Spatial& sp) const;
 
-	virtual void draw(OctreeNode& octnode,
-		uint depth, Octree& octree) const;
+	virtual void draw(const OctreeNode& octnode,
+		uint32_t depth, const Octree& octree) const;
 };
 
 class PassLevelKey;

+ 2 - 2
include/anki/scene/Frustumable.h

@@ -68,10 +68,10 @@ public:
 	/// Called when a frustum parameter changes
 	virtual void frustumUpdate()
 	{
-		spatialMarkUpdated();
+		frustumableMarkUpdated();
 	}
 
-	void spatialMarkUpdated()
+	void frustumableMarkUpdated()
 	{
 		lastUpdateFrame = SceneSingleton::get().getFramesCount();
 	}

+ 2 - 7
include/anki/scene/Octree.h

@@ -5,10 +5,8 @@
 #include <boost/array.hpp>
 #include <boost/ptr_container/ptr_vector.hpp>
 
-
 namespace anki {
 
-
 /// XXX
 class OctreeNode
 {
@@ -62,7 +60,6 @@ private:
 	}
 };
 
-
 /// XXX
 class Octree
 {
@@ -89,7 +86,7 @@ public:
 	OctreeNode* place(const Aabb& aabb);
 
 private:
-	OctreeNode* root;
+	OctreeNode* root = nullptr;
 	boost::ptr_vector<OctreeNode> nodes; ///< For garbage collection
 	uint maxDepth;
 	float looseness;
@@ -111,8 +108,6 @@ private:
 		Aabb& out) const;
 };
 
-
-} // end namespace
-
+} // end namespace anki
 
 #endif

+ 3 - 0
include/anki/scene/Scene.h

@@ -5,6 +5,7 @@
 #include "anki/scene/VisibilityTester.h"
 #include "anki/math/Math.h"
 #include "anki/util/Singleton.h"
+#include "anki/scene/Sector.h"
 #include <vector>
 
 namespace anki {
@@ -107,6 +108,8 @@ public:
 		return (it == nameToNode.end()) ? nullptr : it->second;
 	}
 
+	std::vector<Sector> sectors;
+
 private:
 	Types<SceneNode>::Container nodes;
 	Types<SceneNode>::NameToItemMap nameToNode;

+ 26 - 0
include/anki/scene/Sector.h

@@ -0,0 +1,26 @@
+#ifndef ANKI_SCENE_SECTOR_H
+#define ANKI_SCENE_SECTOR_H
+
+#include "anki/scene/Octree.h"
+
+namespace anki {
+
+class Sector
+{
+public:
+	Sector(const Aabb& box)
+		: octree(box, 3)
+	{}
+
+	const Octree& getOctree() const
+	{
+		return octree;
+	}
+
+private:
+	Octree octree;
+};
+
+} // end namespace anki
+
+#endif

+ 6 - 1
src/renderer/Dbg.cpp

@@ -65,6 +65,11 @@ void Dbg::run()
 
 		sceneDrawer->draw(*node);
 	}
+
+	for(const Sector& sector : scene.sectors)
+	{
+		sceneDrawer->draw(sector.getOctree());
+	}
 }
 
-} // end namespace
+} // end namespace anki

+ 4 - 4
src/renderer/Drawer.cpp

@@ -468,15 +468,15 @@ void SceneDebugDrawer::draw(Spatial& x) const
 }
 
 //==============================================================================
-void SceneDebugDrawer::draw(Octree& octree) const
+void SceneDebugDrawer::draw(const Octree& octree) const
 {
 	dbg->setColor(Vec3(1.0));
 	draw(octree.getRoot(), 0, octree);
 }
 
 //==============================================================================
-void SceneDebugDrawer::draw(OctreeNode& octnode, uint depth,
-	Octree& octree) const
+void SceneDebugDrawer::draw(const OctreeNode& octnode, uint32_t depth,
+	const Octree& octree) const
 {
 	Vec3 color = Vec3(1.0 - float(depth) / float(octree.getMaxDepth()));
 	dbg->setColor(color);
@@ -485,7 +485,7 @@ void SceneDebugDrawer::draw(OctreeNode& octnode, uint depth,
 	octnode.getAabb().accept(v);
 
 	// Children
-	for(uint i = 0; i < 8; ++i)
+	for(uint32_t i = 0; i < 8; ++i)
 	{
 		if(octnode.getChildren()[i] != NULL)
 		{

+ 8 - 16
src/scene/Octree.cpp

@@ -3,10 +3,8 @@
 #include "anki/core/Logger.h"
 #include "anki/collision/CollisionAlgorithmsMatrix.h"
 
-
 namespace anki {
 
-
 //==============================================================================
 Octree::Octree(const Aabb& aabb, uint8_t maxDepth_, float looseness_)
 :	maxDepth(maxDepth_ < 1 ? 1 : maxDepth_),
@@ -17,7 +15,6 @@ Octree::Octree(const Aabb& aabb, uint8_t maxDepth_, float looseness_)
 	nodes.push_back(root);
 }
 
-
 //==============================================================================
 OctreeNode* Octree::place(const Aabb& aabb)
 {
@@ -32,23 +29,21 @@ OctreeNode* Octree::place(const Aabb& aabb)
 	}
 }
 
-
 //==============================================================================
-OctreeNode* Octree::place(const Aabb& aabb, uint depth, OctreeNode& node)
+OctreeNode* Octree::place(const Aabb& aabb, uint32_t depth, OctreeNode& node)
 {
 	if(depth >= maxDepth)
 	{
 		return &node;
 	}
 
-
-	for(uint i = 0; i < 2; ++i)
+	for(uint32_t i = 0; i < 2; ++i)
 	{
-		for(uint j = 0; j < 2; ++j)
+		for(uint32_t j = 0; j < 2; ++j)
 		{
-			for(uint k = 0; k < 2; ++k)
+			for(uint32_t k = 0; k < 2; ++k)
 			{
-				uint id = i * 4 + j * 2 + k;
+				uint32_t id = i * 4 + j * 2 + k;
 
 				Aabb childAabb;
 				if(node.getChildren()[id] != NULL)
@@ -60,7 +55,6 @@ OctreeNode* Octree::place(const Aabb& aabb, uint depth, OctreeNode& node)
 					calcAabb(i, j, k, node.getAabb(), childAabb);
 				}
 
-
 				// If aabb its completely inside the target
 				if(aabb.getMax() <= childAabb.getMax() &&
 					aabb.getMin() >= childAabb.getMin())
@@ -82,9 +76,8 @@ OctreeNode* Octree::place(const Aabb& aabb, uint depth, OctreeNode& node)
 	return &node;
 }
 
-
 //==============================================================================
-void Octree::calcAabb(uint i, uint j, uint k, const Aabb& paabb,
+void Octree::calcAabb(uint32_t i, uint32_t j, uint32_t k, const Aabb& paabb,
 	Aabb& out) const
 {
 	const Vec3& min = paabb.getMin();
@@ -105,7 +98,7 @@ void Octree::calcAabb(uint i, uint j, uint k, const Aabb& paabb,
 	Vec3 nomax = tmp0 * omax + tmp1 * omin;
 
 	// Crop to fit the parent's AABB
-	for(uint n = 0; n < 3; ++n)
+	for(uint32_t n = 0; n < 3; ++n)
 	{
 		if(nomin[n] < min[n])
 		{
@@ -121,5 +114,4 @@ void Octree::calcAabb(uint i, uint j, uint k, const Aabb& paabb,
 	out = Aabb(nomin, nomax);
 }
 
-
-} // end namespace
+} // end namespace anki

+ 3 - 0
testapp/Main.cpp

@@ -98,6 +98,9 @@ void init()
 		Movable::MF_NONE, nullptr);
 	horse->setLocalTransform(Transform(Vec3(-2, 0, 0), Mat3::getIdentity(),
 		1.0));
+
+	// Sectors
+	scene.sectors.push_back(Sector(Aabb(Vec3(-10.0), Vec3(10.0))));
 }
 
 //==============================================================================