예제 #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            DModel dModel = db.DModels.Find(id);

            db.DModels.Remove(dModel);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #2
0
 public ActionResult Edit([Bind(Include = "Id,Url,Name,Description,Weight,Version,Color,Style")] DModel dModel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(dModel).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(dModel));
 }
예제 #3
0
        public ActionResult Create([Bind(Include = "Id,Url,Name,Description,Weight,Version,Color,Style")] DModel dModel)
        {
            if (ModelState.IsValid)
            {
                db.DModels.Add(dModel);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(dModel));
        }
        // 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 of the camera.
                Camera.SetPosition(0.0f, 0.0f, -5.0f);
                #endregion

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

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

                #region Initialize Shaders
                // Create the fire shader object.
                FireShader = new DFireShader();

                if (!FireShader.Initialize(D3D.Device, windowHandle))
                {
                    return(false);
                }
                #endregion

                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
            {
                #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, 2.0f, -10.0f);
                #endregion

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

                // Create the floor model object.
                if (!FloorModel.Initialize(D3D.Device, "floor.txt"))
                {
                    MessageBox.Show("Could not initialize the ground model object", "Error", MessageBoxButtons.OK);
                    return(false);
                }

                // Create the depth shader object.
                DepthShader = new DDepthShader();

                if (!DepthShader.Initialize(D3D.Device, windowHandle))
                {
                    return(false);
                }
                #endregion

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not initialize Direct3D\nError is '" + ex.Message + "'");
                return(false);
            }
        }
예제 #6
0
        // GET: DModels/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DModel dModel = db.DModels.Find(id);

            if (dModel == null)
            {
                return(HttpNotFound());
            }
            return(View(dModel));
        }
예제 #7
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();

                // 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 shader object.
                FogShader = new DFogShader();

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

                Camera.SetPosition(0, 0, -5.0f);

                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, "square.txt", new[] { "stone01.bmp", "dirt01.bmp" }))
                {
                    MessageBox.Show("Could not initialize the model object", "Error", MessageBoxButtons.OK);
                    return(false);
                }

                // Create the multitexture shader object.
                MultiTextureLightShader = new DMultiTextureLightShader();

                // Initialize the multitexture shader object.
                if (!MultiTextureLightShader.Initialize(D3D.Device, windowHandle))
                {
                    MessageBox.Show("Could not initialize the light shader", "Error", MessageBoxButtons.OK);
                    return(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();

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

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

                // Create the shader object.
                TranslateShader = new DTranslateShader();

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

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

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

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

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

                // Set the initial position of the camera.
                Camera.SetPosition(0, 0, -5.0f);

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

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

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

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

                return(true);
            }
            catch
            {
                return(false);
            }
        }
        // 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 initial position of the camera.
                Camera.SetPosition(0.0f, 0.0f, -10.0f);
                #endregion

                #region Initialize Models
                // Create the cube model object.
                CubeModel = new DModel();

                // Initialize the cube model object.
                if (!CubeModel.Initialize(D3D.Device, "cube.txt", "wall01.bmp"))
                {
                    return(false);
                }

                // Set the position for the cube model.
                CubeModel.SetPosition(-2.0f, 2.0f, 0.0f);

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

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

                // Set the position for the sphere model.
                SphereModel.SetPosition(2.0f, 2.0f, 0.0f);

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

                // Initialize the ground model object.
                if (!GroundModel.Initialize(D3D.Device, "plane01.txt", "metal001.bmp"))
                {
                    return(false);
                }

                // Set the position for the ground model.
                GroundModel.SetPosition(0.0f, 1.0f, 0.0f);
                #endregion

                #region Data variables.
                // 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.SetLookAt(0.0f, 0.0f, 0.0f);
                Light.GenerateProjectionMatrix();

                // Create the second light object.
                Light2 = new DLight();
                // Initialize the second light object.
                Light2.SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f);
                Light2.SetLookAt(0.0f, 0.0f, 0.0f);
                Light2.GenerateProjectionMatrix();

                // Set the position of the first & second lights.
                Light.Position  = new Vector3(5.0f, 3.0f, -2.0f);
                Light2.Position = new Vector3(-5.0f, 3.0f, -2.0f);

                // 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 second render to texture object.
                RenderTexture2 = new DRenderTexture();

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

                #region Initialize Shaders
                // Create the depth shader object.
                DepthShader = new DDepthShader();

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

                // Create the shadow shader object.
                ShadowShader = new DShadowShader();

                // Initialize the shadow shader object.
                if (!ShadowShader.Initialize(D3D.Device, windowHandle))
                {
                    return(false);
                }
                #endregion

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not initialize Direct3D\nError is '" + ex.Message + "'");
                return(false);
            }
        }
