本文整理汇总了C#中Particle类的典型用法代码示例。如果您正苦于以下问题:C# Particle类的具体用法?C# Particle怎么用?C# Particle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Particle类属于命名空间,在下文中一共展示了Particle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Process
/// <summary>
/// Processes the specified Particle.
/// </summary>
/// <param name="dt">Elapsed time in whole and fractional seconds.</param>
/// <param name="particle">The particle to be processed.</param>
/// <param name="tag">The tag which has been attached to the Particle (or null).</param>
public override unsafe void Process(float dt, Particle* particle, object tag)
{
float a = particle->Age * 0.07f,
aInv = 1f - a;
particle->Scale = (particle->Scale * aInv) + (this.MergeScale * a);
}
示例2: ProcessLinear
protected override void ProcessLinear(float bias, float scale, float deltaTime, Particle[] particles, int begin, int end)
{
for (int i = begin; i < end; ++i)
{
particles[i].m_rotation = bias + scale * particles[i].m_age / particles[i].m_life;
}
}
示例3: Process
/// <summary>
/// Processes the particles.
/// </summary>
/// <param name="dt">Elapsed time in whole and fractional seconds.</param>
/// <param name="particleArray">A pointer to an array of particles.</param>
/// <param name="count">The number of particles which need to be processed.</param>
protected internal override unsafe void Process(float dt, Particle* particleArray, int count)
{
this.TotalSeconds += dt;
float deltaAmp = this.Amplitude * dt;
for (int i = 0; i < count; i++)
{
Particle* particle = (particleArray + i);
float secondsAlive = this.TotalSeconds - particle->Inception;
float sin = Calculator.Cos(secondsAlive * this.Frequency);
Vector2 force = new Vector2(sin, 0f);
force.X = ((force.X * this.AngleCos) + (force.Y * -this.AngleSin));
force.Y = ((force.X * this.AngleSin) + (force.Y * this.AngleCos));
force.X *= deltaAmp;
force.Y *= deltaAmp;
particle->Velocity.X += force.X;
particle->Velocity.Y += force.Y;
}
}
示例4: IteratesOverEachParticle
public void IteratesOverEachParticle()
{
var buffer = new Particle
{
Age = new float[100],
R = new float[100],
G = new float[100],
B = new float[100]
};
for (var i = 0; i < buffer.Age.Length; i++)
buffer.Age[i] = 1.0f;
var subject = new ColourInterpolator2
{
InitialColour = new Colour(1f, 0f, 0f),
FinalColour = new Colour(0f, 0f, 1f)
};
subject.Update(0.1666666f, ref buffer, buffer.Age.Length);
for (int i = 0; i < buffer.Age.Length; i++)
{
buffer.B[0].Should().BeApproximately(1f, 0.000001f);
}
}
示例5: Update
protected internal override void Update(float elapsedSeconds, ref Particle particle, int count)
{
fixed (float* agePtr = particle.Age)
fixed (float* rPtr = particle.R)
fixed (float* gPtr = particle.G)
fixed (float* bPtr = particle.B)
fixed (float* aPtr = particle.Opacity)
{
var ageDataPtr = agePtr;
var rDataPtr = rPtr;
var gDataPtr = gPtr;
var bDataPtr = bPtr;
var aDataPtr = aPtr;
for (var j = 0; j < count; j++)
{
var age = *(ageDataPtr + j);
var inverseAge = 1.0f - age;
var alpha = InitialColour.A * age;
*(aDataPtr + j) = alpha;
*(rDataPtr + j) = InitialColour.H * inverseAge;
*(gDataPtr + j) = InitialColour.S * inverseAge;
*(bDataPtr + j) = InitialColour.L * inverseAge;
}
}
}
示例6: Process
/// <summary>
/// Processes the particles.
/// </summary>
/// <param name="elapsedSeconds">Elapsed time in whole and fractional seconds.</param>
/// <param name="particle">A pointer to the first item in an array of particles.</param>
/// <param name="count">The number of particles which need to be processed.</param>
protected internal override unsafe void Process(float elapsedSeconds, Particle* particle, int count)
{
particle->Colour.X = (this.InitialColour.X + ((this.UltimateColour.X - this.InitialColour.X) * particle->Age));
particle->Colour.Y = (this.InitialColour.Y + ((this.UltimateColour.Y - this.InitialColour.Y) * particle->Age));
particle->Colour.Z = (this.InitialColour.Z + ((this.UltimateColour.Z - this.InitialColour.Z) * particle->Age));
Particle* previousParticle = particle;
particle++;
for (int i = 1; i < count; i++)
{
if (particle->Age < previousParticle->Age)
{
particle->Colour.X = (this.InitialColour.X + ((this.UltimateColour.X - this.InitialColour.X) * particle->Age));
particle->Colour.Y = (this.InitialColour.Y + ((this.UltimateColour.Y - this.InitialColour.Y) * particle->Age));
particle->Colour.Z = (this.InitialColour.Z + ((this.UltimateColour.Z - this.InitialColour.Z) * particle->Age));
}
else
{
particle->Colour.X = previousParticle->Colour.X;
particle->Colour.Y = previousParticle->Colour.Y;
particle->Colour.Z = previousParticle->Colour.Z;
}
previousParticle++;
particle++;
}
}
示例7: Start
void Start()
{
// Calculate the number of warp needed to handle all the particles
if (particleCount <= 0)
particleCount = 1;
mWarpCount = Mathf.CeilToInt((float)particleCount / WARP_SIZE);
// Initialize the Particle at the start
Particle[] particleArray = new Particle[particleCount];
for (int i = 0; i < particleCount; ++i)
{
particleArray[i].position.x = Random.value * 2 - 1.0f;
particleArray[i].position.y = Random.value * 2 - 1.0f;
particleArray[i].position.z = 0;
particleArray[i].velocity.x = 0;
particleArray[i].velocity.y = 0;
particleArray[i].velocity.z = 0;
}
// Create the ComputeBuffer holding the Particles
particleBuffer = new ComputeBuffer(particleCount, SIZE_PARTICLE);
particleBuffer.SetData(particleArray);
// Find the id of the kernel
mComputeShaderKernelID = computeShader.FindKernel("CSMain");
// Bind the ComputeBuffer to the shader and the compute shader
computeShader.SetBuffer(mComputeShaderKernelID, "particleBuffer", particleBuffer);
material.SetBuffer("particleBuffer", particleBuffer);
}
示例8: Process
/// <summary>
/// Processes the particles.
/// </summary>
/// <param name="dt">Elapsed time in whole and fractional seconds.</param>
/// <param name="particle">A pointer to an array of particles.</param>
/// <param name="count">The number of particles which need to be processed.</param>
protected internal override unsafe void Process(float dt, Particle* particle, int count)
{
for (int i = 0; i < count; i++)
{
Particle* previousParticle = particle - 1;
if (particle->Momentum == previousParticle->Momentum)
{
particle->Rotation = previousParticle->Rotation;
continue;
}
float rads = Calculator.Atan2(particle->Momentum.Y, particle->Momentum.X);
particle->Rotation = (rads + this.RotationOffset);
if (particle->Rotation > Calculator.Pi)
particle->Rotation -= Calculator.TwoPi;
else if (particle->Rotation < -Calculator.Pi)
particle->Rotation += Calculator.TwoPi;
particle++;
}
}
示例9: ParticleSpring
public ParticleSpring(Particle particle, Particle other, float springConstant, float restLength)
: base(particle)
{
_other = other;
_springConstant = springConstant;
_restLength = restLength;
}
示例10: ParticleSystem
public ParticleSystem(int maxParticles)
{
MAX_PARTICLES = maxParticles;
random = new Random();
_textures = new Texture2D[MAX_TEXTURES];
_particles = new Particle[MAX_PARTICLES];
for (int i = 0; i < MAX_PARTICLES; ++i)
{
_particles[i] = new Particle(null, _ttl, 0, 0, 0, 0, 0, 0);
_particles[i]._exists = false;
}
_spawnBox.X = 0;
_spawnBox.Y = 0;
_minRotSpeed = 0;
_maxRotSpeed = 0;
_minRotInit = 0;
_maxRotInit = 0;
Angle = 0;
_spawnCone = (float)Math.PI * 2f;
_minSpeed = 10;
_maxSpeed = 10;
_alphaDecrement = 0.2f;
_decrementTick = 5;
_alphaIncrement = 0.2f;
_incrementTick = 5;
_isOn = true;
}
示例11: ParticleAnchoredSpring
public ParticleAnchoredSpring(Particle particle, Point3D anchor, float springConstant, float restLength)
: base(particle)
{
Anchor = anchor;
SpringConstant = springConstant;
RestLength = restLength;
}
示例12: UpdateParticle
public override void UpdateParticle(GameTime time, Particle spawn)
{
_momentum.X = (float)Math.Cos(spawn.Orientation) * spawn.Speed;
_momentum.Y = (float)Math.Sin(spawn.Orientation) * spawn.Speed;
if (spawn.Position.X < (float)_rect.X)
{
spawn.Position.X = (float)_rect.X;
_momentum.X *= -1f; _momentum.X *= _bounce;
}
else if (spawn.Position.X > (float)_rect.Width)
{
spawn.Position.X = (float)_rect.Width;
_momentum.X *= -1f; _momentum.X *= _bounce;
}
if (spawn.Position.Y < (float)_rect.Y)
{
spawn.Position.Y = (float)_rect.Y;
_momentum.Y *= -1f; _momentum.Y *= _bounce;
}
else if (spawn.Position.Y > (float)_rect.Height)
{
spawn.Position.Y = (float)_rect.Height;
_momentum.Y *= -1f; _momentum.Y *= _bounce;
}
spawn.Orientation = (float)Math.Atan2(_momentum.Y, _momentum.X);
spawn.Speed = _momentum.Length();
}
示例13: Particle
public void Construction_CanCreateAParticleWithAnInitialPositionAndVelocity_AndItsPositionAndVelocityAreInitialised()
{
var particle = new Particle(TestPosition, TestVelocity);
Assert.IsTrue(particle.Position.Equals(TestPosition));
Assert.IsTrue(particle.Velocity.Equals(TestVelocity));
}
示例14: Construction_CanCreateAParticleWithAnInitialPosition_AndItsPositionIsInitialised
public void Construction_CanCreateAParticleWithAnInitialPosition_AndItsPositionIsInitialised()
{
var particle = new Particle(TestPosition);
Assert.IsTrue(particle.Position.Equals(TestPosition));
Assert.IsTrue(particle.Velocity.Equals(Vector3.ZeroVector));
}
示例15: Update
protected internal unsafe override void Update(float elapsedSeconds, ref Particle particle, int count)
{
_totalSeconds += elapsedSeconds;
fixed (float* agePtr = particle.Age)
fixed (float* inceptionPtr = particle.Inception)
{
var ageDataPtr = agePtr;
var inceptionDataPtr = inceptionPtr;
var term = _term;
var totalSeconds = _totalSeconds;
for (var j = 0; j < count; j++)
{
var age = (totalSeconds - *(inceptionDataPtr + j)) / term;
// TODO: There is a fairly systemic bug in the emitter code right now that means that the inception time
// of a particle can be later than the total elapsed time in here. It happens because the modifiers are
// not necessarily updated every frame, while the emitter is.
if (age < 0)
age = 0;
if (age > 1)
age = 1;
*(ageDataPtr + j) = age;
}
}
}