/**
 * Force the bounding box to be updated.
 */
void FParticleBeam2EmitterInstance::ForceUpdateBoundingBox()
{
	if (Component)
	{
		float MaxSizeScale	= 1.0f;
		ParticleBoundingBox.Init();
		ParticleBoundingBox += Component->GetComponentLocation();

		FVector	NoiseMin(0.0f);
		FVector NoiseMax(0.0f);
		// Noise points have to be taken into account...
		if (BeamModule_Noise)
		{
			BeamModule_Noise->GetNoiseRange(NoiseMin, NoiseMax);
		}

		// Take scale into account as well
		FVector Scale = Component->ComponentToWorld.GetScale3D();

		// Take each particle into account
		for (int32 i=0; i<ActiveParticles; i++)
		{
			DECLARE_PARTICLE_PTR(Particle, ParticleData + ParticleStride * ParticleIndices[i]);

			int32						CurrentOffset		= TypeDataOffset;
			FBeam2TypeDataPayload*	BeamData			= NULL;
			FVector*				InterpolatedPoints	= NULL;
			float*					NoiseRate			= NULL;
			float*					NoiseDelta			= NULL;
			FVector*				TargetNoisePoints	= NULL;
			FVector*				NextNoisePoints		= NULL;
			float*					TaperValues			= NULL;
			float*					NoiseDistanceScale	= NULL;
			FBeamParticleModifierPayloadData* SourceModifier = NULL;
			FBeamParticleModifierPayloadData* TargetModifier = NULL;

			BeamTypeData->GetDataPointers(this, (const uint8*)Particle, CurrentOffset, 
				BeamData, InterpolatedPoints, NoiseRate, NoiseDelta, TargetNoisePoints, 
				NextNoisePoints, TaperValues, NoiseDistanceScale,
				SourceModifier, TargetModifier);

			FVector Size = Particle->Size * Scale;

			ParticleBoundingBox += Particle->Location;
			ParticleBoundingBox += Particle->Location + NoiseMin;
			ParticleBoundingBox += Particle->Location + NoiseMax;
			ParticleBoundingBox += BeamData->SourcePoint;
			ParticleBoundingBox += BeamData->SourcePoint + NoiseMin;
			ParticleBoundingBox += BeamData->SourcePoint + NoiseMax;
			ParticleBoundingBox += BeamData->TargetPoint;
			ParticleBoundingBox += BeamData->TargetPoint + NoiseMin;
			ParticleBoundingBox += BeamData->TargetPoint + NoiseMax;

			MaxSizeScale = FMath::Max(MaxSizeScale, Size.GetAbsMax()); //@todo particles: this does a whole lot of compares that can be avoided using SSE/ Altivec.
		}

		ParticleBoundingBox = ParticleBoundingBox.ExpandBy(MaxSizeScale);
	}
}
/**
 *	Update the bounding box for the emitter
 *
 *	@param	DeltaTime		The time slice to use
 */
void FParticleBeam2EmitterInstance::UpdateBoundingBox(float DeltaTime)
{
	SCOPE_CYCLE_COUNTER(STAT_ParticleUpdateBounds);
	if (Component)
	{
		bool bUpdateBox = ((Component->bWarmingUp == false) &&
			(Component->Template != NULL) && (Component->Template->bUseFixedRelativeBoundingBox == false));
		float MaxSizeScale	= 1.0f;
		if (bUpdateBox)
		{
			ParticleBoundingBox.Init();

			//@todo. Currently, we don't support UseLocalSpace for beams
			//if (Template->UseLocalSpace == false) 
			{
				ParticleBoundingBox += Component->GetComponentLocation();
			}
		}

		FVector	NoiseMin(0.0f);
		FVector NoiseMax(0.0f);
		// Noise points have to be taken into account...
		if (BeamModule_Noise)
		{
			BeamModule_Noise->GetNoiseRange(NoiseMin, NoiseMax);
		}

		// Take scale into account as well
		FVector Scale = Component->ComponentToWorld.GetScale3D();

		// Take each particle into account
		for (int32 i=0; i<ActiveParticles; i++)
		{
			DECLARE_PARTICLE_PTR(Particle, ParticleData + ParticleStride * ParticleIndices[i]);

			int32						CurrentOffset		= TypeDataOffset;
			FBeam2TypeDataPayload*	BeamData			= NULL;
			FVector*				InterpolatedPoints	= NULL;
			float*					NoiseRate			= NULL;
			float*					NoiseDelta			= NULL;
			FVector*				TargetNoisePoints	= NULL;
			FVector*				NextNoisePoints		= NULL;
			float*					TaperValues			= NULL;
			float*					NoiseDistanceScale	= NULL;
			FBeamParticleModifierPayloadData* SourceModifier = NULL;
			FBeamParticleModifierPayloadData* TargetModifier = NULL;

			BeamTypeData->GetDataPointers(this, (const uint8*)Particle, CurrentOffset, 
				BeamData, InterpolatedPoints, NoiseRate, NoiseDelta, TargetNoisePoints, 
				NextNoisePoints, TaperValues, NoiseDistanceScale,
				SourceModifier, TargetModifier);

			// Do linear integrator and update bounding box
			Particle->OldLocation = Particle->Location;
			Particle->Location	+= DeltaTime * Particle->Velocity;
			Particle->Rotation	+= DeltaTime * Particle->RotationRate;
			Particle->OldLocation += PositionOffsetThisTick;
			FVector Size = Particle->Size * Scale;
			if (bUpdateBox)
			{
				ParticleBoundingBox += Particle->Location;
				ParticleBoundingBox += Particle->Location + NoiseMin;
				ParticleBoundingBox += Particle->Location + NoiseMax;
				ParticleBoundingBox += BeamData->SourcePoint;
				ParticleBoundingBox += BeamData->SourcePoint + NoiseMin;
				ParticleBoundingBox += BeamData->SourcePoint + NoiseMax;
				ParticleBoundingBox += BeamData->TargetPoint;
				ParticleBoundingBox += BeamData->TargetPoint + NoiseMin;
				ParticleBoundingBox += BeamData->TargetPoint + NoiseMax;
			}

			// Do angular integrator, and wrap result to within +/- 2 PI
			Particle->Rotation	 = FMath::Fmod(Particle->Rotation, 2.f*(float)PI);
			MaxSizeScale		 = FMath::Max(MaxSizeScale, Size.GetAbsMax()); //@todo particles: this does a whole lot of compares that can be avoided using SSE/ Altivec.
		}
		if (bUpdateBox)
		{
			ParticleBoundingBox = ParticleBoundingBox.ExpandBy(MaxSizeScale);
		}
	}
}