当前位置: 首页>>代码示例>>C++>>正文


C++ ParticleSystem::end方法代码示例

本文整理汇总了C++中ParticleSystem::end方法的典型用法代码示例。如果您正苦于以下问题:C++ ParticleSystem::end方法的具体用法?C++ ParticleSystem::end怎么用?C++ ParticleSystem::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ParticleSystem的用法示例。


在下文中一共展示了ParticleSystem::end方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: sqrtf

void
SparkDrawer::draw(const ParticleSystem& psys) const
{
  buffer->clear();
  buffer->set_pos(Vector2f(psys.get_x_pos(), psys.get_y_pos()));

  if (width == 1.0f)
  {
    buffer->set_mode(GL_LINES);
    buffer->set_blend_func(GL_SRC_ALPHA, GL_ONE);
    for(ParticleSystem::const_iterator i = psys.begin(); i != psys.end(); ++i)
    {
      buffer->color(Color(color.r, color.g, color.b, color.a - (color.a * psys.get_progress(i->t))));
      buffer->vertex(i->x + i->v_x/10.0f, i->y + i->v_y/10.0f); 

      buffer->color(Color(0, 0, 0, 0));
      buffer->vertex(i->x, i->y);
    }
  }
  else
  {
    buffer->set_mode(GL_QUADS);
    buffer->set_blend_func(GL_SRC_ALPHA, GL_ONE);
    for(ParticleSystem::const_iterator i = psys.begin(); i != psys.end(); ++i)
    {
      const float len = sqrtf(i->v_x * i->v_x  +  i->v_y * i->v_y);

      const float o_x = i->v_y/len * width;
      const float o_y = i->v_x/len * width;

      const float x1 = i->x;
      const float y1 = i->y;
      const float x2 = i->x + i->v_x/10.0f;
      const float y2 = i->y + i->v_y/10.0f;

      buffer->color(Color(0, 0, 0, 0));
      buffer->vertex(x1 + o_x, y1 - o_y);

      buffer->color(Color(0, 0, 0, 0));
      buffer->vertex(x1 - o_x, y1 + o_y);

      buffer->color(Color(color.r, color.g, color.b, color.a - (color.a * psys.get_progress(i->t))));
      buffer->vertex(x2 - o_x, y2 + o_y); 

      buffer->color(Color(color.r, color.g, color.b, color.a - (color.a * psys.get_progress(i->t))));
      buffer->vertex(x2 + o_x, y2 - o_y); 
    }
  }

  buffer->render(~0u);
}
开发者ID:BackupTheBerlios,项目名称:windstille-svn,代码行数:51,代码来源:spark_drawer.cpp

示例2: execute

void MagnetPSA::execute( ParticleSystem &particleSystem, float dTime )
{
	BW_GUARD_PROFILER( MagnetPSA_execute );

	// Do nothing if the dTime passed was zero or if the particle system
	// is not quite old enough to be active.
	if ( ( age_ < delay() ) || ( dTime <= 0.0f ) )
	{
		age_ += dTime;
		return;
	}

	// If there is no source matrix provider, use the origin of the 
	// particle system itself.
	Vector3 origin;
	if ( source_ )
	{
		Matrix m;
		source_->matrix(m);
		origin = m.applyToOrigin();
	}
	else
	{
		if ( !particleSystem.pRenderer() || !particleSystem.pRenderer()->local() )
		{
			origin = particleSystem.worldTransform().applyToOrigin();
		}
		else
		{
			origin.set(0,0,0);
		}
	}

	Particles::iterator current = particleSystem.begin();
	Particles::iterator endOfParticles = particleSystem.end();
	while ( current != endOfParticles )
	{
		Particle &particle = *current++;

		if (particle.isAlive())
		{
			// Here we go: Apply acceleration to velocity based on magnet position.
			Vector3 dv (origin-particle.position());
			float separation = max(dv.length(), minDist_);
			dv /= separation;
			float factor = (dTime * strength_) / separation;
			Vector3 velocity;
			particle.getVelocity( velocity );
			particle.setVelocity( velocity + (dv * factor) );
		}
	}
}
开发者ID:siredblood,项目名称:tree-bumpkin-project,代码行数:52,代码来源:magnet_psa.cpp

示例3: execute

/**
 *	This method executes the action for the given frame of time. The dTime
 *	parameter is the time elapsed since the last call.
 *
 *	@param particleSystem	The particle system on which to operate.
 *	@param dTime			Elapsed time in seconds.
 */
