Inheritance: NativeElement
Beispiel #1
0
 /// <summary>
 /// Irrlicht Instance.  A handle to the Irrlicht device.
 /// </summary>
 //public IrrlichtDevice Device;
 //public VideoDriver Driver;
 //public SceneManager SceneManager;
 //public GUIEnvironment GuiEnvironment;
 //public IdealistUserControl ViewerControl;
 public RaegastRenderer(RadegastViewer viewer, IrrlichtDevice device)
     : base(viewer)
 {
     //  ViewerControl = viewer.ViewerControl;
     m_viewer = viewer;
     Device = device;
 }
Beispiel #2
0
        public RefController(Viewer viewer)
        {
            this.viewer = viewer;
            device = viewer.Device;

            driver = device.VideoDriver;
            smgr = device.SceneManager;
            guienv = device.GUIEnvironment;
        }
Beispiel #3
0
        public static void Main()
        {
            IrrlichtDevice device = new IrrlichtDevice(DriverType.OpenGL,
                                                    new Dimension2D(640, 480),
                                                    32, false, true, true, true);

            device.FileSystem.WorkingDirectory = "../../medias";
            device.OnEvent += new OnEventDelegate(device_OnEvent);

            string caption = "Irrlicht .NET CP ATMOSpere test";

            driver = device.VideoDriver;
            scene = device.SceneManager;

            terrain = scene.AddTerrainSceneNode(
                "terrain-heightmap.bmp", null, -1,
                new Vector3D(0,0,0), new Vector3D(1,1,1), new Vector3D(40, 4.4f, 40), new Color(255, 255, 255, 255),5,TerrainPatchSize.TPS17);

            terrain.SetMaterialFlag(MaterialFlag.Lighting, false);
            terrain.SetMaterialType(MaterialType.DetailMap);
            terrain.SetMaterialTexture(0, driver.GetTexture("terrain-texture.jpg"));
            terrain.SetMaterialTexture(1, driver.GetTexture("detail2.tga"));

            terrain.ScaleTexture(1.0f, 20.0f);

               	atmo = new ATMOSphere(device.Timer, null, scene, -1);
               	atmo.SkyTexture = driver.GetTexture("sky2.tga");
               	atmo.SunTexture = driver.GetTexture("sun.tga");
               	atmo.StarsTexture = driver.GetTexture("stars.bmp");
               	atmo.CreateSkyPalette();
            atmo.Speed = 600.0f;

                                KeyMap keyMap = new KeyMap();
                    keyMap.AssignAction(KeyAction.MoveForward,KeyCode.Key_W);
                    keyMap.AssignAction(KeyAction.MoveBackward,KeyCode.Key_S);
                    keyMap.AssignAction(KeyAction.StrafeLeft,KeyCode.Key_A);
                    keyMap.AssignAction(KeyAction.StrafeRight,KeyCode.Key_D);

            CameraSceneNode fpsCam = scene.AddCameraSceneNodeFPS(null, 50, 200, false, keyMap);
            fpsCam.Position = Vector3D.From(2200,440,2000);

            device.CursorControl.Visible = false;
            driver.SetTextureFlag(TextureCreationFlag.Always32Bit, true);
            Timer timer = device.Timer;

            new ATMOSkytest();

            while (device.Run() && !Exit)
            {
                driver.BeginScene(true, true, Color.Gray);
               			atmo.Update(device.Timer.RealTime);
                scene.DrawAll();
                driver.EndScene();

            }
        }
Beispiel #4
0
        /// <summary>
        /// Performs initialisation of the scene, such as loading configuration from disk.
        /// </summary>
        public override void Startup()
        {
            m_consoleThread = Thread.CurrentThread;
            if (true)
            {
                m_mainThread = new Thread(new ThreadStart(() =>
                {
                    ViewerControl.InitializeComponent();
                    Device = new IrrlichtDevice(DriverType.OpenGL,
                                                new Dimension2D(WindowWidth,
                                                                WindowHeight),
                                                32, false, true, true, true
                        );

                    StartupComponents();
                    MainLoop(skin, skincolor);
                }));
            }
            else
            {
                m_mainThread = new Thread(new ThreadStart(() =>
                {
                    ViewerControl.InitializeComponent();
                    Device = new IrrlichtDevice(DriverType.OpenGL,
                                                new Dimension2D(WindowWidth,
                                                                WindowHeight),
                                                32, false, true, true, true,

                        ViewerControl.IdealistView.Handle
                        );

                    StartupComponents();
                    MainLoop(skin, skincolor);
                }));

            }


            m_mainThread.Start();
        }
