浏览代码

- Finalizing the SceneDbgDrawer
- Fixing the cmake files
- Adding some consts to the SceneNode

Panagiotis Christopoulos Charitos 14 年之前
父节点
当前提交
7f5761be59
共有 5 个文件被更改,包括 51 次插入121 次删除
  1. 1 1
      CMakeLists.txt
  2. 6 0
      anki/collision/CollisionShape.h
  3. 13 114
      anki/renderer/SceneDbgDrawer.cpp
  4. 8 6
      anki/renderer/SceneDbgDrawer.h
  5. 23 0
      anki/scene/SceneNode.h

+ 1 - 1
CMakeLists.txt

@@ -81,7 +81,7 @@ ENDIF()
 FIND_PACKAGE(PNG 1.2 REQUIRED)
 FIND_PACKAGE(PNG 1.2 REQUIRED)
 FIND_PACKAGE(JPEG 62 REQUIRED)
 FIND_PACKAGE(JPEG 62 REQUIRED)
 
 
-FIND_PACKAGE(Boost 1.47 REQUIRED)
+FIND_PACKAGE(Boost 1.46 REQUIRED)
 SET(Boost_USE_STATIC_LIBS ON)
 SET(Boost_USE_STATIC_LIBS ON)
 IF(Boost_FOUND)
 IF(Boost_FOUND)
 	INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
 	INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})

+ 6 - 0
anki/collision/CollisionShape.h

