Exemple #1
0
        public bool Initialze(DDX11 D3D, IntPtr windowHandle, DSystemConfiguration configuration)
        {
            // Create the user interface object.
            UserInterface = new DUserInterface();
            // Initialize the user interface object.
            if (!UserInterface.Initialize(D3D, configuration))
            {
                return(false);
            }

            // Create the camera object
            Camera = new DCamera();
            // Initialize a base view matrix with the camera for 2D user interface rendering.
            Camera.SetPosition(0.0f, 0.0f, -10.0f);
            Camera.Render();
            Camera.RenderBaseViewMatrix();

            // Create the position object.
            Position = new DPosition();
            // Set the initial position and rotation of the viewer.28.0f, 5.0f, -10.0f
            Position.SetPosition(512.0f, 100.0f, 1084.0f);
            Position.SetRotation(0.0f, 180.0f, 0.0f);

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

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

            // Create and initialize the frustum object.
            Frustum = new DFrustum();
            Frustum.Initialize(DSystemConfiguration.ScreenDepth);

            // Create the sky dome object.
            SkyDomeModel = new DSkyDome();

            // Initialize the sky dome object.
            if (!SkyDomeModel.Initialize(D3D.Device, "skydome.txt"))
            {
                return(false);
            }

            // Initialize the terrain object.
            Terrain = new DTerrain();
            // Initialize the ground model object.
            if (!Terrain.Initialize(D3D.Device, "setupS2TutTerr08.txt"))
            {
                return(false);
            }

            // Set the UI to display by default.
            DisplayUI = true;
            // Set wire frame rendering initially to enabled.
            WireFrame = false;
            // Set the rendering of cell lines initially to enabled.
            CellLines = false;
            // Set the user locked to the terrain height for movement.
            HeightLocked = true;

            return(true);
        }
Exemple #2
0
        public bool Render(DDX11 direct3D, DShaderManager shaderManager, DTextureManager textureManager)
        {
            // Generate the view matrix based on the camera's position.
            Camera.Render();

            // Get the world, view, and projection matrices from the camera and d3d objects.
            Matrix worldMatrix      = direct3D.WorldMatrix;
            Matrix viewCameraMatrix = Camera.ViewMatrix;
            Matrix projectionMatrix = direct3D.ProjectionMatrix;
            Matrix baseViewMatrix   = Camera.BaseViewMatrix;
            Matrix orthoMatrix      = direct3D.OrthoMatrix;

            // Construct the frustum.
            Frustum.ConstructFrustum(projectionMatrix, viewCameraMatrix);

            // Clear the buffers to begin the scene.
            direct3D.BeginScene(0.0f, 0.0f, 0.0f, 1.0f);

            // Turn off back face culling and turn off the Z buffer.
            direct3D.TurnOffCulling();
            direct3D.TurnZBufferOff();

            // Translate the sky dome to be centered around the camera position.
            Matrix.Translation(Camera.GetPosition().X, Camera.GetPosition().Y, Camera.GetPosition().Z, out worldMatrix);

            // Render the sky dome using the sky dome shader.
            SkyDomeModel.Render(direct3D.DeviceContext);
            if (!shaderManager.RenderSkyDomeShader(direct3D.DeviceContext, SkyDomeModel.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, SkyDomeModel.m_apexColor, SkyDomeModel.m_centerColor))
            {
                return(false);
            }

            // Reset the world matrix.
            worldMatrix = direct3D.WorldMatrix;

            // Turn the Z buffer back and back face culling on.
            direct3D.TurnZBufferOn();
            direct3D.TurnOnCulling();

            // Turn on wire frame rendering of the terrain if needed.
            if (WireFrame)
            {
                direct3D.EnableWireFrame();
            }

            // Render the terrain cells (and cell lines if needed).
            for (int i = 0; i < Terrain.m_CellCount; i++)
            {
                // Render each terrain cell if it is visible only.
                if (Terrain.RenderCell(direct3D.DeviceContext, i, Frustum))
                {
                    // Render the cell buffers using the terrain shader.
                    if (!shaderManager.RenderTerrainShader(direct3D.DeviceContext, Terrain.GetCellIndexCount(i), worldMatrix, viewCameraMatrix, projectionMatrix, textureManager.TextureArray[0].TextureResource, textureManager.TextureArray[1].TextureResource, textureManager.TextureArray[2].TextureResource, textureManager.TextureArray[3].TextureResource, Light.Direction, Light.DiffuseColour))
                    {
                        return(false);
                    }

                    // If needed then render the bounding box around this terrain cell using the color shader.
                    if (CellLines)
                    {
                        Terrain.RenderCellLines(direct3D.DeviceContext, i);
                        if (!shaderManager.RenderColorShader(direct3D.DeviceContext, Terrain.GetCellLinesIndexCount(i), worldMatrix, viewCameraMatrix, projectionMatrix))
                        {
                            return(false);
                        }
                    }
                }
            }

            // Turn off wire frame rendering of the terrain if it was on.
            if (WireFrame)
            {
                direct3D.DisableWireFrame();
            }

            // Update the render counts in the UI.
            if (!UserInterface.UpdateRenderCountStrings(Terrain.m_renderCount, Terrain.m_cellsDrawn, Terrain.m_cellsCulled, direct3D.DeviceContext))
            {
                return(false);
            }

            // Render the user interface.
            if (DisplayUI)
            {
                if (!UserInterface.Render(direct3D, shaderManager, worldMatrix, baseViewMatrix, orthoMatrix))
                {
                    return(false);
                }
            }

            // Present the rendered scene to the screen.
            direct3D.EndScene();

            return(true);
        }