Panagiotis Christopoulos Charitos 15 anni fa
parent
commit
dbaac176b5

File diff suppressed because it is too large
+ 306 - 414
build/release/Makefile


+ 5 - 3
src/Physics/RigidBody.cpp

@@ -15,9 +15,11 @@ RigidBody::RigidBody(float mass, const Transform& startTransform, btCollisionSha
 
 	bool isDynamic = (mass != 0.0);
 
-	btVector3 localInertia(0.0, 0.0, 0.0);
+	btVector3 localInertia;
 	if(isDynamic)
-		shape->calculateLocalInertia(mass,localInertia);
+		shape->calculateLocalInertia(mass, localInertia);
+	else
+		localInertia = btVector3(0.0, 0.0, 0.0);
 
 	motionState.reset(new MotionState(toBt(startTransform), *node));
 
@@ -35,7 +37,7 @@ RigidBody::RigidBody(float mass, const Transform& startTransform, btCollisionSha
 
 
 //======================================================================================================================
-// RigidBody                                                                                                           =
+// Destructor                                                                                                          =
 //======================================================================================================================
 RigidBody::~RigidBody()
 {

+ 7 - 8
src/Physics/RigidBody.h

@@ -17,19 +17,15 @@ class MotionState;
  */
 class RigidBody: public btRigidBody
 {
-	private:
-		auto_ptr<MotionState> motionState; ///< Keep it here as well for garbage collection
-
 	public:
 		/**
-		 * Create and register
-		 * @param mass
+		 * Init and register
+		 * @param mass S/E
 		 * @param startTransform Initial pos
-		 * @param shape
-		 * @param node
+		 * @param shape Collision shape
+		 * @param node SceneNode to move
 		 * @param group -1 if not used
 		 * @param mask -1 if not used
-		 * @param parent Object stuff
 		 */
 		RigidBody(float mass, const Transform& startTransform, btCollisionShape* shape, SceneNode* node,
 		          int group = -1, int mask = -1);
@@ -38,6 +34,9 @@ class RigidBody: public btRigidBody
 		 * Unregister it
 		 */
 		~RigidBody();
+
+	private:
+		auto_ptr<MotionState> motionState; ///< Keep it here as well for garbage collection
 };
 
 

+ 27 - 2
src/Resources/ParticleEmitterProps.cpp

@@ -2,7 +2,7 @@
 #include "ParticleEmitterProps.h"
 
 
-static const char* errMsg = "Incorrect value ";
+static const char* errMsg = "Incorrect or missing value ";
 
 
 //======================================================================================================================
@@ -21,6 +21,7 @@ ParticleEmitterPropsStruct::ParticleEmitterPropsStruct():
 	gravityMargin(0.0),
 	startingPos(0.0),
 	startingPosMargin(0.0),
+	size(0.0),
 	usingWorldGrav(true),
 	hasForce(false)
 {}
@@ -66,6 +67,7 @@ bool ParticleEmitterProps::load(const char* filename)
 
 	startingPos = Vec3(0.0, 1.0, 0.0);
 	startingPosMargin = Vec3(0.0, 0.0, 0.0);
+	size = 0.5;
 	maxNumOfParticles = 50;
 	emittionPeriod = 0.05;
 	particlesPerEmittion = 2;
@@ -79,7 +81,7 @@ bool ParticleEmitterProps::load(const char* filename)
 	else
 		hasForce = true;
 
-	usingWorldGrav = M::isZero(gravity.getLength()) ? true : false;
+	usingWorldGrav = M::isZero(gravity.getLength());
 
 
 	// sanity checks
@@ -95,6 +97,29 @@ bool ParticleEmitterProps::load(const char* filename)
 		return false;
 	}
 
+	if(size <= 0.0)
+	{
+		ERROR(errMsg << "size");
+		return false;
+	}
+
+	if(maxNumOfParticles < 1)
+	{
+		ERROR(errMsg << "maxNumOfParticles");
+		return false;
+	}
+
+	if(emittionPeriod <= 0.0)
+	{
+		ERROR(errMsg << "emittionPeriod");
+		return false;
+	}
+
+	if(particlesPerEmittion < 1)
+	{
+		ERROR(errMsg << "particlesPerEmittion");
+		return false;
+	}
 
 	return true;
 }

+ 5 - 3
src/Resources/ParticleEmitterProps.h

@@ -20,7 +20,7 @@ class ParticleEmitterPropsStruct
 		float particleLife; ///< Required and > 0.0
 		float particleLifeMargin;
 
-		Vec3 forceDirection;
+		Vec3 forceDirection; ///< Not-required, any value, If not set only the gravity applies
 		Vec3 forceDirectionMargin;
 		float forceMagnitude; ///< Default 0.0
 		float forceMagnitudeMargin;
@@ -28,11 +28,13 @@ class ParticleEmitterPropsStruct
 		float particleMass; ///< Required and > 0.0
 		float particleMassMargin;
 
-		Vec3 gravity; ///< If not set then it uses the world's default
+		Vec3 gravity; ///< Not-required, any value. If not set then it uses the world's default
 		Vec3 gravityMargin;
 
 		Vec3 startingPos; ///< If not set the default is zero
 		Vec3 startingPosMargin;
+
+		float size; ///< The size of the collision shape. Required and > 0.0
 		/**@}*/
 
 		/**
@@ -40,7 +42,7 @@ class ParticleEmitterPropsStruct
 		 */
 		/**@{*/
 		uint maxNumOfParticles; ///< The size of the particles vector. Required
-		float emittionPeriod; ///< How often the emitter emits new particles. In ms. Required
+		float emittionPeriod; ///< How often the emitter emits new particles. In secs. Required
 		uint particlesPerEmittion; ///< How many particles are emitted every emittion. Required
 		/**@}*/
 

+ 1 - 1
src/Resources/ShaderProg.h

@@ -90,7 +90,7 @@ class ShaderProg: public Resource
 	//====================================================================================================================
 	public:
 		ShaderProg();
-		virtual ~ShaderProg() {}
+		~ShaderProg() {}
 
 		/**
 		 * Accessor to glId

+ 6 - 5
src/Scene/ParticleEmitter.cpp

@@ -37,21 +37,22 @@ void ParticleEmitter::init(const char* filename)
 	me = other;
 
 	// create the particles
-	btCollisionShape* colShape = new btSphereShape(0.5);
+	collShape.reset(new btSphereShape(size));
 	Transform startTransform;
 	startTransform.setIdentity();
 
 	for(uint i = 0; i < maxNumOfParticles; i++)
 	{
-		particles.push_back(new Particle);
-		Particle* particle = &particles.back();
+		Particle* particle = new Particle;
+		particles.push_back(particle);
+
 		float mass = particleMass + Util::randFloat(particleMassMargin) * 2.0 - particleMassMargin;
 
-		RigidBody* body = new RigidBody(mass, startTransform, colShape, particle, Physics::CG_PARTICLE,
+		RigidBody* body = new RigidBody(mass, startTransform, collShape.get(), particle, Physics::CG_PARTICLE,
 		                                Physics::CG_ALL ^ Physics::CG_PARTICLE); ///@todo add parent
 		body->forceActivationState(DISABLE_SIMULATION);
 
-		particle->body = body;
+		particle->body.reset(body);
 	}
 }
 

+ 3 - 2
src/Scene/ParticleEmitter.h

@@ -23,7 +23,7 @@ class ParticleEmitter: public SceneNode, public ParticleEmitterPropsStruct
 		{
 			public:
 				float timeOfDeath; ///< Life of death. If < 0.0 then dead. In seconds
-				RigidBody* body;
+				auto_ptr<RigidBody> body;
 
 				Particle();
 				void render();
@@ -37,10 +37,11 @@ class ParticleEmitter: public SceneNode, public ParticleEmitterPropsStruct
 		void updateWorldStuff();
 
 	private:
+		auto_ptr<btCollisionShape> collShape;
 		ptr_vector<Particle> particles;
 		float timeOfPrevUpdate;
 		float timeOfPrevEmittion;
-		RsrcPtr<ParticleEmitterProps> particleEmitterProps;
+		RsrcPtr<ParticleEmitterProps> particleEmitterProps; ///< The resource
 
 		void update();
 };

+ 1 - 1
src/Scene/Scene.cpp

@@ -17,7 +17,7 @@ Scene::Scene()
 	ambientCol = Vec3(0.1, 0.05, 0.05)*4;
 	sunPos = Vec3(0.0, 1.0, -1.0) * 50.0;
 
-	phyWorld = new Physics;
+	phyWorld.reset(new Physics);
 }
 
 

+ 24 - 23
src/Scene/Scene.h

@@ -1,6 +1,7 @@
-#ifndef _SCENE_H_
-#define _SCENE_H_
+#ifndef SCENE_H
+#define SCENE_H
 
+#include <memory>
 #include "Common.h"
 #include "skybox.h"
 #include "Physics.h"
@@ -22,27 +23,7 @@ class Scene
 {
 	PROPERTY_RW(Vec3, ambientCol, setAmbientCol, getAmbientCol) ///< The global ambient color
 	PROPERTY_RW(Vec3, sunPos, setSunPos, getSunPos)
-	PROPERTY_RW(Physics*, phyWorld, setPhysics, getPhysics) ///< Connection with bullet
-
-	private:
-		/**
-		 * @brief Adds a node in a container
-		 */
-		template<typename ContainerType, typename Type> void putBackNode(ContainerType& container, Type* x)
-		{
-			DEBUG_ERR(std::find(container.begin(), container.end(), x) != container.end());
-			container.push_back(x);
-		}
-
-		/**
-		 * @brief Removes a node from a container
-		 */
-		template<typename ContainerType, typename Type> void eraseNode(ContainerType& container, Type* x)
-		{
-			typename ContainerType::iterator it = std::find(container.begin(), container.end(), x);
-			DEBUG_ERR(it == container.end());
-			container.erase(it);
-		}
+	PROPERTY_R(auto_ptr<Physics>, phyWorld, getPhysics) ///< Connection with bullet
 
 	public:
 		/**
@@ -71,6 +52,26 @@ class Scene
 
 		void updateAllWorldStuff();
 		void updateAllControllers();
+
+	private:
+		/**
+		 * @brief Adds a node in a container
+		 */
+		template<typename ContainerType, typename Type> void putBackNode(ContainerType& container, Type* x)
+		{
+			DEBUG_ERR(std::find(container.begin(), container.end(), x) != container.end());
+			container.push_back(x);
+		}
+
+		/**
+		 * @brief Removes a node from a container
+		 */
+		template<typename ContainerType, typename Type> void eraseNode(ContainerType& container, Type* x)
+		{
+			typename ContainerType::iterator it = std::find(container.begin(), container.end(), x);
+			DEBUG_ERR(it == container.end());
+			container.erase(it);
+		}
 };
 
 #endif

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