Ejemplo n.º 1
0
 public bool Initialize(DSystemConfiguration configuration, IntPtr windowHandle, Surface surface)
 {
     try
     {
         Input = new DInput();
         Input.Initialize(configuration, windowHandle);
         D3D = new DDX11();
         D3D.Initialize(configuration, windowHandle);
         Camera = new DCamera();
         Camera.SetPosition(0.0f, 0.0f, -1.0f);
         Camera.Render();
         Camera.SetPosition(50.0f, 2.0f, 10.0f);
         Terrain = new DSurface();
         Terrain.Initialize(D3D.Device, surface);
         ColorShader = new DColorShader();
         ColorShader.Initialize(D3D.Device, windowHandle);
         Position = new DPosition();
         Position.SetPosition(Camera.GetPosition().X, Camera.GetPosition().Y, Camera.GetPosition().Z);  // Ustawienie Position == Camera
         Camera.SetRotation(0.32f, -0.9f, 0);
         Position.RotationX    = 0.32f;
         Position.RotationY    = -90f;
         PositionChangeHandler = new DPositionChangeHandler(Position, Input);
         return(true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        // Methods.
        public bool Initialize(DSystemConfiguration configuration, IntPtr windowHandle)
        {
            try
            {
                // Create the input object.  The input object will be used to handle reading the keyboard and mouse input from the user.
                Input = new DInput();

                // Initialize the input object.
                if (!Input.Initialize(configuration, windowHandle))
                {
                    return(false);
                }

                // #region Initialize System
                // Create the Direct3D object.
                D3D = new DDX11();

                // Initialize the Direct3D object.
                if (!D3D.Initialize(configuration, windowHandle))
                {
                    return(false);
                }

                // Create the camera object
                Camera = new DCamera();

                // Initialize a base view matrix with the camera for 2D user interface rendering.
                Camera.SetPosition(0.0f, 0.0f, -1.0f);
                Camera.Render();
                Matrix baseViewMatrix = Camera.ViewMatrix;

                // Set the initial position of the camera.
                Camera.SetPosition(50.0f, 2.0f, -7.0f);

                // Create the model object.
                Terrain = new DTerrain();

                // Initialize the terrain object.
                if (!Terrain.Initialize(D3D.Device))
                {
                    return(false);
                }

                // Create the color shader object.
                ColorShader = new DColorShader();

                // Initialize the color shader object.
                if (!ColorShader.Initialize(D3D.Device, windowHandle))
                {
                    return(false);
                }

                // Create the position object.
                Position = new DPosition();

                // Set the initial position of the viewer to the same as the initial camera position.
                Position.SetPosition(Camera.GetPosition().X, Camera.GetPosition().Y, Camera.GetPosition().Z);

                // Create the fps object.
                FPS = new DFPS();

                // Initialize the fps object.
                FPS.Initialize();

                // Create the cpu object.
                CPU = new DCPU();

                // Initialize the cpu object.
                CPU.Initialize();

                // Create the font shader object.
                FontShader = new DFontShader();

                // Initialize the font shader object.
                if (!FontShader.Initialize(D3D.Device, windowHandle))
                {
                    return(false);
                }

                // Create the text object.
                Text = new DText();

                // Initialize the text object.
                if (!Text.Initialize(D3D.Device, D3D.DeviceContext, windowHandle, configuration.Width, configuration.Height, baseViewMatrix))
                {
                    return(false);
                }

                // Set the video card information in the text object.
                if (!Text.SetVideoCard(D3D.VideoCardDescription, D3D.VideoCardMemory, D3D.DeviceContext))
                {
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not initialize Direct3D\nError is '" + ex.Message + "'");
                return(false);
            }
        }