// Methods.
        public bool Initialize(DSystemConfiguration configuration, IntPtr windowHandle)
        {
            try
            {
                #region Initialize System
                // Create the Direct3D object.
                D3D = new DDX11();

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

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

                // Set the position and rotation of the camera;
                Camera.SetPosition(0.0f, 2.0f, -12.0f); // 0.0f, 4.0f, -12.0f
                #endregion

                #region Initialize Models
                // Create the Flat Plane  model class.
                Model = new DModel();

                //// Initialize the ground model object.
                if (!Model.Initialize(D3D.Device, "plane01.txt", new[] { "stone01.bmp" }))
                {
                    MessageBox.Show("Could not initialize the ground model object", "Error", MessageBoxButtons.OK);
                    return(false);
                }
                #endregion

                #region Initialize Shaders
                // Create the light shader object.
                LightShader = new DLightShader();

                // Initialize the light shader object.
                if (!LightShader.Initialize(D3D.Device, windowHandle))
                {
                    MessageBox.Show("Could not initialize the light shader object.", "Error", MessageBoxButtons.OK);
                    return(false);
                }
                #endregion

                #region Initialize Data
                // Create the first light object.
                Light1 = new DLight();
                // Initialize the first light as a red Light.
                Light1.SetDiffuseColor(1.0f, 0.0f, 0.0f, 1.0f);
                Light1.SetPosition(-3.0f, 1.0f, 3.0f);

                // Create the second light object.
                Light2 = new DLight();
                // Initialize the second light as a green Light.
                Light2.SetDiffuseColor(0.0f, 1.0f, 0.0f, 1.0f);
                Light2.SetPosition(3.0f, 1.0f, 3.0f);

                // Create the third light object.
                Light3 = new DLight();
                // Initialize the third light to a blue Light.
                Light3.SetDiffuseColor(0.0f, 0.0f, 1.0f, 1.0f);
                Light3.SetPosition(-3.0f, 1.0f, -3.0f);

                // Create the fourth light object.
                Light4 = new DLight();
                // Initialize the fourth light as a white Light.
                Light4.SetDiffuseColor(1.0f, 1.0f, 0.0f, 1.0f);
                Light4.SetPosition(3.0f, 1.0f, -3.0f);

                // Prep rendering variables here once instead of every frame.
                lightDiffuseColors = new Vector4[LightShader.NumLights];
                lightPositions     = new Vector4[LightShader.NumLights];

                // Create the diffuse color array from the four light colors.
                lightDiffuseColors[0] = Light1.DiffuseColour;
                lightDiffuseColors[1] = Light2.DiffuseColour;
                lightDiffuseColors[2] = Light3.DiffuseColour;
                lightDiffuseColors[3] = Light4.DiffuseColour;

                // Create the light position array from the four light positions.
                lightPositions[0] = Light1.Position;
                lightPositions[1] = Light2.Position;
                lightPositions[2] = Light3.Position;
                lightPositions[3] = Light4.Position;
                #endregion

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not initialize Direct3D\nError is '" + ex.Message + "'");
                return(false);
            }
        }
        // Methods.
        public bool Initialize(DSystemConfiguration configuration, IntPtr windowHandle)
        {
            // Set the size to sample down to.
            screenWidth  = configuration.Width;
            screenHeight = configuration.Height;

            try
            {
                // Create the input object.
                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);
                }
                #endregion

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

                // Set the initial position of the camera.
                Camera.SetPosition(0.0f, 0.0f, -10.0f);
                Camera.Render();
                #endregion

                // Create the model object.
                Model = new DModel();

                // Initialize the model object.
                if (!Model.Initialize(D3D.Device, "sphere.txt", "blue.bmp"))
                {
                    return(false);
                }

                // Create the texture shader object.
                TextureShader = new DTextureShader();

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

                // Create the light shader object.
                LightShader = new DLightShader();

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

                // Create the light object.
                Light = new DLight();

                // Initialize the light object.
                Light.Direction = new Vector3(0.0f, 0.0f, 1.0f);

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

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

                // Create the bitmap object as the mouse pointer.
                BitMap = new DBitmap();

                // Initialize the bitmap object.
                if (!BitMap.Initialize(D3D.Device, configuration.Width, configuration.Height, "mouse.bmp", 32, 32))
                {
                    return(false);
                }

                // Initialize that the user has not clicked on the screen to try an intersection test yet.
                beginMouseChexk = false;

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not initialize Direct3D\nError is '" + ex.Message + "'");
                return(false);
            }
        }
        // Methods.
        public bool Initialize(DSystemConfiguration configuration, IntPtr windowHandle)
        {
            try
            {
                // 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 the camera for 2D user interface rendering.
                Camera.SetPosition(0, 0, -1);
                Camera.Render();
                var baseViewMatrix = Camera.ViewMatrix;

                // Create the model class.
                Model = new DModel();

                // Initialize the model object.
                if (!Model.Initialize(D3D.Device, "cube.txt", new[] { "seafloor.bmp" }))
                {
                    MessageBox.Show("Could not initialize the model object", "Error", MessageBoxButtons.OK);
                    return(false);
                }

                // Create the light shader object.
                LightShader = new DLightShader();

                // Initialize the light shader object.
                if (!LightShader.Initialize(D3D.Device, windowHandle))
                {
                    MessageBox.Show("Could not initialize the light shader", "Error", MessageBoxButtons.OK);
                    return(false);
                }

                // Create the light object.
                Light = new DLight();

                // Initialize the light object.
                Light.SetDiffuseColor(1, 1, 1, 1f);
                Light.SetDirection(0, 0, 1);

                // Create the render to texture object.
                RenderTexture = new DRenderTexture();

                // Initialize the render to texture object.
                if (!RenderTexture.Initialize(D3D.Device, configuration))
                {
                    return(false);
                }

                // Create the debug window object.
                DebugWindow = new DDebugWindow();

                // Initialize the debug window object.  * configuration.Height / configuration.Width
                if (!DebugWindow.Initialize(D3D.Device, configuration.Width, configuration.Height, 100, 100))
                {
                    MessageBox.Show("Could not initialize the debug window object.", "Error", MessageBoxButtons.OK);
                    return(false);
                }

                // Create the texture shader object.
                TextureShader = new DTextureShader();

                // Initialize the texture shader object.
                if (!TextureShader.Initialize(D3D.Device, windowHandle))
                {
                    MessageBox.Show("Could not initialize the texture shader object.", "Error", MessageBoxButtons.OK);
                    return(false);
                }

                Camera.SetPosition(0, 0, -5);

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not initialize Direct3D\nError is '" + ex.Message + "'");
                return(false);
            }
        }