예제 #12
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 of the camera;
                Camera.SetPosition(0, 0, -10);
                #endregion

                #region Initialize Models
                // 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 bitmap object.
                Bitmap = new DBitmap();

                // Initialize the model object.
                if (!Bitmap.Initialize(D3D.Device, configuration.Width, configuration.Height, configuration.Width, configuration.Height))
                {
                    MessageBox.Show("Could not initialize the bitmap object", "Error", MessageBoxButtons.OK);
                    return(false);
                }
                #endregion

                #region Initialize Shader
                // Create the shader object.
                TextureShader = new DTextureShader();

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

                // Create the shader object.
                FadeShader = new DFadeShader();

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

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

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

                #region Initialize Variables
                // Set the fade in time to 3000 milliseconds
                FadeInTime = 5000;
                // Initialize the accumulated time to zero milliseconds.
                AccumulatedTime = 0;
                // Initialize the fade percentage to zero at first so the scene is black.
                FadePercentage = 0;
                // Set the fading in effect to not done.
                FadeDone = false;
                #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)
        {
            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)
        {
            try
            {
                #region Initialize System
                // Create the Direct3D object.
                D3D = new DDX11();

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

                // Create the shader manager object.
                ShaderManager = new DShaderManager();

                // Initialize the shader manager object.
                if (!ShaderManager.Initialize(D3D.Device, windowHandle))
                {
                    return(false);
                }
                #endregion

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

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

                #region Data variables.
                // 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.Direction = new Vector3(0.0f, 0.0f, 1.0f);
                Light.SetSpecularColor(1.0f, 1.0f, 1.0f, 1.0f);
                Light.SetSpecularPower(64.0f);
                #endregion

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

                // Initialize the cube model object.
                if (!CubeModel1.Initialize(D3D.Device, "cube.txt", "marble.bmp"))
                {
                    return(false);
                }

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

                // Initialize the cube model object.
                if (!CubeModel2.Initialize(D3D.Device, "cube.txt", "metal.bmp"))
                {
                    return(false);
                }

                // Create the third bump model object for models with normal maps and related vectors.
                CubeBumpMapModel3 = new DBumpMapModel();

                // Initialize the bump model object.
                if (!CubeBumpMapModel3.Initialize(D3D.Device, "cube.txt", "stone01.bmp", "normal.bmp"))
                {
                    return(false);
                }
                #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 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);
                }

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

                // Set the initial position of the camera and build the matrices needed for rendering.
                Camera.SetPosition(0.0f, 0.0f, -10.0f);
                Camera.Render();
                Camera.RenderBaseViewMatrix();  // This might be mis-implemented.  CHECK THIS !!!

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

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

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

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

                // Create the full screen ortho window object.
                FullScreenWindow = new DOrthoWindow();

                // Initialize the full screen ortho window object.
                if (!FullScreenWindow.Initialize(D3D.Device, configuration.Width, configuration.Height))
                {
                    return(false);
                }

                // Create the deferred buffers object.
                DeferredBuffers = new DDeferredBuffers();

                // Initialize the deferred buffers object.
                if (!DeferredBuffers.Initialize(D3D.Device, configuration.Width, configuration.Height))
                {
                    return(false);
                }

                // Create the deferred shader object.
                DeferredShader = new DDeferredShader();

                // Initialize the deferred shader object.
                if (!DeferredShader.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);
                }

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not initialize Direct3D\nError is '" + ex.Message + "'");
                return(false);
            }
        }