Beispiel #5
0
        public static void Main(string[] args)
        {
            // Do a usuall setup
            DriverType driverType = DriverType.OpenGL;
            device = new IrrlichtDevice(driverType, new Dimension2D(640, 480), 32, false, true, true, true);
            device.FileSystem.WorkingDirectory = "../../medias";

            device.OnEvent += new OnEventDelegate(device_OnEvent);

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

            guienv.Skin.SetColor(GuiDefaultColor.ButtonText, Color.White);

            guienv.AddImage(driver.GetTexture("NETCPlogo.png"),
                new Position2D(10, 10), true, null, 0, "");

            // Static camera should be enough
            CameraSceneNode camera =
                smgr.AddCameraSceneNode(null);

            camera.Position = new Vector3D(0,40,-60);
            camera.Target = new Vector3D(0,40,0);

            smgr.AddLightSceneNode(null, new Vector3D(10, 9, 0), Colorf.White, 10.0f, -1);

            smgr.AddSkyBoxSceneNode(null, new Texture[] {
                driver.GetTexture("irrlicht2_up.jpg"),
                driver.GetTexture("irrlicht2_dn.jpg"),
                driver.GetTexture("irrlicht2_rt.jpg"),
                driver.GetTexture("irrlicht2_lf.jpg"),
                driver.GetTexture("irrlicht2_ft.jpg"),
                driver.GetTexture("irrlicht2_bk.jpg")}, 0);

            // The interesting part
            // First load the mesh with bones.
            AnimatedMesh mesh = smgr.GetMesh("dwarf.x");

            // Check, whether our mesh has bones
            if (mesh.MeshType == AnimatedMeshType.Skinned)
            {
            // Create an animatedmesh scene node from it
            AnimatedMeshSceneNode mesh_node = smgr.AddAnimatedMeshSceneNode(mesh);

            // set joints to controllable state, or irrlicht will try to animate them
            mesh_node.JointMode = JointUpdateOnRenderMode.Control;

            // Get our bones by name
            bone1 = mesh_node.GetJointNode("spine2");
            bone2 = mesh_node.GetJointNode("head");
            bone3 = mesh_node.GetJointNode("rsholda");

            // We add three scrollbars to control our bones
            guienv.AddStaticText("Torso", new Rect(new Position2D(40, driver.ViewPort.Height-110),
                                                               new Dimension2D(240, 20)),
                                     false,
                                     false,
                                     null,
                                     -1,
                                     false);
            GUIScrollBar scroll = guienv.AddScrollBar(true,
                                new Rect(new Position2D(40, driver.ViewPort.Height-100),
                                                               new Dimension2D(240, 20)),
                                null,
                                1);
            scroll.Max = 180;
            // Initial rotation of each bone is 0, so set the scrollbar position to the middle
            // to make controlling more cool
            scroll.Pos = 90;

            guienv.AddStaticText("Head", new Rect(new Position2D(40, driver.ViewPort.Height-80),
                                                               new Dimension2D(240, 20)),
                                     false,
                                     false,
                                     null,
                                     -1,
                                     false);

            scroll = guienv.AddScrollBar(true,
                                new Rect(new Position2D(40, driver.ViewPort.Height-70),
                                                               new Dimension2D(240, 20)),
                                null,
                                2);
            scroll.Max = 160;
            scroll.Pos = 80;

            guienv.AddStaticText("Axe", new Rect(new Position2D(40, driver.ViewPort.Height-50),
                                                               new Dimension2D(240, 20)),
                                     false,
                                     false,
                                     null,
                                     -1,
                                     false);
            scroll = guienv.AddScrollBar(true,
                                new Rect(new Position2D(40, driver.ViewPort.Height-40),
                                                               new Dimension2D(240, 20)),
                                null,
                                3);
            scroll.Max = 90;
            scroll.Pos = 45;
            }

            int lastFPS = -1;

            while (device.Run())
            {
                if (device.WindowActive)
                {
                    driver.BeginScene(true, true, new Color(0, 200, 200, 200));
                    smgr.DrawAll();
                    guienv.DrawAll();
                    driver.EndScene();

                    int fps = device.VideoDriver.FPS;
                    if (lastFPS != fps)
                    {
                        device.WindowCaption = "Skinned Mesh - Irrlicht.NET CP Engine " +
                            "FPS:" + fps.ToString();
                        lastFPS = fps;
                    }
                }
            }
            device.DumpElements();
            device.Close();
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            //We choosed OpenGL because it is cross-platform and GUI does not need
            //Amazing performances...
            IrrlichtDevice device = new IrrlichtDevice(DriverType.OpenGL,
                                                    new Dimension2D(640, 480),
                                                    16, false, false, false, false);
            //Delegate that will catch our events
            device.OnEvent += new OnEventDelegate(device_OnEvent);

            //Does not seem to work on Linux but well...
            device.Resizeable = false;

            //We set a basic caption
            device.WindowCaption = "Irrlicht .NET CP General User Interface Example";

            //We set our handlers
            driver = device.VideoDriver;
            guienv = device.GUIEnvironment;

            //We set the skin as a metallic windows skin
            guienv.Skin = guienv.CreateSkin(GUISkinTypes.WindowsMetallic);
            guienv.Skin.SetColor(GuiDefaultColor.ButtonText, Color.White);

            TTFont font = new TTFont(device.VideoDriver);
            font.Antialias = true;
            TTFace face = new TTFace();
            face.Load("../../medias/FreeSans.ttf");
            font.Attach(face, 14);
            guienv.Skin.Font = font;

            //Our fader. We set it as first because we don't want him to hide our buttons.
            guienv.AddInOutFader(null, (int)GUIItems.Fader);
            //We add several buttons with the IDs we defined downwards
            guienv.AddButton(new Rect(new Position2D(250, 0), new Dimension2D(140, 100)),
                             null, (int)GUIItems.ClickMe, "Click me !");
            guienv.AddButton(new Rect(new Position2D(250, 380), new Dimension2D(140, 100)),
                             null, (int)GUIItems.DontClickMe, "Don't click me !");
            guienv.AddButton(new Rect(new Position2D(0, 190), new Dimension2D(140, 100)),
                             null, (int)GUIItems.FadeMe, "Fade me !");
            guienv.AddButton(new Rect(new Position2D(500, 190), new Dimension2D(140, 100)),
                             null, (int)GUIItems.FunnyEffect, "Funny effect !");

            guienv.AddStaticText ("Move this scrollbar and you'll see the miracle !", new Rect(new Position2D(220, 240), new Dimension2D(240, 30)),
                                  false, true, null, -1, false);

            guienv.AddSpinBox ("", new Rect(new Position2D (220, 270), new Dimension2D (120, 30)), null, -1);
            guienv.AddEditBox ("", new Rect(new Position2D (220, 300), new Dimension2D (120, 30)), true, null, -1);

            listbox = guienv.AddListBox(new Rect(new Position2D(400, 20), new Dimension2D(220, 150)), null, -1, true);
            //Our logo
            guienv.AddImage(driver.GetTexture("../../medias/NETCPlogo.png"), new Position2D(0, 0), true, null, -1, "");

            //And now the scrollbar
            GUIScrollBar scroll = guienv.AddScrollBar(true, new Rect(new Position2D(220, 220), new Dimension2D(240, 20)), null,
                                (int)GUIItems.ScrollBar);

            el = new CustomElement(guienv, null, -1, new Rect(new Position2D(220, 120), new Dimension2D(160, 100)));

            //Var for the funny effects
            int toAdd = 1;
            //While the device is running and we don't want him to exit
            while (device.Run() && !Exit)
            {
                //If our funny effect is enabled, we just scroll the scrollbar
                //It may seems strange but the "ScrollBarChanged" event is NOT fired
                //When we manually change the position... It's a gift and a cursed, depending on the situation.
                if (FunnyEffectEnabled)
                {
                    scroll.Pos += toAdd;
                    if(scroll.Pos >= 100 || scroll.Pos <= 0)
                        toAdd = -toAdd;
                    BackColor = Color.From(255, 255-scroll.Pos * 5 / 2, 255 - (scroll.Pos * 5 / 2), scroll.Pos * 5 / 2);
                }
                //Here we are, we begin the scene
                //Notice that we DO NOT use the ZBuffer because we have only two dimensions
                driver.BeginScene(true, false, BackColor);
                //We draw all the GUI
                guienv.DrawAll();
                //And we end
                driver.EndScene();
            }
            //As in the first example, we need to release main resources
            device.DumpElements();
            device.Close();
        }
Beispiel #7
0
 public MeshFactory(MeshManipulator pmm, IrrlichtDevice pdevice)
 {
     mm = pmm;
     device = pdevice;
 }
