Panagiotis Christopoulos Charitos пре 14 година
родитељ
комит
0cb63b628a

+ 5 - 0
anki/collision/Frustum.h

@@ -304,6 +304,11 @@ public:
 		bottom = bottom_;
 		recalculate();
 	}
+
+	const Obb& getObb() const
+	{
+		return obb;
+	}
 	/// @}
 
 	/// Copy

+ 47 - 19
anki/renderer/CollisionDbgDrawer.cpp

@@ -9,8 +9,8 @@ namespace anki {
 //==============================================================================
 void CollisionDbgDrawer::visit(const Sphere& sphere)
 {
-	dbg.setModelMat(Mat4(sphere.getCenter(), Mat3::getIdentity(), 1.0));
-	dbg.drawSphere(sphere.getRadius());
+	dbg->setModelMat(Mat4(sphere.getCenter(), Mat3::getIdentity(), 1.0));
+	dbg->drawSphere(sphere.getRadius());
 }
 
 
@@ -30,17 +30,9 @@ void CollisionDbgDrawer::visit(const Obb& obb)
 	tsl = Mat4::combineTransformations(rot, scale);
 	tsl = Mat4::combineTransformations(trs, tsl);
 
-	dbg.setModelMat(tsl);
-	dbg.setColor(Vec3(1.0, 1.0, 0.0));
-	dbg.drawCube(2.0);
-
-	/*dbg.setModelMat(Mat4::getIdentity());
-	dbg.begin();
-	dbg.setColor(Vec3(1.0, 1.0, 1.0));
-	dbg.pushBackVertex(obb.getCenter());
-	dbg.setColor(Vec3(1.0, 1.0, 0.0));
-	dbg.pushBackVertex(obb.getCenter() + obb.getRotation() * obb.getExtend());
-	dbg.end();*/
+	dbg->setModelMat(tsl);
+	dbg->setColor(Vec3(1.0, 1.0, 0.0));
+	dbg->drawCube(2.0);
 }
 
 
@@ -55,8 +47,8 @@ void CollisionDbgDrawer::visit(const Plane& plane)
 	rot.rotateXAxis(Math::PI / 2);
 	Mat4 trf(n * o, rot);
 
-	dbg.setModelMat(trf);
-	dbg.renderGrid();
+	dbg->setModelMat(trf);
+	dbg->renderGrid();
 }
 
 
@@ -76,11 +68,47 @@ void CollisionDbgDrawer::visit(const Aabb& aabb)
 	// Translation
 	trf.setTranslationPart((max + min) / 2.0);
 
-	dbg.setModelMat(trf);
-	dbg.drawCube();
+	dbg->setModelMat(trf);
+	dbg->drawCube();
+}
+
 
-	/*dbg.setModelMat(Mat4::getIdentity());
-	dbg.drawLine(min, max, Vec4(1.0, 0.0, 0.0, 1.0));*/
+//==============================================================================
+void CollisionDbgDrawer::visit(const Frustum& f)
+{
+	switch(f.getFrustumType())
+	{
+		case Frustum::FT_ORTHOGRAPHIC:
+			visit(static_cast<const OrthographicFrustum&>(f).getObb());
+			break;
+		case Frustum::FT_PERSPECTIVE:
+		{
+			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;
+
+			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();
+			break;
+		}
+	}
 }
 
 

+ 20 - 26
anki/renderer/CollisionDbgDrawer.h

@@ -8,46 +8,40 @@
 namespace anki {
 
 
-class Sphere;
-class Obb;
-class Plane;
 class Dbg;
 
 
 /// Contains methods to render the collision shapes
 class CollisionDbgDrawer: public CollisionShape::ConstVisitor
 {
-	public:
-		/// Constructor
-		CollisionDbgDrawer(Dbg& dbg_)
-		:	dbg(dbg_)
-		{}
+public:
+	/// Constructor
+	CollisionDbgDrawer(Dbg* dbg_)
+		: dbg(dbg_)
+	{}
 
-		void visit(const LineSegment&)
-		{
-			ANKI_ASSERT(0 && "ToDo");
-		}
+	void visit(const LineSegment&)
+	{
+		ANKI_ASSERT(0 && "ToDo");
+	}
 
-		void visit(const Obb&);
+	void visit(const Obb&);
 
-		void visit(const PerspectiveCameraShape&)
-		{
-			ANKI_ASSERT(0 && "ToDo");
-		}
+	void visit(const Frustum&);
 
-		void visit(const Plane&);
+	void visit(const Plane&);
 
-		void visit(const Ray&)
-		{
-			ANKI_ASSERT(0 && "ToDo");
-		}
+	void visit(const Ray&)
+	{
+		ANKI_ASSERT(0 && "ToDo");
+	}
 
-		void visit(const Sphere&);
+	void visit(const Sphere&);
 
-		void visit(const Aabb&);
+	void visit(const Aabb&);
 
-	private:
-		Dbg& dbg; ///< The debug stage
+private:
+	Dbg* dbg; ///< The debug stage
 };
 
 

+ 3 - 3
anki/scene/VisibilityTester.cpp

@@ -18,10 +18,9 @@ void VisibilityTester::test(Frustumable& cam, Scene& scene,
 {
 	for(SceneNode* node : scene.getAllNodes())
 	{
-		Renderable* r = node->getRenderable();
 		Spatial* sp = node->getSpatial();
 
-		if(!sp || !r)
+		if(!sp)
 		{
 			continue;
 		}
@@ -31,12 +30,13 @@ void VisibilityTester::test(Frustumable& cam, Scene& scene,
 			continue;
 		}
 
+		Renderable* r = node->getRenderable();
 		if(r)
 		{
 			r->enableFlag(Renderable::RF_VISIBLE);
 		}
 
-		vinfo.renderables.push_back(r);
+		vinfo.nodes.push_back(node);
 	}
 }
 

+ 6 - 6
anki/scene/VisibilityTester.h

@@ -10,7 +10,7 @@ namespace anki {
 
 class Camera;
 class Scene;
-class Renderable;
+class SceneNode;
 class Frustumable;
 
 
@@ -20,16 +20,16 @@ class VisibilityInfo
 	friend class VisibilityTester;
 
 public:
-	typedef std::vector<Renderable*> Renderables;
+	typedef std::vector<SceneNode*> SceneNodes;
 
-	boost::iterator_range<Renderables::iterator> getRenderables()
+	boost::iterator_range<SceneNodes::iterator> getNodes()
 	{
-		return boost::iterator_range<Renderables::iterator>(
-			renderables.begin(), renderables.end());
+		return boost::iterator_range<SceneNodes::iterator>(
+			nodes.begin(), nodes.end());
 	}
 
 private:
-	Renderables renderables;
+	SceneNodes nodes;
 };