Browse Source

Reorganizing scene. Wont compile

Panagiotis Christopoulos Charitos 14 years ago
parent
commit
550c91a6b5

+ 0 - 37
src/scene/Camera.cpp

@@ -53,43 +53,6 @@ bool Camera::insideFrustum(const CollisionShape& bvol) const
 }
 
 
-//==============================================================================
-// insideFrustum                                                               =
-//==============================================================================
-bool Camera::insideFrustum(const Camera& cam) const
-{
-	const uint MAX_EXTREME_POINTS_NUM = 10;
-	Vec3 points[MAX_EXTREME_POINTS_NUM];
-	uint pointsNum;
-
-	cam.getExtremePoints(points, pointsNum);
-
-	ASSERT(pointsNum < MAX_EXTREME_POINTS_NUM);
-
-	// the collision code
-	for(uint i = 0; i < 6; i++) // for the 6 planes
-	{
-		uint failed = 0;
-
-		for(uint j = 0; j < pointsNum; j++) // for the n points
-		{
-			if(wspaceFrustumPlanes[i].test(points[j]) < 0.0)
-			{
-				++failed;
-			}
-		}
-		if(failed == pointsNum)
-		{
-			// if all points are behind the plane then the cam is not in
-			// frustum
-			return false;
-		}
-	}
-
-	return true;
-}
-
-
 //==============================================================================
 // updateViewMatrix                                                            =
 //==============================================================================

+ 8 - 2
src/scene/Camera.h

@@ -3,7 +3,7 @@
 
 #include "cln/Collision.h"
 #include "SceneNode.h"
-#include "VisibilityInfo.h"
+#include "VisibilityNode.h"
 #include <boost/array.hpp>
 #include <deque>
 #include <vector>
@@ -17,7 +17,7 @@ class PointLight;
 /// @{
 
 /// Camera SceneNode interface class
-class Camera: public SceneNode, public VisibilityInfo
+class Camera: public SceneNode, public VisibilityNode
 {
 	public:
 		/// @note Don't EVER change the order
@@ -125,6 +125,10 @@ class Camera: public SceneNode, public VisibilityInfo
 		/// Calculate projectionMat and invProjectionMat
 		virtual void calcProjectionMatrix() = 0;
 		virtual void calcLSpaceFrustumPlanes() = 0;
+
+		/// Calculate collision shape in local space
+		virtual void calcColShape() = 0;
+
 		void updateViewMatrix();
 		void updateWSpaceFrustumPlanes();
 
@@ -149,6 +153,7 @@ inline void Camera::setZNear(float znear_)
 	zNear = znear_;
 	calcProjectionMatrix();
 	calcLSpaceFrustumPlanes();
+	calcColShape();
 }
 
 
@@ -157,6 +162,7 @@ inline void Camera::setZFar(float zfar_)
 	zFar = zfar_;
 	calcProjectionMatrix();
 	calcLSpaceFrustumPlanes();
+	calcColShape();
 }
 
 

+ 1 - 1
src/scene/Light.h

@@ -24,7 +24,7 @@
 /// Specular intensity of light:    Sl
 /// Specular intensity of material: Sm
 /// @endcode
-class Light: public SceneNode, public VisibilityInfo
+class Light: public SceneNode, public VisibilityNode
 {
 	public:
 		enum LightType

+ 1 - 2
src/scene/PerspectiveCamera.cpp

@@ -11,8 +11,7 @@ void PerspectiveCamera::setAll(float fovx_, float fovy_, float znear_,
 	fovY = fovy_;
 	zNear = znear_;
 	zFar = zfar_;
-	calcProjectionMatrix();
-	calcLSpaceFrustumPlanes();
+	updateLocals();
 }
 
 

+ 11 - 6
src/scene/PerspectiveCamera.h

@@ -30,7 +30,7 @@ class PerspectiveCamera: public Camera
 		{
 			Camera::moveUpdate();
 			wspaceCShape =
-				lspaceCShape.getCollisionShapeType(getWorldTransform());
+				lspaceCShape.getTransformed(getWorldTransform());
 		}
 
 		/// @copydoc SceneNode::getVisibilityCollisionShapeWorldSpace
@@ -63,6 +63,13 @@ class PerspectiveCamera: public Camera
 		/// Implements Camera::calcProjectionMatrix
 		void calcProjectionMatrix();
 
+		/// Implements Camera::calcColShape
+		void calcColShape()
+		{
+			lspaceCShape.setAll(fovX, fovY, zNear, zFar,
+				Transform::getIdentity());
+		}
+
 		/// Update:
 		/// - The projection matrix
 		/// - The planes
@@ -71,8 +78,7 @@ class PerspectiveCamera: public Camera
 		{
 			calcProjectionMatrix();
 			calcLSpaceFrustumPlanes();
-			lspaceCShape.setAll(fovX, fovY, zNear, zFar,
-				Transform::getIdentity());
+			calcColShape();
 		}
 };
 
