Esempio n. 1
0
    public AnimatedTextureSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      _beeSwarm = BeeSwarm.Create(ContentManager);
      _beeSwarm.Pose = new Pose(new Vector3F(0, 4, 0));

      // Create 100 bees.
      _beeSwarm.AddParticles(100);

      ParticleSystemService.ParticleSystems.Add(_beeSwarm);

      _particleSystemNode = new ParticleSystemNode(_beeSwarm);
      GraphicsScreen.Scene.Children.Add(_particleSystemNode);
    }
Esempio n. 2
0
    private ParticleSystem CreateParticleCloud(ContentManager content)
    {
      var ps = new ParticleSystem
      {
        Name = "Cloud",
        MaxNumberOfParticles = 10,
        Shape = new BoxShape(400, 300, 400),  // This bounding shape must be big enough to include all particles!
        ReferenceFrame = ParticleReferenceFrame.Local,
      };

      ps.Parameters.AddUniform<float>(ParticleParameterNames.Lifetime).DefaultValue = float.PositiveInfinity;

      ps.Parameters.AddVarying<Vector3F>(ParticleParameterNames.Position);
      ps.Effectors.Add(new StartPositionEffector
      {
        Parameter = ParticleParameterNames.Position,
        Distribution = new SphereDistribution
        {
          Center = new Vector3F(0),
          InnerRadius = 0,
          OuterRadius = 1,
          Scale = new Vector3F(100, 50, 100),
        },
      });

      ps.Parameters.AddVarying<float>(ParticleParameterNames.Angle);
      ps.Effectors.Add(new StartValueEffector<float>
      {
        Parameter = ParticleParameterNames.Angle,
        Distribution = new UniformDistributionF(-0.5f, 0.5f),
      });

      ps.Parameters.AddVarying<float>(ParticleParameterNames.Size);
      ps.Effectors.Add(new StartValueEffector<float>
      {
        Parameter = ParticleParameterNames.Size,
        Distribution = new UniformDistributionF(100, 200),
      });

      ps.Parameters.AddUniform<Vector3F>(ParticleParameterNames.Color);
      ps.Effectors.Add(new StartValueEffector<Vector3F>
      {
        Parameter = ParticleParameterNames.Color,
        DefaultValue = new Vector3F(0.6f),
      });

      ps.Parameters.AddUniform<float>(ParticleParameterNames.Alpha).DefaultValue = 0.5f;

      // DigitalRune Graphics supports "texture atlases": The class PackedTexture 
      // describes a single texture or tile set packed into a texture atlas. The 
      // clouds texture in this example consists of 2 tiles.
      ps.Parameters.AddUniform<PackedTexture>(ParticleParameterNames.Texture).DefaultValue =
        new PackedTexture(
          "Clouds",
          content.Load<Texture2D>("Particles/Clouds"),
          Vector2F.Zero, Vector2F.One,
          2, 1);

      // The particle parameter "AnimationTime" determines which tile is used,
      // where 0 = first tile, 1 = last tile. 
      // --> Chooses a random tile for each particle when it is created.
      ps.Parameters.AddVarying<float>(ParticleParameterNames.AnimationTime);
      ps.Effectors.Add(new StartValueEffector<float>
      {
        Parameter = ParticleParameterNames.AnimationTime,
        Distribution = new UniformDistributionF(0, 1),
      });

      // It looks better with back-to-front sorting, but for better performance we skip sorting.
      ps.Parameters.AddUniform<bool>(ParticleParameterNames.IsDepthSorted).DefaultValue = false;

      ps.Parameters.AddUniform<BillboardOrientation>(ParticleParameterNames.BillboardOrientation).DefaultValue = BillboardOrientation.ViewpointOriented;

      // Create some particles.
      ps.AddParticles(ps.MaxNumberOfParticles);

      return ps;
    }