Beispiel #8
0
        public override void Initialize()
        {
            base.Initialize();

            device = new IrrlichtDevice(DriverType.Direct3D9, new Dimension2D(Ox.DataStore.Width, Ox.DataStore.Height), 32, false, false, false, true, Ox.Handle);
            device.OnEvent += new OnEventDelegate(device_OnEvent);
            textureManager = new TextureManager(device.VideoDriver);
            videoManager = new VideoManager(device.VideoDriver);

            RenderData.BlankTexture = textureManager.AddTexture("blank.tga", 1, 1, false);
            RenderData.BlankTexture.SetPixel(0, 0, Color.White);

            System.Type type = this.GetType();
            root = device.SceneManager.AddEmptySceneNode(device.SceneManager.RootSceneNode, 0);
            root.Name = "Root";

            // This node will be changed state change message, when state change running or waiting.
            Root.Visible = false;
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            //We choosed OpenGL because it is cross-platform and we only have the openGL shader
            //So please do not change this unless you change the shader !
            IrrlichtDevice device = new IrrlichtDevice(DriverType.Direct3D9,
                                                    new Dimension2D(640, 480),
                                                    32, false, true, true, false);
            //We set a new working directory
            device.FileSystem.WorkingDirectory = "../../medias";
            device.OnEvent += new OnEventDelegate(device_OnEvent);

            //We set a basic caption
            string caption = "Irrlicht .NET CP Shaders and Particles Example";

            //We set our handlers
            Driver = device.VideoDriver;
            Scene = device.SceneManager;

            //We have already seen that... The only special thing is the pointless emitter (what a funny name isn't it ?)
            //Which is detailed just down.
            Texture fire = Driver.GetTexture("fire.bmp");
            ParticleSystemSceneNode particles = Scene.AddParticleSystemSceneNode(false, null, -1);
            particles.SetEmitter(new PointlessEmitter());
            //particles.AddAffector(new PointlessAffector());
            particles.SetMaterialTexture(0, fire);
            particles.SetMaterialType(MaterialType.TransparentAddColor);
            particles.SetMaterialFlag(MaterialFlag.Lighting, false);
            particles.ParticleSize = new Dimension2Df(50, 50);
            particles.ParticlesAreGlobal = false;

            particles = Scene.AddParticleSystemSceneNode(false, null, -1);
            particles.SetEmitter(new PointlessEmitter());
            //particles.AddAffector(new PointlessAffector());
            particles.SetMaterialTexture(0, fire);
            particles.SetMaterialType(MaterialType.TransparentAddColor);
            particles.SetMaterialFlag(MaterialFlag.Lighting, false);
            particles.ParticleSize = new Dimension2Df(50, 50);
            particles.Position = new Vector3D(0, 400, 0);
            particles.ParticlesAreGlobal = false;

            particles = Scene.AddParticleSystemSceneNode(false, null, -1);
            particles.SetEmitter(new PointlessEmitter());
            //particles.AddAffector(new PointlessAffector());
            particles.SetMaterialTexture(0, fire);
            particles.SetMaterialType(MaterialType.TransparentAddColor);
            particles.SetMaterialFlag(MaterialFlag.Lighting, false);
            particles.ParticleSize = new Dimension2Df(50, 50);
            particles.Position = new Vector3D(0, -400, 0);
            particles.ParticlesAreGlobal = false;

            //Here we only create 3 cubes and add a texture... Nothing exciting
            SceneNode cube1, cube2, cube3;
            cube1 = Scene.AddCubeSceneNode(40f, null, -1);
            cube2 = Scene.AddCubeSceneNode(40f, null, -1);
            cube3 = Scene.AddCubeSceneNode(40f, null, -1);
            cube1.SetMaterialTexture(0, Driver.GetTexture("rockwall.bmp"));
            cube2.SetMaterialTexture(0, Driver.GetTexture("rockwall.bmp"));
            cube3.SetMaterialTexture(0, Driver.GetTexture("rockwall.bmp"));

            //Here comes the fun... We create two low level shaders (taken from Irrlich's shader Example) and we set the base material as
            //Solid for the first one and transparent for the second
            int mat = Driver.GPUProgrammingServices.AddShaderMaterialFromFiles("opengl.vsh", "opengl.psh", OnShaderSet, MaterialType.Solid, 0);
            int mat2 = Driver.GPUProgrammingServices.AddShaderMaterialFromFiles("opengl.vsh", "opengl.psh", OnShaderSet, MaterialType.TransparentAddColor, 0);
            //And now we add both materials... Notice that no cast is needed because SetMaterialType
            //Has an overload especially made for shaders !
            cube2.SetMaterialType(mat);
            cube3.SetMaterialType(mat2);

            cube2.Position = new Vector3D(0, -40, 0);
            cube3.Position = new Vector3D(0, 40, 0);

            //We create a fixed cam for our render target scene
            CameraSceneNode fixedcam = Scene.AddCameraSceneNode(null);
            fixedcam.Position = new Vector3D(50, 0, -1000);
            fixedcam.FarValue = 10000f;
            fixedcam.AddAnimator(Scene.CreateFlyCircleAnimator(fixedcam.Target, 5000f, 0.001f));

            //And a fps cam for our main scene
            CameraSceneNode fpscam = Scene.AddCameraSceneNodeFPS(null, 100f, 400f, false);
            Scene.ActiveCamera.Position = new Vector3D(50, 0, -1000);
            Scene.ActiveCamera.FarValue = 10000f;

            Texture mask = Driver.AddTexture(new Dimension2D(128, 128), "", ColorFormat.A8R8G8B8);

            //Here is another cool feature from .NET CP
            //Direct access to textures via Texture.Lock/Unlock and Texture.SetPixel/GetPixel
            //Uncomment these lines to see the effect :)
            /*int w = mask.OriginalSize.Width;
            int h = mask.OriginalSize.Height;
            double maxdistance = Math.Sqrt(Math.Pow(w, 2) + Math.Pow(h, 2));
            mask.Lock();
            for (int x = 0; x < w; x++)
                for (int y = 0; y < h; y++)
                {
                    double distance = Math.Sqrt(Math.Pow((w - x), 2) + Math.Pow((h - y), 2));
                    double coeff = distance / maxdistance;
                    int color = (int)(255 - (255 * coeff));
                    Color pixel = new Color((int)(color / 1.5), (int)(color / 1.5), (int)(color / 2), (int)(color / 2));
                    mask.SetPixel(x, y, pixel);
                }
            mask.Unlock();
            //Again a useful feature... Direct texture saving to common formats such as png,jpg,bmp or gif...
            //Without coding anything, your texture is directly saved in Irrlicht's working directory !
            mask.Save("image.png");*/

            //You may have noticed that GetPixel/SetPixel is very slow even if you lock the texture.
            //Another insecure but quite faster way to proceed is to convert our lock to a pointer.
            //It needs unsafe code but works very fast...
            //However it is very unsecure and you must know perfectly what you are doing...
            //That's why Modify/Retrieve exists (look down)
            /*int w = mask.OriginalSize.Width;
            int h = mask.OriginalSize.Height;
            double maxdistance = Math.Sqrt(Math.Pow(w, 2) + Math.Pow(h, 2));
            IntPtr lockresult = mask.Lock();
            unsafe
            {
                int* directacces = (int*)(void*)lockresult;
                int pitch = mask.Pitch / 4;
                for (int x = 0; x < w; ++x)
                    for (int y = 0; y < h; ++y)
                    {
                        double distance = Math.Sqrt(Math.Pow((w - x), 2) + Math.Pow((h - y), 2));
                        double coeff = distance / maxdistance;
                        int color = (int)(255 - (255 * coeff));
                        Color pixel = new Color((int)(color / 1.5), (int)(color / 1.5), (int)(color / 2), (int)(color / 2));
                        directacces[x + y * pitch] = pixel.NativeColor;
                    }
            }
            mask.Unlock();*/

            //Here is the SAFEST AND FASTEST way to modify our texture.
            //A simple delegate which takes the coords of the pixel and returns the color
            //It is called on each pixel and you can even return false if you don't want to change the pixel.
            //We can now create our mask without speed or compatibility issue !
            int w = mask.OriginalSize.Width / 2;
            int h = mask.OriginalSize.Height / 2;
            double maxdistance = Math.Sqrt(Math.Pow(w, 2) + Math.Pow(h, 2));
            //We create a delegate to modify each pixel
            ModifyPixel del = delegate(int x, int y, out Color col)
            {
                //Here is our formula... You can modify it as you wish, this is just an example !
                double distance = Math.Sqrt(Math.Pow((w - x), 2) + Math.Pow((h - y), 2));
                double coeff = distance / maxdistance;
                int color = (int)(255 - (255 * coeff));
                //We now set the out color
                col = new Color((int)(color / 1.5), (int)(color / 1.5), (int)(color / 2), (int)(color / 2));
                //And we return true since we created a color.
                //If you return false, the current pixel won't be modified !
                return true;
            };
            //And we modify our texture with our delegate
            mask.Modify(del);
            //Uncomment this line to save our mask on a portable network graphic file !
            //You do not need to know jpg, bmp, gif, png... formats since they are converted automatically
            //mask.Save("mask.png");

            Console.WriteLine();
            Console.WriteLine("============================================");
            Console.WriteLine("Features List :");
            Console.WriteLine();
            for (VideoDriverFeature feat = 0; feat < VideoDriverFeature.Count; feat++)
                Console.WriteLine(feat + " = " + Driver.QueryFeature(feat));
            Console.WriteLine("============================================");

            //Here is our logo
            Texture logo = Driver.GetTexture("NETCPlogo.png");

            //Here is another feature, RenderTarget
            Texture renderTarget = Driver.CreateRenderTargetTexture(new Dimension2D(320, 240));
            int lastfps = -1, fps = 0;
            while (device.Run() && !Exit)
            {
                Driver.BeginScene(true, true, Color.Gray);

                //Driver.SetRenderTarget(renderTarget, true, true, Color.TransparentBlue);
                //Scene.ActiveCamera = fixedcam;
                //Scene.DrawAll();
                //Driver.SetRenderTarget(null, true, true, Color.Gray);

                Scene.ActiveCamera = fpscam;
                Scene.DrawAll();
                //Ok, seems like Irrlicht 1.3.1 doesn't like drawing render target on OpenGL
                //I guess we will disable this for now...
                //Driver.Draw2DImage(renderTarget, new Position2D(0, 0), false);
                Driver.Draw2DImage(mask, new Rect(new Position2D(), Driver.ScreenSize), new Rect(new Position2D(), mask.OriginalSize), Color.White, true);

                //And finally our logo is painted
                Driver.Draw2DImage(logo, new Position2D(0, Driver.ScreenSize.Height - logo.OriginalSize.Height),
                                   new Rect(new Position2D(0, 0),
                                   logo.OriginalSize), Color.White, true);
                Driver.EndScene();

                fps = Driver.FPS;
                if(fps != lastfps)
                {
                    device.WindowCaption = caption + " - FPS : " + fps;
                    lastfps = fps;
                }
            }
            device.Close();
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            IrrlichtDevice device = new IrrlichtDevice(DriverType.OpenGL, new Dimension2D(640, 480),
                                        32, false, false, false, false);

            string basecaption = "Irrlicht .NET CP Examples - Custom Scene Node feature";

            _scene = device.SceneManager;
            _driver = device.VideoDriver;

            CustomSceneNode myNode = new CustomSceneNode(null, _scene, 666);

            _scene.AddCameraSceneNode(null);
            _scene.ActiveCamera.Position = new Vector3D(0, -40, 0);
            _scene.ActiveCamera.Target = new Vector3D();

            myNode.AddAnimator(new CustomAnimator(new Vector3D(0.8f, 0, 0.8f)));
            int lastfps = -1, fps = 0;
            while (device.Run())
            {
                _driver.BeginScene(true, true, Color.Gray);
                _scene.DrawAll();
                _driver.EndScene();

                fps = _driver.FPS;
                if(fps != lastfps)
                {
                    device.WindowCaption = basecaption + " - FPS : " + fps;
                    lastfps = fps;
                }
            }
            device.DumpElements();
            device.Close();
        }