void ScalerPSA::execute( ParticleSystem &particleSystem, float dTime )
{
	BW_GUARD_PROFILER( ScalerPSA_execute );

	// Do nothing if the dTime passed was zero or if the particle system
	// is not quite old enough to be active.
	if ( ( age_ < delay() ) || ( dTime <= 0.0f ) )
	{
		age_ += dTime;
		return;
	}


	Particles::iterator current = particleSystem.begin();
	Particles::iterator endOfParticles = particleSystem.end();
	while ( current != endOfParticles )
	{
		Particle &particle = *current;

		if (particle.isAlive())
		{
			float size = particle.size();

			if ( size > size_ )
			{
				size -= rate_ * dTime;
				if ( size < size_ )
				{
					size = size_;
				}
			}
			else if ( size < size_ )
			{
				size += rate_ * dTime;
				if ( size > size_ )
				{
					size = size_;
				}
			}

			particle.size( size );
		}

		++current;
	}
}
开发者ID:siredblood,项目名称:tree-bumpkin-project,代码行数:53,代码来源:scaler_psa.cpp

示例4: execute

/**
 *	This method executes the action for the given frame of time. The dTime
 *	parameter is the time elapsed since the last call.
 *
 *	@param particleSystem	The particle system on which to operate.
 *	@param dTime			Elapsed time in seconds.
 */
void CollidePSA::execute( ParticleSystem &particleSystem, float dTime )
{
	BW_GUARD;
	SourcePSA* pSource = static_cast<SourcePSA*>( &*particleSystem.pAction( PSA_SOURCE_TYPE_ID ) );

	if ( !pSource )
		return;

	RompColliderPtr pGS = pSource->groundSpecifier();
	if ( !pGS )
		return;

	uint64	tend = timestamp() + stampsPerSecond() / 2000;

	bool soundHit = false;
	float maxVelocity = 0;
	Vector3 soundPos;
	uint materialKind;

	Particles::iterator it = particleSystem.begin();
	Particles::iterator end = particleSystem.end();

	WorldTriangle tri;

	//bust out of the loop if we take more than 0.5 msec

	//Sprite particles don't calculate spin
	while ( it != end && timestamp()<tend )
	{
		Particle &particle = *it++;

		if (!particle.isAlive())
		{		
			continue;
		}

		//note - particles get moved after actions.
		Vector3 velocity;
		particle.getVelocity(velocity);
		Vector3 pos;
		Vector3 newPos;

		if(particleSystem.isLocal())
		{
			Matrix world = particleSystem.worldTransform();
			pos = world.applyPoint(particle.position());
			Vector3 nPos;
			particleSystem.predictPosition( particle, dTime, nPos );
			newPos = world.applyPoint(nPos);
		}
		else
		{
			pos = particle.position();
			particleSystem.predictPosition( particle, dTime, newPos );
		}


		float tValue = pGS->collide( pos, newPos, tri );
		if ( tValue >= 0.f && tValue <= 1.f )
		{
			// calc v as a dotprod of the two normalised vectors (before and after collision)
			Vector3 oldVel = velocity / velocity.length();
			tri.bounce( velocity, elasticity_ );
			particle.setVelocity( velocity );
			float newSpeed = velocity.length();
			Vector3 newVel(velocity / newSpeed);
			float severity = oldVel.dotProduct(newVel);
			//DEBUG_MSG("severity: %1.3f, speed=%1.3f\n", severity, newSpeed);
			float v = (1 - severity) * newSpeed;

			//now spin the particle ( mesh only )
			if ( !spriteBased_ )
			{
				//first, calculate the current rotation, and update the pitch/yaw value.
				Matrix currentRot;
				currentRot.setRotate( particle.yaw(), particle.pitch(), 0.f );
				Matrix spin;
                float spinSpeed = particle.meshSpinSpeed();
                Vector3 meshSpinAxis = particle.meshSpinAxis();
                // If there is no spin direction then creating a rotation 
                // matrix can create weird matrices - e.g. matrices with
                // negative scale components and a translation.  We choose the
                // velocity as the spin direction (aribitrarily choosing, for
                // example up looks weird).
                if (meshSpinAxis == Vector3::zero())
                {
                    meshSpinAxis = velocity;
                    meshSpinAxis.normalise();
                }
				
				D3DXMatrixRotationAxis
                ( 
                    &spin, 
//.........这里部分代码省略.........
开发者ID:siredblood,项目名称:tree-bumpkin-project,代码行数:101,代码来源:collide_psa.cpp


注:本文中的ParticleSystem::end方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。