Panagiotis Christopoulos Charitos vor 15 Jahren
Ursprung
Commit
b6ef9959ed

Datei-Diff unterdrückt, da er zu groß ist
+ 0 - 1
build/debug/Makefile


+ 21 - 4
src/Main.cpp

@@ -163,11 +163,11 @@ void init()
 
 
 
 
 	// Imp
 	// Imp
-	/*imp = new SkinNode();
+	imp = new SkinNode();
 	imp->init("models/imp/imp.skin");
 	imp->init("models/imp/imp.skin");
 	imp->skelAnimModelNodeCtrl = new SkelAnimModelNodeCtrl(*imp);
 	imp->skelAnimModelNodeCtrl = new SkelAnimModelNodeCtrl(*imp);
 	imp->skelAnimModelNodeCtrl->set(imp->getSkin().getSkelAnims()[0].get());
 	imp->skelAnimModelNodeCtrl->set(imp->getSkin().getSkelAnims()[0].get());
-	imp->skelAnimModelNodeCtrl->setStep(0.8);*/
+	imp->skelAnimModelNodeCtrl->setStep(0.8);
 
 
 	return;
 	return;
 
 
@@ -258,7 +258,7 @@ void mainLoopExtra()
 	if(InputSingleton::getInstance().getKey(SDL_SCANCODE_3)) mover = spot_lights[0];
 	if(InputSingleton::getInstance().getKey(SDL_SCANCODE_3)) mover = spot_lights[0];
 	if(InputSingleton::getInstance().getKey(SDL_SCANCODE_4)) mover = point_lights[1];
 	if(InputSingleton::getInstance().getKey(SDL_SCANCODE_4)) mover = point_lights[1];
 	if(InputSingleton::getInstance().getKey(SDL_SCANCODE_5)) mover = spot_lights[1];
 	if(InputSingleton::getInstance().getKey(SDL_SCANCODE_5)) mover = spot_lights[1];
-	if(InputSingleton::getInstance().getKey(SDL_SCANCODE_6)) mover = horse;
+	if(InputSingleton::getInstance().getKey(SDL_SCANCODE_6)) mover = imp;
 	if(InputSingleton::getInstance().getKey(SDL_SCANCODE_M) == 1) InputSingleton::getInstance().warpMouse = !InputSingleton::getInstance().warpMouse;
 	if(InputSingleton::getInstance().getKey(SDL_SCANCODE_M) == 1) InputSingleton::getInstance().warpMouse = !InputSingleton::getInstance().warpMouse;
 
 
 	if(InputSingleton::getInstance().getKey(SDL_SCANCODE_A)) mover->moveLocalX(-dist);
 	if(InputSingleton::getInstance().getKey(SDL_SCANCODE_A)) mover->moveLocalX(-dist);
@@ -307,6 +307,17 @@ void mainLoopExtra()
 	}
 	}
 
 
 	mover->getLocalTransform().getRotation().reorthogonalize();
 	mover->getLocalTransform().getRotation().reorthogonalize();
+
+	//INFO(mover->getSceneNodeName())
+
+	if(spot_lights[0]->getCamera().insideFrustum(spot_lights[1]->getCamera()))
+	{
+		INFO("in");
+	}
+	else
+	{
+		INFO("out");
+	}
 }
 }
 
 
 
 
@@ -328,7 +339,13 @@ void mainLoop()
 		AppSingleton::getInstance().execStdinScpripts();
 		AppSingleton::getInstance().execStdinScpripts();
 		SceneSingleton::getInstance().getPhysics().update(timer.getCrntTime());
 		SceneSingleton::getInstance().getPhysics().update(timer.getCrntTime());
 		SceneSingleton::getInstance().updateAllWorldStuff();
 		SceneSingleton::getInstance().updateAllWorldStuff();
-		SceneSingleton::getInstance().doVisibilityTests(*AppSingleton::getInstance().getActiveCam());
+		//SceneSingleton::getInstance().doVisibilityTests(*AppSingleton::getInstance().getActiveCam());
+		SceneSingleton::getInstance().doVisibilityTests(spot_lights[0]->getCamera());
+		AppSingleton::getInstance().getActiveCam()->getVisibleMsRenderableNodes().clear();
+		AppSingleton::getInstance().getActiveCam()->getVisibleMsRenderableNodes() = spot_lights[0]->getCamera().getVisibleMsRenderableNodes();
+		AppSingleton::getInstance().getActiveCam()->getVisiblePointLights() = spot_lights[0]->getCamera().getVisiblePointLights();
+		AppSingleton::getInstance().getActiveCam()->getVisibleSpotLights() = spot_lights[0]->getCamera().getVisibleSpotLights();
+
 		SceneSingleton::getInstance().updateAllControllers();
 		SceneSingleton::getInstance().updateAllControllers();
 
 
 		MainRendererSingleton::getInstance().render(*AppSingleton::getInstance().getActiveCam());
 		MainRendererSingleton::getInstance().render(*AppSingleton::getInstance().getActiveCam());

