Ejemplo n.º 1
0
        public bool Initialize(SystemConfiguration configuration, IntPtr windowHandle)
        {
            if (Input == null)
            {
                Input = new InputClass();
                if (!Input.Initialize(configuration, windowHandle))
                {
                    MessageBox.Show("Could not initialize input object", "Error", MessageBoxButtons.OK);
                    return false;
                }
            }

            // Create the Direct3D object.
            D3D = new DX11();
            // Initialize the Direct3D object.
            if (!D3D.Initialize(configuration, windowHandle))
            {
                MessageBox.Show("Could not initialize Direct3D", "Error", MessageBoxButtons.OK);
                return false;
            }

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

            // Initialize a base view matrix the camera for 2D user interface rendering.
            Camera.SetPosition(0, 0, -1);
            Camera.Render();
            var baseViewMatrix = Camera.ViewMatrix;

            // Set the initial position of the camera.
            var cameraX = 50f;
            var cameraY = 2f;
            var cameraZ = -7f;

            Camera.SetPosition(cameraX, cameraY, cameraZ);

            // Create the terrain object.
            Terrain = new Terrain();

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

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

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

            // Create and initialize Timer.
            Timer = new Timer();
            if (!Timer.Initialize())
            {
                MessageBox.Show("Could not initialize Timer object", "Error", MessageBoxButtons.OK);
                return false;
            }

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

            // Set the initial position of the viewer to the same as the initial camera position.
            Position.SetPosition(new Vector3(cameraX, cameraY, cameraZ));

            // Create and initialize the FPS object.
            FPS = new FPS();
            FPS.Initialize();

            // Create and initialize the CPU.
            CPU = new CPU();
            CPU.Initialize();

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

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

            // Create the text object.
            Text = new Text();
            if (!Text.Initialize(D3D.Device, D3D.DeviceContext, windowHandle, configuration.Width, configuration.Height, baseViewMatrix))
            {
                MessageBox.Show("Could not initialize the text object", "Error", MessageBoxButtons.OK);
                return false;
            }

            if (!Text.SetVideoCard(D3D.VideoCardDescription, D3D.VideoCardMemory, D3D.DeviceContext))
            {
                MessageBox.Show("Could not set video card into the text object", "Error", MessageBoxButtons.OK);
                return false;
            }

            return true;
        }
Ejemplo n.º 2
0
        protected virtual void FillArrays(out ColorShader.Vertex[] vertices, out int[] indices)
        {
            // Create the vertex array.
            vertices = new ColorShader.Vertex[VertexCount];
            // Create the index array.
            indices = new int[IndexCount];
            var index = 0;

            for (var j = 0; j < TerrainHeight - 1; j++)
            {
                for (var i = 0; i < TerrainWidth - 1; i++)
                {
                    // LINE 1
                    // Upper left
                    vertices[index] = new ColorShader.Vertex()
                    {
                        position = new Vector3(i, 0, j + 1),
                        color = new Vector4(1, 1, 1, 1)
                    };
                    indices[index] = index++;

                    // Upper right
                    vertices[index] = new ColorShader.Vertex()
                    {
                        position = new Vector3(i + 1, 0, j + 1),
                        color = new Vector4(1, 1, 1, 1)
                    };
                    indices[index] = index++;

                    // LINE 2
                    // Upper right
                    vertices[index] = new ColorShader.Vertex()
                    {
                        position = new Vector3(i + 1, 0, j + 1),
                        color = new Vector4(1, 1, 1, 1)
                    };
                    indices[index] = index++;

                    // Bottom right
                    vertices[index] = new ColorShader.Vertex()
                    {
                        position = new Vector3(i + 1, 0, j),
                        color = new Vector4(1, 1, 1, 1)
                    };
                    indices[index] = index++;

                    // LINE 3
                    // Bottom right
                    vertices[index] = new ColorShader.Vertex()
                    {
                        position = new Vector3(i + 1, 0, j),
                        color = new Vector4(1, 1, 1, 1)
                    };
                    indices[index] = index++;

                    // Bottom left
                    vertices[index] = new ColorShader.Vertex()
                    {
                        position = new Vector3(i, 0, j),
                        color = new Vector4(1, 1, 1, 1)
                    };
                    indices[index] = index++;

                    // LINE 4
                    // Bottom left
                    vertices[index] = new ColorShader.Vertex()
                    {
                        position = new Vector3(i, 0, j),
                        color = new Vector4(1, 1, 1, 1)
                    };
                    indices[index] = index++;

                    // Upper left
                    vertices[index] = new ColorShader.Vertex()
                    {
                        position = new Vector3(i, 0, j + 1),
                        color = new Vector4(1, 1, 1, 1)
                    };
                    indices[index] = index++;
                }
            }
        }
