Exemplo n.º 1
0
//--------------------------------------------------------------
void testApp::update(){
    
    // This is how you loop through and delete a particle using iterators and vectors
    // Note how we don't put it++ up in the top of the loop.
    for( vector<Particle>::iterator it=pList.begin(); it!=pList.end(); ){
        it->update();
        
        if( it->bIsDead ){
            it = pList.erase(it);   // When we erase one, it returns the next particle automatically.  It's done the "it++" for us!
            ofLog( OF_LOG_NOTICE, "size is " + ofToString(pList.size()) );
        }else {
            it++;
        }
        
        // When the current batch of fireworks runs out, spawn a new batch at the location of the last firework.
        if (pList.size() <= 1) {
            for( int i=0; i<50; i++ ){
                if (it->pos.x > 0 && it->pos.x < ofGetWindowWidth() && it->pos.y > 0 && it->pos.y < ofGetWindowHeight()) {
                    addParticle(it->pos);
                }else {
                    addParticle(ofGetWindowSize()/2); // If the pos is offscreen, relocate to the center of the screen.
                }
            }
        }
    }
}
Exemplo n.º 2
0
//------------------------------------------------------------------------------
void HamiltonMatrix::computeTimDepMatrixElements(int basisSize)
{
    cout << "Setting up the time dependent part of the Hamilton matrix." << endl;
    int phase;
    int nStates = slaterDeterminants.size();

    bitset<BITS> newState;
    double interactionElement = 1.0 / sqrt(2 * w);

    for (int st = 0; st < nStates; st++) {
        for (int p = 0; p < basisSize-1; p++) {

            // <Psi'|Psi^p_{p+1}>
            newState = slaterDeterminants[st];
            phase = 1;

            newState = removeParticle(p + 1, newState);
            phase *= sign(p + 1, newState);

            newState = addParticle(p, newState);
            phase *= sign(p, newState);

            if (newState[BITS - 1] != 1) {
                for (int st2 = 0; st2 < (int)slaterDeterminants.size(); st2++) {
                    if (newState == slaterDeterminants[st2]) {
                        Ht(st, st2) += sqrt(p+1)*interactionElement * phase;
                        break;
                    }
                }
            }

            // <Psi'|Psi^{p+1}_p>
            newState = slaterDeterminants[st];
            phase = 1;

            newState = removeParticle(p, newState);
            phase *= sign(p, newState);

            newState = addParticle(p + 1, newState);
            phase *= sign(p + 1, newState);

            if (newState[BITS - 1] != 1) {
                for (int st2 = 0; st2 < (int)slaterDeterminants.size(); st2++) {
                    if (newState == slaterDeterminants[st2]) {
                        Ht(st, st2) += sqrt(p+1)*interactionElement * phase;
                        break;
                    }
                }
            }
        }
    }

#if DEBUG
    cout << "computeTimDepMatrixElements(int basisSize)" << endl;
    cout << Ht << endl;
#endif
}
Exemplo n.º 3
0
void HamiltonMatrix::computeMatrixElements() {
    cout << "Computing the Hamilton matrix " << endl;
    int s;
    int nStates = SLBit.size();

    //    int newState;
    bitset<BITS> newState;
    int i, j, k, l;
    double interactionElement;    
    H = zeros(nStates, nStates); 
    
    for (int st = 0; st < SLBit.size(); st++) {
        for (int b = 0; b < interactions.n_rows; b++) {
            newState = SLBit[st];
            i = interactions(b, 0);
            j = interactions(b, 1);
            k = interactions(b, 2);
            l = interactions(b, 3);
            interactionElement = interactions(b, 4);

            // Using the two body operator. Mathematics: a+(i)a+(j)a-(l)a-(k)|psi>
            s = 1;
            newState = removeParticle(k, newState);
            s *= sign(k, newState);

            newState = removeParticle(l, newState);
            s *= sign(l, newState);

            newState = addParticle(j, newState);
            s *= sign(j, newState);

            newState = addParticle(i, newState);
            s *= sign(i, newState);

            if (newState != 0) {
                // Searching for the new state to compute the matrix elements.
                for (int st2 = 0; st2 < SLBit.size(); st2++) {
                    if (newState == SLBit[st2]) {
                        H(st, st2) += interactionElement * s;
                    }
                }
            }
        }

        // One body energies
        H(st, st) += oneBodyEnergy(st);
    }

    // Symmetrizing the Hamilton matrix
    for (int i = 0; i < H.n_rows; i++) {
        for (int j = 0; j < i; j++) {
            H(j, i) = H(i, j);
        }
    }
    cout << "Completed generating the Hamilton matrix" << endl;
}
//--------------------------------------------------------------
void testApp::draw(){
    for( vector<Particle>::iterator it = pList.begin(); it!=pList.end(); it++){
        it->draw();
    }
    
    if(click){
        addParticle();
        addParticle();
    }
    
}
Exemplo n.º 5
0
void timer(int)
{
	display();
	if(PRESSED_LEFT && !SPEED_PARTICLES)
	{
		addParticle(10, 3); //add tiny particle
		PRESSED_LEFT = false;
	}

	if(PRESSED_RIGHT)
	{
		addParticle(10000, 10, 0); //add huge particle
		PRESSED_RIGHT = false;
	}

	if(PRESSED_MIDDLE)
		removeParticles(); //remove all particles

	for(int i = 0; i < particles.size(); i++)
	{
		Particle &p = particles[i];
		bool not_fall = true;
		for(int j = 0; j < particles.size(); j++)
		{
			if(j == i || p.m >= 10000) // we consider the 10000 as infinit (big mass) so this particles won't move
				continue;

			const Particle &p1 = particles[j];

			float d = sqrt((p1.x - p.x)*(p1.x - p.x) + (p1.y - p.y)*(p1.y - p.y));

			if(d > p1.r)
			{
				p.vx += 0.03 * p1.m / (d*d) * (p1.x - p.x)/d; //f = ma => a = f/m
				p.vy += 0.03 * p1.m / (d*d) * (p1.y - p.y)/d;
			}
			else
				not_fall = false;
		}

		if(not_fall)
		{
			p.x += p.vx;
			p.y += p.vy;
		}
		else
			particles.erase(particles.begin()+i);
	}

	glutTimerFunc(1, timer, 0);
}
Exemplo n.º 6
0
void ParticleEmitter::addEffect(EffectType effect, const point &pos)
{
    int i, len;
	switch (effect) {
		case EFFECT_BLOODSQUIRT:
			{
				len = randint(14,28);
				for (i=0; i<len; i++) {
					Particle* p;
					if (i < 20) {
						p = addParticle(Particle::BLOOD_SMALL);
					} else {
						p = addParticle(Particle::BLOOD_BIG);
					}
					if (p != NULL) {
						p->setCenter(pos);
						point dir = {randint(-PX/2, PX/2), randint(-PX, 0)};
						p->setVelocity(dir.x, dir.y);
						p->setAcceleration(0, PX/16); // gravity
					}
				}
				break;
			}
		case EFFECT_NOTE1:
		case EFFECT_NOTE2:
		case EFFECT_NOTE3:
		case EFFECT_NOTE4:
		case EFFECT_NOTE5:
		case EFFECT_OBSTACLE:
			{
				Particle::ParticleType particleType;
				if (effect == EFFECT_NOTE1) particleType = Particle::NOTE1;
				else if (effect == EFFECT_NOTE2) particleType = Particle::NOTE2;
				else if (effect == EFFECT_NOTE3) particleType = Particle::NOTE3;
				else if (effect == EFFECT_NOTE4) particleType = Particle::NOTE4;
				else if (effect == EFFECT_NOTE5) particleType = Particle::NOTE5;
				else if (effect == EFFECT_OBSTACLE) particleType = Particle::OBSTACLE;
				len = randint(20,30);
				for (i=0; i<len; i++) {
					Particle* p = addParticle(particleType);
					if (p != NULL) {
						p->setCenter(pos);
						point dir = {randint(-PX, PX), randint(-PX*2, 0)};
						p->setVelocity(dir.x, dir.y);
						p->setAcceleration(0, PX/16); // gravity
					}
				}
				break;
			}
	}
}
void  ofxParticleControlledEmitter::fireOnce(int x, int y, int vx, int vy)
{
	// If the emitter is active and the emission rate is greater than zero then emit
	// particles
	
	
	// Set variables
	sourcePosition.x = x;
	sourcePosition.y = y;
	sourcePositionVariance.x = vx;
	sourcePositionVariance.y = vy;
	
	
	startParticleEmitter();
	
	emissionRate = maxParticles / particleLifespan;
	
	GLfloat aDelta = (ofGetElapsedTimeMillis()-lastUpdateMillis)/1000.0f;
	
	if(active && emissionRate) {
		float rate = 1.0f/emissionRate;
		emitCounter += aDelta;
		while(particleCount < maxParticles && emitCounter > rate) {
			addParticle();
			emitCounter -= rate;
			particlesFired++;
			particlesLeft--;
		}
		
		
	}
	
}
void ShaderParticleRenderer::_updateRenderQueue(RenderQueue* queue, Ogre::list<Particle*>::type& currentParticles, bool cullIndividually)
{
    // be sure that we have enough space in buffers
    if (!allocateBuffers(currentParticles.size())) {
        assert(0 && "Cannot allocate buffers");
        return;
    }

    // update vertex data
    mRadius = 0.0f;
    if (!currentParticles.empty()) {
        HardwareVertexBufferSharedPtr pVB = mVertexData->vertexBufferBinding->getBuffer(0);
        uchar* pDataVB  = reinterpret_cast<uchar*>(pVB->lock(HardwareBuffer::HBL_DISCARD));
        for (Ogre::list<Particle*>::type::iterator it=currentParticles.begin(); it!=currentParticles.end(); ++it) {
            Particle* pParticle = *it;
            addParticle(pDataVB, *pParticle);
            pDataVB += 4 * mVertexSize;

            float fDist = (mParentNode != NULL) ? mParentNode->getPosition().distance(pParticle->mPosition) : pParticle->mPosition.length();
            if (fDist > mRadius)
                mRadius = fDist;
        }
        pVB->unlock();
    }

    // setup counts
    mVertexData->vertexCount = currentParticles.size() * 4;
    mIndexData->indexCount   = currentParticles.size() * 6;

    // update render queue
    queue->addRenderable(this, mRenderQueueID);
}
Exemplo n.º 9
0
RobotRocketEffect::RobotRocketEffect(GLfloat x, GLfloat y, GLfloat width, GLfloat height, int strength, int count) : GLParticleEffect(strength, strength)
{
  mCount = count;
  mPos.x = x;
  mPos.y = y;
  mRotation.x = 0.0f;
  mRotation.y = 0.0f;
  mAngle = 0.0f;
  mAlpha = 1.0f;

  mWidth = width;
  mHeight = height;
  mVelocity.x = 0.0f;
  mVelocity.y = 0.0f;

  recalculateVectors();
  mMaxDistance = (msrcMid - mdestMid).len();

  for(int i = 0; i < mCount; i++) {
    GLParticleDummy * p = addParticle();
    p->moveTo(0.0f, 0.0f);
    mLifeTime[i] = 0;
  }
  mColor[0] = yellow - red;
  mColor[1] = blue - yellow; 
  mColor[2] = GLvector3f(0.0f, 0.0f, 0.0f); 
}
Exemplo n.º 10
0
  void IncompressibleCloud::inject() {
    if(runTime_.time().value()<tStart || runTime_.time().value()>tEnd) {
      return;
    }

    scalar prop=random.scalar01();

    if(prop<thres) {
      vector tmp=(random.vector01()-vector(0.5,0.5,0.5))*2;
      vector pos=center+tmp*r0;

      tmp=vector(random.GaussNormal(),random.GaussNormal(),random.GaussNormal())/sqrt(3.);
      vector vel=tmp*vel0+vel1;

      scalar d=fabs(random.GaussNormal())*d1+d0;

      label cellI=mesh_.findCell(pos);

      if(cellI>=0) {
	HardBallParticle* ptr=new HardBallParticle(*this,pos,cellI,d,vel);
        
        ptr->stepFraction() = 1;

	addParticle(ptr);
        
        injectedInModel_++;
      }
    }
  }