+ 52 - 0
src/Renderer/Dbg.cpp

@@ -8,6 +8,8 @@
 #include "SceneDbgDrawer.h"
 #include "SceneDbgDrawer.h"
 #include "ParticleEmitter.h"
 #include "ParticleEmitter.h"
 #include "RenderableNode.h"
 #include "RenderableNode.h"
+#include "SkinNode.h"
+#include "SpotLight.h"
 
 
 
 
 //======================================================================================================================
 //======================================================================================================================
@@ -263,6 +265,46 @@ void Dbg::run()
 
 
 	BOOST_FOREACH(const SceneNode* node, SceneSingleton::getInstance().getAllNodes())
 	BOOST_FOREACH(const SceneNode* node, SceneSingleton::getInstance().getAllNodes())
 	{
 	{
+		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())
 		switch(node->getSceneNodeType())
 		{
 		{
 			case SceneNode::SNT_CAMERA:
 			case SceneNode::SNT_CAMERA:
@@ -281,6 +323,16 @@ void Dbg::run()
 					collisionDbgDrawer.draw(rnode.getVisibilityShapeWSpace());
 					collisionDbgDrawer.draw(rnode.getVisibilityShapeWSpace());
 				}*/
 				}*/
 				break;
 				break;
+			case SceneNode::SNT_SKIN:
+			{
+				const SkinNode& node_ = static_cast<const SkinNode&>(*node);
+				sceneDbgDrawer.drawSkinNodeSkeleton(node_);
+				if(showVisibilityBoundingShapesFlag)
+				{
+					collisionDbgDrawer.draw(node_.getVisibilityShapeWSpace());
+				}
+				break;
+			}
 			default:
 			default:
 				break;
 				break;
 		}
 		}

+ 2 - 1
src/Renderer/Drawers/SceneDbgDrawer.cpp

@@ -65,7 +65,7 @@ void SceneDbgDrawer::drawParticleEmitter(const ParticleEmitter& pe) const
 void SceneDbgDrawer::drawSkinNodeSkeleton(const SkinNode& sn) const
 void SceneDbgDrawer::drawSkinNodeSkeleton(const SkinNode& sn) const
 {
 {
 	dbg.setModelMat(Mat4(sn.getWorldTransform()));
 	dbg.setModelMat(Mat4(sn.getWorldTransform()));
-
+	dbg.begin();
 	for(uint i = 0; i < sn.getHeads().size(); i++)
 	for(uint i = 0; i < sn.getHeads().size(); i++)
 	{
 	{
 		dbg.setColor(Vec4(1.0, 0.0, 0.0, 1.0));
 		dbg.setColor(Vec4(1.0, 0.0, 0.0, 1.0));
@@ -73,4 +73,5 @@ void SceneDbgDrawer::drawSkinNodeSkeleton(const SkinNode& sn) const
 		dbg.setColor(Vec4(1.0));
 		dbg.setColor(Vec4(1.0));
 		dbg.pushBackVertex(sn.getTails()[i]);
 		dbg.pushBackVertex(sn.getTails()[i]);
 	}
 	}
+	dbg.end();
 }
 }

+ 2 - 1
src/Resources/Core/ResourceManager.h

@@ -104,7 +104,8 @@ class ResourceManager
 
 
 		/// Dealocate the resource. Its separate for two reasons:
 		/// Dealocate the resource. Its separate for two reasons:
 		/// - Because we want to specialize it for the async loaded resources
 		/// - Because we want to specialize it for the async loaded resources
-		/// - Because we cannot have the operator delete in a template body. Apparently the compiler is to dump to decide
+		/// - Because we cannot have the operator delete in a template body. Apparently the compiler is to dump to
+		///   decide
 		template<typename Type>
 		template<typename Type>
 		void deallocRsrc(Type* rsrc);
 		void deallocRsrc(Type* rsrc);
 };
 };

+ 32 - 32
src/Resources/Skin.cpp

