public override void init() { Device d3dDevice = GuiController.Instance.D3dDevice; GuiController.Instance.CustomRenderEnabled = true; MyMediaDir = GuiController.Instance.ExamplesDir + "Shaders\\WorkshopShaders\\Media\\"; MyShaderDir = GuiController.Instance.ExamplesDir + "Shaders\\WorkshopShaders\\Shaders\\"; circuito = new F1Circuit(); //Cargar terreno: cargar heightmap y textura de color terrain = new TgcSimpleTerrain(); terrain.loadHeightmap(GuiController.Instance.ExamplesMediaDir + "Heighmaps\\" + "TerrainTexture2.jpg", 20, 0.1f, new Vector3(0, -125, 0)); terrain.loadTexture( GuiController.Instance.ExamplesMediaDir + "Heighmaps\\" + "TerrainTexture2.jpg"); //Crear SkyBox skyBox = new TgcSkyBox(); skyBox.Center = new Vector3(0, 500, 0); skyBox.Size = new Vector3(10000, 10000, 10000); string texturesPath = GuiController.Instance.ExamplesMediaDir + "Texturas\\Quake\\SkyBox LostAtSeaDay\\"; skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Up, texturesPath + "lostatseaday_up.jpg"); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Down, texturesPath + "lostatseaday_dn.jpg"); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Left, texturesPath + "lostatseaday_lf.jpg"); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Right, texturesPath + "lostatseaday_rt.jpg"); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Front, texturesPath + "lostatseaday_bk.jpg"); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Back, texturesPath + "lostatseaday_ft.jpg"); skyBox.updateValues(); TgcSceneLoader loader = new TgcSceneLoader(); TgcScene scene = loader.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir + "MeshCreator\\Meshes\\Vehiculos\\Auto\\Auto-TgcScene.xml"); car = scene.Meshes[0]; car.AutoTransformEnable = false; //Cargar Shader personalizado string compilationErrors; effect = Effect.FromFile(GuiController.Instance.D3dDevice,MyShaderDir + "OutRun.fx", null, null, ShaderFlags.PreferFlowControl, null, out compilationErrors); if (effect == null) { throw new Exception("Error al cargar shader. Errores: " + compilationErrors); } //Configurar Technique dentro del shader effect.Technique = "DefaultTechnique"; //Configurar FPS Camara GuiController.Instance.FpsCamera.Enable = true; GuiController.Instance.FpsCamera.MovementSpeed = 250f; GuiController.Instance.FpsCamera.JumpSpeed = 50f; //GuiController.Instance.FpsCamera.setCamera(new Vector3(315.451f, 40, -464.28490f), new Vector3(316.1626f, 40, -463.6029f)); reset_pos(); // para capturar el mouse Control focusWindows = GuiController.Instance.D3dDevice.CreationParameters.FocusWindow; mouseCenter = focusWindows.PointToScreen(new Point(focusWindows.Width / 2,focusWindows.Height / 2)); mouseCaptured = true; Cursor.Hide(); // stencil g_pDepthStencil = d3dDevice.CreateDepthStencilSurface(d3dDevice.PresentationParameters.BackBufferWidth, d3dDevice.PresentationParameters.BackBufferHeight, DepthFormat.D24S8, MultiSampleType.None, 0, true); // inicializo el render target g_pRenderTarget = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default); g_pRenderTarget2 = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default); g_pRenderTarget3 = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default); g_pRenderTarget4 = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default); g_pRenderTarget5 = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default); // Resolucion de pantalla effect.SetValue("screen_dx", d3dDevice.PresentationParameters.BackBufferWidth); effect.SetValue("screen_dy", d3dDevice.PresentationParameters.BackBufferHeight); CustomVertex.PositionTextured[] vertices = new CustomVertex.PositionTextured[] { new CustomVertex.PositionTextured( -1, 1, 1, 0,0), new CustomVertex.PositionTextured(1, 1, 1, 1,0), new CustomVertex.PositionTextured(-1, -1, 1, 0,1), new CustomVertex.PositionTextured(1,-1, 1, 1,1) }; //vertex buffer de los triangulos g_pVBV3D = new VertexBuffer(typeof(CustomVertex.PositionTextured), 4, d3dDevice, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default); g_pVBV3D.SetData(vertices, 0, LockFlags.None); }
public override void init() { Device d3dDevice = GuiController.Instance.D3dDevice; GuiController.Instance.CustomRenderEnabled = true; MyMediaDir = GuiController.Instance.ExamplesDir + "Shaders\\WorkshopShaders\\Media\\"; MyShaderDir = GuiController.Instance.ExamplesDir + "Shaders\\WorkshopShaders\\Shaders\\"; circuito = new F1Circuit(); //Cargar terreno: cargar heightmap y textura de color terrain = new TgcSimpleTerrain(); terrain.loadHeightmap(GuiController.Instance.ExamplesMediaDir + "Heighmaps\\" + "TerrainTexture2.jpg", 20, 0.1f, new Vector3(0, -125, 0)); terrain.loadTexture(GuiController.Instance.ExamplesMediaDir + "Heighmaps\\" + "TerrainTexture2.jpg"); //Crear SkyBox skyBox = new TgcSkyBox(); skyBox.Center = new Vector3(0, 500, 0); skyBox.Size = new Vector3(10000, 10000, 10000); string texturesPath = GuiController.Instance.ExamplesMediaDir + "Texturas\\Quake\\SkyBox LostAtSeaDay\\"; skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Up, texturesPath + "lostatseaday_up.jpg"); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Down, texturesPath + "lostatseaday_dn.jpg"); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Left, texturesPath + "lostatseaday_lf.jpg"); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Right, texturesPath + "lostatseaday_rt.jpg"); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Front, texturesPath + "lostatseaday_bk.jpg"); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Back, texturesPath + "lostatseaday_ft.jpg"); skyBox.updateValues(); TgcSceneLoader loader = new TgcSceneLoader(); TgcScene scene = loader.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir + "MeshCreator\\Meshes\\Vehiculos\\Auto\\Auto-TgcScene.xml"); car = scene.Meshes[0]; car.AutoTransformEnable = false; //Cargar Shader personalizado string compilationErrors; effect = Effect.FromFile(GuiController.Instance.D3dDevice, MyShaderDir + "OutRun.fx", null, null, ShaderFlags.PreferFlowControl, null, out compilationErrors); if (effect == null) { throw new Exception("Error al cargar shader. Errores: " + compilationErrors); } //Configurar Technique dentro del shader effect.Technique = "DefaultTechnique"; //Configurar FPS Camara GuiController.Instance.FpsCamera.Enable = true; GuiController.Instance.FpsCamera.MovementSpeed = 250f; GuiController.Instance.FpsCamera.JumpSpeed = 50f; //GuiController.Instance.FpsCamera.setCamera(new Vector3(315.451f, 40, -464.28490f), new Vector3(316.1626f, 40, -463.6029f)); reset_pos(); // para capturar el mouse Control focusWindows = GuiController.Instance.D3dDevice.CreationParameters.FocusWindow; mouseCenter = focusWindows.PointToScreen(new Point(focusWindows.Width / 2, focusWindows.Height / 2)); mouseCaptured = true; Cursor.Hide(); // stencil g_pDepthStencil = d3dDevice.CreateDepthStencilSurface(d3dDevice.PresentationParameters.BackBufferWidth, d3dDevice.PresentationParameters.BackBufferHeight, DepthFormat.D24S8, MultiSampleType.None, 0, true); // inicializo el render target g_pRenderTarget = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default); g_pRenderTarget2 = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default); g_pRenderTarget3 = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default); g_pRenderTarget4 = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default); g_pRenderTarget5 = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default); // Resolucion de pantalla effect.SetValue("screen_dx", d3dDevice.PresentationParameters.BackBufferWidth); effect.SetValue("screen_dy", d3dDevice.PresentationParameters.BackBufferHeight); CustomVertex.PositionTextured[] vertices = new CustomVertex.PositionTextured[] { new CustomVertex.PositionTextured(-1, 1, 1, 0, 0), new CustomVertex.PositionTextured(1, 1, 1, 1, 0), new CustomVertex.PositionTextured(-1, -1, 1, 0, 1), new CustomVertex.PositionTextured(1, -1, 1, 1, 1) }; //vertex buffer de los triangulos g_pVBV3D = new VertexBuffer(typeof(CustomVertex.PositionTextured), 4, d3dDevice, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default); g_pVBV3D.SetData(vertices, 0, LockFlags.None); }