Example #1
0
        public static Vector3 AggregateAffectors(Vector3 position, List <ParticleAffector> affectors)
        {
            Vector3 extra = new Vector3();

            for (int i = 0, numAffectors = affectors.Count; i < numAffectors; i++)
            {
                ParticleAffector affector        = affectors[i];
                Vector3          delta           = affector.transform.position - position;
                float            distanceSquared = delta.sqrMagnitude;

                float minDistanceSquared = affector.influenceStartRadius * affector.influenceStartRadius;
                float maxDistanceSquared = (affector.influenceStartRadius + affector.influenceSpan) * (affector.influenceStartRadius + affector.influenceSpan);
                if (distanceSquared < maxDistanceSquared && distanceSquared > minDistanceSquared)
                {
                    float distance = Mathf.Sqrt(distanceSquared);

                    float t         = (distance - affector.influenceStartRadius) / affector.influenceSpan;
                    float pullForce = affector.influence.Evaluate(t) * affector.strength;

                    Vector3 pull = delta / distance * pullForce;                     // Optimize with calculated values

                    extra += pull;
                }
            }

            return(extra);
        }
Example #2
0
        public List <Param> xGetExtraAffectorParams(ParticleAffector af)
        {
            List <Param> list = new List <Param>();

            if (af == null)
            {
                return(list);
            }

            // the default
            //Dictionary<string, string> def = xGetDefEmitterParams(pe.Type);

            //////////////////////////////////////////////////////////////////////////
            Const_ParameterList plist = af.GetParameters();

            foreach (ParameterDef_NativePtr c in plist)
            {
                // dont include base emitter properties!
                //if (def.ContainsKey(c.name) == false) continue;

                string value = af.GetParameter(c.name);
                list.Add(new Param()
                {
                    Property = c.name, Value = value, Description = c.description
                });
            }

            return(list);
        }
Example #3
0
        public void Add(SceneNode parent, uint time)
        {
            ParticleSystemSceneNode ps = device.SceneManager.AddParticleSystemSceneNode(false, parent);

            ParticleEmitter em = ps.CreateBoxEmitter(
                new AABBox(parent.BoundingBox.MinEdge / 4, parent.BoundingBox.MaxEdge / 4),
                new Vector3Df(0.0f, 0.025f, 0.0f),
                100, 200,
                new Color(0xffffffff), new Color(0xffffffff),
                1500, 2500);

            em.MinStartSize = new Dimension2Df(parent.BoundingBox.Extent.X, parent.BoundingBox.Extent.Y);
            em.MaxStartSize = em.MinStartSize * 1.5f;

            ps.Emitter = em;
            em.Drop();

            ParticleAffector paf = ps.CreateFadeOutParticleAffector();

            ps.AddAffector(paf);
            paf.Drop();

            ps.SetMaterialFlag(MaterialFlag.Lighting, false);
            ps.SetMaterialFlag(MaterialFlag.ZWrite, false);
            ps.SetMaterialTexture(0, device.VideoDriver.GetTexture("../../media/fireball.bmp"));
            ps.SetMaterialType(MaterialType.TransparentAddColor);

            particleNodes.Add(new ParticleNode(ps, time));
        }
 public void Add(ParticleAffector affector)
 {
     if (!affectors.Contains(affector)) {
         affectors.Add(affector);
         affector.SetParticleController(this);
         affectors.Sort();
     }
 }
 ///<see cref="ParticleAffector.CopyAttributesTo"/>
 public void CopyAttributesTo(ParticleAffector affector)
 {
     if (affector == null)
     {
         throw new ArgumentNullException("affector cannot be null!");
     }
     VelocityMatchingAffector_CopyAttributesTo(nativePtr, affector.nativePtr);
 }