@@ -15,63 +15,63 @@
 void Skin::load(const char* filename)
 void Skin::load(const char* filename)
 {
 {
 	try
 	try
-  {
+	{
 		//
 		//
 		// Load
 		// Load
 		//
 		//
 		using namespace boost::property_tree;
 		using namespace boost::property_tree;
 		ptree pt_;
 		ptree pt_;
-  	read_xml(filename, pt_);
+		read_xml(filename, pt_);
 
 
-  	const ptree& pt = pt_.get_child("skin");
+		const ptree& pt = pt_.get_child("skin");
 
 
-  	// model
-  	model.loadRsrc(pt.get<std::string>("model").c_str());
+		// model
+		model.loadRsrc(pt.get<std::string>("model").c_str());
 
 
-  	// skeleton
-  	skeleton.loadRsrc(pt.get<std::string>("skeleton").c_str());
+		// skeleton
+		skeleton.loadRsrc(pt.get<std::string>("skeleton").c_str());
 
 
-  	// Anims
-  	boost::optional<const ptree&> skelAnimsTree = pt.get_child_optional("skelAnims");
-  	if(skelAnimsTree)
-  	{
-  		BOOST_FOREACH(const ptree::value_type& v, skelAnimsTree.get())
-  		{
-  			if(v.first != "skelAnim")
-  			{
-  				throw EXCEPTION("Expected skelAnim and no " + v.first);
-  			}
+		// Anims
+		boost::optional<const ptree&> skelAnimsTree = pt.get_child_optional("skelAnims");
+		if(skelAnimsTree)
+		{
+			BOOST_FOREACH(const ptree::value_type& v, skelAnimsTree.get())
+			{
+				if(v.first != "skelAnim")
+				{
+					throw EXCEPTION("Expected skelAnim and no " + v.first);
+				}
 
 
-  			const std::string& name = v.second.data();
-  			skelAnims.push_back(RsrcPtr<SkelAnim>());
+				const std::string& name = v.second.data();
+				skelAnims.push_back(RsrcPtr<SkelAnim>());
 				skelAnims.back().loadRsrc(name.c_str());
 				skelAnims.back().loadRsrc(name.c_str());
-  		}
-  	}
+			}
+		}
 
 
-  	//
-  	// Sanity checks
-  	//
+		//
+		// Sanity checks
+		//
 
 
-  	// Anims and skel bones num check
-		for(uint i = 0; i < skelAnims.size(); i++)
+		// Anims and skel bones num check
+		BOOST_FOREACH(const RsrcPtr<SkelAnim>& skelAnim, skelAnims)
 		{
 		{
 			// Bone number problem
 			// Bone number problem
-			if(skelAnims[i]->bones.size() != skeleton->bones.size())
+			if(skelAnim->bones.size() != skeleton->bones.size())
 			{
 			{
-				throw EXCEPTION("Skeleton animation \"" + skelAnims[i].getRsrcName() + "\" and skeleton \"" +
-				                skeleton.getRsrcName() + "\" dont have equal bone count");
+				throw EXCEPTION("Skeleton animation \"" + skelAnim.getRsrcName() + "\" and skeleton \"" +
+								skeleton.getRsrcName() + "\" dont have equal bone count");
 			}
 			}
 		}
 		}
 
 
 		// All meshes should have vert weights
 		// All meshes should have vert weights
-		for(uint i = 0; i < model->getModelPatches().size(); i++)
+		BOOST_FOREACH(const ModelPatch& patch, model->getModelPatches())
 		{
 		{
-			if(!model->getModelPatches()[i].supportsHwSkinning())
+			if(!patch.supportsHwSkinning())
 			{
 			{
 				throw EXCEPTION("Mesh does not support HW skinning");
 				throw EXCEPTION("Mesh does not support HW skinning");
 			}
 			}
 		}
 		}
-  }
+	  }
 	catch(std::exception& e)
 	catch(std::exception& e)
 	{
 	{
 		throw EXCEPTION("Skin \"" + filename + "\": " + e.what());
 		throw EXCEPTION("Skin \"" + filename + "\": " + e.what());

+ 1 - 1
src/Scene/Camera.cpp

@@ -109,7 +109,7 @@ bool Camera::insideFrustum(const Camera& cam) const
 	// transform them to the given camera's world space (exept the eye)
 	// transform them to the given camera's world space (exept the eye)
 	for(uint i = 0; i < 4; i++)
 	for(uint i = 0; i < 4; i++)
 	{
 	{
-		points[i].transform(getWorldTransform());
+		points[i].transform(cam.getWorldTransform());
 	}
 	}
 
 
 	// the collision code
 	// the collision code

+ 7 - 0
src/Scene/SkinNode.cpp

@@ -2,6 +2,7 @@
 #include "SkinNode.h"
 #include "SkinNode.h"
 #include "Skin.h"
 #include "Skin.h"
 #include "SkinPatchNode.h"
 #include "SkinPatchNode.h"
+#include "Skeleton.h"
 
 
 
 
 //======================================================================================================================
 //======================================================================================================================
@@ -15,6 +16,12 @@ void SkinNode::init(const char* filename)
 	{
 	{
 		patches.push_back(new SkinPatchNode(patch, this));
 		patches.push_back(new SkinPatchNode(patch, this));
 	}
 	}
+
+	uint bonesNum = skin->getSkeleton().bones.size();
+	tails.resize(bonesNum);
+	heads.resize(bonesNum);
+	boneRotations.resize(bonesNum);
+	boneTranslations.resize(bonesNum);
 }
 }
 
 
 
 

+ 3 - 0
src/Scene/SkinNode.h

@@ -28,6 +28,7 @@ class SkinNode: public SceneNode
 		GETTER_RW(Vec<Vec3>, boneTranslations, getBoneTranslations)
 		GETTER_RW(Vec<Vec3>, boneTranslations, getBoneTranslations)
 		const Skin& getSkin() const {return *skin;}
 		const Skin& getSkin() const {return *skin;}
 		GETTER_R(Obb, visibilityShapeWSpace, getVisibilityShapeWSpace)
 		GETTER_R(Obb, visibilityShapeWSpace, getVisibilityShapeWSpace)
+		GETTER_R(Vec<SkinPatchNode*>, patches, getPatcheNodes)
 		/// @}
 		/// @}
 
 
 		void init(const char* filename);
 		void init(const char* filename);
@@ -36,6 +37,8 @@ class SkinNode: public SceneNode
 		/// from the previous frame
 		/// from the previous frame
 		void moveUpdate();
 		void moveUpdate();
 
 
+		void frameUpdate() {}
+
 	private:
 	private:
 		RsrcPtr<Skin> skin; ///< The resource
 		RsrcPtr<Skin> skin; ///< The resource
 		Vec<SkinPatchNode*> patches;
 		Vec<SkinPatchNode*> patches;

+ 39 - 0
src/Scene/VisibilityTester.cpp

@@ -2,6 +2,7 @@
 #include "VisibilityTester.h"
 #include "VisibilityTester.h"
 #include "Scene.h"
 #include "Scene.h"
 #include "ModelNode.h"
 #include "ModelNode.h"
+#include "SkinNode.h"
 #include "ModelPatchNode.h"
 #include "ModelPatchNode.h"
 #include "Material.h"
 #include "Material.h"
 #include "Sphere.h"
 #include "Sphere.h"
@@ -72,6 +73,7 @@ void VisibilityTester::test(Camera& cam)
 				{
 				{
 					cam.getVisibleSpotLights().push_back(spotl);
 					cam.getVisibleSpotLights().push_back(spotl);
 					spotl->setVisible(true);
 					spotl->setVisible(true);
+					spotl->getCamera().setVisible(true);
 				}
 				}
 				break;
 				break;
 			}
 			}
