Panagiotis Christopoulos Charitos il y a 14 ans
Parent
commit
1840fd4307

+ 4 - 2
anki/renderer/CollisionDbgDrawer.cpp

@@ -84,10 +84,12 @@ void CollisionDbgDrawer::visit(const Frustum& f)
 		case Frustum::FT_PERSPECTIVE:
 		{
 			dbg->setColor(Vec4(1.0, 0.0, 1.0, 1.0));
+			const PerspectiveFrustum& pf = 
+				static_cast<const PerspectiveFrustum&>(f);
 
 			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;
+			float tmp0 = camLen / tan((Math::PI - pf.getFovX()) * 0.5) + 0.001;
+			float tmp1 = camLen * tan(pf.getFovY() * 0.5) + 0.001;
 
 			Vec3 points[] = {
 				Vec3(0.0, 0.0, 0.0), // 0: eye point

+ 1 - 0
anki/renderer/CollisionDbgDrawer.h

@@ -22,6 +22,7 @@ public:
 
 	void visit(const LineSegment&)
 	{
+		/// XXX
 		ANKI_ASSERT(0 && "ToDo");
 	}
 

+ 2 - 6
anki/renderer/Dbg.cpp

@@ -22,14 +22,10 @@ extern anki::ModelNode* horse;
 namespace anki {
 
 
-//==============================================================================
-// Constructor                                                                 =
 //==============================================================================
 Dbg::Dbg(Renderer& r_)
-	: SwitchableRenderingPass(r_), showAxisEnabled(false),
-		showLightsEnabled(true), showSkeletonsEnabled(true),
-		showCamerasEnabled(true), showVisibilityBoundingShapesFlag(true),
-		sceneDbgDrawer(*this),collisionDbgDrawer(*this)
+	: SwitchableRenderingPass(r_), flags(),
+		sceneDbgDrawer(*this), collisionDbgDrawer(*this)
 {}
 
 

+ 66 - 59
anki/renderer/Dbg.h

@@ -20,70 +20,77 @@ namespace anki {
 /// Debugging stage
 class Dbg: public SwitchableRenderingPass
 {
-	public:
-		Dbg(Renderer& r_);
-		void init(const RendererInitializer& initializer);
-		void run();
+public:
+	enum DebugFlag
+	{
+		DF_NONE = 0,
+		DF_SPATIAL = 1,
+		DF_MOVABLE = 2,
+		DF_FRUSTUMABLE = 4
+	};
 
-		void renderGrid();
-		void drawSphere(float radius, int complexity = 4);
-		void drawCube(float size = 1.0);
-		void drawLine(const Vec3& from, const Vec3& to, const Vec4& color);
+	Dbg(Renderer& r_);
 
-		/// @name Accessors
-		/// @{
-		bool getShowSkeletonsEnabled() const
-		{
-			return showSkeletonsEnabled;
-		}
-		bool& getShowSkeletonsEnabled()
-		{
-			return showSkeletonsEnabled;
-		}
-		void setShowSkeletonsEnabled(const bool x)
-		{
-			showSkeletonsEnabled = x;
-		}
-		/// @todo add others
-		/// @}
+	/// @name Flag manipulation
+	/// @{
+	void enableFlag(DebugFlag flag, bool enable = true)
+	{
+		flags = enable ? flags | flag : flags & ~flag;
+	}
+	void disableFlag(DebugFlag flag)
+	{
+		enableFlag(flag, false);
+	}
+	bool isFlagEnabled(DebugFlag flag) const
+	{
+		return flags & flag;
+	}
+	uint getFlagsBitmask() const
+	{
+		return flags;
+	}
+	/// @}
+	
+	void init(const RendererInitializer& initializer);
+	void run();
+	
+	void renderGrid();
+	void drawSphere(float radius, int complexity = 4);
+	void drawCube(float size = 1.0);
+	void drawLine(const Vec3& from, const Vec3& to, const Vec4& color);
 
-		/// @name Render functions. Imitate the GL 1.1 immediate mode
-		/// @{
-		void begin(); ///< Initiates the draw
-		void end(); ///< Draws
-		void pushBackVertex(const Vec3& pos); ///< Something like glVertex
-		/// Something like glColor
-		void setColor(const Vec3& col) {crntCol = col;}
-		/// Something like glColor
-		void setColor(const Vec4& col) {crntCol = Vec3(col);}
-		void setModelMat(const Mat4& modelMat);
-		/// @}
+	/// @name Render functions. Imitate the GL 1.1 immediate mode
+	/// @{
+	void begin(); ///< Initiates the draw
+	void end(); ///< Draws
+	void pushBackVertex(const Vec3& pos); ///< Something like glVertex
+	/// Something like glColor
+	void setColor(const Vec3& col) {crntCol = col;}
+	/// Something like glColor
+	void setColor(const Vec4& col) {crntCol = Vec3(col);}
+	void setModelMat(const Mat4& modelMat);
+	/// @}
 
-	private:
-		bool showAxisEnabled;
-		bool showLightsEnabled;
-		bool showSkeletonsEnabled;
-		bool showCamerasEnabled;
-		bool showVisibilityBoundingShapesFlag;
-		Fbo fbo;
-		ShaderProgramResourcePointer sProg;
-		static const uint MAX_POINTS_PER_DRAW = 256;
-		boost::array<Vec3, MAX_POINTS_PER_DRAW> positions;
-		boost::array<Vec3, MAX_POINTS_PER_DRAW> colors;
-		Mat4 modelMat;
-		uint pointIndex;
-		Vec3 crntCol;
-		Vbo positionsVbo;
-		Vbo colorsVbo;
-		Vao vao;
-		SceneDbgDrawer sceneDbgDrawer;
-		CollisionDbgDrawer collisionDbgDrawer;
+private:
+	uint flags;
+	Fbo fbo;
+	ShaderProgramResourcePointer sProg;
+	static const uint MAX_POINTS_PER_DRAW = 256;
+	boost::array<Vec3, MAX_POINTS_PER_DRAW> positions;
+	boost::array<Vec3, MAX_POINTS_PER_DRAW> colors;
+	Mat4 modelMat;
+	uint pointIndex;
+	Vec3 crntCol;
+	Vbo positionsVbo;
+	Vbo colorsVbo;
+	Vao vao;
+	SceneDbgDrawer sceneDbgDrawer;
+	CollisionDbgDrawer collisionDbgDrawer;
 
-
-		/// This is a container of some precalculated spheres. Its a map that
-		/// from sphere complexity it returns a vector of lines (Vec3s in
-		/// pairs)
-		std::map<uint, std::vector<Vec3> > complexityToPreCalculatedSphere;
+	/// This is a container of some precalculated spheres. Its a map that
+	/// from sphere complexity it returns a vector of lines (Vec3s in
+	/// pairs)
+	std::map<uint, std::vector<Vec3> > complexityToPreCalculatedSphere;
 };
 
 

+ 16 - 1
anki/renderer/SceneDbgDrawer.cpp

@@ -9,7 +9,22 @@ namespace anki {
 
 
 //==============================================================================
-void SceneDbgDrawer::draw(const Frustumable& fr, Dbg& dbg) const
+void SceneDbgDrawer::draw(const SceneNode& node)
+{
+	if(isFlagEnabled(DF_FRUSTUMABLE) && node.getFrustumable())
+	{
+		draw(*node.getFrustumable());
+	}
+
+	if(isFlagEnabled(DF_SPATIAL) && node.getSpatial())
+	{
+		draw(*node.getSpatial());
+	}
+}
+
+
+//==============================================================================
+void SceneDbgDrawer::draw(const Frustumable& fr) const
 {
 	const Frustum& fs = fr.getFrustum();
 

+ 45 - 12
anki/renderer/SceneDbgDrawer.h

@@ -2,16 +2,12 @@
 #define ANKI_RENDERER_SCENE_DBG_DRAWER_H
 
 #include "anki/util/StdTypes.h"
+#include "anki/scene/SceneNode.h"
 
 
 namespace anki {
 
 
-class Frustumable;
-class Spatial;
-class Octree;
-class OctreeNode;
-
 class Dbg;
 
 
@@ -19,18 +15,55 @@ class Dbg;
 class SceneDbgDrawer
 {
 public:
-	virtual void draw(const Frustumable& fr, Dbg& dbg) const;
+	enum DebugFlag
+	{
+		DF_NONE = 0,
+		DF_SPATIAL = 1,
+		DF_MOVABLE = 2,
+		DF_FRUSTUMABLE = 4
+	};
+
+	SceneDbgDrawer(Dgb* d)
+		: dbg(d), flags(DF_NONE)
+	{}
+
+	/// @name Flag manipulation
+	/// @{
+	void enableFlag(DebugFlag flag, bool enable = true)
+	{
+		flags = enable ? flags | flag : flags & ~flag;
+	}
+	void disableFlag(DebugFlag flag)
+	{
+		enableFlag(flag, false);
+	}
+	bool isFlagEnabled(DebugFlag flag) const
+	{
+		return flags & flag;
+	}
+	uint getFlagsBitmask() const
+	{
+		return flags;
+	}
+	/// @}
+
+	void draw(const SceneNode& node);
+
+private:
+	Dbg* dbg;
+	uint flags;
 
-	virtual void draw(const Spatial& sp, Dbg& dbg) const;
+	virtual void draw(const Frustumable& fr) const;
 
-	virtual void draw(const Octree& octree, Dbg& dbg) const;
+	virtual void draw(const Spatial& sp) const;
+
+	virtual void draw(const Octree& octree) const;
 
 	virtual void draw(const OctreeNode& octnode,
-		uint depth, const Octree& octree, Dbg& dbg) const;
+		uint depth, const Octree& octree) const;
 
-private:
-	virtual void draw(const PerspectiveFrustum& cam, Dbg& dbg) const;
-	virtual void draw(const OrthographicFrustum& cam, Dbg& dbg) const;
+	virtual void draw(const PerspectiveFrustum& cam) const;
+	virtual void draw(const OrthographicFrustum& cam) const;
 };
 
 

+ 2 - 1
anki/scene/Renderable.h

@@ -18,7 +18,6 @@ class Light;
 /// @addtogroup Scene
 /// @{
 
-
 /// XXX
 template<typename T>
 class MaterialVariableProperty: public ReadCowPointerProperty<T>
@@ -119,6 +118,8 @@ private:
 	Properties props;
 	uint flags; ///< Bitmask
 };
+
+
 /// @}
 
 

+ 4 - 4
anki/scene/SceneNode.h

@@ -49,22 +49,22 @@ public:
 	/// @{
 	virtual Movable* getMovable()
 	{
-		return NULL;
+		return nullptr;
 	}
 
 	virtual Renderable* getRenderable()
 	{
-		return NULL;
+		return nullptr;
 	}
 
 	virtual Frustumable* getFrustumable()
 	{
-		return NULL;
+		return nullptr;
 	}
 
 	virtual Spatial* getSpatial()
 	{
-		return NULL;
+		return nullptr;
 	}
 	/// @}