Пример #1
0
        private static void Main()
        {
            // Create Renderer
            Renderer renderer = new Renderer("SharpDX - SceneManager", 1280, 720, 60);

            SceneManager.LoadAndReplaceHierarchyRelative("Solar system.json", renderer);
            //SceneManager.LoadAndReplaceHierarchyRelative("Earth and moon.json", renderer);

            //CreateSolarSystemScene(10f, 1.5f, 0.2f, renderer);
            //CreateEarthAndMoonScene(0.1f, 1f, 3f, renderer);

            // Create camera
            Camera camera = new Camera();

            camera.cameraPosition = new Vector3(0, 3, 10.0f);
            camera.cameraLookAt   = new Vector3(0, 0, 0);
            camera.fov            = (float)Math.PI / 4.0f;
            camera.aspectRatio    = renderer.form.Width / (float)renderer.form.Height;


            //SceneManager.SaveCurrentHierarchyRelative("Test scene 01.json");

            // Use clock
            Time.Start();

            bool isOnFirstScene = true;

            // Main loop
            RenderLoop.Run(renderer.form, () =>
            {
                // Advance time
                Time.NextFrame();

                // Demonstrate switching scenes
                if (isOnFirstScene)
                {
                    if ((int)Time.Elapsed % 8 >= 4)
                    {
                        isOnFirstScene = false;

                        SceneManager.SaveCurrentHierarchyRelative("Solar system.json");
                        SceneManager.LoadAndReplaceHierarchyRelative("Earth and moon.json", renderer);
                    }
                }
                else
                {
                    if ((int)Time.Elapsed % 8 < 4)
                    {
                        isOnFirstScene = true;

                        SceneManager.SaveCurrentHierarchyRelative("Earth and moon.json");
                        SceneManager.LoadAndReplaceHierarchyRelative("Solar system.json", renderer);
                    }
                }

                // Clear views
                renderer.ClearViews();


                // Update objects
                Hierarchy.Update();

                // Render
                Hierarchy.Render(camera, renderer);


                // Present
                renderer.swapChain.Present(0, PresentFlags.None);
            });


            //SceneManager.SaveCurrentHierarchyRelative("Solar system.json");
            //SceneManager.SaveCurrentHierarchyRelative("Earth and moon.json");

            //// Release all resources
            renderer.Dispose();
            Hierarchy.Dispose();
        }