public GrassPatchSceneNode(SceneNode parent, SceneManager mgr, int id, bool createIfEmpty,
                                   Vector3D gridPos, string filepath, Texture heightMap, Texture colourMap,
                                   Texture grassMap, SceneNode terrain, WindGenerator wind)
            : base(parent, mgr, id)
        {
            DrawDistance = GRASS_PATCH_SIZE * 1.5f;
            MaxDensity = 800;
            TerrainHeightMap = heightMap;
            TerrainColourMap = colourMap;
            TerrainGrassMap = grassMap;
            Terrain = terrain;
            WindGen = wind;
            lastwindtime = 0;
            lastdrawcount = 0;
            redrawnextloop = true;
            MaxFPS = 0;
            _mgr = mgr;
            WindRes = 5;

            filename = string.Format("{0}/{1}.{2}.grass", filepath, gridpos.X, gridpos.Z);
            gridpos = gridPos;
            Position = new Vector3D(gridpos.X * GRASS_PATCH_SIZE, 0f,
                                    gridpos.Z * GRASS_PATCH_SIZE);

            ImageCount = new Dimension2D(4, 2);

            if (!Load())
                Create(createIfEmpty);
        }
示例#2
0
 public IrrlichtDevice(DriverType type, Dimension2D dim, int bits, bool fullscreen, bool stencil, bool vsync, bool antialias, IntPtr windowHandle)
 {
     Console.WriteLine("Irrlicht.NET CP v" + CPVersion + " running");
     Initialize(CreateDeviceA(type, dim.ToUnmanaged(), bits, fullscreen, stencil, vsync, antialias, windowHandle));
     AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
     MainNativeEvent = OnNativeEvent;
     Device_SetCallback(_raw, MainNativeEvent);
 }
		public WaterSceneNode(SceneNode parent, SceneManager mgr, Dimension2Df tileSize,
		                      Dimension2D tileCount, Dimension2D precision, int id) : 
			base(parent, mgr, id)
		{
			_scene = mgr;
			_driver = mgr.VideoDriver;
			
			AnimatedMesh wmesh =  _scene.AddHillPlaneMesh("watermesh" + _current,
                tileSize,
                tileCount, 0,
                new Dimension2Df(0, 0),
                new Dimension2Df(1, 1));
           	_current++; 
           	 
            int dmat = (int)MaterialType.Reflection2Layer;
            if(_driver.DriverType == DriverType.OpenGL)
                dmat = _driver.GPUProgrammingServices.AddHighLevelShaderMaterial(
                 WATER_VERTEX_GLSL, "main", VertexShaderType._1_1, WATER_FRAGMENT_GLSL,
                 "main", PixelShaderType._1_1, OnShaderSet, MaterialType.TransparentAlphaChannel, 0);
            else
                dmat = _driver.GPUProgrammingServices.AddHighLevelShaderMaterial(
                 WATER_HLSL, "vertexMain", VertexShaderType._2_0, WATER_HLSL,
                 "pixelMain", PixelShaderType._2_0, OnShaderSet, MaterialType.TransparentAlphaChannel, 2);

            if (_driver.DriverType == DriverType.OpenGL)
                ClampShader = _driver.GPUProgrammingServices.AddHighLevelShaderMaterial(
                 CLAMP_VERTEX_GLSL, "main", VertexShaderType._1_1, CLAMP_FRAGMENT_GLSL,
                 "main", PixelShaderType._1_1, OnShaderSet, MaterialType.TransparentAlphaChannel, 1);
            else
                ClampShader = _driver.GPUProgrammingServices.AddHighLevelShaderMaterial(
                 CLAMP_HLSL, "vertexMain", VertexShaderType._2_0, CLAMP_HLSL,
                 "pixelMain", PixelShaderType._2_0, OnShaderSet, MaterialType.TransparentAlphaChannel, 3);
                 
           	_waternode = _scene.AddMeshSceneNode(wmesh.GetMesh(0), this, -1);  
            _waternode.SetMaterialType(dmat);
            _waternode.SetMaterialFlag(MaterialFlag.BackFaceCulling, false);
            _waternode.SetMaterialFlag(MaterialFlag.Lighting, false);
            _waternode.SetMaterialFlag(MaterialFlag.FogEnable, false);
            
            _rt = _driver.CreateRenderTargetTexture(precision);
            _waternode.SetMaterialTexture(0, _rt); 
            
            CameraSceneNode oldcam = _scene.ActiveCamera;
            _fixedcam = _scene.AddCameraSceneNode(null);
            if(oldcam != null)
            	_scene.ActiveCamera = oldcam;
		}
示例#4
0
 public WaterSceneNode(SceneNode parent, SceneManager mgr, Dimension2Df tileSize, Dimension2D tileCount, Dimension2D precision)
     : this(parent, mgr, tileSize, tileCount, precision, -1)
 {
 }
示例#5
0
 public WaterSceneNode(SceneNode parent, SceneManager mgr, Dimension2Df tileSize, Dimension2D tileCount)
     : this(parent, mgr, tileSize, tileCount, new Dimension2D(256, 256), -1)
 {
 }
