Example #1
0
        public override void OnAttach()
        {
            overlay = SceneObjectFactory.CreateAsteroidOverlay(SceneMgr, this);
            SceneMgr.DelayedAttachToScene(overlay);

            effects = SceneObjectFactory.CreateAsteroidEffects(SceneMgr, this);
            SceneMgr.DelayedAttachToScene(effects);
        }
        internal override bool LoadAttribute(ParticleNode n)
        {
            Vector2 worldCoord = nodeChunk.LocalToWorldCoord(n.localPosition);

            n.isDense = ApplyDensityNoise(worldCoord.x, worldCoord.y) && ApplyHeightNoise(worldCoord.x, worldCoord.y);

            return(true);
        }
Example #3
0
        public static ParticleNode CreateAsteroidEffects(SceneMgr mgr, Asteroid asteroid)
        {
            ParticleNode effects = new ParticleNode(mgr, IdMgr.GetNewId(mgr.GetCurrentPlayer().GetId()));

            effects.AddControl(new CenterCloneControl(asteroid));
            effects.AddControl(new DirectionCloneControl(asteroid));
            effects.AddControl(new DirectionDrivenRotationControl());
            effects.AddControl(new AsteroidBurningControl(asteroid));
            return(effects);
        }
 public void setBottomLeft(ParticleNode node)
 {
     bottomLeft   = node;
     leftCenter   = new SubNode(node.localPosition + Vector3.up * squareScale / 2);
     bottomCenter = new SubNode(node.localPosition + Vector3.right * squareScale / 2);
     if (node.isDense)
     {
         configuration += 1;
     }
 }
 public void setUpRight(ParticleNode node)
 {
     upRight     = node;
     upCenter    = new SubNode(node.localPosition + (Vector3.left * squareScale / 2));
     rightCenter = new SubNode(node.localPosition + (Vector3.down * squareScale / 2));
     if (node.isDense)
     {
         configuration += 4;
     }
 }
 bool LoadNodes()
 {
     particleNodeMap = new ParticleNode[ConvertToNodeMapIndex(m_chunkWidth), ConvertToNodeMapIndex(m_chunkHeight)]; // faz um node extra, para compensar o vertice a menos na criação do mesh.
     for (int x = 0; x < particleNodeMap.GetLength(0); x++)
     {
         for (int y = 0; y < particleNodeMap.GetLength(1); y++)
         {
             particleNodeMap[x, y] = new ParticleNode(false, NodeMapIndexToLocalCoord(x, y));
             LoadNodeLoadPipeline(particleNodeMap[x, y]);
         }
     }
     return(true);
 }
        protected override void InitControl(ISceneObject me)
        {
            if (!(me is ParticleNode))
            {
                throw new ArgumentException("AsteroidBurningControl must by attached to an ParticleNode object");
            }

            meNode = me as ParticleNode;

            events.AddEvent(1, new Event(0.5f, EventType.REPEATABLE, new Action(() => CheckSparkSpawn())));
            if (asteroid.Center.Y < minHeatDistance)
            {
                return;
            }

            float distPct = Math.Min((float)((asteroid.Center.Y - minHeatDistance) / (maxHeatDistance - minHeatDistance)), 1);

            while (distPct >= lastDistProcessed + stepSize && step <= 3)
            {
                step++;
                lastDistProcessed += stepSize;
                ProcessStep();
            }
        }
 internal abstract bool LoadAttribute(ParticleNode n);
 bool LoadNodeLoadPipeline(ParticleNode n)
 {
     m_nodeDensityLoader.LoadAttribute(n);
     return(true);
 }
Example #10
0
        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);
            FireParticleEffect       fireParticles  = new FireParticleEffect(40);
#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);
            SmokePlumeParticleEffect shipSmokeEffect = new SmokePlumeParticleEffect(80);
            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);
        }
        private void CreateSpark()
        {
            ParticleNode node = new ParticleNode(me.SceneMgr, IdMgr.GetNewId(me.SceneMgr.GetCurrentPlayer().GetId()));

            // TODO spawn in a whole volume
            bool left = me.SceneMgr.GetRandomGenerator().Next(2) == 0 ? false : true;

            if (left)
            {
                Vector position = (meNode.Center - (meNode.Direction.Rotate(Math.PI / 4) * (asteroid.Radius)));
                position      += meNode.Direction * (asteroid.Radius * 1.5);
                node.Position  = position;
                node.Direction = meNode.Direction.Rotate(FastMath.DegToRad(-10));
            }
            else
            {
                Vector position = (meNode.Center - (meNode.Direction.Rotate(-Math.PI / 4) * (asteroid.Radius)));
                position      += meNode.Direction * (asteroid.Radius * 1.5);
                node.Position  = position;
                node.Direction = meNode.Direction.Rotate(FastMath.DegToRad(10));
            }

            float minSize = (float)FastMath.LinearInterpolate(0.2, 0.5, me.SceneMgr.GetRandomGenerator().NextDouble());
            float maxSize = minSize * 1.2f;

            ParticleEmmitor smokeEmmitor = ParticleEmmitorFactory.CreateBasicFire(me.SceneMgr, Color.FromArgb(80, 0, 0, 0));

            smokeEmmitor.Amount      = 20;
            smokeEmmitor.MinLife     = 0.3f;
            smokeEmmitor.MaxLife     = 0.4f;
            smokeEmmitor.MinSize     = minSize * 1.3f;
            smokeEmmitor.MaxSize     = maxSize * 1.3f;
            smokeEmmitor.SpawnRadius = 4f;
            smokeEmmitor.Infinite    = true;

            ParticleEmmitor fireEmmitor = ParticleEmmitorFactory.CreateBasicFire(me.SceneMgr, Color.FromArgb(150, 255, 100, 0));

            fireEmmitor.Amount   = 20;
            fireEmmitor.MinLife  = 0.1f;
            fireEmmitor.MaxLife  = 0.2f;
            fireEmmitor.MinSize  = minSize * 1.1f;
            fireEmmitor.MaxSize  = maxSize * 1.1f;
            fireEmmitor.Infinite = true;

            ParticleEmmitor fireEmmitor2 = ParticleEmmitorFactory.CreateBasicFire(me.SceneMgr, Color.FromArgb(200, 255, 200, 0));

            fireEmmitor2.Amount   = 20;
            fireEmmitor2.MinLife  = 0.1f;
            fireEmmitor2.MaxLife  = 0.1f;
            fireEmmitor2.MinSize  = minSize;
            fireEmmitor2.MaxSize  = maxSize;
            fireEmmitor2.Infinite = true;

            EmmitorGroup grp = new EmmitorGroup();

            grp.Add(smokeEmmitor);
            grp.Add(fireEmmitor);
            grp.Add(fireEmmitor2);

            node.AddEmmitorGroup(grp, new Vector(), false);

            NewtonianMovementControl nmc = new NewtonianMovementControl();

            nmc.Speed = (asteroid.GetControlOfType <IMovementControl>().RealSpeed / tpf) * 0.75f;
            node.AddControl(nmc);
            node.AddControl(new LimitedLifeControl((float)FastMath.LinearInterpolate(0.5, 2, me.SceneMgr.GetRandomGenerator().NextDouble())));

            me.SceneMgr.DelayedAttachToScene(node);
        }