@@ -88,15 +94,14 @@ inline PerspectiveCamera::PerspectiveCamera(Scene& scene, ulong flags,
 inline void PerspectiveCamera::setFovX(float fovx_)
 {
 	fovX = fovx_;
-	update();
+	updateLocals();
 }
 
 
 inline void PerspectiveCamera::setFovY(float fovy_)
 {
 	fovY = fovy_;
-	calcProjectionMatrix();
-	calcLSpaceFrustumPlanes();
+	updateLocals();
 }
 
 

+ 1 - 1
src/scene/PointLight.h

@@ -35,7 +35,7 @@ class PointLight: public Light
 
 		void moveUpdate()
 		{
-			wspaceCShape = lspaceCShape.getTransformed();
+			wspaceCShape = lspaceCShape.getTransformed(getWorldTransform());
 		}
 
 	private:

+ 0 - 8
src/scene/VisibilityInfo.cpp

@@ -1,8 +0,0 @@
-#include "VisibilityInfo.h"
-
-
-//==============================================================================
-// Destructor                                                                  =
-//==============================================================================
-VisibilityInfo::~VisibilityInfo()
-{}

+ 20 - 22
src/scene/VisibilityInfo.h

@@ -1,7 +1,6 @@
 #ifndef VISIBILITY_INFO_H
 #define VISIBILITY_INFO_H
 
-#include <deque>
 #include <vector>
 
 
@@ -15,60 +14,59 @@ class SpotLight;
 class VisibilityInfo
 {
 	public:
-		typedef std::deque<const RenderableNode*> RContainer;
-		typedef std::vector<const PointLight*> PLContainer;
-		typedef std::vector<SpotLight*> SLContainer;
-
-		VisibilityInfo() {}
-		~VisibilityInfo();
+		template<typename T>
+		class Types
+		{
+			typedef std::vector<T*> Container;
+		};
 
 		/// @name Accessors
 		/// @{
-		const RContainer& getVisibleMsRenderableNodes() const
+		const Types<RenderableNode>::Container&
+			getVisibleMsRenderableNodes() const
 		{
 			return msRNodes;
 		}
-		RContainer& getVisibleMsRenderableNodes()
+		Types<RenderableNode>::Container& getVisibleMsRenderableNodes()
 		{
 			return msRNodes;
 		}
 
-		const RContainer& getVisibleBsRenderableNodes() const
+		const Types<RenderableNode>::Container&
+			getVisibleBsRenderableNodes() const
 		{
 			return bsRNodes;
 		}
-		RContainer& getVisibleBsRenderableNodes()
+		Types<RenderableNode>::Container& getVisibleBsRenderableNodes()
 		{
 			return bsRNodes;
 		}
 
-		const PLContainer& getVisiblePointLights() const
+		const Types<PointLight>::Container& getVisiblePointLights() const
 		{
 			return pLights;
 		}
-		PLContainer& getVisiblePointLights()
+		Types<PointLight>::Container& getVisiblePointLights()
 		{
 			return pLights;
 		}
 
-		const SLContainer& getVisibleSpotLights() const
+		const Types<SpotLight>::Container& getVisibleSpotLights() const
 		{
 			return sLights;
 		}
-		SLContainer& getVisibleSpotLights()
+		Types<SpotLight>::Container& getVisibleSpotLights()
 		{
 			return sLights;
 		}
 		/// @}
 
-	private:
-		RContainer msRNodes;
-		RContainer bsRNodes;
-		PLContainer pLights; ///< Used only for non-light cameras
-		SLContainer sLights; ///< Used only for non-light cameras
+	protected:
+		Types<RenderableNode>::Container msRNodes;
+		Types<RenderableNode>::Container bsRNodes;
+		Types<PointLight>::Container pLights;
+		Types<SpotLight>::Container sLights;
 };
 
 
 #endif
-
-

+ 16 - 0
src/scene/VisibilityNode.cpp

@@ -0,0 +1,16 @@
+#include "VisibilityNode.h"
+
+
+//==============================================================================
+VisibilityNode::~VisibilityNode()
+{}
+
+
+//==============================================================================
+void VisibilityNode::clearAll()
+{
+	msRNodes.clear();
+	bsRNodes.clear();
+	pLights.clear();
+	sLights.clear();
+}

+ 67 - 0
src/scene/VisibilityNode.h

@@ -0,0 +1,67 @@
+#ifndef VISIBILITY_NODE_H
+#define VISIBILITY_NODE_H
+
+#include "SceneNode.h"
+#include <deque>
+#include <vector>
+
+
+class VisibilityInfo;
+
+
+/// XXX
+class VisibilityNode: public SceneNode
+{
+	public:
+		enum VisibilityNodeType
+		{
+			VNT_LIGHT,
+			VNT_CAMERA
+		};
+
+		VisibilityNode(VisibilityNodeType type, Scene& scene, ulong flags,
+			SceneNode* parent)
+		:	SceneNode(SNT_VISIBILITY_NODE, scene, flags, parent),
+		 	type(type)
+		{}
+
+		virtual ~VisibilityNode();
+
+		/// @name For casting
+		/// @{
+		static bool classof(const SceneNode* x)
+		{
+			return x->getSceneNodeType() == SNT_VISIBILITY_NODE;
+		}
+		static bool classof(const VisibilityNode* x)
+		{
+			return true;
+		}
+		/// @}
+
+		/// @name Accessors
+		/// @{
+		VisibilityNodeType getVisibilityNodeType() const
+		{
+			return type;
+		}
+
+		const VisibilityInfo& getVisibilityInfo() const = 0;
+		VisibilityInfo& getVisibilityInfo() = 0;
+		/// @}
+
+		/// Clear all containers
+		void clearAll();
+
+	private:
+		VisibilityNodeType type;
+		RContainer msRNodes;
+		RContainer bsRNodes;
+		PLContainer pLights; ///< Used only for non-light cameras
+		SLContainer sLights; ///< Used only for non-light cameras
+};
+
+
+#endif
+
+

+ 44 - 23
src/scene/VisibilityTester.cpp

@@ -12,15 +12,6 @@
 #include "core/Logger.h"
 
 
-//==============================================================================
-// Destructor                                                                  =
-//==============================================================================
-VisibilityTester::~VisibilityTester()
-{}
-
-
-//==============================================================================
-// CmpDistanceFromOrigin::operator()                                           =
 //==============================================================================
 bool VisibilityTester::CmpDistanceFromOrigin::operator()(const SceneNode* a,
 	const SceneNode* b) const
@@ -31,26 +22,20 @@ bool VisibilityTester::CmpDistanceFromOrigin::operator()(const SceneNode* a,
 
 
 //==============================================================================
-// Constructor                                                                 =
-//==============================================================================
-VisibilityTester::VisibilityTester(Scene& scene_):
-	scene(scene_)
-{}
-
-
-//==============================================================================
-// test                                                                        =
-//==============================================================================
-void VisibilityTester::test(Camera& cam)
+void VisibilityTester::test(Camera& cam, Scene& scene_)
 {
+	scene = &scene_;
+
 	//
-	// Set all nodes to not visible
+	// Set all nodes set to not visible
 	//
 	BOOST_FOREACH(SceneNode* node, scene.getAllNodes())
 	{
 		node->disableFlag(SceneNode::SNF_VISIBLE);
 	}
 
+
+
 	//
 	// Collect the lights for the main cam
 	//
@@ -125,7 +110,7 @@ bool VisibilityTester::test(const Type& tested, const Camera& cam)
 // getRenderableNodes                                                          =
 //==============================================================================
 void VisibilityTester::getRenderableNodes(bool skipShadowless,
-	const Camera& cam, VisibilityInfo& storage)
+	const Camera& cam, VisibilityNode& storage)
 {
 	storage.getVisibleMsRenderableNodes().clear();
 	storage.getVisibleBsRenderableNodes().clear();
@@ -173,7 +158,7 @@ void VisibilityTester::getRenderableNodesJobCallback(
 
 	const Camera& cam = *jobParameters.cam;
 	bool skipShadowless = jobParameters.skipShadowless;
-	VisibilityInfo& visibilityInfo = *jobParameters.visibilityInfo;
+	VisibilityNode& visibilityInfo = *jobParameters.visibilityInfo;
 	Scene& scene = *jobParameters.scene;
 	boost::mutex& msRenderableNodesMtx = *jobParameters.msRenderableNodesMtx;
 	boost::mutex& bsRenderableNodesMtx = *jobParameters.bsRenderableNodesMtx;
@@ -332,3 +317,39 @@ void VisibilityTester::getRenderableNodesJobCallback(
 		}
 	}
 }
+
+
+//==============================================================================
+void getOverlappingNodes(SceneNode& node)
+{
+	/*node.getVisibleMsRenderableNodes().clear();
+	node.getVisibleBsRenderableNodes().clear();
+	node.getVi*/
+
+	// Run in parallel
+	VisJobParameters jobParameters;
+	jobParameters.cam = &cam;
+	jobParameters.skipShadowless = skipShadowless;
+	jobParameters.visibilityInfo = &storage;
+	jobParameters.scene = &scene;
+	jobParameters.msRenderableNodesMtx = &msRenderableNodesMtx;
+	jobParameters.bsRenderableNodesMtx = &bsRenderableNodesMtx;
+
+	for(uint i = 0;
+		i < parallel::ManagerSingleton::get().getThreadsNum(); i++)
+	{
+		parallel::ManagerSingleton::get().assignNewJob(i,
+			getRenderableNodesJobCallback, jobParameters);
+	}
+	parallel::ManagerSingleton::get().waitForAllJobsToFinish();
+
+	//
+	// Sort the renderables from closest to the camera to the farthest
+	//
+	std::sort(storage.getVisibleMsRenderableNodes().begin(),
+		storage.getVisibleMsRenderableNodes().end(),
+		CmpDistanceFromOrigin(cam.getWorldTransform().getOrigin()));
+	std::sort(storage.getVisibleBsRenderableNodes().begin(),
+		storage.getVisibleBsRenderableNodes().end(),
+		CmpDistanceFromOrigin(cam.getWorldTransform().getOrigin()));
+}

+ 9 - 11
src/scene/VisibilityTester.h

@@ -13,7 +13,7 @@ class RenderableNode;
 class SpotLight;
 class PointLight;
 class SceneNode;
-class VisibilityInfo;
+class VisibilityNode;
 
 
 /// Performs visibility determination tests and fills a few containers with the
@@ -21,23 +21,21 @@ class VisibilityInfo;
 class VisibilityTester
 {
 	public:
-		/// Constructor
-		VisibilityTester(Scene& scene);
-		~VisibilityTester();
-
 		/// This method:
 		/// - Gets the visible renderable nodes
 		/// - Sort them from the closest to the farthest
 		/// - Get the visible lights
 		/// - For every spot light that casts shadow get the visible renderables
-		void test(Camera& cam);
+		void test(Camera& cam, Scene& scene);
 
 	private:
 		/// Used in sorting. Compare the length of 2 nodes from the camera
 		struct CmpDistanceFromOrigin
 		{
 			Vec3 o; ///< The camera origin
-			CmpDistanceFromOrigin(const Vec3& o_): o(o_) {}
+			CmpDistanceFromOrigin(const Vec3& o_)
+			:	o(o_)
+			{}
 			bool operator()(const SceneNode* a, const SceneNode* b) const;
 		};
 
@@ -46,13 +44,13 @@ class VisibilityTester
 		{
 			const Camera* cam;
 			bool skipShadowless;
-			VisibilityInfo* visibilityInfo;
+			VisibilityNode* visibilityInfo;
 			Scene* scene;
 			boost::mutex* msRenderableNodesMtx;
 			boost::mutex* bsRenderableNodesMtx;
 		};
 
-		Scene& scene; ///< Know your father
+		Scene* scene; ///< Know the scene
 
 		/// @name Needed by getRenderableNodesJobCallback
 		/// The vars of this group are needed by the static
@@ -70,10 +68,10 @@ class VisibilityTester
 		/// @param[in] skipShadowless Skip shadowless nodes. If the cam is a
 		/// light cam
 		/// @param[in] cam The camera to test and gather renderable nodes
-		/// @param[out] storage The VisibilityInfo of where we will store the
+		/// @param[out] storage The VisibilityNode of where we will store the
 		/// visible nodes
 		void getRenderableNodes(bool skipShadowless, const Camera& cam,
-			VisibilityInfo& storage);
+			VisibilityNode& storage);
 
 		/// This static method will be fed into the parallel::Manager
 		/// @param data This is actually a pointer to VisibilityTester