示例#6
0
文件: Viewer.cs 项目: Booser/radegast
        public void MainLoop(GUISkin skin, Color skincolor)
        {
            // Main Render Loop
            int minFrameTime = (int) (1000/((float) m_maximumFramesPerSecond));

            m_lastScreenSize = Renderer.Driver.ScreenSize;

            while (Running)
            {
                try
                {
                    NetworkInterface.Process();
                }
                catch (Exception e)
                {
                    m_log.Error("Error processing network messages: " + e);
                }

                try
                {

                    // If you close the gui window, device.Run returns false.
                    Running = Renderer.Device.Run();
                }
                catch (AccessViolationException e)
                {
                    m_log.Error("[VIDEO]: Error in device" + e.ToString());
                }
                catch (OutOfMemoryException e)
                {
                    m_log.Error("[VIDEO]: Error in device" + e.ToString());
                    continue;
                }
                if (!Running)
                    break;
                try
                {
                    //  SceneGraph.WaterNode.Update();
                }
                catch ( /*AccessViolation*/ Exception)
                {
                    m_log.Warn("[water]: Unable to update this round");
                }

                Renderer.Driver.BeginScene(true, true, new Color(0, 255, 255, 255));
                try
                {
                    Renderer.SceneManager.DrawAll();
                }
                catch (Exception e)
                {

                    System.Console.WriteLine("" + e);
                }
                try
                {
                    Renderer.GuiEnvironment.DrawAll();
                }
                catch (Exception e)
                {

                    System.Console.WriteLine("" + e);
                }
                Renderer.Driver.EndScene();

                m_timeSinceLastSceneUpdate += System.Environment.TickCount - m_lastTickCount;
                int frameTime = System.Environment.TickCount - m_lastTickCount;
                m_lastTickCount = System.Environment.TickCount;

                // Update Interpolation targets
                SceneGraph.UpdateMovingObjects();
                // Update camera position and rotation.
                CameraController.CheckTarget();

                if (m_timeSinceLastSceneUpdate > m_baseSceneUpdateTimePeriod)
                {
                    // Repeat any held keys
                    UpdatePressedKeys();

                    m_timeSinceLastSceneUpdate = 0;
                    m_sceneUpdateCounter++;

                    if (m_sceneUpdateCounter == int.MaxValue)
                        m_sceneUpdateCounter = 0;
                }

                if ((m_sceneUpdateCounter%m_avatarModificationProcessingRate) == 0)
                {
                    AvatarController.UpdateRemote();
                    NetworkInterface.SendCameraViewMatrix(CameraController.GetCameraViewMatrix());
                    // process avatar animation changes
                    SceneGraph.ProcessAnimations();
                    // Process Avatar Mod Queue
                    SceneGraph.ProcessObjectModifications(20, ref SceneGraph.AvatarModifications);
                }

                try
                {
                    TerrainManager.Process();
                }
                catch (Exception e)
                {
                    System.Console.WriteLine("" + e);
                }

                if ((m_sceneUpdateCounter%m_objectModificationProcessingRate) == 0)
                {
                    // Process Object Mod Queue.  Parameter is 'Items'
                    try
                    {
                        SceneGraph.ProcessObjectModifications(20, ref SceneGraph.ObjectModifications);
                    }
                    catch (Exception ex)
                    {
                        System.Console.WriteLine("MAINLOOP: ProcessObjectModifications" + ex);
                    }
                    // Process Mesh Queue.  Parameter is 'Items'
                    try
                    {
                        SceneGraph.ProcessMeshModifications(20);
                    }
                    catch (System.Exception ex)
                    {

                        System.Console.WriteLine("MAINLOOP: ProcessMeshModifications" + ex);
                    }
                    // Check the UnAssigned Child Queue for parents that have since rezed
                    try
                    {
                        SceneGraph.ProcessParentWaitingObjects(5);
                    }
                    catch (System.Exception ex)
                    {
                        System.Console.WriteLine("MAINLOOP: ProcessParentWaitingObjects" + ex);
                    }
                    // Apply textures
                    try
                    {
                        SceneGraph.ProcessTextureModifications(10);
                    }
                    catch (System.Exception ex)
                    {
                        System.Console.WriteLine("MAINLOOP: ProcessTextureModifications" + ex);
                    }
                    // Update foliage.
                    try
                    {
                        SceneGraph.ProcessFoliageMeshModifications(3);
                    }
                    catch (System.Exception ex)
                    {
                        System.Console.WriteLine("MAINLOOP: ProcessFoliageMeshModifications" + ex);
                    }
                    // Set the FPS in the window title.
                    Renderer.Device.WindowCaption = "IdealistViewer 0.001, FPS:" + Renderer.Driver.FPS.ToString();

                }

                // process chat
                if (UserInterface.OutboundChatMessages.Count > 0)
                    lock (UserInterface.OutboundChatMessages)
                        for (int i = 0; i < UserInterface.OutboundChatMessages.Count; i++)
                            NetworkInterface.Say(UserInterface.OutboundChatMessages.Dequeue());

                UserInterface.UpdateChatWindow();

                // Sleep until full frame time has been used.                
                if (m_limitFramesPerSecond && frameTime < minFrameTime)
                    Thread.Sleep(minFrameTime - frameTime);

            }
            //In the end, delete the Irrlicht device.
            Shutdown();
        }