Exemplo n.º 11
0
void ParticleSystem::initSmokeParticle(Vector2 const& initialPosition, float initialRotation, Vector2 const& initialVelocity, float positionSpread)
{
    // Grab a particle.
    Particle* p = addParticle(2, true);
    if(!p) return;
        
    // Properties about smoke particles.

    // Set basic particle properties.
    p->mCallback = smokeParticleCb;
    p->mAlpha = 1.0f;

    // Setup image.
    p->mImage.setImage(gImageLibrary->getImage(PARTICLE_SMOKE_00));
    p->mImage.mCenter = initialPosition;
    p->mImage.mRotation = initialRotation;
    p->mImage.makeDirty();
    
    // Offset center.
    if(positionSpread != 0)
    {
        p->mImage.mCenter += Vector2(((float)rand() / RAND_MAX - 0.5) * positionSpread, ((float)rand() / RAND_MAX - 0.5) * positionSpread);
    }
    
    // Setup velocity. InitialVelocity from vehicle plus particle speed rotated for direction.
    p->mVelocity = initialVelocity * Transform2::createRotation(initialRotation);
}
Exemplo n.º 12
0
ParticleSystem::ParticleSystem()
    : m_rate(5000),
      m_nbMax(50000.0),
      m_maxTimeAlive(5000.0),
      m_started(false),
      m_spread(40),
      m_speed(8),
      m_gravity(2),
      m_down(vec3{0.0f, -1.0f, 0.0f}),
      gl_positions(NULL),
      gl_velocities(NULL),
      gl_ages(NULL),
      m_pointSize(1)
{
    addParticle();

    m_orientation.x = 0;
    m_orientation.y = 1;
    m_orientation.z = 0;

    m_position.x = 0;
    m_position.y = 0;
    m_position.z = 0;

    m_randomG.initSeed(clock());

    gl_shader = "Basic";
    gl_texId = -1;

    m_transparent = true;
}
Exemplo n.º 13
0
void mouse(int button, int state, int x, int y)
{
	//set the coordinates
	Mx = x - 250;
	My = y - 250;

	//add speed particles by line draging
	if(SPEED_PARTICLES)
	{
		if(line.x2 != 0 && line.y2 != 0 && state == GLUT_UP && PRESSED_LEFT)
			addParticle(100, 5, 1, line.x1 - line.x2, line.y1 - line.y2); //add a speed particle
		else
		{
			line.x1 = line.x2 = Mx;
			line.y1 = line.y2 = My;
		}
	}

	//check which button is pressed
	if(button == GLUT_LEFT_BUTTON)
		PRESSED_LEFT = state == GLUT_DOWN;
	else if(button == GLUT_RIGHT_BUTTON)
		PRESSED_RIGHT = state == GLUT_DOWN;
	else if(button == GLUT_MIDDLE_BUTTON)
		PRESSED_MIDDLE = state == GLUT_DOWN;
}
Exemplo n.º 14
0
	void ParticleSystem::update(sf::Time dt)
	{
		if (mEmitterActive && mInitializer && mAffector)
		{
			for (unsigned i = mParticles.size(); i < mMaxParticles; i++)
				addParticle();
			//if (mParticles.size() < mMaxParticles || mMaxParticles == 0)
			//	addParticle();

			for (auto& particle : mParticles) {
				(*mAffector)(particle, dt);
				particle.lifetime -= dt;
			}
			if (!mParticles.empty() && mParticles.front().lifetime <= sf::Time::Zero)
				mParticles.erase(mParticles.begin());

			computeVertices();
		}
		else
			std::cout << "\n\nUnable to update ParticleSystem\n"
			          << "3 possible causes:\n"
			          << "  - The Emitter hasn't been activated\n"
			          << "  - The Initializer hasn't been set\n"
			          << "  - The Affector hasn't been set\n\n";
	}
