Exemplo n.º 1
0
		ParticleRotationAffector affRotation; // its pointer back later :(

		void irrThreadMain(object args)
		{
			irrDevice = IrrlichtDevice.CreateDevice(args as IrrlichtCreationParameters);

			// Camera

			CameraSceneNode camera = irrDevice.SceneManager.AddCameraSceneNode(null, new Vector3Df(0), new Vector3Df(0, 80, 0), (int)SceneNodeID.Camera);
			SceneNodeAnimator anim = irrDevice.SceneManager.CreateFlyCircleAnimator(new Vector3Df(0, 100, 0), 200.0f, 0.0002f);
			camera.AddAnimator(anim);
			anim.Drop();

			// Skydome

			irrDevice.SceneManager.AddSkyDomeSceneNode(irrDevice.VideoDriver.GetTexture("../../media/skydome.jpg"), 16, 8, 0.95f, 2.0f);

			// Plane

			var m = irrDevice.SceneManager.AddHillPlaneMesh("plane", new Dimension2Df(1000), new Dimension2Di(1), null, 0, new Dimension2Df(0), new Dimension2Df(8));
			var n = irrDevice.SceneManager.AddAnimatedMeshSceneNode(m, null, (int)SceneNodeID.Plane);
			n.SetMaterialFlag(MaterialFlag.Lighting, false);
			n.SetMaterialTexture(0, irrDevice.VideoDriver.GetTexture("../../media/rockwall.jpg"));

			// Axes

			m = irrDevice.SceneManager.AddArrowMesh("axisX");
			n = irrDevice.SceneManager.AddAnimatedMeshSceneNode(m, null, (int)SceneNodeID.AxisX, new Vector3Df(), new Vector3Df(0, 0, -90), new Vector3Df(50, 120, 50));
			n.GetMaterial(0).EmissiveColor = new Color(250, 250, 250);
			n.GetMaterial(1).EmissiveColor = new Color(250, 0, 0);

			m = irrDevice.SceneManager.AddArrowMesh("axisY");
			n = irrDevice.SceneManager.AddAnimatedMeshSceneNode(m, null, (int)SceneNodeID.AxisY, new Vector3Df(), new Vector3Df(0, 0, 0), new Vector3Df(50, 120, 50));
			n.GetMaterial(0).EmissiveColor = new Color(250, 250, 250);
			n.GetMaterial(1).EmissiveColor = new Color(0, 250, 0);

			m = irrDevice.SceneManager.AddArrowMesh("axisZ");
			n = irrDevice.SceneManager.AddAnimatedMeshSceneNode(m, null, (int)SceneNodeID.AxisZ, new Vector3Df(), new Vector3Df(90, 0, 0), new Vector3Df(50, 120, 50));
			n.GetMaterial(0).EmissiveColor = new Color(250, 250, 250);
			n.GetMaterial(1).EmissiveColor = new Color(0, 0, 250);

			irrThreadShowAxes(false);

			// Particle system

			var ps = irrDevice.SceneManager.AddParticleSystemSceneNode(false, null, (int)SceneNodeID.ParticleSystem);

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

			ParticleEmitter em = ps.CreateSphereEmitter(
				new Vector3Df(), 20,				// position and radius
				new Vector3Df(0.0f, 0.1f, 0.0f),	// initial direction
				150, 300,							// emit rate
				new Color(255, 255, 255, 0),		// darkest color
				new Color(255, 255, 255, 0),		// brightest color
				750, 1500, 0,						// min and max age, angle
				new Dimension2Df(20.0f),			// min size
				new Dimension2Df(40.0f));			// max size

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

			// Particle affectors

			affFadeOut = ps.CreateFadeOutParticleAffector();
			ps.AddAffector(affFadeOut);
			affFadeOut.Drop();

			affGravity = ps.CreateGravityAffector(new Vector3Df(0, -1, 0), 3000);
			affGravity.Enabled = false;
			ps.AddAffector(affGravity);
			affGravity.Drop();

			affRotation = ps.CreateRotationAffector(new Vector3Df(-90, 240, -120), new Vector3Df(0, 100, 0));
			ps.AddAffector(affRotation);
			affRotation.Drop();

			// Rendering loop

			uint rs = 0, re = 0; // render frame time
			while (irrDevice.Run())
			{
				if (irrDevice.VideoDriver.ScreenSize.Area != 0)
				{
					irrDevice.VideoDriver.BeginScene();
					irrDevice.SceneManager.DrawAll();
					re = irrDevice.Timer.Time;

					irrThreadDrawText(new Vector2Di(8, 8),
						"Frame time: " + (irrDevice.VideoDriver.FPS > 1000 ? "< 1" : (re - rs).ToString()) + " ms");

					irrDevice.VideoDriver.EndScene();
				}
				else
				{
					Thread.Sleep(50);
				}

				irrThreadProcessCommandQueue();
				rs = irrDevice.Timer.Time;
			}

			irrDevice.Drop();
		}