Ejemplo n.º 3
0
        protected override void FillArrays(out ColorShader.Vertex[] vertices, out int[] indices)
        {
            // Create the vertex array.
            vertices = new ColorShader.Vertex[VertexCount];
            // Create the index array.
            indices = new int[IndexCount];
            var index = 0;

            for (var j = 0; j < TerrainHeight - 1; j++)
            {
                for (var i = 0; i < TerrainWidth - 1; i++)
                {
                    var indexBottomLeft = TerrainHeight * j + i;
                    var indexBottomRight = TerrainHeight * j + (i + 1);
                    var indexUpperLeft = TerrainHeight * (j + 1) + i;
                    var indexUpperRight = TerrainHeight * (j + 1) + (i + 1);

                    #region First Triangle
                    // Upper left
                    vertices[index] = new ColorShader.Vertex()
                    {
                        position = HeightMap[indexUpperLeft],
                        color = Vector4.One
                    };
                    indices[index] = index++;

                    // Upper right
                    vertices[index] = new ColorShader.Vertex()
                    {
                        position = HeightMap[indexUpperRight],
                        color = Vector4.One
                    };
                    indices[index] = index++;

                    // Upper right
                    vertices[index] = new ColorShader.Vertex()
                    {
                        position = HeightMap[indexUpperRight],
                        color = Vector4.One
                    };
                    indices[index] = index++;

                    // Bottom Left
                    vertices[index] = new ColorShader.Vertex()
                    {
                        position = HeightMap[indexBottomLeft],
                        color = Vector4.One
                    };
                    indices[index] = index++;

                    // Bottom Left
                    vertices[index] = new ColorShader.Vertex()
                    {
                        position = HeightMap[indexBottomLeft],
                        color = Vector4.One
                    };
                    indices[index] = index++;

                    // Upper left
                    vertices[index] = new ColorShader.Vertex()
                    {
                        position = HeightMap[indexUpperLeft],
                        color = Vector4.One
                    };
                    indices[index] = index++;
                    #endregion

                    #region Second Triangle
                    // Bottom Left
                    vertices[index] = new ColorShader.Vertex()
                    {
                        position = HeightMap[indexBottomLeft],
                        color = Vector4.One
                    };
                    indices[index] = index++;

                    // Upper right
                    vertices[index] = new ColorShader.Vertex()
                    {
                        position = HeightMap[indexUpperRight],
                        color = Vector4.One
                    };
                    indices[index] = index++;

                    // Upper right
                    vertices[index] = new ColorShader.Vertex()
                    {
                        position = HeightMap[indexUpperRight],
                        color = Vector4.One
                    };
                    indices[index] = index++;

                    // Bottom right
                    vertices[index] = new ColorShader.Vertex()
                    {
                        position = HeightMap[indexBottomRight],
                        color = Vector4.One
                    };
                    indices[index] = index++;

                    // Bottom right
                    vertices[index] = new ColorShader.Vertex()
                    {
                        position = HeightMap[indexBottomRight],
                        color = Vector4.One
                    };
                    indices[index] = index++;

                    // Bottom Left
                    vertices[index] = new ColorShader.Vertex()
                    {
                        position = HeightMap[indexBottomLeft],
                        color = Vector4.One
                    };
                    indices[index] = index++;
                    #endregion
                }
            }
        }