예제 #17
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 initial position of the camera.
                Camera.SetPosition(0.0f, 0.0f, -10.0f);
                Camera.RenderBaseViewMatrix();
                #endregion

                #region Initialize Models
                // Create the cube model object.
                CubeModel = new DModel();

                // Initialize the cube model object.
                if (!CubeModel.Initialize(D3D.Device, "cube.txt", "wall01.bmp"))
                {
                    return(false);
                }

                // Set the position for the cube model.
                CubeModel.SetPosition(-2.0f, 2.0f, 0.0f);

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

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

                // Set the position for the sphere model.
                SphereModel.SetPosition(2.0f, 2.0f, 0.0f);

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

                // Initialize the ground model object.
                if (!GroundModel.Initialize(D3D.Device, "plane01.txt", "metal001.bmp"))
                {
                    return(false);
                }

                // Set the position for the ground model.
                GroundModel.SetPosition(0.0f, 1.0f, 0.0f);
                #endregion

                #region Data variables.
                // 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.SetLookAt(0.0f, 0.0f, 0.0f);
                Light.GenerateProjectionMatrix();

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

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

                // Create the depth shader object.
                DepthShader = new DDepthShader();

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

                // Create the black and white render to texture object.
                BlackWhiteRenderTexture = new DRenderTexture();

                // Initialize the black and white render to texture object.
                if (!BlackWhiteRenderTexture.Initialize(D3D.Device, 1024, 1024, DSystemConfiguration.ScreenDepth, DSystemConfiguration.ScreenNear))
                {
                    return(false);
                }
                #endregion

                #region Initialize Shaders
                // Create the shadow shader object.
                ShadowShader = new DShadowShader();

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

                // Set the size to sample down to.
                int downSampleWidth  = 1024 / 2;
                int downSampleHeight = 1024 / 2;

                // Create the down sample render to texture object.
                DownSampleTexure = new DRenderTexture();

                // Initialize the down sample render to texture object.
                if (!DownSampleTexure.Initialize(D3D.Device, downSampleWidth, downSampleHeight, DSystemConfiguration.ScreenDepth, DSystemConfiguration.ScreenNear))
                {
                    return(false);
                }

                // Create the small ortho window object.
                SmallWindow = new DOrthoWindow();

                // Initialize the small ortho window object.
                if (!SmallWindow.Initialize(D3D.Device, downSampleWidth, downSampleHeight))
                {
                    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 horizontal blur render to texture object.
                HorizontalBlurTexture = new DRenderTexture();

                // Initialize the horizontal blur render to texture object.
                if (!HorizontalBlurTexture.Initialize(D3D.Device, downSampleWidth, downSampleHeight, DSystemConfiguration.ScreenDepth, 0.1f))
                {
                    return(false);
                }

                // Create the horizontal blur shader object.
                HorizontalBlurShader = new DHorizontalBlurShader();

                // Initialize the horizontal blur shader object.
                if (!HorizontalBlurShader.Initialize(D3D.Device, windowHandle))
                {
                    return(false);
                }

                // Create the vertical blur render to texture object.
                VerticalBlurTexture = new DRenderTexture();

                // Initialize the vertical blur render to texture object.
                if (!VerticalBlurTexture.Initialize(D3D.Device, downSampleWidth, downSampleHeight, DSystemConfiguration.ScreenDepth, 0.1f))
                {
                    return(false);
                }

                // Create the vertical blur shader object.
                VerticalBlurShader = new DVerticalBlurShader();

                // Initialize the vertical blur shader object.
                if (!VerticalBlurShader.Initialize(D3D.Device, windowHandle))
                {
                    return(false);
                }

                // Create the up sample render to texture object.
                UpSampleTexure = new DRenderTexture();

                // Initialize the up sample render to texture object.
                if (!UpSampleTexure.Initialize(D3D.Device, 1024, 1024, DSystemConfiguration.ScreenDepth, 0.1f))
                {
                    return(false);
                }

                // Create the full screen ortho window object.
                FullScreenWindow = new DOrthoWindow();

                // Initialize the full screen ortho window object.
                if (!FullScreenWindow.Initialize(D3D.Device, 1024, 1024))
                {
                    return(false);
                }

                // Create the soft shadow shader object.
                SoftShadowShader = new DSoftShadowShader();

                // Initialize the soft shadow shader object.
                if (!SoftShadowShader.Initialize(D3D.Device, windowHandle))
                {
                    return(false);
                }
                #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, string appTitle, int testTimeSeconds)
        {
            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);
                }

                // Create the timer object.
                Timer = new DTimer();

                // Initialize the timer object.
                if (!Timer.Initialize())
                {
                    return(false);
                }

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

                // Set the initial position.
                Position.SetPosition(0.0f, 7.0f, -11.0f);
                Position.SetRotation(20.0f, 0.0f, 0.0f);
                #endregion

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

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

                // Initialize the light object.
                Light.GenerateOrthoMatrix(15.0f, 15.0f, SHADOWMAP_DEPTH, SHADOWMAP_NEAR);
                #endregion

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

                // Initialize the ground model object.
                if (!GroundModel.Initialize(D3D.Device, "plane01.txt", "dirt.bmp", 2.0f))
                {
                    return(false);
                }

                // Set the position for the ground model.
                GroundModel.SetPosition(0.0f, 1.0f, 0.0f);

                // Create the tree object.
                TreeModel = new DTreeModel();

                // Initialize the shadow shader object.
                if (!TreeModel.Initialize(D3D.Device, "trunk001.txt", "trunk001.bmp", "leaf001.txt", "leaf001.bmp", 0.1f))
                {
                    return(false);
                }

                // Set the position for the tree model.
                TreeModel.SetPosition(0.0f, 1.0f, 0.0f);

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

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

                // Create the depth shader object.
                DepthShader = new DDepthShader();

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

                // Create the transparent depth shader object.
                TransparentDepthShader = new DTransparentDepthShader();

                // Initialize the transparent depth shader object.
                if (!TransparentDepthShader.Initialize(D3D.Device, windowHandle))
                {
                    return(false);
                }

                // Create the shadow shader object.
                ShadowShader = new DShadowShader();

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

                DPerfLogger.Initialize("WinForms C# SharpDX: " + configuration.Width + "x" + configuration.Height + " VSync:" + DSystemConfiguration.VerticalSyncEnabled + " FullScreen:" + DSystemConfiguration.FullScreen + "   " + appTitle, testTimeSeconds, configuration.Width, configuration.Height);

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not initialize Direct3D\nError is '" + ex.Message + "'");
                return(false);
            }
        }
