Panagiotis Christopoulos Charitos 15 years ago
parent
commit
5dad39bd3c

File diff suppressed because it is too large
+ 0 - 1
build/debug/Makefile


+ 0 - 48
src/Collision/Sphere.cpp

@@ -62,51 +62,3 @@ float Sphere::testPlane(const Plane& plane) const
 		return 0.0;
 	}
 }
-
-//======================================================================================================================
-// set                                                                                                                 =
-//======================================================================================================================
-void Sphere::set(const float* pointer, size_t stride, int count)
-{
-	void* tmpPtr = (void*)pointer;
-	Vec3 min(*(Vec3*)tmpPtr);
-	Vec3 max(*(Vec3*)tmpPtr);
-
-	// for all the Vec3 calc the max and min
-	for(int i=1; i<count; i++)
-	{
-		tmpPtr = (char*)tmpPtr + stride;
-
-		const Vec3& tmp = *((Vec3*)tmpPtr);
-
-		for(int j=0; j<3; j++)
-		{
-			if(tmp[j] > max[j])
-			{
-				max[j] = tmp[j];
-			}
-			else if(tmp[j] < min[j])
-			{
-				min[j] = tmp[j];
-			}
-		}
-	}
-
-	center = (min + max) * 0.5; // average
-
-	tmpPtr = (void*)pointer;
-	float maxDist = (*((Vec3*)tmpPtr) - center).getLengthSquared(); // max distance between center and the vec3 arr
-	for(int i = 1; i < count; i++)
-	{
-		tmpPtr = (char*)tmpPtr + stride;
-
-		const Vec3& vertco = *((Vec3*)tmpPtr);
-		float dist = (vertco - center).getLengthSquared();
-		if(dist > maxDist)
-		{
-			maxDist = dist;
-		}
-	}
-
-	radius = M::sqrt(maxDist);
-}

+ 8 - 14
src/Collision/Sphere.h

@@ -28,9 +28,6 @@ class Sphere: public CollisionShape
 		GETTER_SETTER_BY_VAL(float, radius, getRadius, setRadius)
 		/// @}
 
-		/// @see set
-		Sphere(const float* pointer, size_t stride, int count);
-
 		Sphere getTransformed(const Transform& transform) const;
 
 		/// Get the sphere that includes this sphere and the given
@@ -39,15 +36,16 @@ class Sphere: public CollisionShape
 		/// @see CollisionShape::testPlane
 		float testPlane(const Plane& plane) const;
 
-	private:
-		Vec3 center;
-		float radius;
-
-		/// Set from Vec3 array
+		/// Set from a container containing Vec3s
 		/// @param pointer The start of the array
 		/// @param stride The space between the elements
 		/// @param count The number of 3D vectors
-		void set(const float* pointer, size_t stride, int count);
+		template<typename Container>
+		void set(const Container& container);
+
+	private:
+		Vec3 center;
+		float radius;
 };
 
 
@@ -65,11 +63,7 @@ inline Sphere::Sphere(const Vec3& center_, float radius_):
 {}
 
 
-inline Sphere::Sphere(const float* pointer, size_t stride, int count):
-	CollisionShape(CST_SPHERE)
-{
-	set(pointer, stride, count);
-}
+#include "Sphere.inl.h"
 
 
 #endif

+ 46 - 0
src/Collision/Sphere.inl.h

@@ -0,0 +1,46 @@
+#include <boost/foreach.hpp>
+#include <boost/range/iterator_range.hpp>
+#include "Exception.h"
+
+
+//======================================================================================================================
+// set                                                                                                                 =
+//======================================================================================================================
+template<typename Container>
+void Sphere::set(const Container& container)
+{
+	RASSERT_THROW_EXCEPTION(container.size() < 1);
+
+	Vec3 min(container.front());
+	Vec3 max(container.front());
+
+	// for all the Vec3 calc the max and min
+	BOOST_FOREACH(const Vec3& v, boost::make_iterator_range(container.begin() + 1, container.end()))
+	{
+		for(int j = 0; j < 3; j++)
+		{
+			if(v[j] > max[j])
+			{
+				max[j] = v[j];
+			}
+			else if(v[j] < min[j])
+			{
+				min[j] = v[j];
+			}
+		}
+	}
+
+	center = (min + max) * 0.5; // average
+
+	float maxDist = (container.front() - center).getLengthSquared(); // max distance between center and the vec3 arr
+	BOOST_FOREACH(const Vec3& v, boost::make_iterator_range(container.begin() + 1, container.end()))
+	{
+		float dist = (v - center).getLengthSquared();
+		if(dist > maxDist)
+		{
+			maxDist = dist;
+		}
+	}
+
+	radius = M::sqrt(maxDist);
+}

+ 4 - 1
src/Main.cpp