Beispiel #11
0
        public static void Main(string[] args)
        {
            //Shall we fullscreen ? (new verb I just invented)
            bool fullscreen = false;

            //We check the optimal video mode (resolution and screen depth)
            //As a default we choose 800x600x32
            VideoMode optimalmode;
            optimalmode.Resolution = new Dimension2D(800, 600);
            optimalmode.Depth = 32;

            //OpenGL is platform independent whereas DirectX isn't
            //As a default we choose OpenGL
            DriverType drivertype = DriverType.OpenGL;

            //We set a cool caption for our example
            string caption = "Irrlicht.NET CP Example on ";
            //Is the application started on a Windows platform ?
            //You may wonder why I did not wrote "Environment.OSVersion.Platform == PlatformID.Unix"
            //The reason is simple : We do not need to know if we are on an unix platform,
            //We need to know if we ARE NOT ON A WINDOWS platform, that's different indeed.
            if (Environment.OSVersion.Platform != PlatformID.Win32Windows &&
                Environment.OSVersion.Platform != PlatformID.Win32NT &&
                Environment.OSVersion.Platform != PlatformID.Win32S)
            {
                caption += "Linux/Unix System";
                //If the script is compiled on debug mode, we set 1024x768x32 with fullscreen.
                //I guess most of users will have at least a 15' screen...
            #if !DEBUG
                fullscreen = true;
                optimalmode.Resolution = new Dimension2D(1024, 768);
                optimalmode.Depth = 32;
            #endif
            }
            else //We ARE on a Windows Platform
            {
                caption += "Windows";

                //Uncomment this line and the engine will use DirectX 9 on a Windows system
                //I don't like Direct3D 9 but well the choice is yours ;)
                //drivertype = DriverType.Direct3D9;

                //Here we are, if the engine is compiled with release settings,
                //We can play with a funny toy : fakedevice.
                //It does not seem to work on Linux (perhaps one of those bugs that only appear on some cursed computers like mine)
                //With this device, we will determine the ideal video mode by forcing
                //The application to launch on the desktop video mode
                //If a bug occurs (meaning video mode is null for instance)
                //We set the same video mode as on Linux : 1024x768x32 which is the most common video mode.
            #if !DEBUG
                IrrlichtDevice fakedevice = new IrrlichtDevice(DriverType.Null, new Dimension2D(), 16, false, false, false, false);
                optimalmode = fakedevice.DesktopVideoMode;
                if(optimalmode.Resolution.Width == 0 || optimalmode.Resolution.Height == 0)
                {
                    optimalmode.Resolution = new Dimension2D(1024, 768);
                    optimalmode.Depth = 32;
                }
                fakedevice.Dispose();
                fullscreen = true;
            #endif
            }

            //We add a cool caption which says which renderer (OpenGL or Direct3D9 for instance) we use
            caption += " With " + drivertype + " - ";

            //Here we are, we create the device with settings we determined before
            IrrlichtDevice device = new IrrlichtDevice(drivertype,
                                                       optimalmode.Resolution,
                                                       optimalmode.Depth, fullscreen,
                                                       true, //Stencil Buffer (for shadow)
                                                       false, //Vertical Synchronisation (use it if you want your application not to go over 70 FPS)
                                                       false); //Anti Aliasing

            scene = device.SceneManager; //We get some object such as the scene manager
            driver = device.VideoDriver;
            guienv = device.GUIEnvironment;

            device.FileSystem.WorkingDirectory = "../../medias"; //We set Irrlicht's current directory to %application directory%/media
            device.CursorControl.Visible = false; //Let's hide the cursor

            device.OnEvent += new OnEventDelegate(device_OnEvent); //We had a simple delegate that will handle every event
            device.WindowCaption = caption; //And we set a basic caption

            //We create a floor mesh which is actually an hill plane mesh without height
            AnimatedMesh floormesh = scene.AddHillPlaneMesh("_MyHill_", new Dimension2Df(250, 250),
                                                            new Dimension2D(5, 5),
                                                            0f, new Dimension2Df(0, 0),
                                                            new Dimension2Df(10, 10));

            //We make the planar texture mapping to set the texture resolution
            scene.MeshManipulator.MakePlanarTextureMapping(floormesh.GetMesh(0), 0.006f);

            //We create a new mesh with tangents. It is needed for Parallax mapping
            Mesh tFloor = scene.MeshManipulator.CreateMeshWithTangents(floormesh.GetMesh(0));
            Texture heightmap = driver.GetTexture("rockwall_height.bmp"); //Our normal map
            driver.MakeNormalMapTexture(heightmap, 10f); //We make a quite exagerated normal map (just to show off)

            //And here we are, we finally create the scene node
            SceneNode floor = scene.AddMeshSceneNode(tFloor, null, -1);

            //We get the material
            Material mat = floor.GetMaterial(0);
            mat.Texture1 = driver.GetTexture("rockwall.bmp"); //Diffuse texture
            mat.Texture2 = heightmap; //Normal map
            mat.MaterialType = MaterialType.ParallaxMapSolid; //The beautiful Parallax Mapping
            mat.MaterialTypeParam = 0.035f; //Parameter for the height of parallax mapping

            //We create a FPS camera which is a basic camera controlled by
            //Arrow keys and mouse such as the camera in Quake or Doom
            CameraSceneNode cam = scene.AddCameraSceneNodeFPS(null, 50f, 100f, true);
            cam.Position = new Vector3D(0, 100, -100);
            cam.FarValue = 10000f; //We want to see all the scene

            //We add the sword (don't tell me that it is not a katana, I already know it !)
            SceneNode katana = scene.AddMeshSceneNode(scene.GetMesh("katana.x").GetMesh(0), cam, -1);
            Vector3D KInitialRotation = new Vector3D(0, 20, -90);
            Vector3D KInitialPosition = new Vector3D(23, -3, 40);
            //We set our materials (the n 1 is the sword and the 0 the stick)
            katana.Scale = new Vector3D(100f, 100f, 100f);
            mat = katana.GetMaterial(1);
            mat.DiffuseColor = new Color(255, 90, 90, 90);
            mat.AmbientColor = new Color(255, 90, 90, 90);
            mat.EmissiveColor = new Color(255, 90, 90, 90);
            mat.SpecularColor = new Color(255, 90, 90, 90);
            Material mat2 = katana.GetMaterial(0);
            mat2.DiffuseColor = new Color(255, 10, 10, 10);
            mat2.EmissiveColor = new Color(255, 120, 80, 0);

            //We add a little shining effect with particles on the sword
            ParticleSystemSceneNode particles = scene.AddParticleSystemSceneNode(false, katana, -1);
            particles.SetEmitter(particles.CreateBoxEmitter(scene.GetMesh("katana.x").GetMesh(0).GetMeshBuffer(1).BoundingBox,
                                                              new Vector3D(0, 0.002f, 0),
                                                              1000, 1000,
                                                              new Color(0, 255, 255, 255),
                                                              new Color(0, 255, 255, 255),
                                                              200, 200, 0));
            particles.ParticleSize = new Dimension2Df(1f, 3f); //A funny size for our funny effect
            particles.AddAffector(particles.CreateFadeOutParticleAffector(new Color(0, 0, 0, 0), 100));
            particles.SetMaterialTexture(0, driver.GetTexture("fire.bmp"));
            particles.SetMaterialType(MaterialType.TransparentAddColor);
            particles.SetMaterialFlag(MaterialFlag.Lighting, false);

            //We create three dwarves with shadows
            AnimatedMeshSceneNode dwarf = scene.AddAnimatedMeshSceneNode(scene.GetMesh("dwarf.x"));
            dwarf.AnimationSpeed = 15;
            dwarf.Position = new Vector3D(0, 0, 100);
            dwarf.AddShadowVolumeSceneNode(-1, true, 10000f); //Wow... It was really hard to create it !
            dwarf.Scale = new Vector3D(1.5f, 1.5f, 1.5f);

            //Here we have our light that will simply rotate around the dwarf
            LightSceneNode dwarflight = scene.AddLightSceneNode(dwarf, new Vector3D(0, 0, 0), Colorf.White, 10000f, -1);
            dwarflight.AddAnimator(scene.CreateFlyCircleAnimator(new Vector3D(0, 100, 0), 100f, 0.001f));

            dwarf = scene.AddAnimatedMeshSceneNode(scene.GetMesh("dwarf.x"));
            dwarf.AnimationSpeed = 10;
            dwarf.Position = new Vector3D(-100, 0, 100);
            dwarf.AddShadowVolumeSceneNode(-1, true, 10000f);
            dwarf.Scale = new Vector3D(1.5f, 1.5f, 1.5f);

            dwarf = scene.AddAnimatedMeshSceneNode(scene.GetMesh("dwarf.x"));
            dwarf.AnimationSpeed = 20;
            dwarf.Position = new Vector3D(100, 0, 100);
            dwarf.AddShadowVolumeSceneNode(-1, true, 10000f);
            dwarf.Scale = new Vector3D(1.5f, 1.5f, 1.5f);

            //We set the shadow color.
            //I reduced a lot the opacity since our light is not supposed to be the sun
            //And the scene is at night... Thus a shadow is not something very visible.
            scene.ShadowColor = new Color(100, 0, 0, 0);

            //We had a simple billboard to represent physically the light
            BillboardSceneNode lightbill = scene.AddBillboardSceneNode(dwarflight, new Dimension2Df(20, 20), -1);
            Texture fire = driver.GetTexture("fire.bmp");
            lightbill.SetMaterialTexture(0, fire);
            lightbill.SetMaterialType(MaterialType.TransparentAddColor);
            lightbill.SetMaterialFlag(MaterialFlag.Lighting, false);

            //We add a simple skybox
            scene.AddSkyBoxSceneNode(null, new Texture[] { driver.GetTexture("irrlicht2_up.jpg"),
                                                           driver.GetTexture("irrlicht2_dn.jpg"),
                                                           driver.GetTexture("irrlicht2_lf.jpg"),
                                                           driver.GetTexture("irrlicht2_rt.jpg"),
                                                           driver.GetTexture("irrlicht2_ft.jpg"),
                                                           driver.GetTexture("irrlicht2_bk.jpg") },
                                                           -1);

            //We had a simple texture that will be rendered each time
            Texture matthias = driver.GetTexture("matthias.png");

            //Here is our logo
            Texture logo = driver.GetTexture("NETCPlogo.png");

            //Just a simple demonstration of a feature which is not on Irrlicht .NET :
            //Listing children of the node as a simple Array.
            foreach (SceneNode node in cam.Children)
                Console.WriteLine("Child : " + node.ToString() + " Parent : " + node.Parent.ToString());

            //Another cool new feature :
            //FileSystem class with features like listing every file that Irrlicht can load
            //(including files on zip archives for instance)
            //foreach (FileListItem item in device.FileSystem.FileList)
            //    Console.WriteLine(item.ToString());

            double random = 0;
            Random chance = new Random();

            int lastfps = -1;
            while (device.Run() && !Exit)
            {
                //We get the FPS to synchronize all movements
                //Notice that I advice NOT TO USE THE FPS to synchronize
                //Because it is updated every second whereas it can change at every time
                //Use the time between each loop instead
                //(We use it here because it is not very important but be very careful)
                int FPS = driver.FPS;

                if(FPS != lastfps)
                {
                    //And here we are, we set the caption of the main window
                    device.WindowCaption = caption + "FPS : " + FPS;
                    lastfps = FPS;
                }

                if (FPS < 10)
                    FPS = 70;
                random += ((2000f / FPS) + chance.Next(-10, 10)) / 1000f;
                //If someone has played the demo about thirty years...
                if (random >= double.MaxValue)
                    random = 0;
                //Sinuses and Cosines are very useful because we all know that
                //they are between -1 and 1. Thus we don't need to add some "if"
                //And we can control the domain easilly
                //We had a realstic move of the sword because try to hold one during 10 minutes
                //You won't be static... Tested !
                //A nice thing would be to generate it using the camera movement speed or things like that...
                katana.Position = KInitialPosition +
                                    new Vector3D((float)(Math.Sin(random) / 6.0f),
                                                 (float)(Math.Sin(random) / 10f),
                                                 (float)(Math.Cos(random) / 6.0f));
                katana.Rotation = KInitialRotation +
                                    new Vector3D((float)(Math.Cos(random) / 2f),
                                                 (float)(Math.Cos(random)),
                                                 (float)(Math.Sin(random) / 2f));

                //We clear the back buffer and begin the scene
                driver.BeginScene(true, true, Color.From(255, 50, 50, 50));
                //First we draw all 3D Objects such as our sword or the dwarves
                //Notice that the order is very important... Try to move this line just before the
                //driver.EndScene and you will see the difference
                scene.DrawAll();

                //3 rectangles that could for instance represent Health, Mana and Endurance points...
                driver.Draw2DRectangle(new Rect(new Position2D(10, 5), new Dimension2D(300, 15)), Color.Red);
                driver.Draw2DRectangle(new Rect(new Position2D(10, 25), new Dimension2D(300, 15)), Color.Blue);
                driver.Draw2DRectangle(new Rect(new Position2D(10, 45), new Dimension2D(300, 15)), Color.Green);
                //A little image loaded before that could represent for instance our character
                driver.Draw2DImage(matthias, new Position2D(driver.ScreenSize.Width - matthias.OriginalSize.Width, 0),
                                   new Rect(new Position2D(0, 0),
                                   matthias.OriginalSize), Color.White, true);
                //And finally our logo is painted
                driver.Draw2DImage(logo, new Position2D(0, driver.ScreenSize.Height - logo.OriginalSize.Height),
                                   new Rect(new Position2D(0, 0),
                                   logo.OriginalSize), Color.White, true);

                //Finally we draw everything in the GUI Environment... CF the GUI example
                guienv.DrawAll();
                //End of the scene, the back buffer is displayed
                driver.EndScene();
            }
            //ALWAYS DISPOSE THE DEVICE AT THE END
            //It is REQUIRED on Linux because if you don't, XWindow will stay at the old video mode
            //And you can't imagine how ugly it is not to get back to the original video mode
            device.Close();
        }
        public bool InitDevices(Control target_window)
        {
            _target_window = target_window;

            Dimension2D dim = new Dimension2D(target_window.Size.Width, target_window.Size.Height);

            _device = new IrrlichtDevice(DriverType.OpenGL,
                                        dim,
                                        32, false, false, false,
                                        false,target_window.Handle);

            _device.Resizeable = true;

            //_device.OnEvent += new OnEventDelegate(_device_OnEvent);

            _scene = _device.SceneManager;
            _driver = _device.VideoDriver;

            return true;
        }
