示例#1
0
文件: particle.c 项目: kireerik/siva
int animateParticle(Particle **p) {
	if (0 < (*p)->animation.preDuration)
		(*p)->animation.preDuration -= 1000 / fps.fps;
	else if ((*p)->animation.startTime == NULL) {
		(*p)->animation.preDuration = 0;
		(*p)->animation.startTime = timeInMillSec();
	}

	if ((*p)->animation.startTime != NULL) {
		double time = timeInMillSec() - (*p)->animation.startTime;
		if (time <= (*p)->animation.duration) {
			double animationType;
			if (strcmp((*p)->animation.type, "linear") == 0)
				animationType = time;
			(*p)->state.p.x = (*p)->animation.start.p.x + ((*p)->animation.end.p.x - (*p)->animation.start.p.x) / (*p)->animation.duration * animationType;
			(*p)->state.p.y = (*p)->animation.start.p.y + ((*p)->animation.end.p.y - (*p)->animation.start.p.y) / (*p)->animation.duration * animationType;
			(*p)->state.v.x = (*p)->animation.start.v.x + ((*p)->animation.end.v.x - (*p)->animation.start.v.x) / (*p)->animation.duration * animationType;
			(*p)->state.v.y = (*p)->animation.start.v.y + ((*p)->animation.end.v.y - (*p)->animation.start.v.y) / (*p)->animation.duration * animationType;
			(*p)->state.size = (*p)->animation.start.size + ((*p)->animation.end.size - (*p)->animation.start.size) / (*p)->animation.duration * animationType;
			(*p)->state.opacity = (*p)->animation.start.opacity + ((*p)->animation.end.opacity - (*p)->animation.start.opacity) / (*p)->animation.duration * animationType;
			(*p)->state.rotation = (*p)->animation.start.rotation + ((*p)->animation.end.rotation - (*p)->animation.start.rotation) / (*p)->animation.duration * animationType;

			(*p)->state.texture.outline.size = (int) ((*p)->animation.start.texture.outline.size + ((*p)->animation.end.texture.outline.size - (*p)->animation.start.texture.outline.size) / (*p)->animation.duration * animationType);
			(*p)->state.texture.outline.color.r = (int) ((*p)->animation.start.texture.outline.color.r + ((*p)->animation.end.texture.outline.color.r - (*p)->animation.start.texture.outline.color.r) / (*p)->animation.duration * animationType);
			(*p)->state.texture.outline.color.g = (int) ((*p)->animation.start.texture.outline.color.g + ((*p)->animation.end.texture.outline.color.g - (*p)->animation.start.texture.outline.color.g) / (*p)->animation.duration * animationType);
			(*p)->state.texture.outline.color.b = (int) ((*p)->animation.start.texture.outline.color.b + ((*p)->animation.end.texture.outline.color.b - (*p)->animation.start.texture.outline.color.b) / (*p)->animation.duration * animationType);
			(*p)->state.texture.outline.color.a = (int) ((*p)->state.opacity);

			(*p)->state.texture.color.r = (int) ((*p)->animation.start.texture.color.r + ((*p)->animation.end.texture.color.r - (*p)->animation.start.texture.color.r) / (*p)->animation.duration * animationType);
			(*p)->state.texture.color.g = (int) ((*p)->animation.start.texture.color.g + ((*p)->animation.end.texture.color.g - (*p)->animation.start.texture.color.g) / (*p)->animation.duration * animationType);
			(*p)->state.texture.color.b = (int) ((*p)->animation.start.texture.color.b + ((*p)->animation.end.texture.color.b - (*p)->animation.start.texture.color.b) / (*p)->animation.duration * animationType);
			(*p)->state.texture.color.a = (int) ((*p)->state.opacity * 255);
		} else {
			if ((*p)->animation.reverse == 1) {
				State tmpState = (*p)->animation.start;
				(*p)->animation.start = (*p)->animation.end;
				(*p)->animation.end = tmpState;
			}
			if ((*p)->animation.repeat == NULL || 1 < (*p)->animation.repeat) {
				if ((*p)->animation.repeat != NULL)
					(*p)->animation.repeat--;
				(*p)->animation.startTime = NULL;
			} else {
				// add new emitter
				if (0 < (*p)->emitter.reStart) {
					(*p)->emitter.reStart--;
					(*p)->emitter.p.x = (*p)->state.p.x;
					(*p)->emitter.p.y = (*p)->state.p.y;
					addEmitter((*p)->emitter);
				}
				// free up particle
				return 1;
			}
		}
	}
	return 0;
}
示例#2
0
void Main::onInitialize() {
    auto scene = addScene(new dt::Scene("testscene"));

    dt::ResourceManager::get()->addResourceLocation("sinbad.zip","Zip", true);
    dt::ResourceManager::get()->addResourceLocation("particle/","FileSystem", true);
    Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

    // make a scene
    auto camnode = scene->addChildNode(new dt::Node("camnode"));
    camnode->setPosition(Ogre::Vector3(0, 2, 10));
    camnode->addComponent(new dt::CameraComponent("cam"))->lookAt(Ogre::Vector3(0, 2, 0));;

    auto p = scene->addChildNode(new dt::Node("p"));

    p->setScale(0.2);
    auto mesh = p->addComponent(new dt::MeshComponent("Sinbad.mesh"));
    mesh->setAnimation("RunBase");
    mesh->setLoopAnimation(true);
    mesh->playAnimation();

    auto path =
        p->addComponent(new dt::FollowPathComponent(dt::FollowPathComponent::LOOP));
    path->addPoint(Ogre::Vector3(-10, 0, 0));
    path->addPoint(Ogre::Vector3(10, 0, 0));
    path->setDuration(2.f);
    path->setFollowRotation(true);

    // create the particle system
    auto p_sys = p->addComponent(new dt::ParticleSystemComponent("p_sys"));
    p_sys->setMaterialName("Test/Particle");
    p_sys->setParticleCountLimit(1000);
    p_sys->getOgreParticleSystem()->setDefaultDimensions(0.03, 0.03);

    Ogre::ParticleEmitter* e = p_sys->addEmitter("emit1", "Point");
    e->setAngle(Ogre::Degree(10));
    e->setColour(Ogre::ColourValue(1.f, 0.6f, 0.f), Ogre::ColourValue(0.2f, 0.8f, 0.2f));
    e->setEmissionRate(100);
    e->setParticleVelocity(3.f, 4.f);
    e->setTimeToLive(1.f, 2.f);

    p_sys->addScalerAffector("scaler", 1.05);
    p_sys->addLinearForceAffector("force", Ogre::Vector3(0, 5, 0));

    Ogre::ParticleAffector* a = p_sys->addAffector("colour_interpolator", "ColourInterpolator");
    a->setParameter("time0", "0");
    a->setParameter("colour0", "1 1 0 1");
    a->setParameter("time1", "0.5");
    a->setParameter("colour1", "1 0.3 0 1");
    a->setParameter("time2", "1");
    a->setParameter("colour2", "1 0 0 0");
}
示例#3
0
文件: init.c 项目: kireerik/siva
void addExamples() {
	int db = 50;

	for (int i = 1; i < 50; i += 12 + rand()%10)
		for (int j = 1; j < 50; j += 12 + rand()%10)
			addEmitter(newEmitter("smoke", 80 * 1000, 0, "smoke", 100, 400 + i, 400 + j, 0, 360, 0, 10, 14));

	addEmitter(newEmitter("ball", 0, 0, "ball", 100, 0, 0, 0, 0, 0, 0, 0));

	addEmitterGroup("img/siva.png", .4, .4, .01, newEmitter("siva", 0, 0, "siva", 1, (1-.618) * w.width, .618 * w.height, 0, 360, 0, 0, 0));

	int wait = 50 * 1000;
	addEmitter(newEmitter("sun", wait, 0, "sun", 1000, .618 * w.width, (1-.618) * w.height, 0, 360, 50, 30, 100));
	addEmitter(newEmitter("sun", wait, 0, "sun", 100, .618 * w.width - 20, (1-.618) * w.height -20, 0, 360, 0, 10, 10));
	addEmitter(newEmitter("sun", wait, 0, "sun", 100, .618 * w.width + 20, (1-.618) * w.height - 20, 0, 360, 0, 10, 10));
	addEmitter(newEmitter("sun", wait, 0, "sun", 100, .618 * w.width, (1-.618) * w.height + 20, 0, 360, 10, 10, 10));

	for(int i = 1; i <= 4; i++) {
		char str[20];
		sprintf(str, "img/idezet%i.png", i);
		addEmitterGroup(str, 2, 2, .003, newEmitter(str, i * 8 * 1000, 0, "siva", 1, w.width / 2.0, w.height / 2.0, 0, 360, 0, 0, 0));
	}

	//for(int j = 1; j <= 60; j+=50)
	//	for(int i = 1; i <= w.width; i+=50)
	//		addEmitter(newEmitter("water", rand()%1000, 0, "water", 1, i, .9 * w.height + j, 0, 0, 0, 3, 6));
	//addEmitter(newEmitter("smoke", 0 * 1000, 4, "smoke", 10, 400, 200, 0, 360, 0, 5, 10));

	for (int i = 1; i <= 4; i++)
		addEmitter(newEmitter("demoBoubleGroup", 0 * 1000, 0, "bouble", db, i * 100, i * 100, 0, 360, 0, 50, 50));
	addEmitter(newEmitter("demoBoubleGroup5", 40 * 1000, 0, "bouble", 2 * db, 300, 600, 0, 260, 0, 150, 200));

	addEmitter(newEmitter("centeredBouble", 40 * 1000, 0, "bouble", db, w.width / 2.0, w.height / 2.0, 0, 360, 0, 50, 50));
	addEmitter(newEmitter("centeredWind", 40 * 1000, 0, "wind", db, w.width / 2, w.height / 2, 45, 4, 0, 400, 400));

}
示例#4
0
	CLUAEffect::CLUAEffect(const CLUAEffect &luaEffect)
	{				
		for (GLuint i=0; i<luaEffect.emitters.size(); i++)
		{
			addEmitter();

			string init = luaEffect.emitters[i]->getInitLUAFile();
			string update = luaEffect.emitters[i]->getUpdateLUAFile();
			string effDir = luaEffect.emitters[i]->getEffectDirectory();

			GLint mIndex = max(init.find_last_of('/'),init.find_last_of('\\'))+1;
			getEmittter(i)->setInitLUAFile(effDir,init.substr(mIndex));

			mIndex = max(update.find_last_of('/'),update.find_last_of('\\'))+1;
			getEmittter(i)->setUpdateLUAFile(effDir,update.substr(mIndex));			
		}
		init();
	}