예제 #4
0
        // Methods.
        public bool Initialize(DSystemConfiguration configuration, IntPtr windowHandle)
        {
            try
            {
                #region Initialize System
                // Create the Direct3D object.
                D3D = new DDX11();

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

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

                // Set the position and rotation of the camera;
                Camera.SetPosition(-10.0f, 6.0f, -10.0f);
                Camera.SetRotation(0.0f, 45.0f, 0.0f);
                #endregion

                #region Initialize Models
                // Create the ground model class.
                GroundModel = new DModel();

                // Initialize the ground model object.
                if (!GroundModel.Initialize(D3D.Device, "ground.txt", new[] { "ground01.bmp" }))
                {
                    MessageBox.Show("Could not initialize the ground model object", "Error", MessageBoxButtons.OK);
                    return(false);
                }

                // Create the wall model class.
                WallModel = new DModel();

                // Initialize the wall model object.
                if (!WallModel.Initialize(D3D.Device, "wall.txt", new[] { "wall01.bmp" }))
                {
                    MessageBox.Show("Could not initialize the wall model object", "Error", MessageBoxButtons.OK);
                    return(false);
                }

                // Create the bath model class.
                BathModel = new DModel();

                // Initialize the bath model object.
                if (!BathModel.Initialize(D3D.Device, "bath.txt", new[] { "marble01.bmp" }))
                {
                    MessageBox.Show("Could not initialize the bath model object", "Error", MessageBoxButtons.OK);
                    return(false);
                }

                // Create the water model class.
                WaterModel = new DModel();

                // Initialize the water model object.
                if (!WaterModel.Initialize(D3D.Device, "water.txt", new[] { "water01.bmp" }))
                {
                    MessageBox.Show("Could not initialize the bath model object", "Error", MessageBoxButtons.OK);
                    return(false);
                }

                // Create the light object.
                Light = new DLight();

                // Initialize the light object.
                Light.SetAmbientColor(0.15f, 0.15f, 0.15f, 1.0f);
                Light.SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f);
                Light.SetDirection(0.0f, -1.0f, 0.5f);
                Light.SetSpecularColor(0, 1, 1, 1);
                Light.SetSpecularPower(16);
                #endregion

                #region Initialize Data
                // Create the refraction render to texture object.
                RenderRefractionTexture = new DRenderTexture();

                // Initialize the refraction render to texture object.
                if (!RenderRefractionTexture.Initialize(D3D.Device, configuration))
                {
                    MessageBox.Show("Could not initialize the refraction render to texture object.", "Error", MessageBoxButtons.OK);
                    return(false);
                }

                // Create the refraction render to texture object.
                RenderReflectionTexture = new DRenderTexture();

                // Initialize the refraction render to texture object.
                if (!RenderReflectionTexture.Initialize(D3D.Device, configuration))
                {
                    MessageBox.Show("Could not initialize the reflection render to texture object.", "Error", MessageBoxButtons.OK);
                    return(false);
                }
                #endregion

                #region Initialize Shaders
                // Create the light shader object.
                LightShader = new DLightShader();

                // Initialize the light shader object.
                if (!LightShader.Initialize(D3D.Device, windowHandle))
                {
                    MessageBox.Show("Could not initialize the light shader object.", "Error", MessageBoxButtons.OK);
                    return(false);
                }

                // Create the refraction shader object.
                RefractionShader = new DRefractionShader();

                // Initialize the refraction shader object.
                if (!RefractionShader.Initialize(D3D.Device, windowHandle))
                {
                    MessageBox.Show("Could not initialize the refraction shader object.", "Error", MessageBoxButtons.OK);
                    return(false);
                }

                // Create the water shader object.
                WaterShader = new DWaterShader();

                // Initialize the water shader object.
                if (!WaterShader.Initialize(D3D.Device, windowHandle))
                {
                    MessageBox.Show("Could not initialize the water shader object.", "Error", MessageBoxButtons.OK);
                    return(false);
                }
                #endregion

                // Set the height of the water.
                WaterHeight = 2.75f;
                // Initialize the position of the water.
                WaterTranslation = 0f;

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not initialize Direct3D\nError is '" + ex.Message + "'");
                return(false);
            }
        }
