Exemplo n.º 1
0
        /// <summary>
        /// Zwalnia zasoby
        /// </summary>
        public void DisposeHydrax()
        {
            if (hydrax != null)
            {
                if (USE_UPDATER_THREAD)
                {
                    Monitor.Enter(HydraxManager.Singleton);
                    stopUpdater = true;
                    Monitor.Exit(HydraxManager.Singleton);
                    updater.Join();

                    Monitor.Enter(HydraxManager.Singleton);
                    stopUpdater = false;
                    Monitor.Exit(HydraxManager.Singleton);
                }

                if (hydrax.IsCreated)
                {
                    //hydrax.Visible = false;
                    //hydrax.UpdateLoop(0);
                }
                hydrax.Dispose();
                hydrax = null;
            }
        }
Exemplo n.º 2
0
        public void Init(State state)
        {
            if (state.Hydrax != null) return; // Hack for Opening

            state.Hydrax = this;

            ChangeSkyDomeToMesh(state);

            hydrax = new MHydrax.MHydrax(state.SceneManager, state.CameraManager.Camera, state.CameraManager.Viewport);

            CreateHydrax(state);

            // Must be called after frame ends
            state.Root.FrameEnded += Update;

            // Must be disposed before Root
            // state.MainWindow.Disposed+=Disposed;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Tworzy gotow¹ powierzchniê wody.
        /// </summary>
        /// <param name="cfgFileName"></param>
        /// <param name="sceneMgr"></param>
        /// <param name="camera"></param>
        /// <param name="viewport"></param>
        public void CreateHydrax(string cfgFileName, SceneManager sceneMgr, Camera camera, Viewport viewport)
        {
            if (hydrax != null)
            {
                hydrax.Dispose();
                hydrax = null;
            }
            if (USE_UPDATER_THREAD)
            {
                stopUpdater = false;
                updater     = new Thread(UpdateLoop);
            }


            hydrax = new MHydrax.MHydrax(sceneMgr, camera, viewport);

            MProjectedGrid module = new MProjectedGrid( // Hydrax parent pointer
                hydrax,
                // Noise module
                new MHydrax.MPerlin(),
                // Base plane
                new Mogre.Plane(new Vector3(0, 1, 0), new Vector3(0, 0, 0)),
                // Normal mode
                MMaterialManager.MNormalMode.NM_VERTEX,
                // Projected grid options
                new MProjectedGrid.MOptions(32, 10, 5, false, false, true, 3.75f));

            this.cfgFileName = cfgFileName;
            hydrax.SetModule(module);
            if (hydrax.LoadCfg(cfgFileName))
            {
                //  Console.WriteLine("OKOKOK");
            }
            hydrax.Create();


            //    MaterialPtr m = hydrax.MaterialManager.GetMaterial(MMaterialManager.MMaterialType.MAT_UNDERWATER_COMPOSITOR);
            //    m.GetBestTechnique().GetPass(0).GetTextureUnitState(1).SetTextureName("UnderwaterDistortion_none.png");
            //     m = null;
            //   hydrax.MaterialManager.RemoveCompositor();
            //   CompositorPtr com =  hydrax.MaterialManager.GetCompositor(MHydrax.MMaterialManager.MCompositorType.COMP_UNDERWATER);
            //    com.RemoveAllTechniques();
        }
Exemplo n.º 4
0
        public void Init(State state)
        {
            if (state.Hydrax != null)
            {
                return;                       // Hack for Opening
            }
            state.Hydrax = this;

            ChangeSkyDomeToMesh(state);

            hydrax = new MHydrax.MHydrax(state.SceneManager, state.CameraManager.Camera, state.CameraManager.Viewport);

            CreateHydrax(state);

            // Must be called after frame ends
            state.Root.FrameEnded += Update;

            // Must be disposed before Root
            // state.MainWindow.Disposed+=Disposed;
        }
Exemplo n.º 5
0
 public void Disposed(object sender, EventArgs e)
 {
     hydrax.Dispose();
     hydrax = null;
 }
Exemplo n.º 6
0
        //Entities entities = new Entities();
        //SceneNodes nodes = new SceneNodes();
        private void SceneCreating()
        {
            SceneManager sm     = OgreWindow.Instance.mSceneMgr;
            Root         root   = OgreWindow.Instance.mRoot;
            Camera       camera = OgreWindow.Instance.mCamera;
            Viewport     vp     = OgreWindow.Instance.mViewport;

            OgreWindow.Instance.mSceneMgr.SetShadowUseInfiniteFarPlane(true);
            sm.AmbientLight = ColourValue.Black;



            #region shadows
            //sm.ShadowTechnique = ShadowTechnique.SHADOWTYPE_STENCIL_ADDITIVE;
            //sm.ShadowTechnique = ShadowTechnique.SHADOWTYPE_STENCIL_MODULATIVE;

            sm.ShadowTechnique = ShadowTechnique.SHADOWTYPE_NONE; //skyx breaks when shadows are enabled!
            //sm.ShadowTechnique = ShadowTechnique.SHADOWTYPE_TEXTURE_ADDITIVE;
            //sm.ShadowTechnique = ShadowTechnique.SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED;
            //sm.ShadowTechnique = ShadowTechnique.SHADOWTYPE_TEXTURE_MODULATIVE;
            //sm.ShadowTechnique = ShadowTechnique.SHADOWTYPE_TEXTURE_MODULATIVE_INTEGRATED;
            #endregion



            camera.FarClipDistance  = 30000;
            camera.NearClipDistance = .25f;

            //camera.SetPosition(20000, 500, 20000);
            //camera.SetDirection(1, 0, 0);



            skyManager = new SkyManager(sm, OgreWindow.Instance.mCamera);
            skyManager.Create();


            //manager.GPUManager.AddGroundPass(material.GetTechnique(0).CreatePass(), 5000, SceneBlendType.SBT_TRANSPARENT_COLOUR);

            skyManager.CloudsManager.Add(new CloudLayer.LayerOptions());


            #region MHydrax


            if (!DISABLE_MHYDRAX)
            {
                //hydrax = new MHydrax.MHydrax(sm, camera, vp);

                // Hydrax initialization code ---------------------------------------------
                // ------------------------------------------------------------------------

                // Create Hydrax object
                hydrax = new MHydrax.MHydrax(sm, camera, vp);

                // Set hydrax components.
                hydrax.Components = MHydrax.MHydraxComponent.HYDRAX_COMPONENT_CAUSTICS |
                                    MHydrax.MHydraxComponent.HYDRAX_COMPONENT_DEPTH |
                                    MHydrax.MHydraxComponent.HYDRAX_COMPONENT_FOAM |
                                    MHydrax.MHydraxComponent.HYDRAX_COMPONENT_SMOOTH |
                                    MHydrax.MHydraxComponent.HYDRAX_COMPONENT_SUN |
                                    MHydrax.MHydraxComponent.HYDRAX_COMPONENT_UNDERWATER |
                                    MHydrax.MHydraxComponent.HYDRAX_COMPONENT_UNDERWATER_GODRAYS |
                                    MHydrax.MHydraxComponent.HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS;

                //' Create our projected grid module
                //' Parameters:
                //' Hydrax parent pointer
                //' Noise module
                //' Base plane
                //' Normal mode
                //' Projected grid options
                MHydrax.MProjectedGrid m = new MHydrax.MProjectedGrid(hydrax,
                                                                      new MHydrax.MPerlin(new MHydrax.MPerlin.MOptions(8, 0.085f, 0.49f, 1.4f, 1.27f, 2f, new Mogre.Vector3(0.5f, 50f, 150000f))),
                                                                      new Plane(new Mogre.Vector3(0, 1, 0), new Mogre.Vector3(0, 0, 0)),
                                                                      MHydrax.MMaterialManager.MNormalMode.NM_VERTEX,
                                                                      new MHydrax.MProjectedGrid.MOptions(256, 35f, 50f, false, false, true, 3.75f));

                //' Set our module
                hydrax.SetModule(m);

                //' Set all parameters instead of loading all parameters from config file:
                //'hydrax.LoadCfg("ProjectedGridDemo.hdx")
                //' #Main options
                hydrax.Position               = new Mogre.Vector3(5000, 0, -5000);
                hydrax.PlanesError            = 10.5f;
                hydrax.ShaderMode             = MHydrax.MMaterialManager.MShaderMode.SM_HLSL;
                hydrax.FullReflectionDistance = 100000000000;
                hydrax.GlobalTransparency     = 0;
                hydrax.NormalDistortion       = 0.075f;
                hydrax.WaterColor             = new Mogre.Vector3(0.139765f, 0.359464f, 0.425373f);
                //' #Sun parameters
                hydrax.SunPosition = new Mogre.Vector3(0, 10000, 0);
                hydrax.SunStrength = 1.75f;
                hydrax.SunArea     = 150;
                hydrax.SunColor    = new Mogre.Vector3(1f, 0.9f, 0.6f);
                //' #Foam parameters
                hydrax.FoamMaxDistance  = 75000000;
                hydrax.FoamScale        = 0.0075f;
                hydrax.FoamStart        = 0;
                hydrax.FoamTransparency = 1;
                //' #Depth parameters
                hydrax.DepthLimit = 90;
                //' #Smooth transitions parameters
                hydrax.SmoothPower = 5;
                //' #Caustics parameters
                hydrax.CausticsScale = 135;
                hydrax.CausticsPower = 10.5f;
                hydrax.CausticsEnd   = 0.8f;
                //' #God rays parameters
                hydrax.GodRaysExposure  = new Mogre.Vector3(0.76f, 2.46f, 2.29f);
                hydrax.GodRaysIntensity = 0.015f;
                hydrax.GodRaysManager.SimulationSpeed             = 5;
                hydrax.GodRaysManager.NumberOfRays                = 100;
                hydrax.GodRaysManager.RaysSize                    = 0.03f;
                hydrax.GodRaysManager.ObjectsIntersectionsEnabled = false;
                //' #Rtt quality field(0x0 = Auto)
                //' TODO: RTTManager not wrapped yet.
                //'<size>Rtt_Quality_Reflection=0x0
                //'<size>Rtt_Quality_Refraction=0x0
                //'<size>Rtt_Quality_Depth=0x0
                //'<size>Rtt_Quality_URDepth=0x0
                //'<size>Rtt_Quality_GPUNormalMap=0x0

                //' Create water
                hydrax.Create();

                //' Hydrax initialization code end -----------------------------------------
                //' ------------------------------------------------------------------------

                //sm.AmbientLight = new ColourValue(1, 1, 1);
                //camera.FarClipDistance = 99999 * 6;
                //camera.Position = new Mogre.Vector3(312.902f, 206.419f, 1524.02f);
                //camera.Orientation = new Quaternion(0.998f, -0.0121f, -0.0608f, -0.00074f);
            }
            #endregion

            #region physics
            // create the root object
            OgreWindow.Instance.physics = Physics.Create();
            OgreWindow.Instance.physics.Parameters.SkinWidth = 0.0025f;

            // setup default scene params
            SceneDesc sceneDesc = new SceneDesc();
            sceneDesc.SetToDefault();
            sceneDesc.Gravity = new Mogre.Vector3(0, -9.8f, 0);
            sceneDesc.UpAxis  = 1; // NX_Y in c++ (I couldn't find the equivilent enum for C#)

            // your class should implement IUserContactReport to use this
            //sceneDesc.UserContactReport = this;

            OgreWindow.Instance.scene = OgreWindow.Instance.physics.CreateScene(sceneDesc);

            // default material
            OgreWindow.Instance.scene.Materials[0].Restitution     = 0.5f;
            OgreWindow.Instance.scene.Materials[0].StaticFriction  = 0.5f;
            OgreWindow.Instance.scene.Materials[0].DynamicFriction = 0.5f;

            // begin simulation
            OgreWindow.Instance.scene.Simulate(0);
            #endregion

            OgreWindow.Instance.SceneReady = true;
        }
Exemplo n.º 7
0
        //Entities entities = new Entities();
        //SceneNodes nodes = new SceneNodes();
        private void SceneCreating()
        {
            SceneManager sm = OgreWindow.Instance.mSceneMgr;
            Root root = OgreWindow.Instance.mRoot;
            Camera camera = OgreWindow.Instance.mCamera;
            Viewport vp = OgreWindow.Instance.mViewport;
            OgreWindow.Instance.mSceneMgr.SetShadowUseInfiniteFarPlane(true);
            sm.AmbientLight = ColourValue.Black;



            #region shadows
            //sm.ShadowTechnique = ShadowTechnique.SHADOWTYPE_STENCIL_ADDITIVE;
            //sm.ShadowTechnique = ShadowTechnique.SHADOWTYPE_STENCIL_MODULATIVE;

            sm.ShadowTechnique = ShadowTechnique.SHADOWTYPE_NONE; //skyx breaks when shadows are enabled!
            //sm.ShadowTechnique = ShadowTechnique.SHADOWTYPE_TEXTURE_ADDITIVE;
            //sm.ShadowTechnique = ShadowTechnique.SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED;
            //sm.ShadowTechnique = ShadowTechnique.SHADOWTYPE_TEXTURE_MODULATIVE;
            //sm.ShadowTechnique = ShadowTechnique.SHADOWTYPE_TEXTURE_MODULATIVE_INTEGRATED; 
            #endregion





            camera.FarClipDistance = 30000;
            camera.NearClipDistance = .25f;

            //camera.SetPosition(20000, 500, 20000);
            //camera.SetDirection(1, 0, 0);



            skyManager = new SkyManager(sm, OgreWindow.Instance.mCamera);
            skyManager.Create();


            //manager.GPUManager.AddGroundPass(material.GetTechnique(0).CreatePass(), 5000, SceneBlendType.SBT_TRANSPARENT_COLOUR);

            skyManager.CloudsManager.Add(new CloudLayer.LayerOptions());


            #region MHydrax


            if (!DISABLE_MHYDRAX)
            {



                //hydrax = new MHydrax.MHydrax(sm, camera, vp);

                // Hydrax initialization code ---------------------------------------------
                // ------------------------------------------------------------------------

                // Create Hydrax object
                hydrax = new MHydrax.MHydrax(sm, camera, vp);

                // Set hydrax components.
                hydrax.Components = MHydrax.MHydraxComponent.HYDRAX_COMPONENT_CAUSTICS |
                                    MHydrax.MHydraxComponent.HYDRAX_COMPONENT_DEPTH |
                                    MHydrax.MHydraxComponent.HYDRAX_COMPONENT_FOAM |
                                    MHydrax.MHydraxComponent.HYDRAX_COMPONENT_SMOOTH |
                                    MHydrax.MHydraxComponent.HYDRAX_COMPONENT_SUN |
                                    MHydrax.MHydraxComponent.HYDRAX_COMPONENT_UNDERWATER |
                                    MHydrax.MHydraxComponent.HYDRAX_COMPONENT_UNDERWATER_GODRAYS |
                                    MHydrax.MHydraxComponent.HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS;

                //' Create our projected grid module
                //' Parameters:
                //' Hydrax parent pointer
                //' Noise module
                //' Base plane
                //' Normal mode
                //' Projected grid options
                MHydrax.MProjectedGrid m = new MHydrax.MProjectedGrid(hydrax,
                                                    new MHydrax.MPerlin(new MHydrax.MPerlin.MOptions(8, 0.085f, 0.49f, 1.4f, 1.27f, 2f, new Mogre.Vector3(0.5f, 50f, 150000f))),
                                                    new Plane(new Mogre.Vector3(0, 1, 0), new Mogre.Vector3(0, 0, 0)),
                                                    MHydrax.MMaterialManager.MNormalMode.NM_VERTEX,
                                                    new MHydrax.MProjectedGrid.MOptions(256, 35f, 50f, false, false, true, 3.75f));

                //' Set our module
                hydrax.SetModule(m);

                //' Set all parameters instead of loading all parameters from config file:
                //'hydrax.LoadCfg("ProjectedGridDemo.hdx")
                //' #Main options
                hydrax.Position = new Mogre.Vector3(5000, 0, -5000);
                hydrax.PlanesError = 10.5f;
                hydrax.ShaderMode = MHydrax.MMaterialManager.MShaderMode.SM_HLSL;
                hydrax.FullReflectionDistance = 100000000000;
                hydrax.GlobalTransparency = 0;
                hydrax.NormalDistortion = 0.075f;
                hydrax.WaterColor = new Mogre.Vector3(0.139765f, 0.359464f, 0.425373f);
                //' #Sun parameters
                hydrax.SunPosition = new Mogre.Vector3(0, 10000, 0);
                hydrax.SunStrength = 1.75f;
                hydrax.SunArea = 150;
                hydrax.SunColor = new Mogre.Vector3(1f, 0.9f, 0.6f);
                //' #Foam parameters
                hydrax.FoamMaxDistance = 75000000;
                hydrax.FoamScale = 0.0075f;
                hydrax.FoamStart = 0;
                hydrax.FoamTransparency = 1;
                //' #Depth parameters
                hydrax.DepthLimit = 90;
                //' #Smooth transitions parameters
                hydrax.SmoothPower = 5;
                //' #Caustics parameters
                hydrax.CausticsScale = 135;
                hydrax.CausticsPower = 10.5f;
                hydrax.CausticsEnd = 0.8f;
                //' #God rays parameters
                hydrax.GodRaysExposure = new Mogre.Vector3(0.76f, 2.46f, 2.29f);
                hydrax.GodRaysIntensity = 0.015f;
                hydrax.GodRaysManager.SimulationSpeed = 5;
                hydrax.GodRaysManager.NumberOfRays = 100;
                hydrax.GodRaysManager.RaysSize = 0.03f;
                hydrax.GodRaysManager.ObjectsIntersectionsEnabled = false;
                //' #Rtt quality field(0x0 = Auto)
                //' TODO: RTTManager not wrapped yet.
                //'<size>Rtt_Quality_Reflection=0x0
                //'<size>Rtt_Quality_Refraction=0x0
                //'<size>Rtt_Quality_Depth=0x0
                //'<size>Rtt_Quality_URDepth=0x0
                //'<size>Rtt_Quality_GPUNormalMap=0x0

                //' Create water
                hydrax.Create();

                //' Hydrax initialization code end -----------------------------------------
                //' ------------------------------------------------------------------------

                //sm.AmbientLight = new ColourValue(1, 1, 1);
                //camera.FarClipDistance = 99999 * 6;
                //camera.Position = new Mogre.Vector3(312.902f, 206.419f, 1524.02f);
                //camera.Orientation = new Quaternion(0.998f, -0.0121f, -0.0608f, -0.00074f);
            }
            #endregion

            #region physics
            // create the root object
            OgreWindow.Instance.physics = Physics.Create();
            OgreWindow.Instance.physics.Parameters.SkinWidth = 0.0025f;

            // setup default scene params
            SceneDesc sceneDesc = new SceneDesc();
            sceneDesc.SetToDefault();
            sceneDesc.Gravity = new Mogre.Vector3(0, -9.8f, 0);
            sceneDesc.UpAxis = 1; // NX_Y in c++ (I couldn't find the equivilent enum for C#)

            // your class should implement IUserContactReport to use this
            //sceneDesc.UserContactReport = this;

            OgreWindow.Instance.scene = OgreWindow.Instance.physics.CreateScene(sceneDesc);

            // default material
            OgreWindow.Instance.scene.Materials[0].Restitution = 0.5f;
            OgreWindow.Instance.scene.Materials[0].StaticFriction = 0.5f;
            OgreWindow.Instance.scene.Materials[0].DynamicFriction = 0.5f;

            // begin simulation
            OgreWindow.Instance.scene.Simulate(0);
            #endregion

            OgreWindow.Instance.SceneReady = true;
        }
Exemplo n.º 8
0
        protected static void CreateScene()
        {
            sceneMgr = _root.CreateSceneManager(SceneType.ST_EXTERIOR_CLOSE);

            //Image combined = new Image();

            //combined.LoadTwoImagesAsRGBA("terra_DIFFUSE.png", "terra_SPECULAR.png", "General", PixelFormat.PF_BYTE_RGBA);
            //combined.Save("terra_diffusespecular.png");

            //combined.LoadTwoImagesAsRGBA("terra_NORMAL.png", "terra_DISP.png", "General", PixelFormat.PF_BYTE_RGBA);
            //combined.Save("terra_normalheight.png");

            _cam = sceneMgr.CreateCamera("Camera");
            _cam.Pitch(-0.78f);
            _cam.NearClipDistance = 5f;
            _cam.FarClipDistance = 99999 * 6;
            _cam.Move(new Vector3(1084, 346, 1317));

            viewport = _window.AddViewport(_cam);
            _cam.AspectRatio = (float)viewport.ActualWidth / (float)viewport.ActualHeight;

            sceneMgr.ShadowTechnique = ShadowTechnique.SHADOWTYPE_TEXTURE_MODULATIVE;
            sceneMgr.ShadowTextureCount = 8;
            sceneMgr.SetShadowTextureSize(8192);

            CreateNewDude("1");
            CreateNewDude("2");

            Vector3 lightDir = new Vector3(0.55f, -0.3f, 0.75f);
            lightDir.Normalise();

            Light light = sceneMgr.CreateLight("tstLight");
            light.Type = Light.LightTypes.LT_DIRECTIONAL;
            light.Direction = lightDir;
            light.DiffuseColour = ColourValue.White;
            light.SpecularColour = ColourValue.White;
            light.CastShadows = false;
            light.Visible = true;

            sceneMgr.AmbientLight = ColourValue.White;

            tgo = new TerrainGlobalOptions();
            tg = new TerrainGroup(sceneMgr, Terrain.Alignment.ALIGN_X_Z, 513, 12000.0f);
            tg.SetFilenameConvention("Asd", "dat");
            tg.Origin = new Vector3(0, -250, 0);

            ConfigureTerrainDefaults(light);

            for (int x = 0; x <= 0; ++x)
            {
                for (int y = 0; y <= 0; ++y)
                {
                    DefineTerrain(x, y);
                }
            }

            tg.LoadAllTerrains(true);

            if (mTerrainImported)
            {
                foreach (TerrainGroup.TerrainSlot t in tg.GetTerrainIterator())
                {

                    InitBlendMaps(t.instance);
                }
            }

            tg.FreeTemporaryResources();
            //  tg.SaveAllTerrains(true);

            hydrax = new MHydrax.MHydrax(sceneMgr, _cam, viewport);

            hydrax.Components = MHydraxComponent.HYDRAX_COMPONENTS_ALL;

            Plane p = new Plane(new Vector3(0, 1, 0), new Vector3(0, 0, 0));

            MHydrax.MProjectedGrid m = new MProjectedGrid(hydrax,
                            new MPerlin(new MPerlin.MOptions(8, 0.085f, 0.49f, 1.4f, 1.27f, 2, new Vector3(0.5f, 50, 150000))),
                            p,
                            MMaterialManager.MNormalMode.NM_VERTEX,
                            new MHydrax.MProjectedGrid.MOptions(56, 35, 50, false, false, false, 3.75f));

            hydrax.SetModule(m);
            hydrax.CfgFileManager.Load("TestiPeli.hdx");

            hydrax.Create();

            //  sceneMgr.SetSkyDome(true, "Examples/CloudySky", 5, 8);

            mRect = new SelectionRectangle("Selection SelectionRectangle");

            sceneMgr.RootSceneNode.CreateChildSceneNode("debug_object").AttachObject(mRect);
            mRect._camera = _cam;

            ct = new CollisionTools(sceneMgr);
            SetupCaelum(viewport, _window);
        }
Exemplo n.º 9
0
 public void Disposed(object sender, EventArgs e)
 {
     hydrax.Dispose();
     hydrax = null;
 }