Beispiel #13
0
        public TextureManager(Viewer viewer)
            : base(viewer, -1)
        {
            this.viewer = viewer;
            driver = Reference.VideoDriver;
            device = Reference.Device;
            imagefolder = Util.TextureFolder;
            m_user = Reference.Viewer.ProtocolManager.AvatarConnection;
            m_user.OnImageReceived += imageReceivedCallback;

            if (!driver.QueryFeature(VideoDriverFeature.PixelShader_1_1) &&
                !driver.QueryFeature(VideoDriverFeature.ARB_FragmentProgram_1))
            {
                device.Logger.Log("WARNING: Pixel shaders disabled \n" +
                   "because of missing driver/hardware support.");
                shaderYN=false;
            }
            if (!driver.QueryFeature(VideoDriverFeature.VertexShader_1_1) &&
                !driver.QueryFeature(VideoDriverFeature.ARB_FragmentProgram_1))
            {
                device.Logger.Log("WARNING: Vertex shaders disabled \n" +
                   "because of missing driver/hardware support.");
                shaderYN = false;
            }


            if (shaderYN)
            {
                GPUProgrammingServices gpu = driver.GPUProgrammingServices;
                if (gpu != null)
                {
                    OnShaderConstantSetDelegate callBack = OnSetConstants;
                    newMaterialType1 = gpu.AddHighLevelShaderMaterial(GOOCH_VERTEX_GLSL,"main",VertexShaderType._1_1, GOOCH_FRAG_GLSL,"main", PixelShaderType._1_1, callBack, MaterialType.Solid, 0);
                }

            }
        }
