Ejemplo n.º 1
0
        /// <summary>
        /// 窗体加载事件
        /// </summary>
        /// <param name="sender">调用者</param>
        /// <param name="e">参数</param>
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            //创建管理器
            m_host = new WPFHost();
            //注册消息
            WindowInteropHelper helper = new WindowInteropHelper(this);

            m_host.WindowHwnd = helper.Handle;
            HwndSource hwndSource = HwndSource.FromHwnd(m_host.WindowHwnd);

            hwndSource.AddHook(new HwndSourceHook(WndProc));
            //启动服务
            DataCenter.StartService();
            //创建方法库
            m_chart = new OwChart();
            m_chart.CreateNative();
            m_native             = m_chart.Native;
            m_wpfPaint           = new WPFPaint();
            m_native.Paint       = m_wpfPaint;
            m_native.Host        = m_host;
            m_host.Render        = new Render(m_native);
            m_native.DisplaySize = new SIZE(525, 350);
            AddChild(m_host.Render);
            m_host.Container = m_host.Render;
            m_host.Native    = m_native;
            m_chart.Load(WPFHost.GetAppPath() + "\\config\\MainFrame.xml");
            m_host.Render.Chart = m_chart;
            m_chart.ShowLoginWindow();
        }
        void WPFHost.IScene.OnResize(WPFHost.ISceneHost host)
        {
            if (GraphicsDevice == null)
                return;

            lock (this)
            {
                resizeNeeded = true;
            }
        }
        void WPFHost.IScene.Attach(WPFHost.ISceneHost host)
        {
            this.host = host;
            camera = new Camera((float)host.RenderTargetWidth / host.RenderTargetHeight, (float)(75.0 * Math.PI / 180.0), 0.1f, 10000.0f);

            // device setup
            if (host.Device == null)
                throw new Exception("Scene host device is null");
            GraphicsDevice = GraphicsDevice.New(host.Device);
            RenderTarget2D backbufferRenderTarget = RenderTarget2D.New(GraphicsDevice, host.RenderTargetView, true);
            GraphicsDevice.Presenter = new RenderTargetGraphicsPresenter(GraphicsDevice, backbufferRenderTarget);
            GraphicsDevice.SetRenderTargets(backbufferRenderTarget);

            #if RAYMARCH_TERRAIN
            terrain = new TerrainRaymarcher(GraphicsDevice, (float)host.RenderTargetWidth / host.RenderTargetHeight);
            #else
            terrain = new TerrainRasterizer(GraphicsDevice);
            #endif
            terrain.HeightScale = terrainScale;

            // load shader
            sphereBillboardShader = new ShaderAutoReload("shader/spherebillboards.fx", GraphicsDevice);

            // vertex input layout
            sphereVertexInputLayout = VertexInputLayout.New(VertexBufferLayout.New(0, VertexElement.Position(SharpDX.DXGI.Format.R32G32B32_Float)));

            // generate sky
            skyShader = new ShaderAutoReload("shader/sky.fx", GraphicsDevice);
            skyShader.OnReload += ReGenerateSkyCubeMap;
            skyCubemap = RenderTargetCube.New(GraphicsDevice, CUBEMAP_RES, 0, PixelFormat.R8G8B8A8.SNorm);
            TimeOfDay = timeOfDay;

            // constant buffer to defaults
            SetupConstants();
        }