예제 #5
0
        // Methods.
        public bool Initialize(DSystemConfiguration configuration, IntPtr windowHandle)
        {
            try
            {
                // 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 the camera for 2D user interface rendering.
                Camera.SetPosition(0, 0, -1);
                Camera.Render();
                var baseViewMatrix = Camera.ViewMatrix;

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

                // Create the model class.
                Model = new DModel();

                // Initialize the model object.
                if (!Model.Initialize(D3D.Device, "sphere.txt", "seafloor.bmp"))
                {
                    MessageBox.Show("Could not initialize the model object", "Error", MessageBoxButtons.OK);
                    return(false);
                }

                // Create the light shader object.
                LightShader = new DLightShader();

                // Initialize the light shader object.
                if (!LightShader.Initialize(D3D.Device, windowHandle))
                {
                    MessageBox.Show("Could not initialize the light shader", "Error", MessageBoxButtons.OK);
                    return(false);
                }

                // Create the light object.
                Light = new DLight();

                // Initialize the light object.
                Light.SetDirection(0.0f, 0.0f, 1.0f);

                // Create the model list object.
                ModelList = new DModelList();

                // Initialize the model list object.
                if (!ModelList.Initialize(25))
                {
                    MessageBox.Show("Could not initialize the model list object", "Error", MessageBoxButtons.OK);
                    return(false);
                }

                // Create the frustum object.
                Frustum = new DFrustum();

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