Explorar el Código

- Renaming
- Scene changes

Panagiotis Christopoulos Charitos hace 15 años
padre
commit
f3d6c66529

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 0 - 1
build/debug/Makefile


+ 2 - 2
src/Core/Object.cpp

@@ -27,7 +27,7 @@ Object::~Object()
 	}
 
 	// delete all children
-	for(Vec<Object*>::reverse_iterator it=objChilds.rbegin(); it!=objChilds.rend(); it++)
+	for(Container::reverse_iterator it=objChilds.rbegin(); it!=objChilds.rend(); it++)
 	{
 		delete *it;
 	}
@@ -54,7 +54,7 @@ void Object::removeChild(Object* child)
 {
 	RASSERT_THROW_EXCEPTION(child == NULL);
 
-	Vec<Object*>::iterator it = std::find(objChilds.begin(), objChilds.end(), child);
+	Container::iterator it = std::find(objChilds.begin(), objChilds.end(), child);
 
 	if(it == objChilds.end())
 	{

+ 12 - 1
src/Core/Object.h

@@ -9,6 +9,8 @@
 class Object
 {
 	public:
+		typedef Vec<Object*> Container;
+
 		/// Calls addChild if parent is not NULL
 		/// @exception Exception
 		Object(Object* parent);
@@ -16,9 +18,18 @@ class Object
 		/// Delete childs from the last entered to the first and update parent
 		virtual ~Object();
 
+	protected:
+		/// @name Accessors
+		/// @{
+		const Object* getObjParent() const {return objParent;}
+		Object* getObjParent() {return objParent;}
+		const Container& getObjChildren() const {return objChilds;}
+		Container& getObjChildren() {return objChilds;}
+		/// @}
+
 	private:
 		Object* objParent;
-		Vec<Object*> objChilds;
+		Container objChilds;
 
 		void addChild(Object* child);
 		void removeChild(Object* child);

+ 1 - 1
src/Renderer/Bs.h

@@ -20,7 +20,7 @@ class Bs: public RenderingPass
 		void run();
 
 	private:
-		Fbo fbo; ///< Writes to pps.prePassFai
+		Fbo fbo; ///< Writes to Pps::prePassFai
 		Fbo refractFbo; ///< Writes to refractFai
 		RsrcPtr<ShaderProg> refractSProg;
 		Texture refractFai;

+ 1 - 1
src/Renderer/Dbg.cpp

@@ -274,7 +274,7 @@ void Dbg::run()
 	{
 		const SceneNode& node = *(*it);
 
-		switch(node.type)
+		switch(node.getSceneNodeType())
 		{
 			case SceneNode::SNT_CAMERA:
 				sceneDbgDrawer.drawCamera(static_cast<const Camera&>(node));

+ 6 - 3
src/Renderer/Is.h

@@ -7,7 +7,6 @@
 #include "RsrcPtr.h"
 #include "ShaderProg.h"
 #include "Math.h"
-#include "Properties.h"
 #include "Vbo.h"
 #include "Vao.h"
 #include "Sm.h"
@@ -21,17 +20,21 @@ class SpotLight;
 /// Illumination stage
 class Is: private RenderingPass
 {
-	PROPERTY_R(Texture, fai, getFai) ///< The one and only FAI
-
 	public:
 		Is(Renderer& r_);
 		void init(const RendererInitializer& initializer);
 		void run();
 
+		/// @name Accessors
+		/// @{
+		const Texture& getFai() const {return fai;}
+		/// @}
+
 	private:
 		Sm sm; ///< Shadowmapping pass
 		Smo smo; /// Stencil masking optimizations pass
 		Fbo fbo; ///< This FBO writes to the Is::fai
+		Texture fai; ///< The one and only FAI
 		uint stencilRb; ///< Illumination stage stencil buffer
 		RsrcPtr<ShaderProg> ambientPassSProg; ///< Illumination stage ambient pass shader program
 		RsrcPtr<ShaderProg> pointLightSProg; ///< Illumination stage point light shader program

+ 0 - 1
src/Renderer/Renderer.h

@@ -20,7 +20,6 @@
 class Camera;
 class RendererInitializer;
 class ModelNode;
-class ModelNode;
 
 
 /// Offscreen renderer

+ 3 - 3
src/Renderer/SceneDrawer.cpp

@@ -1,7 +1,7 @@
 #include "SceneDrawer.h"
 #include "Math.h"
 #include "Material.h"
-#include "SceneNodePatch.h"
+#include "SceneRenderable.h"
 #include "Camera.h"
 #include "Renderer.h"
 #include "App.h"
@@ -226,9 +226,9 @@ void SceneDrawer::setupShaderProg(const Material& mtl, const Transform& nodeWorl
 
 
 //======================================================================================================================
-// renderSceneNodePatch                                                                                                =
+// renderSceneRenderable                                                                                                =
 //======================================================================================================================
-void SceneDrawer::renderSceneNodePatch(const SceneNodePatch& renderable, const Camera& cam, RenderingPassType rtype)
+void SceneDrawer::renderSceneRenderable(const SceneRenderable& renderable, const Camera& cam, RenderingPassType rtype)
 {
 	const Material* mtl;
 	const Vao* vao;

+ 3 - 3
src/Renderer/SceneDrawer.h

@@ -4,13 +4,13 @@
 #include "Math.h"
 
 
-class SceneNodePatch;
+class SceneRenderable;
 class Renderer;
 class Camera;
 class Material;
 
 
-/// It includes all the functions to render a SceneNodePatch
+/// It includes all the functions to render a SceneRenderable
 class SceneDrawer
 {
 	public:
@@ -23,7 +23,7 @@ class SceneDrawer
 		/// The one and only contructor
 		SceneDrawer(const Renderer& r_): r(r_) {}
 
-		void renderSceneNodePatch(const SceneNodePatch& renderable, const Camera& cam, RenderingPassType rtype);
+		void renderSceneRenderable(const SceneRenderable& renderable, const Camera& cam, RenderingPassType rtype);
 
 	private:
 		const Renderer& r; ///< Keep it here cause the class wants a few stuff from it

+ 10 - 1
src/Scene/ModelNodePatch.cpp

@@ -4,13 +4,14 @@
 #include "MeshData.h"
 #include "ModelPatch.h"
 #include "ModelNode.h"
+#include "ModelNode.h"
 
 
 //======================================================================================================================
 // Constructor                                                                                                         =
 //======================================================================================================================
 ModelNodePatch::ModelNodePatch(const ModelNode& modelNode, const ModelPatch& modelPatch_):
-	SceneNodePatch(modelNode),
+	node(modelNode),
 	modelPatchRsrc(modelPatch_)
 {
 	boost::array<const Vbo*, Mesh::VBOS_NUM> vboArr;
@@ -25,6 +26,14 @@ ModelNodePatch::ModelNodePatch(const ModelNode& modelNode, const ModelPatch& mod
 }
 
 
+//======================================================================================================================
+// getWorldTransform                                                                                                   =
+//======================================================================================================================
+const Transform& ModelNodePatch::getWorldTransform() const
+{
+	return node.getWorldTransform();
+}
+
 //======================================================================================================================
 // createVao                                                                                                           =
 //======================================================================================================================

+ 4 - 2
src/Scene/ModelNodePatch.h

@@ -7,7 +7,7 @@
 #include "RsrcPtr.h"
 #include "ModelPatch.h"
 #include "Properties.h"
-#include "SceneNodePatch.h"
+#include "SceneRenderable.h"
 
 
 class Material;
@@ -15,7 +15,7 @@ class ModelNode;
 
 
 /// A fragment of the ModelNode
-class ModelNodePatch: public SceneNodePatch
+class ModelNodePatch: public SceneRenderable
 {
 	/// VAO for MS and BS. All VBOs could be attached except for the vert weights
 	PROPERTY_R(Vao, cpVao, getCpVao)
@@ -30,11 +30,13 @@ class ModelNodePatch: public SceneNodePatch
 		/// @{
 		const Material& getCpMtl() const {return modelPatchRsrc.getCpMtl();}
 		const Material& getDpMtl() const {return modelPatchRsrc.getDpMtl();}
+		const Transform& getWorldTransform() const;
 		const ModelPatch& getModelPatchRsrc() const {return modelPatchRsrc;}
 		uint getVertIdsNum() const {return modelPatchRsrc.getMesh().getVertIdsNum();}
 		/// @}
 
 	protected:
+		const ModelNode& node; ///< Know your father
 		const ModelPatch& modelPatchRsrc;
 
 		static void createVao(const Material& material, const boost::array<const Vbo*, Mesh::VBOS_NUM>& vbos, Vao& vao);

+ 7 - 5
src/Scene/Scene.cpp

@@ -15,7 +15,7 @@
 Scene::Scene()
 {
 	ambientCol = Vec3(0.1, 0.05, 0.05)*4;
-	sunPos = Vec3(0.0, 1.0, -1.0) * 50.0;
+	//sunPos = Vec3(0.0, 1.0, -1.0) * 50.0;
 
 	physics.reset(new Physics);
 }
@@ -94,7 +94,7 @@ void Scene::unregisterController(Controller* controller)
 void Scene::updateAllWorldStuff()
 {
 	RASSERT_THROW_EXCEPTION(nodes.size() > 1024);
-	SceneNode* queue [1024];
+	boost::array<SceneNode*, 1024> queue;
 	uint head = 0, tail = 0;
 	uint num = 0;
 
@@ -102,7 +102,7 @@ void Scene::updateAllWorldStuff()
 	// put the roots
 	for(uint i=0; i<nodes.size(); i++)
 	{
-		if(nodes[i]->parent == NULL)
+		if(nodes[i]->getObjParent() == NULL)
 		{
 			queue[tail++] = nodes[i]; // queue push
 		}
@@ -118,9 +118,11 @@ void Scene::updateAllWorldStuff()
 		obj->update();
 		++num;
 
-		for(uint i=0; i<obj->childs.size(); i++)
+		Object::Container::iterator it = obj->getObjChildren().begin();
+		for(; it != obj->getObjChildren().end(); it++)
 		{
-			queue[tail++] = obj->childs[i];
+			SceneNode* node = static_cast<SceneNode*>(*it);
+			queue[tail++] = node;
 		}
 	}
 

+ 15 - 13
src/Scene/Scene.h

@@ -19,22 +19,24 @@ class ModelNode;
 /// The Scene contains all the dynamic entities
 class Scene
 {
-	//PROPERTY_RW(Vec3, ambientCol, setAmbientCol, getAmbientCol) ///< The global ambient color
-	PROPERTY_RW(Vec3, sunPos, getSunPos, setSunPos)
-	//PROPERTY_R(Physics*, phyWorld, getPhysics) ///< Connection with bullet
-
 	public:
-		/// The container template class. Extends vector
-		template<typename Type> class Container: public Vec<Type*>
-		{};
+		/// Typetraits
+		template<typename Type>
+		class Types
+		{
+			public:
+				typedef Vec<Type*> Container;
+				typedef typename Container::iterator Iterator;
+				typedef typename Container::const_iterator ConstIterator;
+		};
 
 		// Containers of scene's data
-		Container<SceneNode> nodes;
-		Container<Light> lights;
-		Container<Camera> cameras;
-		Container<ParticleEmitter> particleEmitters;
-		Container<ModelNode> modelNodes;
-		Container<Controller> controllers;
+		Types<SceneNode>::Container nodes;
+		Types<Light>::Container lights;
+		Types<Camera>::Container cameras;
+		Types<ParticleEmitter>::Container particleEmitters;
+		Types<ModelNode>::Container modelNodes;
+		Types<Controller>::Container controllers;
 
 		// The funcs
 		Scene();

+ 6 - 40
src/Scene/SceneNode.cpp

@@ -1,21 +1,17 @@
 #include <algorithm>
 #include "SceneNode.h"
-#include "Renderer.h"
-#include "Controller.h"
 #include "Scene.h"
-#include "App.h"
 
 
 //======================================================================================================================
-// commonConstructorCode                                                                                               =
+// Constructor                                                                                                         =
 //======================================================================================================================
-void SceneNode::commonConstructorCode()
+SceneNode::SceneNode(SceneNodeType type_, SceneNode* parent):
+	Object(parent),
+	type(type_)
 {
-	parent = NULL;
-	isCompound = false;
 	getWorldTransform().setIdentity();
 	getLocalTransform().setIdentity();
-
 	SceneSingleton::getInstance().registerNode(this);
 }
 
@@ -34,8 +30,9 @@ SceneNode::~SceneNode()
 //======================================================================================================================
 void SceneNode::updateWorldTransform()
 {
-	if(parent)
+	if(getObjParent())
 	{
+		const SceneNode* parent = static_cast<const SceneNode*>(getObjParent());
 		worldTransform = Transform::combineTransformations(parent->getWorldTransform(), localTransform);
 	}
 	else // else copy
@@ -81,7 +78,6 @@ void SceneNode::updateWorldTransform()
 
 //======================================================================================================================
 // Move(s)                                                                                                             =
-// Move the object according to it's local axis                                                                        =
 //======================================================================================================================
 void SceneNode::moveLocalX(float distance)
 {
@@ -101,33 +97,3 @@ void SceneNode::moveLocalZ(float distance)
 	getLocalTransform().origin += z_axis * distance;
 }
 
-
-//======================================================================================================================
-// addChild                                                                                                            =
-//======================================================================================================================
-void SceneNode::addChild(SceneNode* node)
-{
-	if(node->parent != NULL)
-	{
-		throw EXCEPTION("Node already has parent");
-	}
-
-	node->parent = this;
-	childs.push_back(node);
-}
-
-
-//======================================================================================================================
-// removeChild                                                                                                         =
-//======================================================================================================================
-void SceneNode::removeChild(SceneNode* child)
-{
-	Vec<SceneNode*>::iterator it = std::find(childs.begin(), childs.end(), child);
-	if(it == childs.end())
-	{
-		throw EXCEPTION("Child not found");
-	}
-
-	child->parent = NULL;
-	childs.erase(it);
-}

+ 14 - 28
src/Scene/SceneNode.h

@@ -2,7 +2,6 @@
 #define SCENE_NODE_H
 
 #include <memory>
-#include "Vec.h"
 #include "Math.h"
 #include "Object.h"
 #include "Properties.h"
@@ -13,7 +12,7 @@ class Controller;
 
 
 /// The backbone of scene. It is also an Object for memory management reasons
-class SceneNode: public Object
+class SceneNode: private Object
 {
 	friend class Scene;
 
@@ -26,26 +25,24 @@ class SceneNode: public Object
 			SNT_PARTICLE_EMITTER,
 			SNT_MODEL
 		};
-
-	PROPERTY_RW(Transform, localTransform, getLocalTransform, setLocalTransform) ///< The transformation in local space
-	PROPERTY_RW(Transform, worldTransform, getWorldTransform, setWorldTransform) ///< The transformation in world space (local combined with parent transformation)
-
-	public:
-		SceneNode* parent;
-		Vec<SceneNode*> childs;
-		SceneNodeType type;
-		bool isCompound;
 		
 		SceneNode(SceneNodeType type_, SceneNode* parent = NULL);
 		virtual ~SceneNode();
 		virtual void init(const char*) = 0; ///< init using a script
 
+		/// @name Accessors
+		/// @{
+		GETTER_SETTER(Transform, localTransform, getLocalTransform, setLocalTransform)
+		GETTER_SETTER(Transform, worldTransform, getWorldTransform, setWorldTransform)
+		SceneNodeType getSceneNodeType() const {return type;}
+		/// @}
+
 		/// @name Updates
 		/// Two separate updates happen every loop. The update happens anyway and the updateTrf only when the node is being
 		/// moved
 		/// @{
-		virtual void update() {};
-		virtual void updateTrf() {};
+		virtual void update() {}
+		virtual void updateTrf() {}
 		/// @}
 
 		/// @name Mess with the local transform
@@ -58,25 +55,14 @@ class SceneNode: public Object
 		void moveLocalZ(float distance);
 		/// @}
 
-		void addChild(SceneNode* node);
-		void removeChild(SceneNode* node);
-
 	private:
+		Transform localTransform; ///< The transformation in local space
+		Transform worldTransform; ///< The transformation in world space (local combined with parent's transformation)
+		SceneNodeType type;
+
 		void commonConstructorCode(); ///< Cause we cannot call constructor from other constructor
 		void updateWorldTransform(); ///< This update happens only when the object gets moved
 };
 
 
-inline SceneNode::SceneNode(SceneNodeType type_, SceneNode* parent):
-	Object(parent),
-	type(type_)
-{
-	commonConstructorCode();
-	if(parent != NULL)
-	{
-		parent->addChild(this);
-	}
-}
-
-
 #endif

+ 6 - 12
src/Scene/SceneNodePatch.h → src/Scene/SceneRenderable.h

@@ -1,29 +1,23 @@
-#ifndef SCENE_NODE_PATCH_H
-#define SCENE_NODE_PATCH_H
+#ifndef SCENE_RENDERABLE_H
+#define SCENE_RENDERABLE_H
 
-#include "SceneNode.h"
+#include "Math.h"
 
 
 class Vao;
 class Material;
 
 
-/// Abstract class, patch of a compound SceneNode derivative.
-/// Despite of what the name suggests the class is not a SceneNode derivative.
-class SceneNodePatch
+/// Abstract class that acts as an interface for the renderable objects of the scene
+class SceneRenderable
 {
 	public:
-		SceneNodePatch(const SceneNode& father_): father(father_) {}
-
 		virtual const Vao& getCpVao() const = 0; ///< Get color pass VAO
 		virtual const Vao& getDpVao() const = 0; ///< Get depth pass VAO
 		virtual uint getVertIdsNum() const = 0;  ///< Get vert ids number for rendering
 		virtual const Material& getCpMtl() const = 0;  ///< Get color pass material
 		virtual const Material& getDpMtl() const = 0;  ///< Get depth pass material
-		const Transform& getWorldTransform() const {return father.getWorldTransform();}
-
-	private:
-		const SceneNode& father;
+		virtual const Transform& getWorldTransform() const = 0; ///< Get the world transformation
 };
 
 

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio