Pārlūkot izejas kodu

- XML in lights
- Adding code for orthographic camera

Panagiotis Christopoulos Charitos 14 gadi atpakaļ
vecāks
revīzija
7f6bc26b8b

+ 9 - 5
build/debug/Makefile

@@ -43,9 +43,10 @@ Main.o: ../../src/Main.cpp ../../src/Input/Input.h \
  ../../src/Collision/Sphere.h ../../src/Collision/Sphere.inl.h \
  ../../src/Collision/Obb.h ../../src/Collision/Obb.inl.h \
  ../../src/Scene/SceneNode.h ../../src/Core/Object.h \
- ../../src/Collision/Obb.h ../../src/Renderer/Renderer.h \
- ../../src/Renderer/BufferObjects/Fbo.h ../../extern/include/GL/glew.h \
- ../../src/Util/Exception.h ../../src/Resources/Texture/Texture.h \
+ ../../src/Collision/Obb.h ../../src/Scene/Cameras/OrthographicCamera.h \
+ ../../src/Renderer/Renderer.h ../../src/Renderer/BufferObjects/Fbo.h \
+ ../../extern/include/GL/glew.h ../../src/Util/Exception.h \
+ ../../src/Resources/Texture/Texture.h \
  ../../src/Resources/ShaderProg/ShaderProg.h \
  ../../src/Util/CharPtrHashMap.h \
  ../../src/Resources/ShaderProg/SProgUniVar.h \
@@ -4040,7 +4041,9 @@ Smo.o: ../../src/Renderer/Smo.cpp ../../src/Renderer/Smo.h \
  ../../src/Resources/LightRsrc.h ../../src/Scene/Lights/PointLight.h \
  ../../src/Scene/Lights/Light.h ../../src/Scene/Lights/SpotLight.h \
  ../../src/Scene/Cameras/PerspectiveCamera.h \
- ../../src/Scene/Cameras/Camera.h
+ ../../src/Scene/Cameras/Camera.h \
+ ../../src/Scene/Cameras/OrthographicCamera.h \
+ ../../src/Resources/Mesh/Mesh.h
 	@echo Compiling ../../src/Renderer/Smo.cpp...
 	@$(CXX) $(INCPATH) $(CFLAGS) ../../src/Renderer/Smo.cpp -o Smo.o
 
@@ -4913,7 +4916,8 @@ SceneDbgDrawer.o: ../../src/Renderer/Drawers/SceneDbgDrawer.cpp \
  ../../src/Resources/Material/Material.h \
  ../../src/Resources/Material/MtlUserDefinedVar.h \
  ../../src/Scene/Cameras/PerspectiveCamera.h \
- ../../src/Scene/Cameras/Camera.h
+ ../../src/Scene/Cameras/Camera.h \
+ ../../src/Scene/Cameras/OrthographicCamera.h
 	@echo Compiling ../../src/Renderer/Drawers/SceneDbgDrawer.cpp...
 	@$(CXX) $(INCPATH) $(CFLAGS) ../../src/Renderer/Drawers/SceneDbgDrawer.cpp -o SceneDbgDrawer.o
 

+ 4 - 0
src/Main.cpp

@@ -4,6 +4,7 @@
 
 #include "Input.h"
 #include "PerspectiveCamera.h"
+#include "OrthographicCamera.h"
 #include "Math.h"
 #include "Renderer.h"
 #include "Ui.h"
@@ -128,6 +129,9 @@ void init()
 	cam->moveLocalX(-0.3);
 	AppSingleton::getInstance().setActiveCam(cam);
 
+	OrthographicCamera* ocam = new OrthographicCamera(false, NULL);
+	ocam->setAll(-1, 1, 1.0, -1.0, 0.1, 10.0);
+
 	// lights
 	point_lights[0] = new PointLight();
 	point_lights[0]->init("maps/temple/light0.light");

+ 2 - 36
src/Renderer/Dbg.cpp

@@ -266,46 +266,12 @@ void Dbg::run()
 
 	BOOST_FOREACH(const SceneNode* node, SceneSingleton::getInstance().getAllNodes())
 	{
-		if(!node->isVisible())
+		/*if(!node->isVisible())
 		{
 			continue;
-		}
-
-		/*if(node->getSceneNodeName() == "Light:5")
-		{
-			const SpotLight* sl = static_cast<const SpotLight*>(node);
-			const Camera& cam = sl->getCamera();
-
-			boost::array<Vec3, 5> points;
-
-			// get 3 sample floats
-			float x = cam.getZFar() / tan((PI - cam.getFovX()) / 2.0);
-			float y = tan(cam.getFovY() / 2.0) * cam.getZFar();
-			float z = -cam.getZFar();
-
-			// the actual points in local space
-			points[0] = Vec3(x, y, z); // top right
-			points[1] = Vec3(-x, y, z); // top left
-			points[2] = Vec3(-x, -y, z); // bottom left
-			points[3] = Vec3(x, -y, z); // bottom right
-			points[4] = cam.getWorldTransform().getOrigin(); // eye (already in world space)
-
-			for(uint i = 0; i < 4; i++)
-			{
-				points[i].transform(cam.getWorldTransform());
-			}
-
-			setModelMat(Mat4::getIdentity());
-			setColor(Vec3(1,0,0));
-			begin();
-				for(uint i = 0; i < 4; i++)
-				{
-					pushBackVertex(points[4]);
-					pushBackVertex(points[i]);
-				}
-			end();
 		}*/
 
+
 		switch(node->getSceneNodeType())
 		{
 			case SceneNode::SNT_CAMERA:

+ 47 - 3
src/Renderer/Drawers/SceneDbgDrawer.cpp

@@ -5,6 +5,7 @@
 #include "ParticleEmitter.h"
 #include "SkinNode.h"
 #include "PerspectiveCamera.h"
+#include "OrthographicCamera.h"
 
 
 //======================================================================================================================
@@ -22,11 +23,13 @@ void SceneDbgDrawer::drawCamera(const Camera& cam) const
 		}
 
 		case Camera::CT_ORTHOGRAPHIC:
-			/// @todo
-			ASSERT(false && "todo");
+		{
+			const OrthographicCamera& ocam = static_cast<const OrthographicCamera&>(cam);
+			drawOrthographicCamera(ocam);
 			break;
+		}
 
-		case Camera::CT_NUM:
+		default:
 			ASSERT(false && "WTF?");
 			break;
 	}
@@ -64,6 +67,47 @@ void SceneDbgDrawer::drawPerspectiveCamera(const PerspectiveCamera& cam) const
 }
 
 
+//======================================================================================================================
+// drawOrthographicCamera                                                                                              =
+//======================================================================================================================
+void SceneDbgDrawer::drawOrthographicCamera(const OrthographicCamera& ocam) const
+{
+	dbg.setColor(Vec4(0.0, 1.0, 0.0, 1.0));
+	dbg.setModelMat(Mat4(ocam.getWorldTransform()));
+
+	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();
+}
+
+
 //======================================================================================================================
 // drawLight                                                                                                           =
 //======================================================================================================================

+ 2 - 0
src/Renderer/Drawers/SceneDbgDrawer.h

@@ -8,6 +8,7 @@ class Light;
 class ParticleEmitter;
 class SkinNode;
 class PerspectiveCamera;
+class OrthographicCamera;
 
 
 /// This is a drawer for some scene nodes that need debug
@@ -33,6 +34,7 @@ class SceneDbgDrawer
 		Dbg& dbg; ///< The debug stage
 
 		virtual void drawPerspectiveCamera(const PerspectiveCamera& cam) const;
+		virtual void drawOrthographicCamera(const OrthographicCamera& cam) const;
 };
 
 

+ 27 - 7
src/Renderer/Smo.cpp

@@ -8,6 +8,7 @@
 #include "Vao.h"
 #include "Vbo.h"
 #include "PerspectiveCamera.h"
+#include "OrthographicCamera.h"
 #include "Mesh.h"
 
 
@@ -102,7 +103,7 @@ void Smo::run(const SpotLight& light)
 	glDisable(GL_CULL_FACE);
 
 	// Calc the camera shape scale matrix
-	Mat4 scaleMat(Mat4::getIdentity());
+	Mat4 localMat(Mat4::getIdentity());
 	const Geom& cg = camGeom[lcam.getType()];
 
 	switch(lcam.getType())
@@ -110,16 +111,35 @@ void Smo::run(const SpotLight& light)
 		case Camera::CT_PERSPECTIVE:
 		{
 			const PerspectiveCamera& pcam = static_cast<const PerspectiveCamera&>(lcam);
-			scaleMat(0, 0) = tan(pcam.getFovX() / 2.0) * pcam.getZFar(); // Scale in x
-			scaleMat(1, 1) = tan(pcam.getFovY() / 2.0) * pcam.getZFar(); // Scale in y
-			scaleMat(2, 2) = pcam.getZFar(); // Scale in z
+			localMat(0, 0) = tan(pcam.getFovX() / 2.0) * pcam.getZFar(); // Scale in x
+			localMat(1, 1) = tan(pcam.getFovY() / 2.0) * pcam.getZFar(); // Scale in y
+			localMat(2, 2) = pcam.getZFar(); // Scale in z
 			break;
 		}
 
 		case Camera::CT_ORTHOGRAPHIC:
-			/// @todo
-			ASSERT(false && "todo");
+		{
+			const OrthographicCamera& ocam = static_cast<const OrthographicCamera&>(lcam);
+			Vec3 tsl;
+			float left = ocam.getLeft();
+			float right = ocam.getRight();
+			float zNear = ocam.getZNear();
+			float zFar = ocam.getZFar();
+			float top = ocam.getTop();
+			float bottom = ocam.getBottom();
+
+			localMat(0, 0) = (right - left) / 2.0;
+			tsl.x() = (right + left) / 2.0;
+
+			localMat(1, 1) = (top - bottom) / 2.0;
+			tsl.y() = (top + bottom) / 2.0;
+
+			localMat(2, 2) = (zFar - zNear) / 2.0;
+			tsl.z() = -(zNear + zFar) / 2.0;
+
+			localMat.setTranslationPart(tsl);
 			break;
+		}
 
 		case Camera::CT_NUM:
 			ASSERT(false && "WTF?");
@@ -130,7 +150,7 @@ void Smo::run(const SpotLight& light)
 	sProg->bind();
 	Mat4 modelMat = Mat4(lcam.getWorldTransform());
 
-	Mat4 trf = r.getViewProjectionMat() * modelMat * scaleMat;
+	Mat4 trf = r.getViewProjectionMat() * modelMat * localMat;
 	sProg->findUniVar("modelViewProjectionMat")->set(&trf);
 
 	//

+ 140 - 105
src/Resources/LightRsrc.cpp

@@ -1,7 +1,12 @@
 #include <cstring>
+#include <string>
+#include <boost/property_tree/ptree.hpp>
+#include <boost/property_tree/xml_parser.hpp>
+#include <boost/foreach.hpp>
+#include <boost/lexical_cast.hpp>
 #include "LightRsrc.h"
-#include "Parser.h"
 #include "Texture.h"
+#include "PropertyTree.h"
 
 
 //======================================================================================================================
@@ -14,8 +19,9 @@ LightRsrc::LightRsrc()
 	castsShadowFlag = false;
 	radius = 1.0;
 	distance = 3.0;
-	fovX = M::PI / 4.0;
-	fovY = M::PI / 4.0;
+	fovX = fovY = M::PI / 4.0;
+	width = height = 1.0;
+	spotLightCameraType = SLCT_PERSPECTIVE;
 }
 
 
@@ -24,150 +30,179 @@ LightRsrc::LightRsrc()
 //======================================================================================================================
 void LightRsrc::load(const char* filename)
 {
-	Scanner scanner(filename);
-	const Scanner::Token* token;
-	type = LT_NUM;
-
-	while(true)
+	try
 	{
-		token = &scanner.getNextToken();
+		using namespace boost::property_tree;
+		ptree rpt;
+		read_xml(filename, rpt);
+
+		const ptree& pt = rpt.get_child("light");
 
+		//
 		// type
-		if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "type"))
+		//
+		std::string type_ = pt.get<std::string>("type");
+		if(type_ == "POINT")
 		{
-			token = &scanner.getNextToken();
-			if(token->getCode() == Scanner::TC_IDENTIFIER)
-			{
-				if(!strcmp(token->getValue().getString(), "LT_SPOT"))
-				{
-					type = LT_SPOT;
-				}
-				else if(!strcmp(token->getValue().getString(), "LT_POINT"))
-				{
-					type = LT_POINT;
-				}
-				else
-				{
-					throw PARSER_EXCEPTION_EXPECTED("LT_SPOT or LT_POINT");
-				}
-			}
+			type = LT_POINT;
 		}
+		else if(type_ == "SPOT")
+		{
+			type = LT_SPOT;
+		}
+		else
+		{
+			throw EXCEPTION("Incorrect type: " + type_);
+		}
+
+		//
 		// diffuseCol
-		else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "diffuseCol"))
+		//
+		boost::optional<const ptree&> diffColTree = pt.get_child_optional("diffuseCol");
+		if(diffColTree)
 		{
-			Parser::parseMathVector(scanner, diffuseCol);
+			diffuseCol = PropertyTree::getVec3(diffColTree.get());
 		}
+
+		//
 		// specularCol
-		else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "specularCol"))
+		//
+		boost::optional<const ptree&> specColTree = pt.get_child_optional("specularCol");
+		if(specColTree)
 		{
-			Parser::parseMathVector(scanner, specularCol);
+			specularCol = PropertyTree::getVec3(specColTree.get());
 		}
-		// radius
-		else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "radius"))
-		{
-			token = &scanner.getNextToken();
-			if(token->getCode() != Scanner::TC_NUMBER)
-			{
-				throw PARSER_EXCEPTION_EXPECTED("number");
-			}
 
-			radius = (token->getDataType() == Scanner::DT_FLOAT) ? token->getValue().getFloat() :
-			                                                     float(token->getValue().getInt());
+		//
+		// castsShadow
+		//
+		boost::optional<bool> castsShadow_ = PropertyTree::getBoolOptional(pt, "castsShadow");
+		if(castsShadow_)
+		{
+			castsShadowFlag = castsShadow_.get();
 		}
-		// castsShadowFlag
-		else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "castsShadow"))
+
+		//
+		// radius
+		//
+		boost::optional<float> radius_ = pt.get_optional<float>("radius");
+		if(radius_)
 		{
-			token = &scanner.getNextToken();
-			if(token->getCode() == Scanner::TC_IDENTIFIER)
-			{
-				if(!strcmp(token->getValue().getString(), "true"))
-				{
-					castsShadowFlag = true;
-				}
-				else if(!strcmp(token->getValue().getString(), "false"))
-				{
-					castsShadowFlag = false;
-				}
-				else
-				{
-					throw PARSER_EXCEPTION_EXPECTED("true or false");
-				}
-			}
-			else
+			radius = radius_.get();
+
+			if(type == LT_SPOT)
 			{
-				throw PARSER_EXCEPTION_EXPECTED("true or false");
+				WARNING("File \"" << filename << "\": No radius for spot lights");
 			}
 		}
+
+		//
 		// distance
-		else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "distance"))
+		//
+		boost::optional<float> distance_ = pt.get_optional<float>("distance");
+		if(distance_)
 		{
-			token = &scanner.getNextToken();
-			if(token->getCode() != Scanner::TC_NUMBER)
+			distance = distance_.get();
+
+			if(type == LT_POINT)
 			{
-				throw PARSER_EXCEPTION_EXPECTED("number");
+				WARNING("File \"" << filename << "\": No distance for point lights");
 			}
-
-			distance = (token->getDataType() == Scanner::DT_FLOAT) ? token->getValue().getFloat() :
-			                                                       float(token->getValue().getInt());
-			type = LT_SPOT;
 		}
+
+		//
 		// fovX
-		else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "fovX"))
+		//
+		boost::optional<float> fovX_ = pt.get_optional<float>("fovX");
+		if(fovX_)
 		{
-			token = &scanner.getNextToken();
-			if(token->getCode() != Scanner::TC_NUMBER)
+			fovX = fovX_.get();
+
+			if(type == LT_POINT)
 			{
-				throw PARSER_EXCEPTION_EXPECTED("number");
+				WARNING("File \"" << filename << "\": No fovX for point lights");
 			}
-
-			fovX = (token->getDataType() == Scanner::DT_FLOAT) ? token->getValue().getFloat() :
-			                                                   float(token->getValue().getInt());
-			type = LT_SPOT;
 		}
+
+		//
 		// fovY
-		else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "fovY"))
+		//
+		boost::optional<float> fovY_ = pt.get_optional<float>("fovY");
+		if(fovY_)
 		{
-			token = &scanner.getNextToken();
-			if(token->getCode() != Scanner::TC_NUMBER)
+			fovY = fovY_.get();
+
+			if(type == LT_POINT)
 			{
-				throw PARSER_EXCEPTION_EXPECTED("number");
+				WARNING("File \"" << filename << "\": No fovY for point lights");
 			}
-
-			fovY = (token->getDataType() == Scanner::DT_FLOAT) ? token->getValue().getFloat() :
-			                                                   float(token->getValue().getInt());
-			type = LT_SPOT;
 		}
-		// texture
-		else if(token->getCode() == Scanner::TC_IDENTIFIER && !strcmp(token->getValue().getString(), "texture"))
+
+		//
+		// width
+		//
+		boost::optional<float> width_ = pt.get_optional<float>("width");
+		if(width_)
 		{
-			token = &scanner.getNextToken();
-			if(token->getCode() != Scanner::TC_STRING)
+			width = width_.get();
+
+			if(type == LT_POINT)
 			{
-				throw PARSER_EXCEPTION_EXPECTED("string");
+				WARNING("File \"" << filename << "\": No width for point lights");
 			}
+		}
 
-			texture.loadRsrc(token->getValue().getString());
-			texture->setRepeat(false);
-			texture->setAnisotropy(0);
-			texture->setFiltering(Texture::TFT_LINEAR);
-			type = LT_SPOT;
+		//
+		// height
+		//
+		boost::optional<float> height_ = pt.get_optional<float>("height");
+		if(height_)
+		{
+			height = height_.get();
+
+			if(type == LT_POINT)
+			{
+				WARNING("File \"" << filename << "\": No height for point lights");
+			}
 		}
-		// end of file
-		else if(token->getCode() == Scanner::TC_EOF)
+
+		//
+		// texture
+		//
+		boost::optional<std::string> tex = pt.get_optional<std::string>("texture");
+		if(tex)
 		{
-			break;
+			texture.loadRsrc(tex.get().c_str());
+
+			if(type == LT_POINT)
+			{
+				WARNING("File \"" << filename << "\": No texture for point lights");
+			}
 		}