@@ -146,6 +146,8 @@ void init()
 	horse->init("meshes/horse/horse.mdl");
 	horse->setLocalTransform(Transform(Vec3(-2, 0, 1), Mat3::getIdentity(), 1.0));
 
+	return;
+
 
 	// Sponza
 	ModelNode* sponza = new ModelNode();
@@ -260,7 +262,7 @@ void mainLoop()
 		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_5)) mover = spot_lights[1];
-		if(InputSingleton::getInstance().getKey(SDL_SCANCODE_6)) mover = partEmitter;
+		if(InputSingleton::getInstance().getKey(SDL_SCANCODE_6)) mover = horse;
 		if(InputSingleton::getInstance().getKey(SDL_SCANCODE_M) == 1) InputSingleton::getInstance().warpMouse = !InputSingleton::getInstance().warpMouse;
 
 		if(InputSingleton::getInstance().getKey(SDL_SCANCODE_A)) mover->moveLocalX(-dist);
@@ -315,6 +317,7 @@ void mainLoop()
 		SceneSingleton::getInstance().updateAllControllers();
 		SceneSingleton::getInstance().updateAllWorldStuff();
 		SceneSingleton::getInstance().doVisibilityTests(*AppSingleton::getInstance().getActiveCam());
+		//SceneSingleton::getInstance().doVisibilityTests(spot_lights[0]->getCamera());
 
 		MainRendererSingleton::getInstance().render(*AppSingleton::getInstance().getActiveCam());
 

+ 15 - 8
src/Renderer/Dbg.cpp

@@ -8,6 +8,7 @@
 #include "RendererInitializer.h"
 #include "SceneDbgDrawer.h"
 #include "ParticleEmitter.h"
+#include "RenderableNode.h"
 
 
 //======================================================================================================================
@@ -19,6 +20,7 @@ Dbg::Dbg(Renderer& r_):
 	showLightsEnabled(true),
 	showSkeletonsEnabled(true),
 	showCamerasEnabled(true),
+	showVisibilityBoundingShapesFlag(true),
 	sceneDbgDrawer(*this)
 {}
 
@@ -259,21 +261,26 @@ void Dbg::run()
 	setModelMat(Mat4::getIdentity());
 	renderGrid();
 
-	Scene::Types<SceneNode>::ConstIterator it = SceneSingleton::getInstance().getAllNodes().begin();
-	for(; it != SceneSingleton::getInstance().getAllNodes().end(); ++it)
+	BOOST_FOREACH(const SceneNode* node, SceneSingleton::getInstance().getAllNodes())
 	{
-		const SceneNode& node = *(*it);
-
-		switch(node.getSceneNodeType())
+		switch(node->getSceneNodeType())
 		{
 			case SceneNode::SNT_CAMERA:
-				sceneDbgDrawer.drawCamera(static_cast<const Camera&>(node));
+				sceneDbgDrawer.drawCamera(static_cast<const Camera&>(*node));
 				break;
 			case SceneNode::SNT_LIGHT:
-				sceneDbgDrawer.drawLight(static_cast<const Light&>(node));
+				sceneDbgDrawer.drawLight(static_cast<const Light&>(*node));
 				break;
 			case SceneNode::SNT_PARTICLE_EMITTER:
-				sceneDbgDrawer.drawParticleEmitter(static_cast<const ParticleEmitter&>(node));
+				sceneDbgDrawer.drawParticleEmitter(static_cast<const ParticleEmitter&>(*node));
+				break;
+			case SceneNode::SNT_RENDERABLE:
+				if(showVisibilityBoundingShapesFlag)
+				{
+					const RenderableNode& rnode = static_cast<const RenderableNode&>(*node);
+					setModelMat(Mat4(rnode.getWorldTransform()) * Mat4(rnode.getBoundingShapeWSpace().getCenter(), Mat3::getIdentity(), 1.0));
+					drawSphere(rnode.getBoundingShapeWSpace().getRadius());
+				}
 				break;
 			default:
 				break;

+ 1 - 0
src/Renderer/Dbg.h

@@ -50,6 +50,7 @@ class Dbg: public RenderingPass
 		bool showLightsEnabled;
 		bool showSkeletonsEnabled;
 		bool showCamerasEnabled;
+		bool showVisibilityBoundingShapesFlag;
 		Fbo fbo;
 		RsrcPtr<ShaderProg> sProg;
 		static const uint MAX_POINTS_PER_DRAW = 256;

+ 1 - 1
src/Resources/Mesh.cpp

@@ -28,7 +28,7 @@ void Mesh::load(const char* filename)
 
 		createVbos(meshData);
 
-		boundingShape = Sphere((const float*)(&meshData.getVertCoords()[0]), 0, meshData.getVertCoords().size());
+		boundingShape.set(meshData.getVertCoords());
 	}
 	catch(std::exception& e)
 	{

Some files were not shown because too many files changed in this diff