protected override void OnPaint(PaintEventArgs e)
        {
            if (DesignView.Context == null || GameEngine.IsInError)
            {
                e.Graphics.Clear(DesignView.BackColor);
                if (GameEngine.IsInError)
                {
                    e.Graphics.DrawString(GameEngine.CriticalError, Font, Brushes.Red, 1, 1);
                }
                return;
            }

            FrameTime ft = DesignView.GetFrameTime();

            GameEngine.SetGameLevel(DesignView.Context.Cast <NativeObjectAdapter>());
            GameEngine.Update(ft.TotalTime, ft.ElapsedTime, false);
            Render();
            // draw selection
            if (IsPicking)
            {
                Rectangle rect = MakeRect(FirstMousePoint, CurrentMousePoint);
                if (rect.Width > 0 && rect.Height > 0)
                {
                    e.Graphics.DrawRectangle(s_marqueePen, rect);
                }
            }
        }
 public override void Tick(FrameTime ft)
 {
     GameEngine.SetGameLevel(Context.Cast <NativeObjectAdapter>());
     GameEngine.Update(ft.TotalTime, ft.ElapsedTime, false);
     foreach (NativeDesignControl view in Views)
     {
         view.Render();
     }
 }
        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>());
                GameEngine.Update(0, 0, true);

                IBoundable boundable = gob.Cast <IBoundable>();
                Sce.Atf.VectorMath.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);
            }
        }
Exemple #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);
                }
            }