Beispiel #14
0
        public void Initialize3D()
        {
            device = new IrrlichtDevice(DriverType.Direct3D9, /* TODO: for Linux/OSX it should be OpenGL */
                new Dimension2D(800, 600), 32, false, true, true, true, GetHandle());
            device.FileSystem.WorkingDirectory = "3d";
            device.Resizeable = true;

            // setup a simple 3d scene
            SceneManager sceneManager = device.SceneManager;

            VideoDriver driver = device.VideoDriver;

            camera = sceneManager.AddCameraSceneNodeFPS(null, 100.0f, 50000.0f, false);
            camera.Position = new Vector3D(1900 * 2, 255 * 2, 3700 * 2);
            camera.Target = new Vector3D(2397 * 2, 343 * 2, 2700 * 2);
            camera.FarValue = 12000.0f;

            camera.InputReceiverEnabled = false;

            /*
            Here comes the terrain renderer scene node: We add it just like any 
            other scene node to the scene using ISceneManager::addTerrainSceneNode(). 
            The only parameter we use is a file name to the heightmap we use. A heightmap
            is simply a gray scale texture. The terrain renderer loads it and creates 
            the 3D terrain from it.
            To make the terrain look more big, we change the scale factor of it to (40, 4.4, 40).
            Because we don't have any dynamic lights in the scene, we switch off the lighting,
            and we set the file terrain-texture.jpg as texture for the terrain and 
            detailmap3.jpg as second texture, called detail map. At last, we set
            the scale values for the texture: The first texture will be repeated only one time over 
            the whole terrain, and the second one (detail map) 20 times. 
            */

            terrain = sceneManager.AddTerrainSceneNode("terrain-heightmap.bmp",
                null,                               // parent node
                -1,									// node id
                new Vector3D(0f, 0f, 0f),			// position
                new Vector3D(0f, 0f, 0f),			// rotation
                new Vector3D(40f, 4.4f, 40f),		// scale
                new Color(255, 255, 255, 255),	    // vertexColor,
                5,									// maxLOD
                TerrainPatchSize.TPS17				// patchSize
            );

            terrain.SetMaterialFlag(MaterialFlag.Lighting, false);
            terrain.SetMaterialTexture(0, driver.GetTexture("terrain-texture.jpg"));
            terrain.SetMaterialTexture(1, driver.GetTexture("detailmap3.jpg"));
            terrain.SetMaterialType(MaterialType.DetailMap);
            terrain.ScaleTexture(1.0f, 20.0f);
            //terrain->setDebugDataVisible ( true );

            /*
            To be able to do collision with the terrain, we create a triangle selector.
            If you want to know what triangle selectors do, just take a look into the 
            collision tutorial. The terrain triangle selector works together with the
            terrain. To demonstrate this, we create a collision response animator 
            and attach it to the camera, so that the camera will not be able to fly 
            through the terrain.
            */

            // create triangle selector for the terrain	
            TriangleSelector selector = sceneManager.CreateTerrainTriangleSelector(terrain, 0);
            terrain.TriangleSelector = selector;

            // create collision response animator and attach it to the camera
            Animator animator = sceneManager.CreateCollisionResponseAnimator(selector, camera, new Vector3D(60, 100, 60), new Vector3D(0, 0, 0), new Vector3D(0, 50, 0), 0);
            selector.Dispose();
            camera.AddAnimator(animator);
            animator.Dispose(); ;

            /*
            To make the user be able to switch between normal and wireframe mode, we create
            an instance of the event reciever from above and let Irrlicht know about it. In 
            addition, we add the skybox which we already used in lots of Irrlicht examples.
            */

            // create skybox
            driver.SetTextureFlag(TextureCreationFlag.CreateMipMaps, false);

            sceneManager.AddSkyBoxSceneNode(null, new Texture[] {
                driver.GetTexture("irrlicht2_up.jpg"),
                driver.GetTexture("irrlicht2_dn.jpg"),
                driver.GetTexture("irrlicht2_lf.jpg"),
                driver.GetTexture("irrlicht2_rt.jpg"),
                driver.GetTexture("irrlicht2_ft.jpg"),
                driver.GetTexture("irrlicht2_bk.jpg")
            }, -1);

            while (device.Run())
            {
                driver.BeginScene(true, true, new Color());
                sceneManager.DrawAll();
                driver.EndScene();
            }

            device.Dispose();

            return;
        }