예제 #19
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 of the camera;
                Camera.SetPosition(0, 0, -5.0f);
                #endregion

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

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

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

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

                #region Initialize Textures
                // Create the shader object.
                TextureShader = new DTextureShader();

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

                // Create the shader object.
                TransparentShader = new DTransparentShader();

                // Initialize the shader object.
                if (!TransparentShader.Initialize(D3D.Device, windowHandle))
                {
                    MessageBox.Show("Could not initialize the shader", "Error", MessageBoxButtons.OK);
                    return(false);
                }
                #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)
        {
            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 shader manager object.
                ShaderManager = new DShaderManager();

                // Initialize the shader manager object.
                if (!ShaderManager.Initilize(D3D, windowHandle))
                {
                    return(false);
                }

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

                // Set the initial position and rotation of the viewer.
                Position.SetPosition(0.0f, 1.5f, -4.0f);
                Position.SetRotation(15.0f, 0.0f, 0.0f);

                // 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, -10.0f);
                Camera.Render();
                Camera.RenderBaseViewMatrix();

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

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

                // Create the user interface object.
                UserInterface = new DUserInterface();

                // Initialize the user interface object.
                if (!UserInterface.Initialize(D3D, configuration))
                {
                    return(false);
                }

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

                // Initialize the ground model object.
                if (!GroundModel.Initialize(D3D.Device, "plane01.txt", "rock015.bmp"))
                {
                    return(false);
                }

                // Create the foliage object.
                Foliage = new DFoliage();

                // Initialize the foliage object.
                if (!Foliage.Initialize(D3D.Device, "grass01.bmp", 500))
                {
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not initialize Direct3D\nError is '" + ex.Message + "'");
                return(false);
            }
        }
예제 #21
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 of the camera.
                Camera.SetPosition(0.0f, 0.0f, -5.0f);
                #endregion

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

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

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

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

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

                // Initialize the render to texture object.
                RenderTexture.Initialize(D3D.Device, configuration);
                #endregion

                #region Initialize Shaders
                // Create the texture shader object.
                TextureShader = new DTextureShader();

                // Initialize the texture shader object.
                TextureShader.Initialize(D3D.Device, windowHandle);

                // Create the glass shader object.
                GlassShader = new DGlassShader();

                // Initialize the glass shader object.
                GlassShader.Initialize(D3D.Device, windowHandle);
                #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)
        {
            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 of the camera;
                Camera.SetPosition(0, 0, -10);
                #endregion

                #region Initialize Models
                // 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 model class.
                FloorModel = new DModel();

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

                #region Initialize Shaders
                // Create the shader object.
                TextureShader = new DTextureShader();

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

                // Create the Reflection shader object.
                ReflectionShader = new DReflectionShader();

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

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

                // Initialize the render to texture object.
                if (!RenderTexture.Initialize(D3D.Device, configuration))
                {
                    return(false);
                }
                #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)
        {
            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);
            }
        }