@@ -31,6 +31,9 @@ public:
 	/// Generic mutable visitor
 	/// Generic mutable visitor
 	struct MutableVisitor
 	struct MutableVisitor
 	{
 	{
+		virtual ~MutableVisitor()
+		{}
+
 		virtual void visit(LineSegment&) = 0;
 		virtual void visit(LineSegment&) = 0;
 		virtual void visit(Obb&) = 0;
 		virtual void visit(Obb&) = 0;
 		virtual void visit(Frustum&) = 0;
 		virtual void visit(Frustum&) = 0;
@@ -43,6 +46,9 @@ public:
 	/// Generic const visitor
 	/// Generic const visitor
 	struct ConstVisitor
 	struct ConstVisitor
 	{
 	{
+		virtual ~ConstVisitor()
+		{}
+
 		virtual void visit(const LineSegment&) = 0;
 		virtual void visit(const LineSegment&) = 0;
 		virtual void visit(const Obb&) = 0;
 		virtual void visit(const Obb&) = 0;
 		virtual void visit(const Frustum&) = 0;
 		virtual void visit(const Frustum&) = 0;

+ 13 - 114
anki/renderer/SceneDbgDrawer.cpp

@@ -1,5 +1,6 @@
 #include "anki/renderer/SceneDbgDrawer.h"
 #include "anki/renderer/SceneDbgDrawer.h"
 #include "anki/renderer/Dbg.h"
 #include "anki/renderer/Dbg.h"
+#include "anki/renderer/CollisionDbgDrawer.h"
 #include "anki/scene/Octree.h"
 #include "anki/scene/Octree.h"
 #include "anki/scene/Frustumable.h"
 #include "anki/scene/Frustumable.h"
 #include "anki/scene/Spatial.h"
 #include "anki/scene/Spatial.h"
@@ -28,137 +29,35 @@ void SceneDbgDrawer::draw(const Frustumable& fr) const
 {
 {
 	const Frustum& fs = fr.getFrustum();
 	const Frustum& fs = fr.getFrustum();
 
 
-	switch(fs.getFrustumType())
-	{
-		case Frustum::FT_PERSPECTIVE:
-			draw(static_cast<const PerspectiveFrustum&>(fs), dbg);
-			break;
-
-		case Frustum::FT_ORTHOGRAPHIC:
-			draw(static_cast<const OrthographicFrustum&>(fs), dbg);
-			break;
-
-		default:
-			ANKI_ASSERT(0 && "WTF?");
-			break;
-	}
+	CollisionDbgDrawer coldraw(dbg);
+	fs.accept(coldraw);
 }
 }
 
 
 
 
 //==============================================================================
 //==============================================================================
-void SceneDbgDrawer::draw(const PerspectiveFrustum& pf, Dbg& dbg) const
+void SceneDbgDrawer::draw(const Spatial& x) const
 {
 {
-	dbg.setColor(Vec4(1.0, 0.0, 1.0, 1.0));
-
-	float camLen = pf.getFar();
-	float tmp0 = camLen / tan((Math::PI - cam.getFovX()) * 0.5) + 0.001;
-	float tmp1 = camLen * tan(cam.getFovY() * 0.5) + 0.001;
+	const CollisionShape& cs = x.getSpatialCollisionShape();
 
 
-	Vec3 points[] = {
-		Vec3(0.0, 0.0, 0.0), // 0: eye point
-		Vec3(-tmp0, tmp1, -camLen), // 1: top left
-		Vec3(-tmp0, -tmp1, -camLen), // 2: bottom left
-		Vec3(tmp0, -tmp1, -camLen), // 3: bottom right
-		Vec3(tmp0, tmp1, -camLen) // 4: top right
-	};
-
-	const uint indeces[] = {0, 1, 0, 2, 0, 3, 0, 4, 1, 2, 2, 3, 3, 4, 4, 1};
-
-	dbg.begin();
-		for(uint i = 0; i < sizeof(indeces) / sizeof(uint); i++)
-		{
-			dbg.pushBackVertex(points[indeces[i]]);
-		}
-	dbg.end();
-}
-
-
-//==============================================================================
-void SceneDbgDrawer::draw(const OrthographicFrustum& of) const
-{
-	dbg.setColor(Vec4(0.0, 1.0, 0.0, 1.0));
-
-	float left = ocam.getLeft();
-	float right = ocam.getRight();
-	float zNear = ocam.getZNear();
-	float zFar = ocam.getZFar();
-	float top = ocam.getTop();
-	float bottom = ocam.getBottom();
-
-	boost::array<Vec3, 8> positions = {{
-		Vec3(right, top, -zNear),
-		Vec3(left, top, -zNear),
-		Vec3(left, bottom, -zNear),
-		Vec3(right, bottom, -zNear),
-		Vec3(right, top, -zFar),
-		Vec3(left, top, -zFar),
-		Vec3(left, bottom, -zFar),
-		Vec3(right, bottom, -zFar)
-	}};
-
-	boost::array<uint, 24> indeces = {{
-		0, 1, 1, 2, 2, 3, 3, 0,
-		4, 5, 5, 6, 6, 7, 7, 4,
-		0, 4, 1, 5, 2, 6, 3, 7}};
-
-	dbg.begin();
-		//BOOST_FOREACH(uint i, indeces)
-		for(uint i = 0; i < 24; i++)
-		{
-			dbg.pushBackVertex(positions[indeces[i]]);
-		}
-	dbg.end();
-}
-
-
-//==============================================================================
-void SceneDbgDrawer::drawLight(const Light& light) const
-{
-	dbg.setColor(light.getDiffuseColor());
-	dbg.setModelMat(Mat4(light.getWorldTransform()));
-	dbg.drawSphere(0.1);
-}
-
-
-//==============================================================================
-void SceneDbgDrawer::drawParticleEmitter(const ParticleEmitterNode& pe) const
-{
-	dbg.setColor(Vec4(1.0));
-	dbg.setModelMat(Mat4(pe.getWorldTransform()));
-	dbg.drawCube();
-}
-
-
-//==============================================================================
-void SceneDbgDrawer::drawSkinNodeSkeleton(const SkinNode& sn) const
-{
-	dbg.setModelMat(Mat4(sn.getWorldTransform()));
-	dbg.begin();
-	for(uint i = 0; i < sn.getHeads().size(); i++)
-	{
-		dbg.setColor(Vec4(1.0, 0.0, 0.0, 1.0));
-		dbg.pushBackVertex(sn.getHeads()[i]);
-		dbg.setColor(Vec4(1.0));
-		dbg.pushBackVertex(sn.getTails()[i]);
-	}
-	dbg.end();
+	CollisionDbgDrawer coldraw(dbg);
+	cs.accept(coldraw);
 }
 }
 
 
 
 
 //==============================================================================
 //==============================================================================
-void SceneDbgDrawer::drawOctree(const Octree& octree) const
+void SceneDbgDrawer::draw(const Octree& octree) const
 {
 {
-	dbg.setColor(Vec3(1.0));
-	drawOctreeNode(octree.getRoot(), 0, octree);
+	dbg->setColor(Vec3(1.0));
+	draw(octree.getRoot(), 0, octree);
 }
 }
 
 
 
 
 //==============================================================================
 //==============================================================================
-void SceneDbgDrawer::drawOctreeNode(const OctreeNode& octnode, uint depth,
+void SceneDbgDrawer::draw(const OctreeNode& octnode, uint depth,
 	const Octree& octree) const
 	const Octree& octree) const
 {
 {
 	Vec3 color = Vec3(1.0 - float(depth) / float(octree.getMaxDepth()));
 	Vec3 color = Vec3(1.0 - float(depth) / float(octree.getMaxDepth()));
-	dbg.setColor(color);
+	dbg->setColor(color);
 
 
 	CollisionDbgDrawer v(dbg);
 	CollisionDbgDrawer v(dbg);
 	octnode.getAabb().accept(v);
 	octnode.getAabb().accept(v);
@@ -168,7 +67,7 @@ void SceneDbgDrawer::drawOctreeNode(const OctreeNode& octnode, uint depth,
 	{
 	{
 		if(octnode.getChildren()[i] != NULL)
 		if(octnode.getChildren()[i] != NULL)
 		{
 		{
-			drawOctreeNode(*octnode.getChildren()[i], depth + 1, octree);
+			draw(*octnode.getChildren()[i], depth + 1, octree);
 		}
 		}
 	}
 	}
 }
 }

+ 8 - 6
anki/renderer/SceneDbgDrawer.h

@@ -9,6 +9,8 @@ namespace anki {
 
 
 
 
 class Dbg;
 class Dbg;
+class Octree;
+class OctreeNode;
 
 
 
 
 /// This is a drawer for some scene nodes that need debug
 /// This is a drawer for some scene nodes that need debug
@@ -23,10 +25,13 @@ public:
 		DF_FRUSTUMABLE = 4
 		DF_FRUSTUMABLE = 4
 	};
 	};
 
 
-	SceneDbgDrawer(Dgb* d)
+	SceneDbgDrawer(Dbg* d)
 		: dbg(d), flags(DF_NONE)
 		: dbg(d), flags(DF_NONE)
 	{}
 	{}
 
 
+	virtual ~SceneDbgDrawer()
+	{}
+
 	/// @name Flag manipulation
 	/// @name Flag manipulation
 	/// @{
 	/// @{
 	void enableFlag(DebugFlag flag, bool enable = true)
 	void enableFlag(DebugFlag flag, bool enable = true)
@@ -49,6 +54,8 @@ public:
 
 
 	void draw(const SceneNode& node);
 	void draw(const SceneNode& node);
 
 
+	virtual void draw(const Octree& octree) const;
+
 private:
 private:
 	Dbg* dbg;
 	Dbg* dbg;
 	uint flags;
 	uint flags;
@@ -57,13 +64,8 @@ private:
 
 
 	virtual void draw(const Spatial& sp) const;
 	virtual void draw(const Spatial& sp) const;
 
 
-	virtual void draw(const Octree& octree) const;
-
 	virtual void draw(const OctreeNode& octnode,
 	virtual void draw(const OctreeNode& octnode,
 		uint depth, const Octree& octree) const;
 		uint depth, const Octree& octree) const;
-
-	virtual void draw(const PerspectiveFrustum& cam) const;
-	virtual void draw(const OrthographicFrustum& cam) const;
 };
 };
 
 
 
 

+ 23 - 0
anki/scene/SceneNode.h

@@ -68,6 +68,29 @@ public:
 	}
 	}
 	/// @}
 	/// @}
 
 
+	/// @name Accessors of components (const version)
+	/// @{
+	const Movable* getMovable() const
+	{
+		return const_cast<const Movable*>(getMovable());
+	}
+
+	const Renderable* getRenderable() const
+	{
+		return const_cast<const Renderable*>(getRenderable());
+	}
+
+	const Frustumable* getFrustumable() const
+	{
+		return const_cast<const Frustumable*>(getFrustumable());
+	}
+
+	const Spatial* getSpatial() const
+	{
+		return const_cast<const Spatial*>(getSpatial());
+	}
+	/// @}
+
 	/// This is called by the scene every frame after logic and before
 	/// This is called by the scene every frame after logic and before
 	/// rendering. By default it does nothing
 	/// rendering. By default it does nothing
 	/// @param[in] prevUpdateTime Timestamp of the previous update
 	/// @param[in] prevUpdateTime Timestamp of the previous update