public bool Initialize(DSystemConfiguration configuration, IntPtr windowHandle, Surface surface) { try { Input = new DInput(); Input.Initialize(configuration, windowHandle); D3D = new DDX11(); D3D.Initialize(configuration, windowHandle); Camera = new DCamera(); Camera.SetPosition(0.0f, 0.0f, -1.0f); Camera.Render(); Camera.SetPosition(50.0f, 2.0f, 10.0f); Terrain = new DSurface(); Terrain.Initialize(D3D.Device, surface); ColorShader = new DColorShader(); ColorShader.Initialize(D3D.Device, windowHandle); Position = new DPosition(); Position.SetPosition(Camera.GetPosition().X, Camera.GetPosition().Y, Camera.GetPosition().Z); // Ustawienie Position == Camera Camera.SetRotation(0.32f, -0.9f, 0); Position.RotationX = 0.32f; Position.RotationY = -90f; PositionChangeHandler = new DPositionChangeHandler(Position, Input); return(true); } catch (Exception ex) { throw ex; } }
// Methods. public bool Initialize(DSystemConfiguration configuration, IntPtr windowHandle) { try { #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); } }
// Methods. public bool Initialize(DSystemConfiguration configuration, IntPtr windowHandle) { try { // Create the input object. The input object will be used to handle reading the keyboard and mouse input from the user. Input = new DInput(); // Initialize the input object. if (!Input.Initialize(configuration, windowHandle)) { return(false); } // #region Initialize System // Create the Direct3D object. D3D = new DDX11(); // Initialize the Direct3D object. if (!D3D.Initialize(configuration, windowHandle)) { return(false); } // Create the camera object Camera = new DCamera(); // Initialize a base view matrix with the camera for 2D user interface rendering. Camera.SetPosition(0.0f, 0.0f, -10.0f); Camera.RenderBaseViewMatrix(); Matrix baseViewMatrix = Camera.BaseViewMatrix; // Set the initial position of the camera. (Since the ViewMatrix is already created from a base position.) 250.0f Camera.SetPosition(100.0f, 2.0f, 250.0f); Camera.SetRotation(0, 180.0f, 0); // Create the model object. TerrainModel = new DTerrainHeightMap(); // Initialize the terrain object. if (!TerrainModel.Initialize(D3D.Device, "heightmap01.bmp", "dirt02.bmp", "bump.bmp")) { return(false); } // Create the position object. Position = new DPosition(); // Set the initial position of the viewer to the same as the initial camera position. Position.SetPosition(Camera.GetPosition().X, Camera.GetPosition().Y, Camera.GetPosition().Z); Position.SetRotation(Camera.GetRotation().X, Camera.GetRotation().Y, Camera.GetRotation().Z); // Create the fps object. FPS = new DFPS(); // Initialize the fps object. FPS.Initialize(); // Create the cpu object. CPU = new DCPU(); // Initialize the cpu object. CPU.Initialize(); // Create the text object. Text = new DText(); // Initialize the text object. if (!Text.Initialize(D3D.Device, D3D.DeviceContext, windowHandle, configuration.Width, configuration.Height, baseViewMatrix)) { return(false); } // Set the video card information in the text object. if (!Text.SetVideoCard(D3D.VideoCardDescription, D3D.VideoCardMemory, D3D.DeviceContext)) { return(false); } // Create the color shader object. TerrainBumpMapShader = new DBumpMapShader(); // Initialize the color shader object. if (!TerrainBumpMapShader.Initialize(D3D.Device, windowHandle)) { return(false); } // 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.75f, -0.5f, 0.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 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); } }