Exemplo n.º 15
0
void LenJonSim::addline(QLineF l,double dx)
{

    double startx, starty, endx, endy, distance, step,x,y;

    QPointF *p1 = new QPointF(l.p1().x(),l.p1().y());
    qDebug()<<p1->x()<<p1->y();
    QPointF *p2 = new QPointF(l.p2().x(),l.p2().y());

    startx = p1->x();
    starty = p1->y();
    endx = p2->x();
    endy = p2->y();

    distance = sqrt(pow(endx - startx,2)+pow(endy-starty,2));


    step = (dx / distance);
    for(double i = 0; i <= 1; i+=step){
        x = startx + (endx - startx) * i;
        y = starty + (endy - starty) * i;
        addParticle(x,y);
        nonMovableParticles++;
    }
}
Exemplo n.º 16
0
//--------------------------------------------------------------
void testApp::setupOrbits() {
    
    // Matt adds: clear the vectors on setup (allows restarting).
    particleList.clear();
    setOfOrbits.clear();
    
    ofSetVerticalSync(true);
    ofSeedRandom();
    ofBackground( 0);
    
    
    //    acc.set(0);
    
    for( int i = 0; i < 18; i++){
        
        _size = ofRandom(2, 5);
        pos.set(ofRandom(ofGetWindowWidth()), ofRandom(ofGetWindowHeight()));
        vel.set(ofRandom(0,.9));
        rotDia = ofRandom(100,800);
        addParticle();
        addOrbit();
        
        
    }
}
Exemplo n.º 17
0
//--------------------------------------------------------------
void testApp::setup(){
    
    ofSetVerticalSync(true);
    ofSeedRandom();
  
    
    for( int i = 0; i < 17; i++){
        
        
         float coe = 1.02 * powf(1.19, i);
        float _orbit;
        _orbit = (40);
        diameterList.push_back( _orbit * coe );
        
    }
    
    for( int i = 0; i < 17; i++){
        
        _size = ofRandom(2, 5);
        pos.set(ofRandom(ofGetWindowWidth()), ofRandom(ofGetWindowHeight()));
        vel.set(ofRandom(0,.9));
       
        
        
        addOrbit(diameterList[i] );
        addParticle(diameterList[i] );
    }
    
}
Exemplo n.º 18
0
void ParticleEmitter::init()
{
	for (int i = 0; i < count; i++)
	{
		addParticle();
	}
}
TEST(TransferParticlesToPointCloudBehaviorTests, UpdateTest)
{
	auto runtime = std::make_shared<Framework::Runtime>();
	runtime->addManager(std::make_shared<Framework::BehaviorManager>());
	runtime->addManager(std::make_shared<Physics::PhysicsManager>());

	auto sceneElement = std::make_shared<Framework::BasicSceneElement>("Element");

	auto particles = std::make_shared<Particles::SphRepresentation>("Particles");
	particles->setMaxParticles(10);
	particles->setMassPerParticle(1.0);
	particles->setDensity(1.0);
	particles->setGasStiffness(1.0);
	particles->setKernelSupport(1.0);
	for (size_t particleId = 0; particleId < 10; particleId++)
	{
		particles->addParticle(Vector3d(static_cast<double>(particleId), 0.0, 0.0), Vector3d::Zero(), 100000);
	}
	sceneElement->addComponent(particles);

	auto pointCloud = std::make_shared<Graphics::OsgPointCloudRepresentation>("Graphics");
	sceneElement->addComponent(pointCloud);

	auto behavior = std::make_shared<TransferParticlesToPointCloudBehavior>("Behavior");
	behavior->setSource(particles);
	behavior->setTarget(pointCloud);
	sceneElement->addComponent(behavior);

	auto scene = runtime->getScene();
	scene->addSceneElement(sceneElement);

	particles->update(0.1);
	behavior->update(0.1);
	auto sourceVertices = particles->getParticles().safeGet()->getVertices();
	auto targetVertices = pointCloud->getVertices()->getVertices();
	ASSERT_EQ(sourceVertices.size(), targetVertices.size());

	auto sourceVertex = sourceVertices.begin();
	auto targetVertex = targetVertices.begin();
	for (; sourceVertex != sourceVertices.end(); ++sourceVertex, ++targetVertex)
	{
		EXPECT_TRUE(sourceVertex->position.isApprox(targetVertex->position));
	}

	particles->removeParticle(0);
	particles->removeParticle(1);
	particles->update(0.1);
	behavior->update(0.1);

	sourceVertices = particles->getParticles().safeGet()->getVertices();
	targetVertices = pointCloud->getVertices()->getVertices();
	ASSERT_EQ(sourceVertices.size(), targetVertices.size());

	sourceVertex = sourceVertices.begin();
	targetVertex = targetVertices.begin();
	for (; sourceVertex != sourceVertices.end(); ++sourceVertex, ++targetVertex)
	{
		EXPECT_TRUE(sourceVertex->position.isApprox(targetVertex->position));
	}
}
Exemplo n.º 20
0
	void ParticleManager::addRandomParticles(unsigned int count){
		for(size_t i = 0; i < count; ++i) {
			glm::vec3 position = glm::vec3(1.2f, glm::linearRand(-1.f,5.f), 0.f);//glm::vec3(glm::linearRand(-5.f,5.f), glm::linearRand(0.f,5.f), glm::linearRand(-5.f,5.f));
			glm::vec3 speed = glm::vec3(0.f, 0.f, 0.f);
			glm::vec3 force = glm::vec3(0.f, 0.f, 0.f);
			glm::vec3 color = glm::vec3(glm::linearRand(0.f,1.f),glm::linearRand(0.f,1.f),glm::linearRand(0.f,1.f));
            addParticle(position, speed, glm::linearRand(0.01f,0.5f), force, color);
        }
	}