-		// other crap
-		else
+
+		//
+		// cameraType
+		//
+		boost::optional<std::string> cam = pt.get_optional<std::string>("cameraType");
+		if(cam)
 		{
-			throw PARSER_EXCEPTION_UNEXPECTED();
+			if(cam.get() == "PERSPECTIVE")
+			{
+				spotLightCameraType = SLCT_PERSPECTIVE;
+			}
+			else if(cam.get() == "ORTHOGRAPHIC")
+			{
+				spotLightCameraType = SLCT_ORTHOGRAPHIC;
+			}
+			else
+			{
+				throw EXCEPTION("Incorrect cameraYype: " + cam.get());
+			}
 		}
-	} // end while
 
-	
-	// sanity checks
-	if(type == LT_NUM)
+	}
+	catch(std::exception& e)
 	{
-		throw EXCEPTION("File \"" + filename + "\": Forgot to set type");
+		throw EXCEPTION("Material \"" + filename + "\": " + e.what());
 	}
 }

+ 13 - 2
src/Resources/LightRsrc.h

@@ -25,8 +25,10 @@ struct LightProps
 	/// @name Spot light properties
 	/// @{
 	float distance; ///< AKA camera's zFar
-	float fovX;
-	float fovY;
+	float fovX; ///< For perspective camera
+	float fovY; ///< For perspective camera
+	float width; ///< For orthographic camera
+	float height; ///< For orthographic camera
 	/// @}
 };
 
@@ -42,6 +44,12 @@ class LightRsrc: private LightProps
 			LT_NUM
 		};
 
+		enum SpotLightCameraType
+		{
+			SLCT_PERSPECTIVE,
+			SLCT_ORTHOGRAPHIC
+		};
+
 		LightRsrc();
 		~LightRsrc() {}
 
@@ -57,6 +65,8 @@ class LightRsrc: private LightProps
 		GETTER_R_BY_VAL(float, distance, getDistance)
 		GETTER_R_BY_VAL(float, fovX, getFovX)
 		GETTER_R_BY_VAL(float, fovY, getFovY)
+		GETTER_R_BY_VAL(float, width, getWidth)
+		GETTER_R_BY_VAL(float, height, getHeight)
 		const Texture& getTexture() const;
 		/// @}
 
@@ -64,6 +74,7 @@ class LightRsrc: private LightProps
 
 	private:
 		LightType type;
+		SpotLightCameraType spotLightCameraType;
 		RsrcPtr<Texture> texture;
 };
 

+ 3 - 1
src/Scene/Cameras/Camera.h

@@ -131,7 +131,9 @@ class Camera: public SceneNode
 inline Camera::Camera(CameraType camType, bool compoundFlag, SceneNode* parent):
 	SceneNode(SNT_CAMERA, compoundFlag, parent),
 	type(camType)
-{}
+{
+	name = "Camera:" + name;
+}
 
 
 inline void Camera::setZNear(float znear_)

+ 16 - 0
src/Scene/Cameras/OrthographicCamera.cpp

@@ -1,6 +1,22 @@
 #include "OrthographicCamera.h"
 
 
+//======================================================================================================================
+// setAll                                                                                                              =
+//======================================================================================================================
+void OrthographicCamera::setAll(float left_, float right_, float top_, float bottom_, float zNear_, float zFar_)
+{
+	left = left_;
+	right = right_;
+	top = top_;
+	bottom = bottom_;
+	zNear = zNear_;
+	zFar = zFar_;
+	calcProjectionMatrix();
+	calcLSpaceFrustumPlanes();
+}
+
+
 //======================================================================================================================
 // calcLSpaceFrustumPlanes                                                                                             =
 //======================================================================================================================

+ 10 - 3
src/Scene/Cameras/OrthographicCamera.h

@@ -4,11 +4,11 @@
 #include "Camera.h"
 
 
