Ejemplo n.º 1
0
        // render the scene.
        public void Render()
        {
            bool skipRender =
                SurfaceId == 0 ||
                GameEngine.IsInError ||
                Width == 0 ||
                Height == 0 ||
                DesignView.Context == null;

            if (skipRender)
            {
                return;
            }

            m_clk.Start();
            GameEngine.SetObjectProperty(swapChainId, SurfaceId, BkgColorPropId, DesignView.BackColor);
            GameEngine.SetRenderState(RenderState);
            GameEngine.Begin(SurfaceId, Camera.ViewMatrix, Camera.ProjectionMatrix);

            IGame        game       = DesignView.Context.As <IGame>();
            GridRenderer gridRender = game.Grid.Cast <GridRenderer>();

            gridRender.Render(Camera);

            bool renderSelected = RenderState.DisplayBound == DisplayFlagModes.Selection ||
                                  RenderState.DisplayCaption == DisplayFlagModes.Selection ||
                                  RenderState.DisplayPivot == DisplayFlagModes.Selection;


            if (renderSelected)
            {
                // for testing draw bounds for selected objects
                var selection = DesignView.Context.As <ISelectionContext>().Selection;
                IEnumerable <DomNode> rootDomNodes = DomNode.GetRoots(selection.AsIEnumerable <DomNode>());
                RenderProperties(rootDomNodes,
                                 RenderState.DisplayCaption == DisplayFlagModes.Selection,
                                 RenderState.DisplayBound == DisplayFlagModes.Selection,
                                 RenderState.DisplayPivot == DisplayFlagModes.Selection);
            }

            RenderProperties(Items,
                             RenderState.DisplayCaption == DisplayFlagModes.Always,
                             RenderState.DisplayBound == DisplayFlagModes.Always,
                             RenderState.DisplayPivot == DisplayFlagModes.Always);

            GameEngine.RenderGame();


            if (DesignView.Manipulator != null)
            {
                DesignView.Manipulator.Render(this);
            }

            string str = string.Format("View Type: {0}   time-per-frame: {1:0.00} ms", ViewType, m_clk.Milliseconds);

            GameEngine.DrawText2D(str, Util3D.CaptionFont, 1, 1, Color.White);

            RenderSystemAxis();
            GameEngine.End();
        }
Ejemplo n.º 2
0
        private void GenThumbnail(Uri resourceUri, string thumbnailPath)
        {
            NativeObjectAdapter gameLevel = GameEngine.GetGameLevel();

            try
            {
                IResource   resource = m_resourceService.Load(resourceUri);
                IGameObject gob      = m_resourceConverterService.Convert(resource);
                if (gob == null)
                {
                    return;
                }

                m_game.RootGameObjectFolder.GameObjects.Add(gob);

                GameEngine.SetRenderState(m_renderState);
                GameEngine.SetGameLevel(m_game.Cast <NativeObjectAdapter>());

                m_gameEngine.WaitForPendingResources();
                FrameTime fr = new FrameTime(0, 0);
                m_gameEngine.Update(fr, UpdateType.Paused);

                IBoundable boundable = gob.Cast <IBoundable>();
                Sphere3F   sphere    = boundable.BoundingBox.ToSphere();

                if (Math.Abs(sphere.Radius) <= float.Epsilon)
                {
                    sphere.Radius = 1.0f;
                }

                m_cam.SetPerspective(
                    (float)Math.PI / 4,
                    1.0f,
                    sphere.Radius * 0.01f,
                    sphere.Radius * 4.0f);


                Vec3F camPos = sphere.Center + new Vec3F(sphere.Radius, sphere.Radius, sphere.Radius) * 1.5f;
                m_cam.Set(camPos, sphere.Center, new Vec3F(0, 1, 0));

                GameEngine.Begin(m_renderSurface.InstanceId, m_cam.ViewMatrix, m_cam.ProjectionMatrix);
                GameEngine.RenderGame();
                GameEngine.End();
                GameEngine.SaveRenderSurfaceToFile(m_renderSurface.InstanceId, thumbnailPath);
                m_game.RootGameObjectFolder.GameObjects.Remove(gob);

                m_resourceService.Unload(resourceUri);
            }
            finally
            {
                GameEngine.SetGameLevel(gameLevel);
            }
        }
Ejemplo n.º 3
0
        // render the scene.
        public override void Render()
        {
            bool skipRender =
                SurfaceId == 0 ||
                GameEngine.IsInError ||
                Width == 0 ||
                Height == 0 ||
                DesignView.Context == null;

            if (skipRender)
            {
                return;
            }

            m_clk.Start();
            GameEngine.SetObjectProperty(swapChainId, SurfaceId, BkgColorPropId, DesignView.BackColor);
            GameEngine.SetRenderState(RenderState);
            GameEngine.Begin(SurfaceId, Camera.ViewMatrix, Camera.ProjectionMatrix);

            IGame        game       = DesignView.Context.As <IGame>();
            GridRenderer gridRender = game.Grid.Cast <GridRenderer>();

            gridRender.Render(Camera);

            GameEngine.RenderGame();

            bool renderSelected = RenderState.DisplayBound == DisplayFlagModes.Selection ||
                                  RenderState.DisplayCaption == DisplayFlagModes.Selection ||
                                  RenderState.DisplayPivot == DisplayFlagModes.Selection;

            if (renderSelected)
            {
                var selection = DesignView.Context.As <ISelectionContext>().Selection;
                IEnumerable <DomNode> rootDomNodes = DomNode.GetRoots(selection.AsIEnumerable <DomNode>());
                RenderProperties(rootDomNodes,
                                 RenderState.DisplayCaption == DisplayFlagModes.Selection,
                                 RenderState.DisplayBound == DisplayFlagModes.Selection,
                                 RenderState.DisplayPivot == DisplayFlagModes.Selection);
            }

            RenderProperties(Items,
                             RenderState.DisplayCaption == DisplayFlagModes.Always,
                             RenderState.DisplayBound == DisplayFlagModes.Always,
                             RenderState.DisplayPivot == DisplayFlagModes.Always);

            GameEngine.SetRendererFlag(BasicRendererFlags.Foreground | BasicRendererFlags.Lit);
            if (DesignView.Manipulator != null)
            {
                DesignView.Manipulator.Render(this);
            }

            string str = string.Format("View Type: {0}   time per frame-render call: {1:0.00} ms", ViewType, m_clk.Milliseconds);

            GameEngine.DrawText2D(str, Util3D.CaptionFont, 1, 1, Color.White);
            GameEngine.End();

            if (IsPicking)
            {// todo: use Directx to draw marque.
                using (Graphics g = CreateGraphics())
                {
                    Rectangle rect = MakeRect(FirstMousePoint, CurrentMousePoint);
                    if (rect.Width > 0 && rect.Height > 0)
                    {
                        g.DrawRectangle(s_marqueePen, rect);
                    }
                }
            }
        }
Ejemplo n.º 4
0
            // render the scene.
            public void Render()
            {
                if (GameEngine.IsInError ||
                    SurfaceId == 0 ||
                    Visible == false ||
                    Width == 0 ||
                    Height == 0 ||
                    Game == null)
                {
                    return;
                }


                NativeObjectAdapter gameLevel = GameEngine.GetGameLevel();

                try
                {
                    NativeObjectAdapter game = Game.As <NativeObjectAdapter>();
                    GameEngine.SetGameLevel(game);
                    GameEngine.SetRenderState(m_renderState);
                    if (Game.RootGameObjectFolder.GameObjects.Count > 0)
                    {
                        GameEngine.Update(0, 0, true);
                    }

                    if (ResetCamera)
                    {
                        // save view type
                        ViewTypes viewtype = this.ViewType;
                        ViewType = ViewTypes.Perspective;
                        Size       sz        = ClientSize;
                        float      aspect    = (float)sz.Width / (float)sz.Height;
                        IBoundable boundable = Game.RootGameObjectFolder.Cast <IBoundable>();
                        Sce.Atf.VectorMath.Sphere3F sphere = boundable.BoundingBox.ToSphere();
                        float nearZ = sphere.Radius * 0.01f;
                        nearZ = Math.Min(0.1f, nearZ);
                        Camera.SetPerspective(
                            (float)Math.PI / 4,
                            aspect,
                            nearZ,
                            sphere.Radius * 10.0f);

                        Vec3F camPos = sphere.Center + new Vec3F(sphere.Radius, sphere.Radius, sphere.Radius) * 1.2f;
                        Camera.Set(camPos, sphere.Center, new Vec3F(0, 1, 0));
                        ViewType    = viewtype;
                        ResetCamera = false;
                    }

                    GameEngine.Begin(SurfaceId, Camera.ViewMatrix, Camera.ProjectionMatrix);
                    if (Game.RootGameObjectFolder.GameObjects.Count > 0)
                    {
                        GameEngine.RenderGame();
                    }
                    string str = "View Type: " + ViewType.ToString();
                    GameEngine.DrawText2D(str, Util3D.CaptionFont, 1, 1, Color.White);
                    GameEngine.End();
                }
                finally
                {
                    GameEngine.SetGameLevel(gameLevel);
                }
            }