示例#7
0
 public virtual void SetMinSize(Dimension2D size)
 {
     GuiElem_SetMinSize(_raw, size.ToUnmanaged());
 }
        public override void OnRegisterSceneNode()
        {
            if (Visible)
            {
                Position2D pm = smgr.CollisionManager.GetScreenCoordinatesFrom3DPosition(AbsolutePosition,
                                                        smgr.ActiveCamera);

                if (!ign_geom)
                {
                    SceneNode node = smgr.CollisionManager.GetSceneNodeFromScreenCoordinates(pm, 0, true);

                    if (node != this && node != this.Parent && node != null)
                    {
                        draw_flare = false;
                    }
                    else
                    {
                        draw_flare = true;
                    }
                }
                else
                {
                    draw_flare = true;
                }
                if (draw_flare)
                {
                screensize = smgr.VideoDriver.ScreenSize;
                    if (Rect.From(Position2D.From(0, 0), Position2D.FromUnmanaged(screensize.ToUnmanaged())).IsPointInside(pm))
                    {
                        smgr.RegisterNodeForRendering(this, SceneNodeRenderPass.Transparent);
                        base.OnRegisterSceneNode();

                    }
                }
            }
        }
		public override void SetMinSize (Dimension2D size)
		{
			CGE_PVOID_METHODS(_raw, CGE_VOID_METHOD.SET_MIN_SIZE, IntPtr.Zero, 0, 0, size.ToUnmanaged());
		}
示例#10
0
 /// <summary>
 /// Adds a static terrain mesh
 /// </summary>
 /// <returns>The static mesh</returns>
 /// <param name="name">Name of this mesh</param>
 /// <param name="texture">Image of the texture. Please notice that it is an Image, not a Texture, and it is supposed to be hardware-created</param>
 /// <param name="heightmap">Image of the heigthmap</param>
 /// <param name="stretchSize">How big a pixel on the image is rendered on the terrain</param>
 /// <param name="maxHeight">Maximal height</param>
 /// <param name="defaultVertexBlockSize">Should be (64,64)</param>
 public Mesh AddTerrainMesh(string name, Image texture, Image heightmap, Dimension2D stretchSize, float maxHeight, Dimension2D defaultVertexBlockSize)
 {
     return (Mesh)
         NativeElement.GetObject(SceneManager_AddTerrainMesh(_raw, name, texture.Raw, heightmap.Raw, stretchSize.ToUnmanaged(), maxHeight, defaultVertexBlockSize.ToUnmanaged()),
                                 typeof(Mesh));
 }
示例#11
0
 /// <summary>
 /// Creates a hill plane mesh (used for instance for any water)
 /// </summary>
 /// <returns>The mesh</returns>
 /// <param name="name">Name of this mesh</param>
 /// <param name="tileSize">Size of each tile from the mesh</param>
 /// <param name="tileCount">Number of tiles</param>
 /// <param name="hillHeight">Height of each hills</param>
 /// <param name="countHills">Number of hills</param>
 /// <param name="textureRepeatCount">Texture repeatition count</param>
 public AnimatedMesh AddHillPlaneMesh(string name, Dimension2Df tileSize, Dimension2D tileCount, float hillHeight, Dimension2Df countHills, Dimension2Df textureRepeatCount)
 {
     return (AnimatedMesh)
         NativeElement.GetObject(SceneManager_AddHillPlaneMesh(_raw, name, tileSize.ToUnmanaged(), tileCount.ToUnmanaged(), hillHeight, countHills.ToUnmanaged(), textureRepeatCount.ToUnmanaged()),
                                 typeof(AnimatedMesh));
 }
示例#12
0
 public Texture CreateRenderTargetTexture(Dimension2D size)
 {
     return (Texture)
         NativeElement.GetObject(VideoDriver_CreateRenderTargetTexture(_raw, size.ToUnmanaged()),
                                 typeof(Texture));
 }
示例#13
0
 /// <summary>
 /// Creates an empty texture
 /// </summary>
 /// <param name="size">Size of the teture</param>
 /// <param name="name">Name of the texture on the texture pool</param>
 /// <param name="fmt">Pixel format</param>
 /// <returns>The created texture</returns>
 public Texture AddTexture(Dimension2D size, string name, ColorFormat fmt)
 {
     return (Texture)
         NativeElement.GetObject(VideoDriver_AddTexture(_raw, size.ToUnmanaged(), name, fmt),
                                 typeof(Texture));
 }
        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;
        }
示例#15
0
 public void Set(Position2D pos, Dimension2D size)
 {
     UpperLeftCorner = pos;
     LowerRightCorner = new Position2D(pos.X + size.Width, pos.Y + size.Height);
 }
示例#16
0
 public Rect(Position2D pos, Dimension2D size)
 {
     UpperLeftCorner = new Position2D();
     LowerRightCorner = new Position2D();
     Set(pos, size);
 }