示例#5
0
ParticleSystem& ParticleSystem::operator=(const ParticleSystem& rhs)
{
    // Blank this system's emitters & affectors
    removeAllEmitters();
    removeAllEmittedEmitters();
    removeAllAffectors();

    // Copy emitters
    for (unsigned short i = 0; i < rhs.getNumEmitters(); ++i)
    {
        ParticleEmitter* rhsEm = rhs.getEmitter(i);
        ParticleEmitter* newEm = addEmitter(rhsEm->getType());
        rhsEm->copyParametersTo(newEm);
    }

    // Copy affectors
    /*for(unsigned short i = 0; i < rhs.getNumAffectors(); ++i)
    {
        ParticleAffector* rhsAf = rhs.getAffector(i);
        ParticleAffector* newAf = addAffector(rhsAf->getType());
        //rhsAf->copyParametersTo(newAf);
    }*/

    setParticleQuota(rhs.getParticleQuota());
    setEmittedEmitterQuota(rhs.getEmittedEmitterQuota());
    setDefaultDimensions(rhs.mDefaultWidth, rhs.mDefaultHeight);
    mCullIndividual = rhs.mCullIndividual;
    mSorted = rhs.mSorted;
    mLocalSpace = rhs.mLocalSpace;
    mIterationInterval = rhs.mIterationInterval;
    mIterationIntervalSet = rhs.mIterationIntervalSet;
    mNonvisibleTimeout = rhs.mNonvisibleTimeout;
    mNonvisibleTimeoutSet = rhs.mNonvisibleTimeoutSet;
    // last frame visible and time since last visible should be left default

    setRenderer(rhs.getRendererName());
    // Copy settings
    /*if (mRenderer && rhs.getRenderer())
    {
        //rhs.getRenderer()->copyParametersTo(mRenderer);
    }*/

    return *this;
}
示例#6
0
文件: System.cpp 项目: Jose-Luis/mpe
//------------------------------------------------------------------------------
//       Class:  System
//      Method:  initFromFile
// Description:  load the emitter from an xml file
//------------------------------------------------------------------------------
bool System::initFromFile(std::string theFilename)
{
   tinyxml2::XMLDocument aFile;

   if (tinyxml2::XML_NO_ERROR != aFile.LoadFile(theFilename.c_str()))
   {
      return false;
   }

   tinyxml2::XMLElement* aEmittersNode {aFile.FirstChildElement("emitters")};

   if(!aEmittersNode)
   {
      return false;
   }

   tinyxml2::XMLElement* aEmitterNode {aEmittersNode->FirstChildElement("emitter")};

   while(aEmitterNode)
   {
      Emitter aEmitter {aEmitterNode->Attribute("id")};
      std::string aShape {aEmitterNode->Attribute("shape")};

      if(aShape == "CIRCLE")
      {
         aEmitter.setShape(Emitter::CIRCLE);
      }
      else if (aShape == "RECTANGLE")
      {
         aEmitter.setShape(Emitter::RECTANGLE);
      }

      std::string aDispersion {aEmitterNode->Attribute("dispersion")};

      if(aDispersion == "LINEAR")
      {
         aEmitter.setDispersion(Emitter::LINEAR);
      }
      else if(aDispersion == "RADIAL")
      {
         aEmitter.setDispersion(Emitter::RADIAL);
      }
      else if(aDispersion == "REFLECT")
      {
         aEmitter.setDispersion(Emitter::REFLECT);
      }
      else if(aDispersion == "RANDOM")
      {
         aEmitter.setDispersion(Emitter::RANDOM);
      }
      else if(aDispersion == "STATIC")
      {
         aEmitter.setDispersion(Emitter::STATIC);
      }

      tinyxml2::XMLElement* aTextRectNode {aEmitterNode->FirstChildElement("textRect")};

      if(!aTextRectNode)
      {
         return false;
      }

      aEmitter.setTextRect(TextRect {aTextRectNode->IntAttribute("x"),
                                     aTextRectNode->IntAttribute("y"),
                                     aTextRectNode->IntAttribute("width"),
                                     aTextRectNode->IntAttribute("height")
                                    });

      tinyxml2::XMLElement* aGeneratorNode {aEmitterNode->FirstChildElement("ranges")};

      if(!aGeneratorNode)
      {
         return false;
      }

      tinyxml2::XMLElement* aNode {aGeneratorNode->FirstChildElement("focusTOL")};

      if(!aNode)
      {
         return false;
      }

      aEmitter.setGeneratorFocusTOL(aNode->FloatAttribute("min"),
                                aNode->FloatAttribute("max"));

      aNode = aGeneratorNode->FirstChildElement("focusWidth");

      if(!aNode)
      {
         return false;
      }

      //float aFloat{aNode->FloatAttribute("min")};
      //float aFloat1{aNode->FloatAttribute("max")};

      aEmitter.setGeneratorFocusWidth(aNode->FloatAttribute("min"),
                                  aNode->FloatAttribute("max"));

      aNode = aGeneratorNode->FirstChildElement("focusHeight");

      if(!aNode)
      {
         return false;
      }

      aEmitter.setGeneratorFocusHeight(aNode->FloatAttribute("min"),
                                   aNode->FloatAttribute("max"));

      aNode = aGeneratorNode->FirstChildElement("focusNP");

      if(!aNode)
      {
         return false;
      }

      aEmitter.setGeneratorFocusNP(aNode->IntAttribute("min"),
                               aNode->IntAttribute("max"));

      aNode = aGeneratorNode->FirstChildElement("focusPPS");

      if(!aNode)
      {
         return false;
      }

      aEmitter.setGeneratorFocusPPS(aNode->FloatAttribute("min"),
                                aNode->FloatAttribute("max"));

      aNode = aGeneratorNode->FirstChildElement("particleTOL") ;

      if(!aNode)
      {
         return false;
      }

      aEmitter.setGeneratorParticleTOL(aNode->FloatAttribute("min"),
                                   aNode->FloatAttribute("max"));

      aNode = aGeneratorNode->FirstChildElement("particleSize") ;

      if(!aNode)
      {
         return false;
      }

      aEmitter.setGeneratorParticleSize(aNode->FloatAttribute("min"),
                                     aNode->FloatAttribute("max"));


      aNode = aGeneratorNode->FirstChildElement("particleAngle") ;

      if(!aNode)
      {
         return false;
      }

      aEmitter.setGeneratorParticleAngle(aNode->FloatAttribute("min"),
                                     aNode->FloatAttribute("max"));

      aNode = aGeneratorNode->FirstChildElement("particleLV") ;

      if(!aNode)
      {
         return false;
      }

      aEmitter.setGeneratorParticleLV(aNode->FloatAttribute("min"),
                                  aNode->FloatAttribute("max"));

      aNode = aGeneratorNode->FirstChildElement("particleAV") ;

      if(!aNode)
      {
         return false;
      }

      aEmitter.setGeneratorParticleAV(aNode->FloatAttribute("min"),
                                  aNode->FloatAttribute("max"));

      addEmitter(aEmitter);
      aEmitterNode = aEmitterNode->NextSiblingElement("emitter");
   }
   return true;
}