Example #6
0
 public virtual void destroyAffector(ParticleAffector e)
 {
     OgrePINVOKE.ParticleAffectorFactory_destroyAffector(swigCPtr, ParticleAffector.getCPtr(e));
     if (OgrePINVOKE.SWIGPendingException.Pending)
     {
         throw OgrePINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public void _destroyAffector(ParticleAffector affector)
 {
     OgrePINVOKE.ParticleSystemManager__destroyAffector(swigCPtr, ParticleAffector.getCPtr(affector));
     if (OgrePINVOKE.SWIGPendingException.Pending)
     {
         throw OgrePINVOKE.SWIGPendingException.Retrieve();
     }
 }
Example #8
0
 ///<see cref="ParticleAffector.CopyAttributesTo"/>
 void CopyAttributesTo(ParticleAffector affector)
 {
     if (affector == null)
     {
         throw new ArgumentNullException("affector cannot be null!");
     }
     TextureAnimator_CopyAttributesTo(nativePtr, affector.nativePtr);
 }
 ///<see cref="ParticleAffector.CopyAttributesTo"/>
 public void CopyAttributesTo(ParticleAffector affector)
 {
     if (affector == null)
     {
         throw new ArgumentNullException("affector cannot be null!");
     }
     PlaneCollider_CopyAttributesTo(nativePtr, affector.nativePtr);
 }
Example #10
0
        private void button4_Click(object sender, EventArgs e)
        {
            ParticleAffector af = App.Singleton.xAddAffector(affectorBox.Text);

            if (af == null)
            {
                return;
            }
            App.Singleton.xSelectAffector(af);
            UpdateAffectorValues(true);
        }
        public ParticleAffector __deref__()
        {
            global::System.IntPtr cPtr = OgrePINVOKE.ParticleAffectorPtr___deref__(swigCPtr);
            ParticleAffector      ret  = (cPtr == global::System.IntPtr.Zero) ? null : new ParticleAffector(cPtr, false);

            if (OgrePINVOKE.SWIGPendingException.Pending)
            {
                throw OgrePINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Example #12
0
        public virtual ParticleAffector createAffector(ParticleSystem psys)
        {
            global::System.IntPtr cPtr = OgrePINVOKE.ParticleAffectorFactory_createAffector(swigCPtr, ParticleSystem.getCPtr(psys));
            ParticleAffector      ret  = (cPtr == global::System.IntPtr.Zero) ? null : new ParticleAffector(cPtr, false);

            if (OgrePINVOKE.SWIGPendingException.Pending)
            {
                throw OgrePINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Example #13
0
        public ParticleAffector addAffector(string affectorType)
        {
            global::System.IntPtr cPtr = OgrePINVOKE.ParticleSystem_addAffector(swigCPtr, affectorType);
            ParticleAffector      ret  = (cPtr == global::System.IntPtr.Zero) ? null : new ParticleAffector(cPtr, false);

            if (OgrePINVOKE.SWIGPendingException.Pending)
            {
                throw OgrePINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Example #14
0
        public ParticleAffector getAffector(ushort index)
        {
            global::System.IntPtr cPtr = OgrePINVOKE.ParticleSystem_getAffector(swigCPtr, index);
            ParticleAffector      ret  = (cPtr == global::System.IntPtr.Zero) ? null : new ParticleAffector(cPtr, false);

            if (OgrePINVOKE.SWIGPendingException.Pending)
            {
                throw OgrePINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
        public ParticleAffector _createAffector(string affectorType, ParticleSystem psys)
        {
            global::System.IntPtr cPtr = OgrePINVOKE.ParticleSystemManager__createAffector(swigCPtr, affectorType, ParticleSystem.getCPtr(psys));
            ParticleAffector      ret  = (cPtr == global::System.IntPtr.Zero) ? null : new ParticleAffector(cPtr, false);

            if (OgrePINVOKE.SWIGPendingException.Pending)
            {
                throw OgrePINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
Example #16
0
        // clear existing particle systems
        public void xClearEverything()
        {
            while (plist.Count > 0)
            {
                this.xRemoveSystem(plist[0]);
                //plist.RemoveAt(0); // not needed handles in xRemoveSystem()
            }

            sceneMgr.DestroyAllParticleSystems(); // just to make sure all is clear

            psystem   = null;
            pemitter  = null;
            paffector = null;
        }
Example #17
0
        private void listBox1_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            ParticleSystem ps = App.Singleton.xGetCurrentSystem();

            if (ps == null)
            {
                return;
            }

            ParticleAffector af = ps.GetAffector((ushort)affectorList.SelectedIndex);

            App.Singleton.xSelectAffector(af);
            UpdateAffectorValues(false);
        }
Example #18
0
        private void UpdateAffectorValues(bool reset)
        {
            if (reset)
            {
                // re-fill tables
                ParticleSystem ps = App.Singleton.xGetCurrentSystem();
                if (ps == null)
                {
                    tabBox.TabPages.Remove(affectorTab);
                    return;
                }

                App.Singleton.xSelectAffector(null);

                if (tabBox.TabPages.Contains(affectorTab) == false)
                {
                    tabBox.TabPages.Add(affectorTab);
                }

                List <string> namelist = new List <string>();
                for (int i = 0; i < ps.NumAffectors; i++)
                {
                    ParticleAffector af = ps.GetAffector((ushort)i);
                    namelist.Add("Affector" + i + ":" + af.Type);
                }
                affectorList.DataSource = namelist;
                affectorList.Update();

                if (affectorList.Items.Count > 0)
                {
                    // select first affector
                    affectorList.SelectedIndex = 0;
                    if (affectorBox.Items.Count > 0)
                    {
                        affectorBox.SelectedIndex = 0;
                    }
                    ParticleAffector af = ps.GetAffector(0);
                    App.Singleton.xSelectAffector(af);
                }
            }

            // list selected affector values
            ParticleAffector curr = App.Singleton.xGetCurrentAffector();

            affectorParamGrid.DataSource = App.Singleton.xGetExtraAffectorParams(curr);
            affectorParamGrid.Update();
        }
                public static ParticleAffector FromBaseObject(BaseObject baseObj)
                {
                    if (baseObj == null || baseObj.NativeObject == IntPtr.Zero)
                    {
                        return(null);
                    }
                    ParticleAffector obj = baseObj as  ParticleAffector;

                    if (object.Equals(obj, null))
                    {
                        obj = new ParticleAffector(CreatedWhenConstruct.CWC_NotToCreate);
                        obj.BindNativeObject(baseObj.NativeObject, "CParticleAffector");
                        obj.IncreaseCast();
                    }

                    return(obj);
                }
Example #20
0
 private void affectorParamGrid_CellValueChanged(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         DataGridViewRow  row       = affectorParamGrid.Rows[e.RowIndex];
         string           paramName = (string)row.Cells[0].Value;
         string           value     = (string)row.Cells[1].Value;
         ParticleAffector af        = App.Singleton.xGetCurrentAffector();
         if (af != null)
         {
             af.SetParameter(paramName, value);
             UpdateAffectorValues(false);
         }
     }
     catch (Exception err)
     {
         MessageBox.Show("Error: invalid parameter " + err);
     }
 }
Example #21
0
 public void xSelectAffector(ParticleAffector af)
 {
     paffector = af;
 }
                public BaseObject Create()
                {
                    ParticleAffector emptyInstance = new ParticleAffector(CreatedWhenConstruct.CWC_NotToCreate);

                    return(emptyInstance);
                }
Example #23
0
        // export ogre particle script
        public void xExportScript(string filename)
        {
            StreamWriter fp = null;

            try
            {
                fp = File.CreateText(filename);
            }
            catch (Exception err)
            {
                MessageBox.Show("Error: " + err.Message);
                return;
            }

            for (int i = 0; i < plist.Count; i++)
            {
                ParticleSystem ps = plist[i];
                fp.WriteLine("particle_system {0}", ps.Name);
                fp.WriteLine("{");

                fp.WriteLine("\tmaterial {0}", ps.MaterialName);
                fp.WriteLine("\tparticle_width {0}", ps.DefaultWidth);
                fp.WriteLine("\tparticle_height {0}", ps.DefaultHeight);
                fp.WriteLine("\tcull_each {0}", ps.CullIndividually);
                fp.WriteLine("\tquota {0}", ps.ParticleQuota);
                fp.WriteLine("\tsorted {0}", ps.SortingEnabled);
                fp.WriteLine("\tbillboard_type {0}", ps.Renderer.GetParameter("billboard_type"));
                fp.WriteLine("\tcommon_direction {0}", ps.Renderer.GetParameter("common_direction"));
                fp.WriteLine("\tcommon_up_vector {0}", ps.Renderer.GetParameter("common_up_vector"));
                fp.WriteLine();

                // emitters
                for (int j = 0; j < ps.NumEmitters; j++)
                {
                    ParticleEmitter pe = ps.GetEmitter((ushort)j);
                    fp.WriteLine("\temitter {0}", pe.Type);
                    fp.WriteLine("\t{");

                    foreach (ParameterDef_NativePtr param in pe.GetParameters())
                    {
                        string value = pe.GetParameter(param.name);
                        if (value == "")
                        {
                            continue;              // no empty
                        }
                        if (param.name == "name")
                        {
                            continue;
                        }
                        fp.WriteLine("\t\t{0} {1}", param.name, value);
                    }

                    fp.WriteLine("\t}");
                    fp.WriteLine();
                }

                // affectors
                for (int j = 0; j < ps.NumAffectors; j++)
                {
                    ParticleAffector af = ps.GetAffector((ushort)j);
                    fp.WriteLine("\taffector {0}", af.Type);
                    fp.WriteLine("\t{");

                    foreach (ParameterDef_NativePtr param in af.GetParameters())
                    {
                        string value = af.GetParameter(param.name);
                        fp.WriteLine("\t\t{0} {1}", param.name, value);
                    }

                    fp.WriteLine("\t}");
                    fp.WriteLine();
                }

                fp.WriteLine("}");
                fp.WriteLine();
            }

            fp.Close();
        }
Example #24
0
        // save flow file
        public void xSaveConfinguration(string filename)
        {
            XmlTextWriter xml = null;

            try
            {
                xml = new XmlTextWriter(filename, null);
            }
            catch (Exception err)
            {
                MessageBox.Show("Error: " + err.Message);
                return;
            }

            xml.Formatting = Formatting.Indented; // tabs & newlines
            xml.WriteStartDocument();
            {
                xml.WriteStartElement("config");
                xml.WriteStartAttribute("version");
                xml.WriteValue(1000);
                xml.WriteEndAttribute();

                for (int i = 0; i < plist.Count; i++)
                {
                    ParticleSystem p = plist[i];
                    xml.WriteStartElement("system");
                    xml.WriteStartAttribute("name");
                    xml.WriteValue(p.Name);
                    xml.WriteEndAttribute();

                    xml.WriteStartElement("params");
                    foreach (ParameterDef_NativePtr param in p.GetParameters())
                    {
                        xml.WriteStartElement("add");
                        xml.WriteStartAttribute("key");
                        xml.WriteValue(param.name);
                        xml.WriteEndAttribute();

                        xml.WriteStartAttribute("value");
                        xml.WriteValue(p.GetParameter(param.name));
                        xml.WriteEndAttribute();
                        xml.WriteEndElement();
                    }

                    // billboard type
                    xml.WriteStartElement("add");
                    xml.WriteStartAttribute("key");
                    xml.WriteValue("billboard_type");
                    xml.WriteEndAttribute();

                    xml.WriteStartAttribute("value");
                    xml.WriteValue(p.Renderer.GetParameter("billboard_type"));
                    xml.WriteEndAttribute();
                    xml.WriteEndElement();

                    // common dir
                    xml.WriteStartElement("add");
                    xml.WriteStartAttribute("key");
                    xml.WriteValue("common_direction");
                    xml.WriteEndAttribute();

                    xml.WriteStartAttribute("value");
                    xml.WriteValue(p.Renderer.GetParameter("common_direction"));
                    xml.WriteEndAttribute();
                    xml.WriteEndElement();
                    xml.WriteEndElement();

                    // affectors
                    for (int j = 0; j < p.NumAffectors; j++)
                    {
                        ParticleAffector af = p.GetAffector((ushort)j);

                        xml.WriteStartElement("affector");
                        xml.WriteStartAttribute("type");
                        xml.WriteValue(af.Type);
                        xml.WriteEndAttribute();

                        xml.WriteStartAttribute("name");
                        xml.WriteValue("Affector" + j);
                        xml.WriteEndAttribute();
                        {
                            xml.WriteStartElement("params");
                            foreach (ParameterDef_NativePtr param in af.GetParameters())
                            {
                                xml.WriteStartElement("add");
                                xml.WriteStartAttribute("key");
                                xml.WriteValue(param.name);
                                xml.WriteEndAttribute();

                                xml.WriteStartAttribute("value");
                                xml.WriteValue(af.GetParameter(param.name));
                                xml.WriteEndAttribute();
                                xml.WriteEndElement();
                            }
                            xml.WriteEndElement();
                        }
                        xml.WriteEndElement();
                    }

                    // emitters
                    for (int j = 0; j < p.NumEmitters; j++)
                    {
                        ParticleEmitter em = p.GetEmitter((ushort)j);
                        xml.WriteStartElement("emitter");
                        xml.WriteStartAttribute("type");
                        xml.WriteValue(em.Type);
                        xml.WriteEndAttribute();

                        xml.WriteStartAttribute("name");
                        xml.WriteValue("Emitter" + j);
                        xml.WriteEndAttribute();
                        {
                            xml.WriteStartElement("params");
                            foreach (ParameterDef_NativePtr param in em.GetParameters())
                            {
                                xml.WriteStartElement("add");
                                xml.WriteStartAttribute("key");
                                xml.WriteValue(param.name);
                                xml.WriteEndAttribute();

                                xml.WriteStartAttribute("value");
                                xml.WriteValue(em.GetParameter(param.name));
                                xml.WriteEndAttribute();
                                xml.WriteEndElement();
                            }
                            xml.WriteEndElement();
                        }
                        xml.WriteEndElement();
                    }

                    xml.WriteEndElement();     // </system>
                }

                xml.WriteEndElement();//</config>
            }
            xml.WriteEndDocument();
            xml.Close();
        }
Example #25
0
        static void Main()
        {
            DriverType?driverType = AskForDriver();

            if (!driverType.HasValue)
            {
                return;
            }

            IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType.Value, new Dimension2Di(640, 480));

            if (device == null)
            {
                return;
            }

            VideoDriver    driver = device.VideoDriver;
            SceneManager   smgr   = device.SceneManager;
            GUIEnvironment env    = device.GUIEnvironment;

            driver.SetTextureCreationFlag(TextureCreationFlag.Always32Bit, true);

            // add irrlicht logo
            env.AddImage(driver.GetTexture("../../media/irrlichtlogoalpha2.tga"), new Vector2Di(10));

            // add camera
            CameraSceneNode camera = smgr.AddCameraSceneNodeFPS();

            camera.Position = new Vector3Df(-200, 200, -200);

            // disable mouse cursor
            device.CursorControl.Visible = false;

            driver.Fog = new Fog(new Color(138, 125, 81, 0), FogType.Linear, 250, 1000, 0.003f, true, false);

            AnimatedMesh roomMesh = smgr.GetMesh("../../media/room.3ds");
            SceneNode    room     = null;
            SceneNode    earth    = null;

            if (roomMesh != null)
            {
                // the room mesh doesn't have proper texture mapping on the floor,
                // so we can recreate them on runtime
                smgr.MeshManipulator.MakePlanarTextureMapping(roomMesh.GetMesh(0), 0.003f);

                Texture normalMap = driver.GetTexture("../../media/rockwall_height.bmp");
                if (normalMap != null)
                {
                    driver.MakeNormalMapTexture(normalMap, 9.0f);
                }

                Mesh tangentMesh = smgr.MeshManipulator.CreateMeshWithTangents(roomMesh.GetMesh(0));
                room = smgr.AddMeshSceneNode(tangentMesh);
                room.SetMaterialTexture(0, driver.GetTexture("../../media/rockwall.jpg"));
                room.SetMaterialTexture(1, normalMap);
                room.GetMaterial(0).SpecularColor = new Color(0);
                room.GetMaterial(0).Shininess     = 0.0f;
                room.SetMaterialFlag(MaterialFlag.Fog, true);
                room.SetMaterialType(MaterialType.ParallaxMapSolid);
                room.GetMaterial(0).MaterialTypeParam = 1.0f / 64.0f; // adjust height for parallax effect

                tangentMesh.Drop();                                   // drop mesh because we created it with a "create" call
            }

            // add earth sphere
            AnimatedMesh earthMesh = smgr.GetMesh("../../media/earth.x");

            if (earthMesh != null)
            {
                // perform various task with the mesh manipulator
                MeshManipulator manipulator = smgr.MeshManipulator;

                // create mesh copy with tangent informations from original earth.x mesh
                Mesh tangentSphereMesh = manipulator.CreateMeshWithTangents(earthMesh.GetMesh(0));

                // set the alpha value of all vertices to 200
                manipulator.SetVertexColorAlpha(tangentSphereMesh, 200);

                // scale the mesh by factor 50
                Matrix m = new Matrix();
                m.Scale = new Vector3Df(50);
                manipulator.Transform(tangentSphereMesh, m);

                earth          = smgr.AddMeshSceneNode(tangentSphereMesh);
                earth.Position = new Vector3Df(-70, 130, 45);

                // load heightmap, create normal map from it and set it
                Texture earthNormalMap = driver.GetTexture("../../media/earthbump.jpg");
                if (earthNormalMap != null)
                {
                    driver.MakeNormalMapTexture(earthNormalMap, 20);
                    earth.SetMaterialTexture(1, earthNormalMap);
                    earth.SetMaterialType(MaterialType.NormalMapTransparentVertexAlpha);
                }

                // adjust material settings
                earth.SetMaterialFlag(MaterialFlag.Fog, true);

                // add rotation animator
                SceneNodeAnimator anim = smgr.CreateRotationAnimator(new Vector3Df(0, 0.1f, 0));
                earth.AddAnimator(anim);
                anim.Drop();

                // drop mesh because we created it with a "create" call.
                tangentSphereMesh.Drop();
            }

            // add light 1 (more green)
            LightSceneNode light1 = smgr.AddLightSceneNode(null, new Vector3Df(), new Colorf(0.5f, 1.0f, 0.5f, 0.0f), 800);

            if (light1 != null)
            {
                light1.DebugDataVisible = DebugSceneType.BBox;

                // add fly circle animator to light
                SceneNodeAnimator anim = smgr.CreateFlyCircleAnimator(new Vector3Df(50, 300, 0), 190.0f, -0.003f);
                light1.AddAnimator(anim);
                anim.Drop();

                // attach billboard to the light
                BillboardSceneNode bill = smgr.AddBillboardSceneNode(light1, new Dimension2Df(60, 60));
                bill.SetMaterialFlag(MaterialFlag.Lighting, false);
                bill.SetMaterialFlag(MaterialFlag.ZWrite, false);
                bill.SetMaterialType(MaterialType.TransparentAddColor);
                bill.SetMaterialTexture(0, driver.GetTexture("../../media/particlegreen.jpg"));
            }

            // add light 2 (red)
            SceneNode light2 = smgr.AddLightSceneNode(null, new Vector3Df(), new Colorf(1.0f, 0.2f, 0.2f, 0.0f), 800.0f);

            if (light2 != null)
            {
                // add fly circle animator to light
                SceneNodeAnimator anim = smgr.CreateFlyCircleAnimator(new Vector3Df(0, 150, 0), 200.0f, 0.001f, new Vector3Df(0.2f, 0.9f, 0.0f));
                light2.AddAnimator(anim);
                anim.Drop();

                // attach billboard to light
                SceneNode bill = smgr.AddBillboardSceneNode(light2, new Dimension2Df(120, 120));
                bill.SetMaterialFlag(MaterialFlag.Lighting, false);
                bill.SetMaterialFlag(MaterialFlag.ZWrite, false);
                bill.SetMaterialType(MaterialType.TransparentAddColor);
                bill.SetMaterialTexture(0, driver.GetTexture("../../media/particlered.bmp"));

                // add particle system
                ParticleSystemSceneNode ps = smgr.AddParticleSystemSceneNode(false, light2);

                // create and set emitter
                ParticleEmitter em = ps.CreateBoxEmitter(
                    new AABBox(-3, 0, -3, 3, 1, 3),
                    new Vector3Df(0.0f, 0.03f, 0.0f),
                    80, 100,
                    new Color(255, 255, 255, 10), new Color(255, 255, 255, 10),
                    400, 1100);

                em.MinStartSize = new Dimension2Df(30.0f, 40.0f);
                em.MaxStartSize = new Dimension2Df(30.0f, 40.0f);

                ps.Emitter = em;
                em.Drop();

                // create and set affector
                ParticleAffector paf = ps.CreateFadeOutParticleAffector();
                ps.AddAffector(paf);
                paf.Drop();

                // adjust some material settings
                ps.SetMaterialFlag(MaterialFlag.Lighting, false);
                ps.SetMaterialFlag(MaterialFlag.ZWrite, false);
                ps.SetMaterialTexture(0, driver.GetTexture("../../media/fireball.bmp"));
                ps.SetMaterialType(MaterialType.TransparentAddColor);
            }

            MyEventReceiver receiver = new MyEventReceiver(device, room, earth);

            int lastFPS = -1;

            while (device.Run())
            {
                if (device.WindowActive)
                {
                    driver.BeginScene(ClearBufferFlag.All, new Color(0));

                    smgr.DrawAll();
                    env.DrawAll();

                    driver.EndScene();

                    int fps = driver.FPS;
                    if (lastFPS != fps)
                    {
                        device.SetWindowCaption(String.Format(
                                                    "Per pixel lighting example - Irrlicht Engine [{0}] fps: {1}",
                                                    driver.Name, fps));

                        lastFPS = fps;
                    }
                }
            }

            device.Drop();
        }
Example #26
0
 public ParticleAffectorTranslator()
     : base()
 {
     this._Affector = null;
 }
 ///<see cref="ParticleAffector.CopyAttributesTo"/>
 public void CopyAttributesTo(ParticleAffector affector)
 {
     if (affector == null)
         throw new ArgumentNullException("affector cannot be null!");
     GravityAffector__CopyAttributesTo(nativePtr, affector.nativePtr);
 }
Example #28
0
 public void xSelectAffector(ParticleAffector af)
 {
     paffector = af;
 }
Example #29
0
        public List<Param> xGetExtraAffectorParams(ParticleAffector af)
        {
            List<Param> list = new List<Param>();

            if (af == null) return list;

            // the default
            //Dictionary<string, string> def = xGetDefEmitterParams(pe.Type);

            //////////////////////////////////////////////////////////////////////////
            Const_ParameterList plist = af.GetParameters();
            foreach (ParameterDef_NativePtr c in plist)
            {
                // dont include base emitter properties!
                //if (def.ContainsKey(c.name) == false) continue;

                string value = af.GetParameter(c.name);
                list.Add(new Param() { Property = c.name, Value = value, Description = c.description });
            }

            return list;
        }
Example #30
0
        // clear existing particle systems
        public void xClearEverything()
        {
            while (plist.Count > 0)
            {
                this.xRemoveSystem(plist[0]);
                //plist.RemoveAt(0); // not needed handles in xRemoveSystem()
            }

            sceneMgr.DestroyAllParticleSystems(); // just to make sure all is clear

            psystem = null;
            pemitter = null;
            paffector = null;
        }
 /// <summary>
 ///		Destroys the affector referenced by the parameter.
 /// </summary>
 /// <param name="e">The Affector to destroy.</param>
 public virtual void Destroy(ParticleAffector e)
 {
     // remove the affector from the list
     this.affectorList.Remove(e);
 }
Example #32
0
        // load flow file
        public void xLoadConfinguration(string filename)
        {
            this.xClearEverything();

            XPathDocument doc = null;

            try
            {
                doc = new XPathDocument(filename);
            }
            catch (Exception err)
            {
                MessageBox.Show("Error: " + err.Message);
                return;
            }

            XPathNavigator nav = doc.CreateNavigator();

            try
            {
                XPathNodeIterator it = nav.Select("/config");
                it.MoveNext();
                string version = it.Current.GetAttribute("version", "");

                // get all systems
                XPathNodeIterator sysnames = nav.Select("//system/@name");

                while (sysnames.MoveNext())
                {
                    string         sysName = sysnames.Current.Value;
                    ParticleSystem ps      = this.xAddParticleSystem(sysName);
                    this.xSelectSystem(ps);

                    // get system params
                    string            path  = String.Format("//system[@name='{0}']/params/add", sysName);
                    XPathNodeIterator param = nav.Select(path);
                    while (param.MoveNext())
                    {
                        string pName  = param.Current.GetAttribute("key", "");
                        string pValue = param.Current.GetAttribute("value", "");
                        ps.SetParameter(pName, pValue);
                    }

                    // create affectors
                    string            affpath = String.Format("//system[@name='{0}']/affector", sysName);
                    XPathNodeIterator affit   = nav.Select(affpath);

                    while (affit.MoveNext())
                    {
                        string           af_type = affit.Current.GetAttribute("type", "");
                        string           af_name = affit.Current.GetAttribute("name", "");
                        ParticleAffector af      = this.xAddAffector(af_type);

                        string affparam = String.Format(
                            "//system[@name='{0}']/affector[@name='{1}']/params/add",
                            sysName, af_name);
                        XPathNodeIterator pit = nav.Select(affparam);
                        while (pit.MoveNext())
                        {
                            string pName  = pit.Current.GetAttribute("key", "");
                            string pValue = pit.Current.GetAttribute("value", "");
                            af.SetParameter(pName, pValue);
                        }
                    }

                    // create emitters
                    string            empath = String.Format("//system[@name='{0}']/emitter", sysName);
                    XPathNodeIterator emit   = nav.Select(empath);

                    while (emit.MoveNext())
                    {
                        string          em_type = emit.Current.GetAttribute("type", "");
                        string          em_name = emit.Current.GetAttribute("name", "");
                        ParticleEmitter em      = this.xAddTypedEmitter(em_type,
                                                                        this.xGetDefEmitterParams(em_type));

                        string emparam = String.Format(
                            "//system[@name='{0}']/emitter[@name='{1}']/params/add",
                            sysName, em_name);
                        XPathNodeIterator pit = nav.Select(emparam);
                        while (pit.MoveNext())
                        {
                            string pName = pit.Current.GetAttribute("key", "");
                            if (pName == "name")
                            {
                                continue;                  // do not overwrite name!
                            }
                            string pValue = pit.Current.GetAttribute("value", "");
                            em.SetParameter(pName, pValue);
                        }
                    }
                }
            }
            catch (Exception err)
            {
                MessageBox.Show("Error: " + err);
            }

            // select first
            if (plist.Count > 0)
            {
                this.xSelectSystem(plist[0]);
                if (plist[0] != null && plist[0].NumEmitters > 0)
                {
                    this.xSelectEmitter(plist[0].GetEmitter(0));
                }
            }
        }
Example #33
0
        static void Main()
        {
            bool shadows = AskForRealtimeShadows();

            DriverType?driverType = AskForDriver();

            if (!driverType.HasValue)
            {
                return;
            }

            IrrlichtDevice device = IrrlichtDevice.CreateDevice(driverType.Value, new Dimension2Di(640, 480), 16, false, shadows);

            if (device == null)
            {
                return;
            }

            VideoDriver  driver = device.VideoDriver;
            SceneManager smgr   = device.SceneManager;

            AnimatedMesh mesh = smgr.GetMesh("../../media/room.3ds");

            smgr.MeshManipulator.MakePlanarTextureMapping(mesh.GetMesh(0), 0.004f);

            SceneNode node = smgr.AddAnimatedMeshSceneNode(mesh);

            node.SetMaterialTexture(0, driver.GetTexture("../../media/wall.jpg"));
            node.GetMaterial(0).SpecularColor = new Color(0);

            mesh = smgr.AddHillPlaneMesh("myHill",
                                         new Dimension2Df(20, 20),
                                         new Dimension2Di(40, 40), null, 0,
                                         new Dimension2Df(0),
                                         new Dimension2Df(10, 10));

            node          = smgr.AddWaterSurfaceSceneNode(mesh.GetMesh(0), 3.0f, 300.0f, 30.0f);
            node.Position = new Vector3Df(0, 7, 0);

            node.SetMaterialTexture(0, driver.GetTexture("../../media/stones.jpg"));
            node.SetMaterialTexture(1, driver.GetTexture("../../media/water.jpg"));

            node.SetMaterialType(MaterialType.Reflection2Layer);

            // create light

            node = smgr.AddLightSceneNode(null, new Vector3Df(0), new Colorf(1.0f, 0.6f, 0.7f, 1.0f), 800);
            SceneNodeAnimator anim = smgr.CreateFlyCircleAnimator(new Vector3Df(0, 150, 0), 250);

            node.AddAnimator(anim);
            anim.Drop();

            // attach billboard to light

            node = smgr.AddBillboardSceneNode(node, new Dimension2Df(50, 50));
            node.SetMaterialFlag(MaterialFlag.Lighting, false);
            node.SetMaterialType(MaterialType.TransparentAddColor);
            node.SetMaterialTexture(0, driver.GetTexture("../../media/particlewhite.bmp"));

            // create a particle system

            ParticleSystemSceneNode ps = smgr.AddParticleSystemSceneNode(false);

            if (ps != null)
            {
                ParticleEmitter em = ps.CreateBoxEmitter(
                    new AABBox(-7, 0, -7, 7, 1, 7),   // emitter size
                    new Vector3Df(0.0f, 0.06f, 0.0f), // initial direction
                    80, 100,                          // emit rate
                    new Color(255, 255, 255, 0),      // darkest color
                    new Color(255, 255, 255, 0),      // brightest color
                    800, 2000, 0,                     // min and max age, angle
                    new Dimension2Df(10.0f),          // min size
                    new Dimension2Df(20.0f));         // max size

                ps.Emitter = em;                      // this grabs the emitter
                em.Drop();                            // so we can drop it here without deleting it

                ParticleAffector paf = ps.CreateFadeOutParticleAffector();

                ps.AddAffector(paf);                 // same goes for the affector
                paf.Drop();

                ps.Position = new Vector3Df(-70, 60, 40);
                ps.Scale    = new Vector3Df(2);
                ps.SetMaterialFlag(MaterialFlag.Lighting, false);
                ps.SetMaterialFlag(MaterialFlag.ZWrite, false);
                ps.SetMaterialTexture(0, driver.GetTexture("../../media/fire.bmp"));
                ps.SetMaterialType(MaterialType.TransparentAddColor);
            }

            VolumeLightSceneNode n = smgr.AddVolumeLightSceneNode(null, -1,
                                                                  32,                          // Subdivisions on U axis
                                                                  32,                          // Subdivisions on V axis
                                                                  new Color(255, 255, 255, 0), // foot color
                                                                  new Color(0, 0, 0, 0));      // tail color

            if (n != null)
            {
                n.Scale    = new Vector3Df(56);
                n.Position = new Vector3Df(-120, 50, 40);

                // load textures for animation
                List <Texture> textures = new List <Texture>();
                for (int i = 7; i > 0; i--)
                {
                    string s = string.Format("../../media/portal{0}.bmp", i);
                    textures.Add(driver.GetTexture(s));
                }

                // create texture animator
                SceneNodeAnimator glow = smgr.CreateTextureAnimator(textures, 0.150f);

                // add the animator
                n.AddAnimator(glow);

                // drop the animator because it was created with a create() function
                glow.Drop();
            }

            // add animated character

            mesh = smgr.GetMesh("../../media/dwarf.x");
            AnimatedMeshSceneNode anode = smgr.AddAnimatedMeshSceneNode(mesh);

            anode.Position       = new Vector3Df(-50, 20, -60);
            anode.AnimationSpeed = 15;

            // add shadow
            anode.AddShadowVolumeSceneNode();
            smgr.ShadowColor = new Color(0, 0, 0, 150);

            // make the model a little bit bigger and normalize its normals
            // because of the scaling, for correct lighting
            anode.Scale = new Vector3Df(2);
            anode.SetMaterialFlag(MaterialFlag.NormalizeNormals, true);

            CameraSceneNode camera = smgr.AddCameraSceneNodeFPS();

            camera.Position = new Vector3Df(-50, 50, -150);

            // disable mouse cursor
            device.CursorControl.Visible = false;

            int lastFPS = -1;

            while (device.Run())
            {
                if (device.WindowActive)
                {
                    driver.BeginScene(ClearBufferFlag.All, new Color(0));
                    smgr.DrawAll();
                    driver.EndScene();

                    int fps = driver.FPS;
                    if (lastFPS != fps)
                    {
                        device.SetWindowCaption(String.Format(
                                                    "SpecialFX example - Irrlicht Engine [{0}] fps: {1}",
                                                    driver.Name, fps));

                        lastFPS = fps;
                    }
                }
            }

            device.Drop();
        }
Example #34
0
            /// <see cref="Translator.Translate"/>
            public override void Translate(ScriptCompiler compiler, AbstractNode node)
            {
                var obj = (ObjectAbstractNode)node;

                // Must have a type as the first value
                if (obj.Values.Count == 0)
                {
                    compiler.AddError(CompileErrorCode.StringExpected, obj.File, obj.Line);
                    return;
                }

                var type = string.Empty;

                if (!getString(obj.Values[0], out type))
                {
                    compiler.AddError(CompileErrorCode.InvalidParameters, obj.File, obj.Line);
                    return;
                }

                var system = (ParticleSystem)obj.Parent.Context;

                this._Affector = system.AddAffector(type);

                foreach (var i in obj.Children)
                {
                    if (i is PropertyAbstractNode)
                    {
                        var prop  = (PropertyAbstractNode)i;
                        var value = string.Empty;

                        // Glob the values together
                        foreach (var it in prop.Values)
                        {
                            if (it is AtomAbstractNode)
                            {
                                if (string.IsNullOrEmpty(value))
                                {
                                    value = ((AtomAbstractNode)it).Value;
                                }
                                else
                                {
                                    value = value + " " + ((AtomAbstractNode)it).Value;
                                }
                            }
                            else
                            {
                                compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line);
                                break;
                            }
                        }

                        if (!this._Affector.SetParam(prop.Name, value))
                        {
                            compiler.AddError(CompileErrorCode.InvalidParameters, prop.File, prop.Line);
                        }
                    }
                    else
                    {
                        processNode(compiler, i);
                    }
                }
            }
 public void Remove(ParticleAffector affector)
 {
     affectors.Remove(affector);
     affectors.Sort();
 }
		/// <summary>
		///		Destroys the affector referenced by the parameter.
		/// </summary>
		/// <param name="e">The Affector to destroy.</param>
		public virtual void Destroy( ParticleAffector e )
		{
			// remove the affector from the list
			this.affectorList.Remove( e );
		}