Browse Source

Working on the ParticleEmitter

Panagiotis Christopoulos Charitos 16 years ago
parent
commit
9f0b25d3bc
6 changed files with 39 additions and 26 deletions
  1. 4 4
      blenderscripts/mesh.py
  2. 5 5
      src/Main.cpp
  3. 1 1
      src/Physics/PhyWorld.h
  4. 3 3
      src/Renderer/Vbo.h
  5. 6 6
      src/Resources/Mesh.cpp
  6. 20 7
      src/Scene/ParticleEmitter.cpp

+ 4 - 4
blenderscripts/mesh.py

@@ -223,8 +223,8 @@ def ScriptMesh( mesh_init ):
 				else:
 					ERROR( "The mesh \"" + mesh.name + "\" More than 1 coords for the " + str(vert_id) + " vert" )
 					mesh.verts[vert_id].sel=1
-					return "error"
-					#print " %f %f %f %f" % ( vertuvs[ vert_id ][0], vertuvs[ vert_id ][1], uvx, uvy )
+					#return "error"
+					print " %f %f %f %f" % ( vertuvs[ vert_id ][0], vertuvs[ vert_id ][1], uvx, uvy )
 			
 			# do the same if quat for the other forming triangle
 			if( len( face.verts ) == 4 ):
@@ -243,8 +243,8 @@ def ScriptMesh( mesh_init ):
 					else:
 						ERROR( "The mesh \"" + mesh.name + "\" More than 1 coords for the " + str(vert_id) + " vert" )
 						mesh.verts[vert_id].sel=1
-						return "error"
-						#print " %f %f %f %f" % ( vertuvs[ vert_id ][0], vertuvs[ vert_id ][1], uvx, uvy )
+						#return "error"
+						print " %f %f %f %f" % ( vertuvs[ vert_id ][0], vertuvs[ vert_id ][1], uvx, uvy )
 	# endif has UVs
 				
 	# now put the UVs in the ftxt

+ 5 - 5
src/Main.cpp

@@ -122,6 +122,7 @@ void initPhysics()
 		float start_y = START_POS_Y;
 		float start_z = START_POS_Z - ARRAY_SIZE_Z/2;
 
+		btRigidBody* body;
 		for (int k=0;k<ARRAY_SIZE_Y;k++)
 		{
 			for (int i=0;i<ARRAY_SIZE_X;i++)
@@ -140,22 +141,21 @@ void initPhysics()
 					crate->scaleLspace = 1.11;
 					MotionState* myMotionState = new MotionState( startTransform, crate);
 					btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,colShape,localInertia);
-					btRigidBody* body = new btRigidBody(rbInfo);
+					//btRigidBody* body = new btRigidBody(rbInfo);
+					body = new btRigidBody(rbInfo);
 
-					if( i=2 ) body->setActivationState(ISLAND_SLEEPING);
+					//if( i=2 ) body->setActivationState(ISLAND_SLEEPING);
 
 					//body->setActivationState(ISLAND_SLEEPING);
+					//body->setGravity( btVector3( 0.0, -1.0, 0.0 ) );
 
 					dynamicsWorld->addRigidBody(body);
-					//body->setActivationState(ISLAND_SLEEPING);
 				}
 			}
 		}
 	}
 
 
-
-
 	//dynamicsWorld->setDebugDrawer(&debugDrawer);
 }
 

+ 1 - 1
src/Physics/PhyWorld.h

@@ -36,7 +36,7 @@ class PhyWorld
 			broadphase = new btDbvtBroadphase();
 			sol = new btSequentialImpulseConstraintSolver;
 			dynamicsWorld = new btDiscreteDynamicsWorld( dispatcher, broadphase, sol, collisionConfiguration );
-			dynamicsWorld->setGravity(btVector3(0,-10,0));
+			dynamicsWorld->setGravity( btVector3(0,-10,0) );
 		}
 };
 

+ 3 - 3
src/Renderer/Vbo.h

@@ -24,11 +24,11 @@ class Vbo
 		/**
 		 * Creates a new VBO with the given params and checks if everything went OK
 		 * @param target_ It should be: GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER only!!!!!
-		 * @param size_in_bytes The size of the buffer that we will allocate in bytes
-		 * @param data_ptr Points to the data buffer to copy to the VGA memory. Put NULL if you want just to allocate memory
+		 * @param sizeInBytes The size of the buffer that we will allocate in bytes
+		 * @param dataPtr Points to the data buffer to copy to the VGA memory. Put NULL if you want just to allocate memory
 		 * @param usage_ It should be: GL_STREAM_DRAW or GL_STATIC_DRAW or GL_DYNAMIC_DRAW only!!!!!!!!!
 		 */