Exemplo n.º 2
0
        ParticleRotationAffector affRotation;       // its pointer back later :(

        void irrThreadMain(object args)
        {
            irrDevice = IrrlichtDevice.CreateDevice(args as IrrlichtCreationParameters);

            // Camera

            CameraSceneNode   camera = irrDevice.SceneManager.AddCameraSceneNode(null, new Vector3Df(0), new Vector3Df(0, 80, 0), (int)SceneNodeID.Camera);
            SceneNodeAnimator anim   = irrDevice.SceneManager.CreateFlyCircleAnimator(new Vector3Df(0, 100, 0), 200.0f, 0.0002f);

            camera.AddAnimator(anim);
            anim.Drop();

            // Skydome

            irrDevice.SceneManager.AddSkyDomeSceneNode(irrDevice.VideoDriver.GetTexture("../../media/skydome.jpg"), 16, 8, 0.95f, 2.0f);

            // Plane

            var m = irrDevice.SceneManager.AddHillPlaneMesh("plane", new Dimension2Df(1000), new Dimension2Di(1), null, 0, new Dimension2Df(0), new Dimension2Df(8));
            var n = irrDevice.SceneManager.AddAnimatedMeshSceneNode(m, null, (int)SceneNodeID.Plane);

            n.SetMaterialFlag(MaterialFlag.Lighting, false);
            n.SetMaterialTexture(0, irrDevice.VideoDriver.GetTexture("../../media/rockwall.jpg"));

            // Axes

            m = irrDevice.SceneManager.AddArrowMesh("axisX");
            n = irrDevice.SceneManager.AddAnimatedMeshSceneNode(m, null, (int)SceneNodeID.AxisX, new Vector3Df(), new Vector3Df(0, 0, -90), new Vector3Df(50, 120, 50));
            n.GetMaterial(0).EmissiveColor = new Color(250, 250, 250);
            n.GetMaterial(1).EmissiveColor = new Color(250, 0, 0);

            m = irrDevice.SceneManager.AddArrowMesh("axisY");
            n = irrDevice.SceneManager.AddAnimatedMeshSceneNode(m, null, (int)SceneNodeID.AxisY, new Vector3Df(), new Vector3Df(0, 0, 0), new Vector3Df(50, 120, 50));
            n.GetMaterial(0).EmissiveColor = new Color(250, 250, 250);
            n.GetMaterial(1).EmissiveColor = new Color(0, 250, 0);

            m = irrDevice.SceneManager.AddArrowMesh("axisZ");
            n = irrDevice.SceneManager.AddAnimatedMeshSceneNode(m, null, (int)SceneNodeID.AxisZ, new Vector3Df(), new Vector3Df(90, 0, 0), new Vector3Df(50, 120, 50));
            n.GetMaterial(0).EmissiveColor = new Color(250, 250, 250);
            n.GetMaterial(1).EmissiveColor = new Color(0, 0, 250);

            irrThreadShowAxes(false);

            // Particle system

            var ps = irrDevice.SceneManager.AddParticleSystemSceneNode(false, null, (int)SceneNodeID.ParticleSystem);

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

            ParticleEmitter em = ps.CreateSphereEmitter(
                new Vector3Df(), 20,                                    // position and radius
                new Vector3Df(0.0f, 0.1f, 0.0f),                        // initial direction
                150, 300,                                               // emit rate
                new Color(255, 255, 255, 0),                            // darkest color
                new Color(255, 255, 255, 0),                            // brightest color
                750, 1500, 0,                                           // min and max age, angle
                new Dimension2Df(20.0f),                                // min size
                new Dimension2Df(40.0f));                               // max size

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

            // Particle affectors

            affFadeOut = ps.CreateFadeOutParticleAffector();
            ps.AddAffector(affFadeOut);
            affFadeOut.Drop();

            affGravity         = ps.CreateGravityAffector(new Vector3Df(0, -1, 0), 3000);
            affGravity.Enabled = false;
            ps.AddAffector(affGravity);
            affGravity.Drop();

            affRotation = ps.CreateRotationAffector(new Vector3Df(-90, 240, -120), new Vector3Df(0, 100, 0));
            ps.AddAffector(affRotation);
            affRotation.Drop();

            // Rendering loop

            uint rs = 0, re = 0;             // render frame time

            while (irrDevice.Run())
            {
                if (irrDevice.VideoDriver.ScreenSize.Area != 0)
                {
                    irrDevice.VideoDriver.BeginScene();
                    irrDevice.SceneManager.DrawAll();
                    re = irrDevice.Timer.Time;

                    irrThreadDrawText(new Vector2Di(8, 8),
                                      "Frame time: " + (irrDevice.VideoDriver.FPS > 1000 ? "< 1" : (re - rs).ToString()) + " ms");

                    irrDevice.VideoDriver.EndScene();
                }
                else
                {
                    Thread.Sleep(50);
                }

                irrThreadProcessCommandQueue();
                rs = irrDevice.Timer.Time;
            }

            irrDevice.Drop();
        }