コード例 #1
0
        public override Node CloneNode()
        {
            ParticleNode node = (ParticleNode)base.CloneNode();

            node.ParticleEffects.AddRange(particleEffects);
            node.WorldTransformation = worldTransformation;
            node.UpdateHandler       = UpdateHandler;

            return(node);
        }
コード例 #2
0
ファイル: Tutorial6.cs プロジェクト: NinjaSteph/SureShot
        private void CreateObject()
        {
            // Loads a textured model of a ship
            ModelLoader loader = new ModelLoader();
            Model shipModel = (Model)loader.Load("", "p1_wedge");

            // Create a geometry node of a loaded ship model
            GeometryNode shipNode = new GeometryNode("Ship");
            shipNode.Model = shipModel;
            ((Model)shipNode.Model).UseInternalMaterials = true;

            // Create a transform node to define the transformation for the ship
            TransformNode shipTransNode = new TransformNode();
            shipTransNode.Translation = new Vector3(0, 0, -50);
            shipTransNode.Scale = new Vector3(0.01f, 0.01f, 0.01f); // It's huge!
            shipTransNode.Rotation = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0),
                MathHelper.ToRadians(90));

            shipTransParentNode = new TransformNode();
            shipTransParentNode.Translation = Vector3.Zero;

            // Create a geometry node with model of a torus
            GeometryNode torusNode = new GeometryNode("Torus");
            torusNode.Model = new Torus(12f, 15.5f, 20, 20);

            TransformNode torusTransNode = new TransformNode();
            torusTransNode.Translation = new Vector3(-50, 0, 0);
            torusTransNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitX,
                MathHelper.ToRadians(90));

            // Create a material node for this torus model
            Material torusMaterial = new Material();
            torusMaterial.Diffuse = Color.DarkGoldenrod.ToVector4();
            torusMaterial.Specular = Color.White.ToVector4();
            torusMaterial.SpecularPower = 5;

            torusNode.Material = torusMaterial;

            // Now add the above nodes to the scene graph in appropriate order
            scene.RootNode.AddChild(shipTransParentNode);
            shipTransParentNode.AddChild(shipTransNode);
            shipTransNode.AddChild(shipNode);

            scene.RootNode.AddChild(torusTransNode);
            torusTransNode.AddChild(torusNode);

            // Now create couple of particle effects to attach to the models

            // Create a smoke particle effect and fire particle effect to simulate a
            // ring of fire around the torus model
#if WINDOWS_PHONE
            SmokePlumeParticleEffect smokeParticles = new SmokePlumeParticleEffect(20, spriteBatch);
            FireParticleEffect fireParticles = new FireParticleEffect(40, spriteBatch);
#else
            SmokePlumeParticleEffect smokeParticles = new SmokePlumeParticleEffect();
            FireParticleEffect fireParticles = new FireParticleEffect();
            // The order defines which particle effect to render first. Since we want
            // to show the fire particles in front of the smoke particles, we make
            // the smoke particles to be rendered first, and then fire particles
            smokeParticles.DrawOrder = 200;
            fireParticles.DrawOrder = 300;
#endif

            // Create a particle node to hold these two particle effects
            ParticleNode fireRingEffectNode = new ParticleNode();
            fireRingEffectNode.ParticleEffects.Add(smokeParticles);
            fireRingEffectNode.ParticleEffects.Add(fireParticles);

            // Implement an update handler for each of the particle effects which will be called
            // every "Update" call 
            fireRingEffectNode.UpdateHandler += new ParticleUpdateHandler(UpdateRingOfFire);

            torusNode.AddChild(fireRingEffectNode);

            // Create another set of fire and smoke particle effects to simulate the fire
            // the ship catches when the ship passes the ring of fire
#if WINDOWS_PHONE
            FireParticleEffect shipFireEffect = new FireParticleEffect(150, spriteBatch);
            SmokePlumeParticleEffect shipSmokeEffect = new SmokePlumeParticleEffect(80, spriteBatch);
            shipFireEffect.MinScale *= 1.5f;
            shipFireEffect.MaxScale *= 1.5f;
#else
            FireParticleEffect shipFireEffect = new FireParticleEffect();
            SmokePlumeParticleEffect shipSmokeEffect = new SmokePlumeParticleEffect();
            shipSmokeEffect.DrawOrder = 400;
            shipFireEffect.DrawOrder = 500;
#endif

            ParticleNode shipFireNode = new ParticleNode();
            shipFireNode.ParticleEffects.Add(shipFireEffect);
            shipFireNode.ParticleEffects.Add(shipSmokeEffect);

            shipFireNode.UpdateHandler += new ParticleUpdateHandler(UpdateShipFire);

            shipNode.AddChild(shipFireNode);
        }