-		void Create( GLenum target_, uint sizeInBytes, const void* dataPtr, GLenum usage_ )
+		void create( GLenum target_, uint sizeInBytes, const void* dataPtr, GLenum usage_ )
 		{
 			DEBUG_ERR( glId!=0 ); // VBO already initialized
 			DEBUG_ERR( target_!=GL_ARRAY_BUFFER && target_!=GL_ELEMENT_ARRAY_BUFFER ); // unacceptable target_

+ 6 - 6
src/Resources/Mesh.cpp

@@ -304,15 +304,15 @@ void Mesh::createVertTangents()
 //=====================================================================================================================================
 void Mesh::createVBOs()
 {
-	vbos.vertIndeces.Create( GL_ELEMENT_ARRAY_BUFFER, vertIndeces.getSizeInBytes(), &vertIndeces[0], GL_STATIC_DRAW );
-	vbos.vertCoords.Create( GL_ARRAY_BUFFER, vertCoords.getSizeInBytes(), &vertCoords[0], GL_STATIC_DRAW );
-	vbos.vertNormals.Create( GL_ARRAY_BUFFER, vertNormals.getSizeInBytes(), &vertNormals[0], GL_STATIC_DRAW );
+	vbos.vertIndeces.create( GL_ELEMENT_ARRAY_BUFFER, vertIndeces.getSizeInBytes(), &vertIndeces[0], GL_STATIC_DRAW );
+	vbos.vertCoords.create( GL_ARRAY_BUFFER, vertCoords.getSizeInBytes(), &vertCoords[0], GL_STATIC_DRAW );
+	vbos.vertNormals.create( GL_ARRAY_BUFFER, vertNormals.getSizeInBytes(), &vertNormals[0], GL_STATIC_DRAW );
 	if( vertTangents.size() > 1 )
-		vbos.vertTangents.Create( GL_ARRAY_BUFFER, vertTangents.getSizeInBytes(), &vertTangents[0], GL_STATIC_DRAW );
+		vbos.vertTangents.create( GL_ARRAY_BUFFER, vertTangents.getSizeInBytes(), &vertTangents[0], GL_STATIC_DRAW );
 	if( texCoords.size() > 1 )
-		vbos.texCoords.Create( GL_ARRAY_BUFFER, texCoords.getSizeInBytes(), &texCoords[0], GL_STATIC_DRAW );
+		vbos.texCoords.create( GL_ARRAY_BUFFER, texCoords.getSizeInBytes(), &texCoords[0], GL_STATIC_DRAW );
 	if( vertWeights.size() > 1 )
-		vbos.vertWeights.Create( GL_ARRAY_BUFFER, vertWeights.getSizeInBytes(), &vertWeights[0], GL_STATIC_DRAW );
+		vbos.vertWeights.create( GL_ARRAY_BUFFER, vertWeights.getSizeInBytes(), &vertWeights[0], GL_STATIC_DRAW );
 }
 
 

+ 20 - 7
src/Scene/ParticleEmitter.cpp

@@ -53,7 +53,7 @@ void ParticleEmitter::init( const char* filename )
 		btRigidBody::btRigidBodyConstructionInfo rbInfo( mass, mState, colShape, localInertia );
 		btRigidBody* body = new btRigidBody( rbInfo );
 		particles[i]->body = body;
-		body->setActivationState(ISLAND_SLEEPING);
+		//body->setActivationState(ISLAND_SLEEPING);
 		app->scene->getPhyWorld()->getDynamicsWorld()->addRigidBody( body, PhyWorld::CG_PARTICLE, PhyWorld::CG_MAP );
 	}
 }
@@ -69,20 +69,33 @@ void ParticleEmitter::update()
 	// deactivate the dead particles
 	for( Vec<Particle*>::iterator it=particles.begin(); it!=particles.end(); ++it )
 	{
-		Particle& part = **it;
+		Particle* part = *it;
 
-		part.lifeTillDeath -= crntTime-timeOfPrevUpdate;
-		if( part.lifeTillDeath < 1 )
+		part->lifeTillDeath -= crntTime-timeOfPrevUpdate;
+		if( part->lifeTillDeath < 1 )
 		{
-			part.body->setActivationState( ISLAND_SLEEPING );
+			part->body->setActivationState( ISLAND_SLEEPING );
 		}
 	}
 
+	//
+	DEBUG_ERR( particlesPerEmittion == 0 );
 	if( (crntTime - timeOfPrevEmittion) > emittionPeriod )
 	{
-		timeOfPrevEmittion = crntTime;
+		uint partNum = 0;
+		for( Vec<Particle*>::iterator it=particles.begin(); it!=particles.end(); ++it )
+		{
+			Particle* part = *it;
+			if( part->lifeTillDeath > 0 ) continue;
+
+			// reinit particle
+			//part->body->setActivationState(  );
 
-		//for(  )
+			++partNum;
+			if( partNum >= particlesPerEmittion ) break;
+		}
+
+		timeOfPrevEmittion = crntTime;
 	}
 
 	timeOfPrevUpdate = crntTime;