private void updateParticle2(float step_time, Particle p, cWorld world) { p.Vel.Y += (Constants.GRAVITY * 40.0f * (step_time * step_time)); // p.Vel.X *= p.SlowDown; // p.Vel.Y *= p.SlowDown; AppMath.Vec2Truncate(ref p.Vel, p.MaxSpeed); //world.collideParticleSAT(p, step_time, false); //p.Heading = cAppMath.Vec2NormalizeReturn(p.Vel); p.LastPos = p.Pos; p.Pos.X += p.Vel.X * step_time; p.Pos.Y += p.Vel.Y * step_time; if (!AppMath.Vec2IsZero(p.Vel)) { p.Heading = AppMath.Vec2NormalizeReturn(p.Vel); p.Rotation = (float)AppMath.GetAngleOfVector(p.Heading); } world.collideParticleRayTrace(p, step_time); p.Opacity -= p.Fade * step_time; }
public override void Update(float step_time) { cWorld world = particleManager.Scene.World; for (int i = 0; i < pool.CountActive; ++i) { Particle p = pool.get(i); if (!p.Intersects) { /* * p.Dims.Y += p.ScaleSpeed * step_time; //+= * p.Dims.y += p.ScaleSpeed * step_time; //+= */ AppMath.Vec2Truncate(ref p.Vel, p.MaxSpeed * 1.5f); p.Vel.Y += (Constants.GRAVITY * 40.0f * (step_time * step_time)); p.Vel.X *= p.SlowDown; p.Vel.Y *= p.SlowDown; //p.Heading = cAppMath.Vec2NormalizeReturn(p.Vel); p.LastPos = p.Pos; p.Pos.X += p.Vel.X * step_time; p.Pos.Y += p.Vel.Y * step_time; if (!AppMath.Vec2IsZero(p.Vel)) { p.Heading = AppMath.Vec2NormalizeReturn(p.Vel); p.Rotation = (float)AppMath.GetAngleOfVector(p.Heading); } world.collideParticleRayTrace(p, step_time); } p.Opacity -= p.Fade * step_time; if (p.Opacity <= 0.0f) { p.Opacity = 0.0f; pool.deactivate(i); } p.Color.A = (byte)p.Opacity; } }
public void Update(float step_time) { force.Y = (startPosition.Y - position.Y) * SPEED; //cAppMath.Vec2Truncate(ref force, MAX_FORCE); acceleration.Y = force.Y * step_time; velocity.Y += acceleration.Y * step_time; AppMath.Vec2Truncate(ref velocity, MAX_VELOCITY); lastPosition = position; position.Y += velocity.Y * step_time; // * factor; force.Y = 0.0f; }
/// <summary> /// Main update protocol. /// </summary> /// <param name="step_time"></param> /// <param name="p"></param> /// <param name="world"></param> private void updateParticle1(float step_time, Particle p, cWorld world) { // Particle's update code comes here. p.Dims.X += p.ScaleSpeed * step_time; //+= p.Dims.Y += p.ScaleSpeed * step_time; //+= if (AppMath.Vec2Length(p.Dims) < 0.5f) { p.Dims.X = 0.0f; p.Dims.Y = 0.0f; } p.Vel.Y += (Constants.GRAVITY * 40.0f * (step_time * step_time)); p.Vel.X *= p.SlowDown; p.Vel.Y *= p.SlowDown; AppMath.Vec2Truncate(ref p.Vel, p.MaxSpeed * 1.5f); // world.collideParticleSAT(p, step_time, false); //p.Heading = cAppMath.Vec2NormalizeReturn(p.Vel); p.LastPos = p.Pos; p.Pos.X += p.Vel.X * step_time; p.Pos.Y += p.Vel.Y * step_time; if (!AppMath.Vec2IsZero(p.Vel)) { p.Heading = AppMath.Vec2NormalizeReturn(p.Vel); p.Rotation = (float)AppMath.GetAngleOfVector(p.Heading); } world.collideParticleRayTrace(p, step_time); p.Opacity -= p.Fade * step_time; }
public override void Update(float step_time) { this.renderer.Update(step_time); cPlayer player = Scene.Player; if (this.pulling) { Vector2f predicted = AppMath.Vec2NormalizeReturn((player.Bounds.center + (player.Velocity * step_time)) - this.Bounds.center); // pull pickup //Vector2f toPlayer = cAppMath.Vec2NormalizeReturn(player.Bounds.center - this.Bounds.center); // G * ((m1*m2) / (d*d)) float f = PULL_FORCE * 150f; // * (100000.0f / ( d*d) ); this.AddForce(predicted * f); } /* * else * { * this.pulling = false; * } */ // applying some gravity force.Y += (false == pulling) ? (Constants.GRAVITY * 40.0f * step_time) : 0.0f; velocity.X += force.X * step_time; velocity.Y += force.Y * step_time; //velocity.X = Math.Abs(velocity.X) < 0.05f ? 0.0f : velocity.X; //velocity.Y = Math.Abs(velocity.Y) < 0.05f ? 0.0f : velocity.Y; double len = AppMath.Vec2Length(velocity); if (len < 0.1) { velocity = new Vector2f(0.0f, 0.0f); } AppMath.Vec2Truncate(ref velocity, MaxSpeed); // get more precise result calling it here (because of the updated velocity) // instead of calling at the beginning of this update method checkCollisionWithWorld(step_time); lastPosition = position; position.X += velocity.X * step_time; position.Y += velocity.Y * step_time; Bounds.SetPosByCenter(position); this.hitCollisionRect = Bounds; if (!AppMath.Vec2IsZero(velocity)) { heading = AppMath.Vec2NormalizeReturn(velocity); orientation = AppMath.GetAngleOfVector(heading); } force = new Vector2f(0.0f, 0.0f); }
public override void Update(float step_time) { cWorld world = particleManager.Scene.World; /* * if(emiting && this.emitTimer.isReady()) * { * // initParticle(); * remaining -= 1; * emiting = remaining > 0; * } */ for (int i = 0; i < pool.CountActive; ++i) { Particle p = pool.get(i); // p.Vel.Y += (Constants.GRAVITY*30 * (step_time * step_time)); p.Vel.X *= p.SlowDown; p.Vel.Y *= p.SlowDown; AppMath.Vec2Truncate(ref p.Vel, p.MaxSpeed); //world.collideParticleSAT(p, step_time); //p.Heading = cAppMath.Vec2NormalizeReturn(p.Vel); Vector2u uSize = this.renderStates.Texture.Size; p.Scale -= p.ScaleSpeed * step_time; p.Dims = new Vector2f(uSize.X * p.Scale, uSize.Y * p.Scale); p.LastPos = p.Pos; p.Pos.X += p.Vel.X * step_time; p.Pos.Y += p.Vel.Y * step_time; if (!AppMath.Vec2IsZero(p.Vel)) { p.Heading = AppMath.Vec2NormalizeReturn(p.Vel); // p.Rotation = (float)cAppMath.GetAngleOfVector(p.Heading); } world.collideParticleRayTrace(p, step_time, true, false); p.Opacity -= p.Fade * step_time; if (p.Opacity <= 0.0f || p.Scale <= 0.0f) { p.Opacity = 0.0f; p.Scale = 0.0f; p.Life -= 1.0f; if (p.Life <= 0.0f) { pool.deactivate(i); } else { this.reinit(p); } } p.Color.A = (byte)p.Opacity; } }