Beispiel #15
0
        private void StartupGUI(object target)
        {
            // Enforce the underlying Irrlicht engine to load a local D3DX9_40.dll
            // (Note: Environment.CurrentDirectory is visible to other plug-ins)
            Environment.CurrentDirectory = Util.ApplicationDataDirectory;

            SetupAddins();
            SetupLog();

            f = new RenderForm(this);
            f.Width = width;
            f.Height = height;
            f.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            f.ImeMode = System.Windows.Forms.ImeMode.Inherit;
            try
            {
                SetParent(f.Handle, (IntPtr)target);

            #if MANAGED_D3D
                Microsoft.DirectX.Direct3D.PresentParameters pp = new Microsoft.DirectX.Direct3D.PresentParameters();
                pp.Windowed = true;
                pp.SwapEffect = Microsoft.DirectX.Direct3D.SwapEffect.Discard;

                try
                {
                    d3ddevice = new Microsoft.DirectX.Direct3D.Device(
                        0,
                        Microsoft.DirectX.Direct3D.DeviceType.Hardware,
                        f,
                        Microsoft.DirectX.Direct3D.CreateFlags.SoftwareVertexProcessing,
                        pp
                        );
                }
                catch
                {
                    try
                    {
                        d3ddevice = new Microsoft.DirectX.Direct3D.Device(
                            0,
                            Microsoft.DirectX.Direct3D.DeviceType.Reference,
                            f,
                            Microsoft.DirectX.Direct3D.CreateFlags.SoftwareVertexProcessing,
                            pp
                            );
                    }
                    catch
                    {
                    }
                }

                CreateVideoObject();
            #endif
            }
            catch (System.Exception)
            {

            }
            f.Location = new System.Drawing.Point(0, 0);
            //f.FormClosed += new System.Windows.Forms.FormClosedEventHandler(f_FormClosed);
            f.Show();
            renderTarget = f.Handle;

            try
            {
                string iniconfig = System.IO.Path.Combine(Util.ConfigFolder, "OpenViewer.ini");
                m_config.Load(iniconfig);

                // Check and clean cache if request last time.
                string cacheFlag = m_config.Source.Configs["Startup"].Get("cache_delete", "false");
                if (cacheFlag == "true")
                {
                    CleanChache();
                }

            }
            catch (Exception e)
            {
                m_log.Fatal("can't load config file.", e);
            }

            try
            {
                device = new IrrlichtDevice(DriverType.Direct3D9, new Dimension2D(width, height), 32, false, true, false, false, renderTarget);
                if (device == null)
                {
                    m_log.Error("can't create irrlicht device.");
                    System.Windows.Forms.MessageBox.Show(DialogText.ErrorGraphicDriverMessage, DialogText.ErrorGraphicDriverCaption);
                }
            }
            catch (Exception e)
            {
                m_log.Error("can't create irrlicht device.", e);
                System.Windows.Forms.MessageBox.Show(DialogText.ErrorGraphicDriverMessage, DialogText.ErrorGraphicDriverCaption);

                device = null;
            }

            if (device == null)
            {
                // release all.

                // exit application.

                return;
            }
            else
            {
                m_log.InfoFormat("AdapterVendorID: 0x{0:x8}", device.VideoDriver.AdapterVendorId);
                m_log.InfoFormat("AdapterDeviceId: 0x{0:x8}", device.VideoDriver.AdapterDeviceId);
                m_log.InfoFormat("AdapterSubSysId: 0x{0:x8}", device.VideoDriver.AdapterSubSysId);
                m_log.InfoFormat("AdapterRevision: 0x{0:x8}", device.VideoDriver.AdapterRevision);
                m_log.InfoFormat("AdapterMaxTextureHeight: {0}", device.VideoDriver.AdapterMaxTextureHeight);
                m_log.InfoFormat("AdapterMaxTextureWidth: {0}", device.VideoDriver.AdapterMaxTextureWidth);
                m_log.InfoFormat("AdapterMaxActiveLights: {0}", device.VideoDriver.AdapterMaxActiveLights);
                m_log.InfoFormat("AdapterVertexShaderVersion: 0x{0:x8}", device.VideoDriver.AdapterVertexShaderVersion);
                m_log.InfoFormat("AdapterPixelShaderVersion: 0x{0:x8}", device.VideoDriver.AdapterPixelShaderVersion);

                // AdapterVendorId
                // 0x1002 : ATI Technologies Inc.
                // 0x10DE : NVIDIA Corporation
                // 0x102B : Matrox Electronic Systems Ltd.
                // 0x121A : 3dfx Interactive Inc
                // 0x5333 : S3 Graphics Co., Ltd.
                // 0x8086 : Intel Corporation
                //
                if (device.VideoDriver.AdapterVendorId == 0x1002)
                {
                    string warningMessage = DialogText.WarningGraphicCardMessage;
                    string warningCaption = DialogText.WarningGraphicCardCaption;

                    System.Windows.Forms.DialogResult yesno = System.Windows.Forms.MessageBox.Show(warningMessage, warningCaption, System.Windows.Forms.MessageBoxButtons.YesNo);
                    if (System.Windows.Forms.DialogResult.Yes != yesno)
                    {
                        return;
                    }
                }
            }

            reference = new RefController(this);

            device.OnEvent += new OnEventDelegate(device_OnEvent);

            // If enabled is true, videotexture is not correctly render.
            device.VideoDriver.SetTextureFlag(TextureCreationFlag.CreateMipMaps, false);

            #if DEBUG
            device.Logger.LogLevel = LogLevel.Information;
            #endif
            // Create video Textrue
            videoTexture = device.VideoDriver.GetTexture(Util.ApplicationDataDirectory + @"\media\textures\videoTexture.tga");

            IrrlichtNETCP.Extensions.TTFont font = new TTFont(Device.VideoDriver);
            IrrlichtNETCP.Extensions.TTFace face = new TTFace();
            bool font_loaded = false;
            uint fontsize = 16;
            string fontface = Config.Source.Configs["Startup"].GetString("guifont_face");

            if (!string.IsNullOrEmpty(Config.Source.Configs["Startup"].GetString("guifont_size")))
            {
                fontsize = (uint)Config.Source.Configs["Startup"].GetInt("guifont_size");
            }

            if (!string.IsNullOrEmpty(fontface))
            {
                if (System.IO.File.Exists(System.Environment.SystemDirectory + @"\..\Fonts\" + fontface))
                {
                    face.Load(System.Environment.SystemDirectory + @"\..\Fonts\" + fontface);
                    font.Attach(face, fontsize);
                    font.Antialias = true;
                    Reference.GUIEnvironment.Skin.Font = font;
                    font_loaded = true;
                }
                else
                {
                    m_log.Warn("[FONT]: The specified font (" + fontface + ") was not available on this system. Reverting to default.");
                }
            }
            if (!font_loaded)
            {
                if (System.IO.File.Exists(System.Environment.SystemDirectory + @"\..\Fonts\msgothic.ttc"))
                {
                    face.Load(System.Environment.SystemDirectory + @"\..\Fonts\msgothic.ttc");
                    font.Attach(face, fontsize);
                    font.Antialias = true;
                    Reference.GUIEnvironment.Skin.Font = font;
                }
                else
                {
                    JapaneseEnabled = false;
                    Locale = "en";
                    System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
                    if (System.IO.File.Exists(System.Environment.SystemDirectory + @"\..\Fonts\arial.ttf"))
                    {
                        face.Load(System.Environment.SystemDirectory + @"\..\Fonts\arial.ttf");
                        font.Attach(face, fontsize);
                        font.Antialias = true;
                        Reference.GUIEnvironment.Skin.Font = font;
                    }
                    else
                    {
                        // Use built in font--- this looks horrible and should be avoided if possible
                        Reference.GUIEnvironment.Skin.Font = Reference.GUIEnvironment.BuiltInFont;
                    }
                }
            }
            font.Drop();
            face.Drop();
            // if font and face are being used, at this point face and font should both have reference counts of 1.
            // if font and face are not being used (last else branch above, using built-in font), font and face should both be deleted at this point.

            // Zaki: Adding Japanese support end

            Reference.VideoDriver.SetFog(new Color(0, 255, 255, 255), false, 9999, 9999, 0, false, false);

            //Reference.Device.FileSystem.WorkingDirectory = Util.UserCacheDirectory;
            Reference.Device.FileSystem.AddFolderFileArchive(Util.ApplicationDataDirectory);
            Reference.Device.FileSystem.AddFolderFileArchive(Util.ModelFolder);
            Reference.Device.FileSystem.AddFolderFileArchive(Util.TextureFolder);

            camera = new Camera(this);

            // Create managers.
            cacheManager = new CacheManager(this, -1);
            try
            {
                string iniconfig = System.IO.Path.Combine(Util.ConfigFolder, "OpenViewer.ini");
                m_config.Load(iniconfig);

                // Check and clean cache if request last time.
                string s_cacheMB = m_config.Source.Configs["Startup"].Get("cache_size", DEFAULT_CACHE_MB_SIZE.ToString());

                long cacheMB = DEFAULT_CACHE_MB_SIZE;
                if (long.TryParse(s_cacheMB, out cacheMB))
                {
                    cacheMB = cacheMB * 1000 * 1000;

                    cacheManager.CacheMaxSize = cacheMB;
                    cacheManager.Clean();
                }
            }
            catch (Exception e)
            {
                m_log.Fatal("can't load config file.", e);
            }

            // Locale can be used from this point on
            if (Locale == "en")
            {
                DialogText.Culture = new System.Globalization.CultureInfo("en-US");
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
            }
            if (Locale == "jp")
            {
                DialogText.Culture = new System.Globalization.CultureInfo("ja-JP");
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("ja-JP");
            }

            stateManager = new Managers.StateManager(this);
            protocolManager = new Managers.ProtocolManager(this);
            guiManager = new GuiManager(this);
            menuManager = new MenuManager(this);
            shaderManager = new ShaderManager(this);
            entityManager = new EntityManager(this);
            irrManager = new IrrManager(this, -1);
            textureManager = new TextureManager(this);
            textureManager.OnTextureLoaded += OnTextureComplete;
            terrainManager = new Managers.TerrainManager(this);
            avatarManager = new Managers.AvatarManager(this);
            effectManager = new Managers.EffectManager(this);
            chatManager = new Managers.ChatManager(this);
            soundManager = new Managers.SoundManager(this);
            debugManager = new DebugManager(this, -1);

            // Experimental manager plugin loader
            LoadPlugins();

            // Initialize.
            Initialize();

            // Event
            stateManager.OnChanged += StateChanged;

            clearColor = Color.FromBCL(Util.FromString(BackgroundColor));
            progressBarColor = Color.FromBCL(Util.FromString(ProgressColor, System.Drawing.Color.FromArgb(63, 0, 0, 0)));

            guiManager.LoadBackgrounds();

            soundManager.InitWindowBackgroundMusicURL = InitBackgroundMusicURL;
            soundManager.LoadBackgroundMusic();

            // After all managers all initialized
            stateManager.State = State.INITIALIZED;

            adapter.Initialize(this.reference);

            adapter.CallSetWorldAmbientColor(WorldAmbientColor);
            adapter.CallSetFixDirectional(FixDirectional);
            adapter.CallSetFixDirectionalRotation(FixDirectionalRotation);
            adapter.CallSetFixDirectionalDiffuseColor(FixDirectionalDiffuseColor);
            adapter.CallSetFixDirectionalAmbientColor(FixDirectionalAmbientColor);

            SetLogFilter();

            guiManager.ShowLoginWindow(new LoginInfo(ServerURI, FirstName, LastName, Password, LoginMode, true, true));

            // Hide mouse cursor.
            ShowCursor(false);

            #if _SECOND_SURFACE_ON
            pip = Reference.VideoDriver.CreateRenderTargetTexture(new Dimension2D(256, 256));
            pipImage = Reference.GUIEnvironment.AddImage(pip, new Position2D(Width - pip.OriginalSize.Width - 10, 40), false, Reference.GUIEnvironment.RootElement, -1, "");

            CameraSceneNode oldCam = Reference.SceneManager.ActiveCamera;
            pipCamera = Reference.SceneManager.AddCameraSceneNode(Reference.SceneManager.RootSceneNode);
            material.Lighting = false;
            if (Reference.SceneManager.ActiveCamera.Raw != oldCam.Raw)
                Reference.SceneManager.ActiveCamera = oldCam;
            #endif

            System.Windows.Forms.DialogResult dialogRes = System.Windows.Forms.DialogResult.Retry;
            while (dialogRes == System.Windows.Forms.DialogResult.Retry)
            {
                dialogRes = RenderLoop();
            }

            #if MANAGED_D3D
            try
            {
                if (video != null)
                {
                    lock (video)
                    {
                        video.Stop();
                        video.Dispose();
                    }
                }

                if (d3ddevice != null)
                {
                    lock (d3ddevice)
                    {
                        d3ddevice.Dispose();
                        d3ddevice = null;
                    }
                }
            }
            catch
            {
            }
            #endif

            if (device != null)
            {
                device.Dispose();
                device = null;
            }
        }
Beispiel #16
0
        static void Main(string[] args)
        {
            // ask user for driver
            DriverType driverType = DriverType.OpenGL;

            // Ask user to select driver:
            // Create device and exit if creation fails:
            device = new IrrlichtDevice(driverType, new Dimension2D(640, 480), 32, false, true, true, true);
            device.FileSystem.WorkingDirectory = "../../medias"; //We set Irrlicht's current directory to %application directory%/media
            //MyEventReceiver receiver(room, env, driver);
            device.OnEvent += new OnEventDelegate(device_OnEvent); //We had a simple delegate that will handle every event

            /*************************************************/
            /* First, we add standard stuff to the scene: A nice irrlicht engine logo,
               a small help text, a user controlled camera, and we disable the mouse
               cursor.*/
            SceneManager smgr = device.SceneManager;
            VideoDriver driver = device.VideoDriver;
            GUIEnvironment env = device.GUIEnvironment;

            driver.SetTextureFlag(TextureCreationFlag.Always32Bit, true);

            // add irrlicht logo
            env.AddImage(driver.GetTexture("NETCPlogo.png"),
                new Position2D(10, 10), true, null, 0, "");

            // add some help text
            GUIStaticText text = env.AddStaticText(
                "Press 'W' to change wireframe mode\nPress 'D' to toggle detail map",
                new Rect(new Position2D(10, 453), new Position2D(200, 475)), true, true, null, -1,true);

            // add camera
            CameraSceneNode camera =
                smgr.AddCameraSceneNodeFPS(null, 100.0f, 1200.0f, false);
            camera.Position = new Vector3D(1900 * 2, 255 * 2, 3700 * 2);
            camera.Target = new Vector3D(2397 * 2, 343 * 2, 2700 * 2);
            camera.FarValue = 120000.0f;

            // disable mouse cursor
            device.CursorControl.Visible = false;
            /* Here comes the terrain renderer scene node: We add it just like any other scene
               node to the scene using ISceneManager::addTerrainSceneNode(). The only parameter
               we use is a file name to the heightmap we use. A heightmap is simply a gray
               scale texture. The terrain renderer loads it and creates the 3D terrain
               from it.
               To make the terrain look more big, we change the scale factor of it to
               (40, 4.4, 40). Because we don't have any dynamic lights in the scene, we
               switch off the lighting, and we set the file terrain-texture.jpg as texture
               for the terrain and detailmap3.jpg as second texture, called detail map.
               At last, we set the scale values for the texture: The first texture will be
               repeated only one time over the whole terrain, and the second one (detail map)
               20 times.
             */
            // add terrain scene node
            terrain = smgr.AddTerrainSceneNode(
                "terrain-heightmap.bmp", null, -1,
                new Vector3D(0,0,0), new Vector3D(1,1,1), new Vector3D(40, 4.4f, 40), new Color(255, 255, 255, 255),3,TerrainPatchSize.TPS9);

            terrain.SetMaterialFlag(MaterialFlag.Lighting, false);
            terrain.SetMaterialType(MaterialType.DetailMap);
            terrain.SetMaterialTexture(0, driver.GetTexture("terrain-texture.jpg"));
            terrain.SetMaterialTexture(1, driver.GetTexture("detailmap3.jpg"));

            terrain.ScaleTexture(1.0f, 20.0f);

            /*WaterSceneNode water = new WaterSceneNode(null, smgr, new Dimension2Df(64,64), new Dimension2D(100,100));
            water.Position = new Vector3D(1900 * 2, 255 * 2, 3700 * 2);*/

            /* To be able to do collision with the terrain, we create a triangle selector.
               If you want to know what triangle selectors do, just take a look into the
               collision tutorial. The terrain triangle selector works together with the
               terrain. To demonstrate this, we create a collision response animator and
               attach it to the camera, so that the camera will not be able to fly through
               the terrain.*/
            // create triangle selector for the terrain
            TriangleSelector selector =
                smgr.CreateTerrainTriangleSelector(terrain, 0);

            // create collision response animator and attach it to the camera
            Animator anim = smgr.CreateCollisionResponseAnimator(
                selector, camera, new Vector3D(60, 100, 60),
                new Vector3D(0, 0, 0),
                new Vector3D(0, 50, 0), 0.0005f);
            camera.AddAnimator(anim);

            //we add the skybox which we already used in lots of Irrlicht examples.
            driver.SetTextureFlag(TextureCreationFlag.CreateMipMaps, false);

            smgr.AddSkyBoxSceneNode(null, new Texture[] {
                driver.GetTexture("irrlicht2_up.jpg"),
                driver.GetTexture("irrlicht2_dn.jpg"),
                driver.GetTexture("irrlicht2_rt.jpg"),
                driver.GetTexture("irrlicht2_lf.jpg"),
                driver.GetTexture("irrlicht2_ft.jpg"),
                driver.GetTexture("irrlicht2_bk.jpg")}, 0);

            driver.SetTextureFlag(TextureCreationFlag.CreateMipMaps, true);

            /* That's it, draw everything. Now you know how to use terrain
               in Irrlicht.
            */
            int lastFPS = -1;

            while (device.Run())
            {
                if (device.WindowActive)
                {
                    driver.BeginScene(true, true, new Color(0, 200, 200, 200));
                    smgr.DrawAll();
                    env.DrawAll();
                    driver.EndScene();

                    int fps = device.VideoDriver.FPS;
                    if (lastFPS != fps)
                    {
                        device.WindowCaption = "Terrain Renderer - Irrlicht Engine " +
                            "FPS:" + fps.ToString();
                        lastFPS = fps;
                    }
                }
            }

            /*
            In the end, delete the Irrlicht device.
            */
            device.Close();
        }