Exemplo n.º 21
0
//--------------------------------------------------------------
void testApp::setup(){
    ofSetVerticalSync(true);
    ofSetFrameRate(60);
    ofBackground(255);
    
    for (int i = 0; i < 1000; i++){
        addParticle();
    }
}
Exemplo n.º 22
0
void Simulation::generateRandomParticles(float range, bool canBeNegative) {
    int index = 0;
    while(index < particlesNumber) {
        Particle p = generateRandomParticle(range, canBeNegative);
        p.mass = 0.000001f;
        addParticle(p);
        index ++;
    }
}
Exemplo n.º 23
0
LeadSkeleton::LeadSkeleton (Field3D * const s, const CPoint& position, const CPoint& rootMoveFactor,
			    uint pls, float u, float noiseIncrement, float noiseMin, float noiseMax) :
  Skeleton (s, position, rootMoveFactor,pls),
  m_noiseGenerator(noiseIncrement, noiseMin, noiseMax)
{
  m_u = u;
  m_perturbateCount=0;
  addParticle(&m_root);
}
Exemplo n.º 24
0
void ParticleSystem::emit(uint32 num)
{
	if (!active)
		return;

	num = std::min(num, maxParticles - activeParticles);

	while (num--)
		addParticle(1.0f);
}
Exemplo n.º 25
0
void Emitter::update()
{
    addParticle();
    if(!particleList.empty()){
        for(int i =0; i<particleList.size(); i++)
        {
            particleList.at(i)->update();
        }
    }
}
Exemplo n.º 26
0
// ----------------------------------------------------- PARTICLE MANAGMENT
void MSAParticleSystem3D::addParticles( Vec3f _pos, int _count)
{
    int max_x = width/2;
    int max_y = height/2;
    
    for(int i=0; i<_count; i++)
//		addParticle( Vec3f( _pos.x + ofRandom(-max_x, max_x), _pos.y + ofRandom(-max_y,max_y), _pos.z + 0) ); //ofRandom(0,-max_y*2)) ); // + Rand::randVec3f() * 300 );
        addParticle( Vec3f( _pos.x, _pos.y, _pos.z) ); //ofRandom(0,-max_y*2)
//		addParticle( Vec3f( _pos.x , _pos.y, _pos.z ) ); // + Rand::randVec3f() * 300 );
}
Exemplo n.º 27
0
//--------------------------------------------------------------
void testApp::setup(){
    ofSetVerticalSync( true );
    ofBackground( 0 );
    
    dest.set( ofRandomWidth(), ofRandomHeight() );
    
    for (int i = 0; i < 1; i++) {
        addParticle();
    }
}
Exemplo n.º 28
0
//--------------------------------------------------------------
void testApp::setup(){
    ofBackground(0);
    ofSetVerticalSync(true);
    ofSetFrameRate(60);
    
    // make 50 particles up front!
    for( int i=0; i<50; i++ ){
        addParticle(ofGetWindowSize()/2);
    }
}
Exemplo n.º 29
0
void ParticleSystem::addExplosion(QPointF p, qreal r, qreal v,
                                  uint particleCount) {
  for (uint i = 0; i < particleCount; i++) {
    qreal angle = i * 2 * M_PI / particleCount;
    qreal dx = cos(angle);
    qreal dy = sin(angle);

    addParticle({p.x(), p.y(), r, dx * v, dy * v, 0.0, 0.0, 60, time()});
  }
}
Exemplo n.º 30
0
void ParticleManager::addNodeParticle(IGameDef* gamedef, scene::ISceneManager* smgr,
		LocalPlayer *player, v3s16 pos, const TileSpec tiles[])
{
	// Texture
	u8 texid = myrand_range(0, 5);
	video::ITexture *texture;
	struct TileAnimationParams anim;
	anim.type = TAT_NONE;

	// Only use first frame of animated texture
	if (tiles[texid].material_flags & MATERIAL_FLAG_ANIMATION)
		texture = tiles[texid].frames[0].texture;
	else
		texture = tiles[texid].texture;

	float size = rand() % 64 / 512.;
	float visual_size = BS * size;
	v2f texsize(size * 2, size * 2);
	v2f texpos;
	texpos.X = ((rand() % 64) / 64. - texsize.X);
	texpos.Y = ((rand() % 64) / 64. - texsize.Y);

	// Physics
	v3f velocity((rand() % 100 / 50. - 1) / 1.5,
			rand() % 100 / 35.,
			(rand() % 100 / 50. - 1) / 1.5);

	v3f acceleration(0,-9,0);
	v3f particlepos = v3f(
		(f32) pos.X + rand() %100 /200. - 0.25,
		(f32) pos.Y + rand() %100 /200. - 0.25,
		(f32) pos.Z + rand() %100 /200. - 0.25
	);

	Particle* toadd = new Particle(
		gamedef,
		smgr,
		player,
		m_env,
		particlepos,
		velocity,
		acceleration,
		rand() % 100 / 100., // expiration time
		visual_size,
		true,
		false,
		false,
		texture,
		texpos,
		texsize,
		anim,
		0);

	addParticle(toadd);
}