예제 #24
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);
            }
        }
예제 #25
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);
            }
        }
        // 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 initial position and rotation of the camera.
                Camera.SetPosition(0.0f, 7.0f, -10.0f);
                Camera.SetRotation(35.0f, 0.0f, 0.0f);
                #endregion

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

                // Initialize the ground model object.
                if (!GroundModel.Initialize(D3D.Device, "floor.txt", "stone.bmp"))
                {
                    return(false);
                }

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

                // Initialize the cube model object.
                if (!CubeModel.Initialize(D3D.Device, "cube.txt", "seafloor.bmp"))
                {
                    return(false);
                }
                #endregion

                #region Data variables.
                // 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.Position = new Vector3(2.0f, 5.0f, -2.0f);
                #endregion

                #region Initialize Shaders
                // Create the projection shader object.
                ProjectionShader = new DProjectionShader();

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

                // Create the projection texture object.
                ProjectionTexture = new DTexture();

                // Initialize the projection texture object.
                if (!ProjectionTexture.Initialize(D3D.Device, DSystemConfiguration.DataFilePath + "grate.bmp"))
                {
                    return(false);
                }

                // Create the view point object.
                ViewPoint = new DViewPoint();

                // Initialize the view point object.
                ViewPoint.SetPosition(2.0f, 5.0f, -2.0f);
                ViewPoint.SetLookAt(0.0f, 0.0f, 0.0f);
                ViewPoint.SetProjectionParameters((float)(Math.PI / 2.0f), 1.0f, 0.1f, 100.0f);
                ViewPoint.GenerateViewMatrix();
                ViewPoint.GenerateProjectionMatrix();
                #endregion

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

            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 initial position of the camera.
                Camera.SetPosition(0.0f, 0.0f, -10.0f);
                #endregion

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

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

                #region Initialize Shaders
                // Create the texture shader object.
                TextureShader = new DTextureShader();

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

                // Create the horizontal blur shader object.
                HorizontalBlurShader = new DHorizontalBlurShader();

                // Initialize the horizontal blur shader object.
                if (!HorizontalBlurShader.Initialize(D3D.Device, windowHandle))
                {
                    return(false);
                }

                // Create the vertical blur shader object.
                VerticalBlurShader = new DVerticalBlurShader();

                // Initialize the vertical blur shader object.
                if (!VerticalBlurShader.Initialize(D3D.Device, windowHandle))
                {
                    return(false);
                }

                // 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 down sample render to texture object.
                DownSampleTexure = new DRenderTexture();

                // Temporarily alter Texture widths for small Down Sampled RenderTextures.
                int fullSizeWidth    = configuration.Width;
                int fullScreenHeight = configuration.Height;
                configuration.Width  /= 2;
                configuration.Height /= 2;

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

                // Create the horizontal blur render to texture object.
                HorizontalBlurTexture = new DRenderTexture();

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

                // Create the vertical blur render to texture object.
                VerticalBlurTexture = new DRenderTexture();

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

                // Put back the setting for other RenderTexture objects to its fell screen resultion settings.
                configuration.Width  = fullSizeWidth;
                configuration.Height = fullScreenHeight;

                // Create the up sample render to texture object.
                UpSampleTexure = new DRenderTexture();

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

                // Create the small ortho window object.
                SmallWindow = new DOrthoWindow();

                // Initialize the small ortho window object at half the width and height of a full screen.
                if (!SmallWindow.Initialize(D3D.Device, configuration.Width / 2, configuration.Height / 2))
                {
                    return(false);
                }

                // Create the full screen ortho window object.
                FullScreenWindow = new DOrthoWindow();

                // Initialize the full screen ortho window object.
                if (!FullScreenWindow.Initialize(D3D.Device, configuration.Width, configuration.Height))
                {
                    return(false);
                }
                #endregion

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