-/// @todo
+/// Orthographic camera defined by pairs of parallel planes
 class OrthographicCamera: public Camera
 {
 	public:
-		OrthographicCamera(bool compoundFlag, SceneNode* parent): Camera(CT_ORTHOGRAPHIC, compoundFlag, parent) {}
+		OrthographicCamera(bool compoundFlag, SceneNode* parent);
 
 		/// @name Accessors
 		/// @{
@@ -21,7 +21,7 @@ class OrthographicCamera: public Camera
 		float getTop() const {return top;}
 		void setTop(float f);
 
-		float getBottom() const {return top;}
+		float getBottom() const {return bottom;}
 		void setBottom(float f);
 		/// @}
 
@@ -57,6 +57,13 @@ class OrthographicCamera: public Camera
 };
 
 
+inline OrthographicCamera::OrthographicCamera(bool compoundFlag, SceneNode* parent):
+	Camera(CT_ORTHOGRAPHIC, compoundFlag, parent)
+{
+	name = "OrthographicCamera:" + name;
+}
+
+
 inline void OrthographicCamera::setLeft(float f)
 {
 	left = f;

+ 7 - 1
src/Scene/Cameras/PerspectiveCamera.h

@@ -8,7 +8,7 @@
 class PerspectiveCamera: public Camera
 {
 	public:
-		PerspectiveCamera(bool compoundFlag, SceneNode* parent): Camera(CT_PERSPECTIVE, compoundFlag, parent) {}
+		PerspectiveCamera(bool compoundFlag, SceneNode* parent);
 
 		/// @name Accessors
 		/// @{
@@ -42,6 +42,12 @@ class PerspectiveCamera: public Camera
 };
 
 
+inline PerspectiveCamera::PerspectiveCamera(bool compoundFlag, SceneNode* parent):
+	Camera(CT_PERSPECTIVE, compoundFlag, parent)
+{
+	name = "PerspectiveCamera:" + name;
+}
+
 inline void PerspectiveCamera::setFovX(float fovx_)
 {
 	fovX = fovx_;

+ 1 - 24
src/Scene/SceneNode.cpp

@@ -23,30 +23,7 @@ SceneNode::SceneNode(SceneNodeType type_, bool compoundFlag_, SceneNode* parent)
 	getLocalTransform().setIdentity();
 	SceneSingleton::getInstance().registerNode(this);
 
-	switch(type)
-	{
-		case SNT_GHOST:
-			name = "GhostNode:" + boost::lexical_cast<std::string>(uid);
-			break;
-		case SNT_LIGHT:
-			name = "Light:" + boost::lexical_cast<std::string>(uid);
-			break;
-		case SNT_CAMERA:
-			name = "Camera:" + boost::lexical_cast<std::string>(uid);
-			break;
-		case SNT_PARTICLE_EMITTER:
-			name = "ParticleEmitter:" + boost::lexical_cast<std::string>(uid);
-			break;
-		case SNT_MODEL:
-			name = "ModelNode:" + boost::lexical_cast<std::string>(uid);
-			break;
-		case SNT_SKIN:
-			name = "SkinNode:" + boost::lexical_cast<std::string>(uid);
-			break;
-		case SNT_RENDERABLE:
-			name = "RenderableNode:" + boost::lexical_cast<std::string>(uid);
-			break;
-	}
+	name = boost::lexical_cast<std::string>(uid);
 
 	++uid;
 }

+ 3 - 1
src/Scene/SceneNode.h

@@ -81,13 +81,15 @@ class SceneNode: public Object
 		/// This update happens only when the object gets moved. Called only by the Scene
 		void updateWorldTransform();
 
+	protected:
+		std::string name;
+
 	private:
 		Transform localTransform; ///< The transformation in local space
 		Transform worldTransform; ///< The transformation in world space (local combined with parent's transformation)
 
 		SceneNodeType type;
 		bool compoundFlag; ///< This means that the children will inherit the world transform of this node
-		std::string name;
 
 		static uint uid; ///< Unique identifier