@@ -111,6 +113,9 @@ void VisibilityTester::getRenderableNodes(bool skipShadowless, Camera& cam)
 	cam.getVisibleMsRenderableNodes().clear();
 	cam.getVisibleMsRenderableNodes().clear();
 	cam.getVisibleBsRenderableNodes().clear();
 	cam.getVisibleBsRenderableNodes().clear();
 
 
+	//
+	// ModelNodes
+	//
 	BOOST_FOREACH(ModelNode* node, scene.getModelNodes())
 	BOOST_FOREACH(ModelNode* node, scene.getModelNodes())
 	{
 	{
 		// Skip if the ModeNode is not visible
 		// Skip if the ModeNode is not visible
@@ -146,6 +151,40 @@ void VisibilityTester::getRenderableNodes(bool skipShadowless, Camera& cam)
 		}
 		}
 	}
 	}
 
 
+	//
+	// SkinNodes
+	//
+	BOOST_FOREACH(SkinNode* node, scene.getSkinNodes())
+	{
+		// Skip if the SkinNode is not visible
+		if(!test(*node, cam))
+		{
+			continue;
+		}
+
+		node->setVisible(true);
+
+		// Put all the patches into the visible container
+		/*BOOST_FOREACH(SkinPatchNode* patchNode, node->getPatcheNodes())
+		{
+			// Skip shadowless
+			if(skipShadowless && !patchNode->getCpMtl().isShadowCaster())
+			{
+				continue;
+			}
+
+			if(patchNode->getCpMtl().renderInBlendingStage())
+			{
+				cam.getVisibleBsRenderableNodes().push_back(patchNode);
+			}
+			else
+			{
+				cam.getVisibleMsRenderableNodes().push_back(patchNode);
+			}
+			patchNode->setVisible(true);
+		}*/
+	}
+
 	//
 	//
 	// Sort the renderables from closest to the camera to the farthest
 	// Sort the renderables from closest to the camera to the farthest
 	//
 	//

Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden.