public override void init() { Device d3dDevice = GuiController.Instance.D3dDevice; //Path de Heightmap default del terreno y Modifier para cambiarla currentHeightmap = GuiController.Instance.ExamplesMediaDir + "Heighmaps\\" + "Heightmap2.jpg"; GuiController.Instance.Modifiers.addTexture("heightmap", currentHeightmap); //Modifiers para variar escala del mapa currentScaleXZ = 20f; GuiController.Instance.Modifiers.addFloat("scaleXZ", 0.1f, 100f, currentScaleXZ); currentScaleY = 1.3f; GuiController.Instance.Modifiers.addFloat("scaleY", 0.1f, 10f, currentScaleY); //Path de Textura default del terreno y Modifier para cambiarla currentTexture = GuiController.Instance.ExamplesMediaDir + "Heighmaps\\" + "TerrainTexture2.jpg"; GuiController.Instance.Modifiers.addTexture("texture", currentTexture); //Cargar terreno: cargar heightmap y textura de color terrain = new TgcSimpleTerrain(); terrain.loadHeightmap(currentHeightmap, currentScaleXZ, currentScaleY, new Vector3(0, 0, 0)); terrain.loadTexture(currentTexture); //Configurar FPS Camara GuiController.Instance.FpsCamera.Enable = true; GuiController.Instance.FpsCamera.MovementSpeed = 100f; GuiController.Instance.FpsCamera.JumpSpeed = 100f; GuiController.Instance.FpsCamera.setCamera(new Vector3(-722.6171f, 495.0046f, -31.2611f), new Vector3(164.9481f, 35.3185f, -61.5394f)); }
/// <summary> /// Crear Terrain /// </summary> private void terrainCreate_Click(object sender, EventArgs e) { if (heighmapFilePath == null || terrainTextureFilePath == null) { MessageBox.Show("No se especificó un Heightmap y una Textura para el terreno", "Creación de Terreno"); return; } try { //quitar terreno, si hay terrainRemove_Click(sender, e); //Crear nuevo tgcTerrain = new TgcSimpleTerrain(); tgcTerrain.loadHeightmap(heighmapFilePath, (float)terrainXZscale.Value, (float)terrainYscale.Value, getTerrainCenter()); tgcTerrain.loadTexture(terrainTextureFilePath); } catch (Exception ex) { MessageBox.Show("Hubo un error al crea un terreno desde el Heightmap " + heighmap.Text, "Error al cargar Heightmap", MessageBoxButtons.OK, MessageBoxIcon.Error); Debug.Write("Error al cargar Heightmap " + ex.Message); } }
public override void Init() { var d3dDevice = D3DDevice.Instance.Device; #region configurarEfecto Texture alphaMap = TextureLoader.FromFile(d3dDevice, GameModel.mediaDir + "texturas\\terrain\\Heightmap3_1.jpg"); efecto = TgcShaders.loadEffect(GameModel.shadersDir + "shaderTierra.fx"); efecto.SetValue("alphaMap", alphaMap); Texture mainText = TextureLoader.FromFile(d3dDevice, GameModel.mediaDir + "texturas\\terrain\\terreno.jpg"); efecto.SetValue("mainText", mainText); #endregion #region configurarObjeto terrain.loadTexture(GameModel.mediaDir + "texturas\\terrain\\TerrainTexture1.jpg"); terrain.loadHeightmap(GameModel.mediaDir + "texturas\\terrain\\Heightmap3.jpg", 255f, 1.6f, new TGCVector3(0, -100, 0)); terrain.Effect = efecto; terrain.Technique = "RenderScene"; tecnica = "RenderScene"; objetos.Add(terrain); #endregion PostProcess.agregarPostProcessObject(this); }
public void crearHeightmaps() { currentHeightmap2 = GuiController.Instance.AlumnoEjemplosMediaDir + "RenderGroup\\texturas\\piedra2.jpg"; currentTexture2 = GuiController.Instance.AlumnoEjemplosMediaDir + "RenderGroup\\texturas\\piedras.JPG"; terrain2 = new TgcSimpleTerrain(); terrain2.loadHeightmap(currentHeightmap2, 165f, 5.3f, new Vector3(0, -30, 0)); terrain2.loadTexture(currentTexture2); }
public override void Init() { time = 0; playerModel.Init(); collectModel.Init(); collectModel.Player = playerModel; historyModel.Init(); youWinModel.Init(); //Skybox LoadSkyBox(); //LoadSkyBoxUndersea(); //Heightmap currentHeightmap = MediaDir + "\\Level1\\Heigthmap\\" + "hm_level1.jpg"; var currentTexture = MediaDir + "\\Level1\\Textures\\" + "level1.PNG"; currentScaleXZ = 150f; currentScaleY = 2f; underseaTerrain = new TgcSimpleTerrain(); underseaTerrain.loadHeightmap(currentHeightmap, currentScaleXZ, currentScaleY, new TGCVector3(0, 0, 0)); underseaTerrain.loadTexture(currentTexture); underseaTerrain.AlphaBlendEnable = true; bulletManager = new BulletSharpManager(initialPosition, Input, Camera, playerModel); bulletManager.Init(underseaTerrain); //Surface LoadSurface(); //Meshes LoadMeshes(); //Collectables LoadCollectableMeshes(); //HUD hudModel.Init(); //Shaders LoadShaders(); fogEffect = TGCShaders.Instance.LoadEffect(ShadersDir + "TgcFogShader.fx"); //OnlyForDebug(); music = new TgcMp3Player(); music.FileName = MediaDir + "\\Sounds\\rain.mp3"; music.play(true); }
public void InstanciarHeightmap() //va en el init() { currentScaleXZ = 600f; currentScaleY = 100f; currentHeightmap = MediaDir + "Heighmaps\\alfajorGrandote.jpg"; currentTexture = MediaDir + "Heighmaps\\Grass.jpg"; heightmap.loadHeightmap(currentHeightmap, currentScaleXZ, currentScaleY, new TGCVector3(0, -4, 0)); heightmap.loadTexture(currentTexture); }
public static void Cargar() { // Cargar terreno y textura terrain = new TgcSimpleTerrain(); string heightmap = GuiController.Instance.ExamplesMediaDir + "Heighmaps\\" + "HeightmapHawaii.jpg"; string textura = Utiles.TexturasDir("IslaTextura.png"); Vector3 PosicionIsla = new Vector3(0, 0, 0); PosicionIsla.Y = -Oceano.AplicarCPUShader(PosicionIsla).Y - 100; terrain.AlphaBlendEnable = false; terrain.loadHeightmap(heightmap, 100, 5f, PosicionIsla); terrain.loadTexture(textura); }
public override void Init() { terrain = new TgcSimpleTerrain(); var position = TGCVector3.Empty; terrain.loadHeightmap(MediaDir + "Heighmaps\\" + "TerrainTexture2.jpg", 20, 0.5f, position); terrain.loadTexture(MediaDir + "Heighmaps\\" + "grass.jpg"); physicsExample = new TriangleSpherePhysics(); physicsExample.SetTriangleDataVB(terrain.getData()); physicsExample.Init(MediaDir); Camara = new TgcRotationalCamera(new TGCVector3(0, 20, 0), 1000, Input); }
private void crearNivel2() { //El segundo nivel quedó a medio hacer, la idea era tener un nivel por personaje TgcBox piso; TgcSimpleTerrain terrain; string currentHeightmap; string currentTexture; float currentScaleXZ; float currentScaleY; //Path de Heightmap default del terreno y Modifier para cambiarla currentHeightmap = GuiController.Instance.ExamplesMediaDir + "Heighmaps\\" + "Heightmap2.jpg"; //Modifiers para variar escala del mapa currentScaleXZ = 20f; currentScaleY = 1.3f; //Path de Textura default del terreno y Modifier para cambiarla currentTexture = GuiController.Instance.ExamplesMediaDir + "Heighmaps\\" + "TerrainTexture2.jpg"; //Cargar terreno: cargar heightmap y textura de color terrain = new TgcSimpleTerrain(); terrain.loadHeightmap(currentHeightmap, currentScaleXZ, currentScaleY, new Vector3(50, -120, 50)); terrain.loadTexture(currentTexture); TgcTexture textura = TgcTexture.createTexture(GuiController.Instance.D3dDevice, GuiController.Instance.AlumnoEjemplosMediaDir + "LosBorbotones\\escenario\\pista3.jpg"); piso = TgcBox.fromSize(new Vector3(0, 0, 0), new Vector3(15000, 0, 5000), textura); //es un cubo plano con una textura (foto de la pista) cielo = new TgcSkyBox(); cielo.Center = new Vector3(0, 500, 0); cielo.Size = new Vector3(20000, 5000, 20000); string texturesPath = GuiController.Instance.ExamplesMediaDir + "Texturas\\Quake\\SkyBox LostAtSeaDay\\"; cielo.setFaceTexture(TgcSkyBox.SkyFaces.Up, texturesPath + "lostatseaday_up.jpg"); cielo.setFaceTexture(TgcSkyBox.SkyFaces.Down, texturesPath + "lostatseaday_dn.jpg"); cielo.setFaceTexture(TgcSkyBox.SkyFaces.Left, texturesPath + "lostatseaday_lf.jpg"); cielo.setFaceTexture(TgcSkyBox.SkyFaces.Right, texturesPath + "lostatseaday_rt.jpg"); cielo.setFaceTexture(TgcSkyBox.SkyFaces.Front, texturesPath + "lostatseaday_bk.jpg"); cielo.setFaceTexture(TgcSkyBox.SkyFaces.Back, texturesPath + "lostatseaday_ft.jpg"); cielo.updateValues(); cajas.Add(piso); terrenos.Add(terrain); }
private void LoadSurface() { var surfaceTexture = TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + "\\Level1\\Textures\\" + "surface.PNG"); //surfacePlane = new TgcPlane(surfacePosition, new TGCVector3(12800, 0f, 12800), TgcPlane.Orientations.XZplane, surfaceTexture); surfacePlane = new TgcSimpleTerrain(); surfacePlane.loadHeightmap(MediaDir + "Level1\\Heigthmap\\heighmapmar2.jpg", 1000, 1, new TGCVector3(0, 3850, 0)); surfacePlane.loadTexture(MediaDir + "\\Level1\\Textures\\" + "surface.PNG"); surfacePlane.AlphaBlendEnable = true; wavesEffect = TGCShaders.Instance.LoadEffect(ShadersDir + "\\Waves2.fx"); wavesEffect.Technique = "WavesScene"; surfacePlane.Effect = wavesEffect; surfacePlane.Technique = "WavesScene"; }
public void InitTerrain() { string heightmapPath = $"{MediaDir}\\Heightmaps\\canyon1.jpg"; string texturePath = $"{MediaDir}\\Textures\\canyon-horizontal.png"; var center = TGCVector3.Empty; float scaleXZ = 40f; float scaleY = 1.3f; Terrain = new TgcSimpleTerrain(); Terrain.loadHeightmap(heightmapPath, scaleXZ, scaleY, center); Terrain.loadTexture(texturePath); heightmapPath = $"{MediaDir}\\Heightmaps\\water.jpg"; texturePath = $"{MediaDir}\\Textures\\water-surface.png"; scaleY = 3f; Water = new TgcSimpleTerrain(); Water.loadHeightmap(heightmapPath, scaleXZ, scaleY, center); Water.loadTexture(texturePath); }
public override void Render() { PreRender(); //Ver si cambio el heightmap var selectedHeightmap = (string)Modifiers["heightmap"]; if (currentHeightmap != selectedHeightmap) { //Volver a cargar el Heightmap currentHeightmap = selectedHeightmap; terrain.loadHeightmap(currentHeightmap, currentScaleXZ, currentScaleY, new Vector3(0, 0, 0)); } //Ver si cambio alguno de los valores de escala var selectedScaleXZ = (float)Modifiers["scaleXZ"]; var selectedScaleY = (float)Modifiers["scaleY"]; if (currentScaleXZ != selectedScaleXZ || currentScaleY != selectedScaleY) { //Volver a cargar el Heightmap currentScaleXZ = selectedScaleXZ; currentScaleY = selectedScaleY; terrain.loadHeightmap(currentHeightmap, currentScaleXZ, currentScaleY, new Vector3(0, 0, 0)); } //Ver si cambio la textura del terreno var selectedTexture = (string)Modifiers["texture"]; if (currentTexture != selectedTexture) { //Volver a cargar el DiffuseMap currentTexture = selectedTexture; terrain.loadTexture(currentTexture); } //Renderizar terreno terrain.render(); PostRender(); }
public override void render(float elapsedTime) { Device d3dDevice = GuiController.Instance.D3dDevice; //Ver si cambio el heightmap string selectedHeightmap = (string)GuiController.Instance.Modifiers["heightmap"]; if (currentHeightmap != selectedHeightmap) { //Volver a cargar el Heightmap currentHeightmap = selectedHeightmap; terrain.loadHeightmap(currentHeightmap, currentScaleXZ, currentScaleY, new Vector3(0, 0, 0)); } //Ver si cambio alguno de los valores de escala float selectedScaleXZ = (float)GuiController.Instance.Modifiers["scaleXZ"]; float selectedScaleY = (float)GuiController.Instance.Modifiers["scaleY"]; if (currentScaleXZ != selectedScaleXZ || currentScaleY != selectedScaleY) { //Volver a cargar el Heightmap currentScaleXZ = selectedScaleXZ; currentScaleY = selectedScaleY; terrain.loadHeightmap(currentHeightmap, currentScaleXZ, currentScaleY, new Vector3(0, 0, 0)); } //Ver si cambio la textura del terreno string selectedTexture = (string)GuiController.Instance.Modifiers["texture"]; if (currentTexture != selectedTexture) { //Volver a cargar el DiffuseMap currentTexture = selectedTexture; terrain.loadTexture(currentTexture); } //Renderizar terreno terrain.render(); }
public override void Init() { //Path de Heightmap default del terreno y Modifier para cambiarla currentHeightmap = MediaDir + "Heighmaps\\" + "Heightmap2.jpg"; Modifiers.addTexture("heightmap", currentHeightmap); //Modifiers para variar escala del mapa currentScaleXZ = 20f; Modifiers.addFloat("scaleXZ", 0.1f, 100f, currentScaleXZ); currentScaleY = 1.3f; Modifiers.addFloat("scaleY", 0.1f, 10f, currentScaleY); //Path de Textura default del terreno y Modifier para cambiarla currentTexture = MediaDir + "Heighmaps\\" + "TerrainTexture2.jpg"; Modifiers.addTexture("texture", currentTexture); //Cargar terreno: cargar heightmap y textura de color terrain = new TgcSimpleTerrain(); terrain.loadHeightmap(currentHeightmap, currentScaleXZ, currentScaleY, new Vector3(0, 0, 0)); terrain.loadTexture(currentTexture); //Configurar FPS Camara Camara = new TgcFpsCamera(new Vector3(-722.6171f, 495.0046f, -31.2611f), 100f, 100f); }
public override void Init() { var d3dDevice = D3DDevice.Instance.Device; #region configurarEfecto efecto = TgcShaders.loadEffect(GameModel.shadersDir + "shaderAgua.fx"); Texture alphaMap = TextureLoader.FromFile(d3dDevice, GameModel.mediaDir + "texturas\\terrain\\Heightmap3_1.jpg"); efecto.SetValue("texAlphaMap", alphaMap); Texture normalMap = TextureLoader.FromFile(d3dDevice, GameModel.mediaDir + "texturas\\terrain\\bump.jpg"); efecto.SetValue("NormalMap", normalMap); #endregion #region configurarObjeto agua.loadTexture(GameModel.mediaDir + "texturas\\terrain\\agua1.jpg"); agua.loadHeightmap(GameModel.mediaDir + "texturas\\terrain\\negro.jpg", 255f, 1.5f, new TGCVector3(0, -95, 0)); agua.Effect = efecto; agua.Technique = "RenderScene"; tecnica = "RenderScene"; objetos.Add(agua); #endregion PostProcess.agregarPostProcessObject(this); }
public override void Init() { Device d3dDevice = D3DDevice.Instance.Device; //Cargamos un escenario TgcSceneLoader loader = new TgcSceneLoader(); TgcScene scene = loader.loadSceneFromFile(MediaDir + "MeshCreator\\Scenes\\Selva\\Selva-TgcScene.xml"); meshes = scene.Meshes; TgcScene scene2 = loader.loadSceneFromFile(MediaDir + "MeshCreator\\Meshes\\Vegetacion\\Pasto\\Pasto-TgcScene.xml"); pasto = scene2.Meshes[0]; TgcScene scene3 = loader.loadSceneFromFile(MediaDir + "MeshCreator\\Meshes\\Vegetacion\\ArbolSelvatico\\ArbolSelvatico-TgcScene.xml"); arbol = scene3.Meshes[0]; arbol.Transform = TGCMatrix.Scaling(1, 3, 1); TgcScene scene4 = loader.loadSceneFromFile(MediaDir + "MeshCreator\\Meshes\\Vegetacion\\Arbusto2\\Arbusto2-TgcScene.xml"); arbusto = scene4.Meshes[0]; //Cargar terreno: cargar heightmap y textura de color terrain = new TgcSimpleTerrain(); terrain.loadHeightmap(MediaDir + "Heighmaps\\" + "TerrainTexture2.jpg", 20, 0.3f, new TGCVector3(0, -115, 0)); terrain.loadTexture(MediaDir + "Heighmaps\\" + "grass.jpg"); //Crear SkyBox skyBox = new TgcSkyBox(); skyBox.Center = new TGCVector3(0, 500, 0); skyBox.Size = new TGCVector3(10000, 10000, 10000); string texturesPath = MediaDir + "Texturas\\Quake\\SkyBox2\\"; skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Up, texturesPath + "lun4_up.jpg"); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Down, texturesPath + "lun4_dn.jpg"); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Left, texturesPath + "lun4_lf.jpg"); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Right, texturesPath + "lun4_rt.jpg"); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Front, texturesPath + "lun4_bk.jpg"); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Back, texturesPath + "lun4_ft.jpg"); skyBox.Init(); //Cargar Shader personalizado string compilationErrors; effect = Effect.FromFile(d3dDevice, ShadersDir + "WorkshopShaders\\GaussianBlur.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"; //Camara en primera persona TGCVector3 positionEye = new TGCVector3(-944.1269f, 100f, -1033.307f); Camera = new TgcFpsCamera(positionEye, 300, 10, Input); 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.A16B16G16R16F, Pool.Default); g_pGlowMap = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth, d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget, Format.A16B16G16R16F, Pool.Default); g_pRenderTarget4 = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth / 4, d3dDevice.PresentationParameters.BackBufferHeight / 4, 1, Usage.RenderTarget, Format.A16B16G16R16F, Pool.Default); g_pRenderTarget4Aux = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth / 4, d3dDevice.PresentationParameters.BackBufferHeight / 4, 1, Usage.RenderTarget, Format.A16B16G16R16F, Pool.Default); // Para computar el promedio de Luminance int tx_size = 1; for (int i = 0; i < NUM_REDUCE_TX; ++i) { g_pLuminance[i] = new Texture(d3dDevice, tx_size, tx_size, 1, Usage.RenderTarget, Format.A16B16G16R16F, Pool.Default); tx_size *= 4; } g_pLuminance_ant = new Texture(d3dDevice, 1, 1, 1, Usage.RenderTarget, Format.A16B16G16R16F, Pool.Default); effect.SetValue("g_RenderTarget", g_pRenderTarget); // 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); activarGlowModifier = AddBoolean("activar_glow", "Activar Glow", true); pantallaCompletaModifier = AddBoolean("pantalla_completa", "Pant.completa", true); tmIzqModifier = AddEnum("tm_izq", typeof(ToneMapping), ToneMapping.MiddleGray); tmDerModifier = AddEnum("tm_der", typeof(ToneMapping), ToneMapping.Nada); adaptacionPupilaModifier = AddInterval("adaptacion_pupila", new object[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f }, 2); }
public override void Init() { var d3dDevice = D3DDevice.Instance.Device; MyShaderDir = ShadersDir + "WorkshopShaders\\"; circuito = new F1Circuit(MediaDir); //Cargar terreno: cargar heightmap y textura de color terrain = new TgcSimpleTerrain(); terrain.loadHeightmap(MediaDir + "Heighmaps\\" + "TerrainTexture2.jpg", 20, 0.1f, new TGCVector3(0, -125, 0)); terrain.loadTexture(MediaDir + "Heighmaps\\" + "TerrainTexture2.jpg"); //Crear SkyBox skyBox = new TgcSkyBox(); skyBox.Center = new TGCVector3(0, 500, 0); skyBox.Size = new TGCVector3(10000, 10000, 10000); var texturesPath = MediaDir + "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.Init(); var loader = new TgcSceneLoader(); var scene = loader.loadSceneFromFile(MediaDir + "MeshCreator\\Meshes\\Vehiculos\\Auto\\Auto-TgcScene.xml"); car = scene.Meshes[0]; //Cargar Shader personalizado string compilationErrors; effect = Effect.FromFile(D3DDevice.Instance.Device, 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 Camara.SetCamera(new TGCVector3(315.451f, 40, -464.28490f), new TGCVector3(315.451f, 40, -465.28490f)); reset_pos(); // para capturar el mouse var focusWindows = D3DDevice.Instance.Device.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); g_pDepthStencilOld = d3dDevice.DepthStencilSurface; // 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(-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); }
private void crearNivel1( ) { //Construcción del escenario del nivel 1 int cantVueltas = 1; //este nivel va tener una vuelta para que se pueda ganar TgcBox piso; // ----- PÉRGOLA ----- // TgcSimpleTerrain terrain; string currentHeightmap; string currentTexture; float currentScaleXZ; float currentScaleY; //Path de Heightmap default del terreno y Modifier para cambiarla currentHeightmap = Shared.mediaPath + "\\otros\\heighmap.jpg"; currentScaleXZ = 12f; currentScaleY = 2.2f; currentTexture = Shared.mediaPath + "\\otros\\block02.png"; //Cargar terreno: cargar heightmap y textura de color terrain = new TgcSimpleTerrain(); terrain.loadHeightmap(currentHeightmap, currentScaleXZ, currentScaleY, new Vector3(0, 0, -300)); terrain.loadTexture(currentTexture); //elementos.Add(hongo); List <TgcScene> arboles = EjemploAlumno.getInstance().getArboles(); float separacionEntreArboles = 0f; float inclinacionFila = 0f; foreach (TgcScene escenaArbol in arboles) { TgcMesh arbol = escenaArbol.Meshes[0]; arbol.Position = new Vector3(600 + separacionEntreArboles, 0, 2400 + inclinacionFila); arbol.Scale = new Vector3(23f, 23f, 23f); elementos.Add(arbol); separacionEntreArboles += 500f; inclinacionFila += 60f; } TgcTexture textura = TgcTexture.createTexture(GuiController.Instance.D3dDevice, GuiController.Instance.AlumnoEjemplosMediaDir + "LosBorbotones\\escenario\\pista3.jpg"); piso = TgcBox.fromSize(new Vector3(0, 0, 0), new Vector3(15000, 0, 10000), textura); //es un cubo plano con una textura (foto de la pista) cielo = new TgcSkyBox(); //Se crea el cielo, es como un cubo grande que envuelve todo y sirve de límite cielo.Center = new Vector3(0, 0, 0); cielo.Size = new Vector3(20000, 9000, 18000); cielo.setFaceTexture(TgcSkyBox.SkyFaces.Up, Shared.mediaPath + "\\escenario\\cielo.jpg"); cielo.setFaceTexture(TgcSkyBox.SkyFaces.Down, Shared.mediaPath + "\\escenario\\cielo.jpg"); cielo.setFaceTexture(TgcSkyBox.SkyFaces.Left, Shared.mediaPath + "\\escenario\\cielo.jpg"); cielo.setFaceTexture(TgcSkyBox.SkyFaces.Right, Shared.mediaPath + "\\escenario\\cielo.jpg"); cielo.setFaceTexture(TgcSkyBox.SkyFaces.Front, Shared.mediaPath + "\\escenario\\cielo.jpg"); cielo.setFaceTexture(TgcSkyBox.SkyFaces.Back, Shared.mediaPath + "\\escenario\\cielo.jpg"); cielo.updateValues(); cajas.Add(piso); //CARGAR OBSTÁCULOS obstaculos.Add(new ObstaculoRigido(-100, 0, -1800, 3700, 300, 80, Shared.mediaPath + "\\otros\\block01.jpg")); obstaculos.Add(new ObstaculoRigido(-1300, 0, -100, 80, 300, 3200, Shared.mediaPath + "\\otros\\block01.jpg")); obstaculos.Add(new ObstaculoRigido(Shared.mediaPath + "\\ambientacion\\columna\\columna-TgcScene.xml", new Vector3(5650, 0, -3000), new Vector3(15f, 15f, 15f))); obstaculos.Add(new ObstaculoRigido(Shared.mediaPath + "\\ambientacion\\columna\\columna-TgcScene.xml", new Vector3(5500, 0, -3250), new Vector3(10f, 10f, 10f))); obstaculos.Add(new ObstaculoRigido(Shared.mediaPath + "\\ambientacion\\columna\\columna-TgcScene.xml", new Vector3(5850, 0, -3000), new Vector3(5f, 5f, 5f))); obstaculos.Add(new ObstaculoRigido(Shared.mediaPath + "\\ambientacion\\carnivora\\carnivora-TgcScene.xml", new Vector3(2000, 0, 0), new Vector3(7f, 7f, 7f))); ObstaculoRigido p = new ObstaculoRigido(Shared.mediaPath + "\\ambientacion\\carnivora\\carnivora-TgcScene.xml", new Vector3(2200, 0, 100), new Vector3(5f, 5f, 5f)); p.mesh.rotateY(0.5f); obstaculos.Add(p); //guardabarros obstaculos.Add(new ObstaculoRigido(7625, -400, 0, 250, 1100, 10000, Shared.mediaPath + "\\otros\\block01.jpg")); obstaculos.Add(new ObstaculoRigido(-7625, -400, 0, 250, 1100, 10000, Shared.mediaPath + "\\otros\\block01.jpg")); obstaculos.Add(new ObstaculoRigido(0, -400, 5125, 15000, 1100, 250, Shared.mediaPath + "\\otros\\block01.jpg")); obstaculos.Add(new ObstaculoRigido(0, -400, -5125, 15000, 1100, 250, Shared.mediaPath + "\\otros\\block01.jpg")); //Checkpoints for (int m = 0; m < cantVueltas; m++) { this.PosicionesCheckpoints.Add(new Vector3(5300, -4000, 0)); this.PosicionesCheckpoints.Add(new Vector3(0, 0, 0)); this.PosicionesCheckpoints.Add(new Vector3(6000, 2500, 0)); this.PosicionesCheckpoints.Add(new Vector3(-5000, 4500, 0)); this.PosicionesCheckpoints.Add(new Vector3(-5000, 1750, 0)); this.PosicionesCheckpoints.Add(new Vector3(-2500, -500, 0)); this.PosicionesCheckpoints.Add(new Vector3(-5500, -2500, 0)); this.PosicionesCheckpoints.Add(new Vector3(-5000, -4500, 0)); this.PosicionesCheckpoints.Add(new Vector3(0, -2500, 0)); } this.agregarCheckpoints(); checkpointActual = checkpoints.ElementAt(0); checkpointsRestantes = new TgcText2d(); checkpointsRestantes.Text = checkpoints.Count().ToString(); checkpointsRestantes.Color = Color.DarkRed; checkpointsRestantes.Align = TgcText2d.TextAlign.RIGHT; checkpointsRestantes.Position = new Point(630, 30); checkpointsRestantes.Size = new Size(100, 50); checkpointsRestantes.changeFont(new System.Drawing.Font("TimesNewRoman", 25, FontStyle.Bold)); ObstaculoRigido hV = new ObstaculoRigido(Shared.mediaPath + "\\ambientacion\\HongoVerde\\HongoVerde-TgcScene.xml", new Vector3(-4300, 0, -300), new Vector3(2f, 2f, 2f)); hV.mesh.rotateY(0.2f); obstaculos.Add(hV); obstaculos.Add(new ObstaculoRigido(Shared.mediaPath + "\\ambientacion\\HongoRojo\\HongoRojo-TgcScene.xml", new Vector3(-4200, 0, -300), new Vector3(0.5f, 0.5f, 0.5f))); obstaculos.Add(new ObstaculoRigido(Shared.mediaPath + "\\ambientacion\\HongoRojo\\HongoRojo-TgcScene.xml", new Vector3(-4300, 0, -400), new Vector3(1.2f, 1.2f, 1.2f))); obstaculos.Add(new ObstaculoRigido(Shared.mediaPath + "\\ambientacion\\HongoRojo\\HongoRojo-TgcScene.xml", new Vector3(-5000, 0, 3000), new Vector3(2f, 2f, 2f))); obstaculos.Add(new ObstaculoRigido(Shared.mediaPath + "\\ambientacion\\HongoVerde\\HongoVerde-TgcScene.xml", new Vector3(-5100, 0, 3000), new Vector3(0.5f, 0.5f, 0.5f))); obstaculos.Add(new ObstaculoRigido(Shared.mediaPath + "\\ambientacion\\HongoVerde\\HongoVerde-TgcScene.xml", new Vector3(-5100, 0, 3000), new Vector3(1.5f, 1.5f, 1.5f))); obstaculos.Add(new ObstaculoRigido(Shared.mediaPath + "\\ambientacion\\HongoVerde\\HongoVerde-TgcScene.xml", new Vector3(-4900, 0, 3100), new Vector3(0.2f, 0.2f, 0.2f))); ObstaculoRigido b = new ObstaculoRigido(Shared.mediaPath + "\\ambientacion\\bar\\bar-TgcScene.xml", new Vector3(2300, 0, 2600), new Vector3(67f, 15f, 20f)); obstaculos.Add(b); foreach (ObstaculoRigido obstaculo in obstaculos) { objetos.Add(obstaculo.mesh); } foreach (TgcMesh elemento in elementos) { objetos.Add(elemento); } foreach (Recursos recurso in recursos) { objetos.Add(recurso.modelo); } //Crear grilla quadtree = new Quadtree(); quadtree.create(objetos, escenarioBB); quadtree.createDebugQuadtreeMeshes(); GuiController.Instance.Modifiers.addBoolean("showQuadtree", "Show Quadtree", false); terrenos.Add(terrain); }
public unsafe override void Init() { Device d3dDevice = GuiController.Instance.D3dDevice; GuiController.Instance.CustomRenderEnabled = true; MyMediaDir = MediaDir + "WorkshopShaders\\"; MyShaderDir = ShadersDir + "WorkshopShaders\\"; time = 0f; vel_x = new float[MAX_DS, MAX_DS]; vel_z = new float[MAX_DS, MAX_DS]; pos_x = new float[MAX_DS, MAX_DS]; pos_y = new float[MAX_DS, MAX_DS]; pos_z = new float[MAX_DS, MAX_DS]; //Crear loader TgcSceneLoader loader = new TgcSceneLoader(); // ------------------------------------------------------------ //Path de Heightmap default del terreno y Path de Textura default del terreno TGCVector3 PosTerrain = new TGCVector3(0, 0, 0); currentHeightmap = MyMediaDir + "Heighmaps\\" + "Heightmap2.jpg"; currentScaleXZ = 100f; currentScaleY = 6f; currentTexture = MyMediaDir + "Heighmaps\\" + "Heightmap2.JPG"; //+ "grid.JPG"; terrain = new TgcSimpleTerrain(); terrain.loadHeightmap(currentHeightmap, currentScaleXZ, currentScaleY, PosTerrain); terrain.loadTexture(currentTexture); // tomo el ancho de la textura, ojo tiene que ser cuadrada float terrain_width = (float)terrain.HeightmapData.GetLength(0); // mesh principal scene = loader.loadSceneFromFile(MediaDir + "ModelosTgc\\Sphere\\Sphere-TgcScene.xml"); Bitmap b = (Bitmap)Bitmap.FromFile(MyMediaDir + "Heighmaps\\grid.jpg"); g_pBaseTexture = Texture.FromBitmap(d3dDevice, b, Usage.None, Pool.Managed); b.Dispose(); mesh = scene.Meshes[0]; mesh.Scale = new TGCVector3(0.5f, 0.5f, 0.5f); mesh.Position = new TGCVector3(0f, 0f, 0f); mesh.AutoTransformEnable = false; TGCVector3 size = mesh.BoundingBox.calculateSize(); esfera_radio = Math.Abs(size.Y) / 2; //Cargar Shader string compilationErrors; effect = Effect.FromFile(d3dDevice, MyShaderDir + "GPUCompute.fx", null, null, ShaderFlags.None, null, out compilationErrors); if (effect == null) { throw new Exception("Error al cargar shader. Errores: " + compilationErrors); } //Configurar Technique effect.Technique = "DefaultTechnique"; effect.SetValue("map_size", terrain_width); effect.SetValue("map_desf", 0.5f / terrain_width); arrow = new TgcArrow(); arrow.Thickness = 1f; arrow.HeadSize = new TGCVector2(2f, 2f); arrow.BodyColor = Color.Blue; arrowN = new TgcArrow(); arrowN.Thickness = 1f; arrowN.HeadSize = new TGCVector2(2f, 2f); arrowN.BodyColor = Color.Red; arrowT = new TgcArrow(); arrowT.Thickness = 1f; arrowT.HeadSize = new TGCVector2(2f, 2f); arrowT.BodyColor = Color.Green; GuiController.Instance.RotCamera.CameraCenter = new TGCVector3(0, 0, 0); GuiController.Instance.RotCamera.CameraDistance = 3200; GuiController.Instance.RotCamera.RotationSpeed = 2f; LookAt = new TGCVector3(0, 0, 0); LookFrom = new TGCVector3(3200, 3000, 3200); float aspectRatio = (float)GuiController.Instance.Panel3d.Width / GuiController.Instance.Panel3d.Height; GuiController.Instance.CurrentCamera.updateCamera(); d3dDevice.Transform.Projection = TGCMatrix.PerspectiveFovLH(Geometry.DegreeToRadian(45.0f), aspectRatio, 5f, 40000f); // Creo el mapa de velocidad g_pVelocidad = new Texture(d3dDevice, MAX_DS, MAX_DS, 1, Usage.RenderTarget, Format.A32B32G32R32F, Pool.Default); g_pVelocidadOut = new Texture(d3dDevice, MAX_DS, MAX_DS, 1, Usage.RenderTarget, Format.A32B32G32R32F, Pool.Default); // Mapa de Posicion g_pPos = new Texture(d3dDevice, MAX_DS, MAX_DS, 1, Usage.RenderTarget, Format.A32B32G32R32F, Pool.Default); g_pPosOut = new Texture(d3dDevice, MAX_DS, MAX_DS, 1, Usage.RenderTarget, Format.A32B32G32R32F, Pool.Default); // stencil compatible sin multisampling g_pDepthStencil = d3dDevice.CreateDepthStencilSurface(MAX_DS, MAX_DS, DepthFormat.D24S8, MultiSampleType.None, 0, true); // temporaria para recuperar los valores g_pTempVel = new Texture(d3dDevice, MAX_DS, MAX_DS, 1, 0, Format.A32B32G32R32F, Pool.SystemMemory); g_pTempPos = new Texture(d3dDevice, MAX_DS, MAX_DS, 1, 0, Format.A32B32G32R32F, Pool.SystemMemory); effect.SetValue("g_pVelocidad", g_pVelocidad); effect.SetValue("g_pPos", g_pPos); // Textura del heigmap g_pHeightmap = TextureLoader.FromFile(d3dDevice, currentHeightmap); effect.SetValue("height_map", g_pHeightmap); // Resolucion de pantalla effect.SetValue("screen_dx", d3dDevice.PresentationParameters.BackBufferWidth); effect.SetValue("screen_dy", d3dDevice.PresentationParameters.BackBufferHeight); effect.SetValue("currentScaleXZ", currentScaleXZ); effect.SetValue("currentScaleY", currentScaleY); //Se crean 2 triangulos con las dimensiones de la pantalla con sus posiciones ya transformadas // x = -1 es el extremo izquiedo de la pantalla, x=1 es el extremo derecho // Lo mismo para la Y con arriba y abajo // la Z en 1 simpre 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); g_pVB = new VertexBuffer(typeof(CustomVertex.PositionColored), MAX_DS * MAX_DS, d3dDevice, Usage.Dynamic | Usage.None, CustomVertex.PositionColored.Format, Pool.Default); // inicializo el mapa de velocidades Device device = GuiController.Instance.D3dDevice; TGCMatrix ant_Proj = device.Transform.Projection; TGCMatrix ant_World = device.Transform.World; TGCMatrix ant_View = device.Transform.View; device.Transform.Projection = TGCMatrix.Identity; device.Transform.World = TGCMatrix.Identity; device.Transform.View = TGCMatrix.Identity; // rt1 = velocidad Surface pOldRT = device.GetRenderTarget(0); Surface pSurf = g_pVelocidad.GetSurfaceLevel(0); device.SetRenderTarget(0, pSurf); Surface pOldDS = device.DepthStencilSurface; device.DepthStencilSurface = g_pDepthStencil; // rt2 = posicion Surface pSurf2 = g_pPos.GetSurfaceLevel(0); device.SetRenderTarget(1, pSurf2); device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); device.BeginScene(); effect.Technique = "ComputeVel"; device.VertexFormat = CustomVertex.PositionTextured.Format; device.SetStreamSource(0, g_pVBV3D, 0); effect.Begin(FX.None); effect.BeginPass(0); device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); effect.EndPass(); effect.End(); device.EndScene(); effect.SetValue("Kp", esfera_radio * (float)Math.PI / 2); // restauro los RT device.SetRenderTarget(0, pOldRT); device.SetRenderTarget(1, null); device.DepthStencilSurface = pOldDS; // restauro las Transf. device.Transform.Projection = ant_Proj; device.Transform.World = ant_World; device.Transform.View = ant_View; Modifiers.addBoolean("dibujar_terreno", "Dibujar Terreno", true); }
/// <summary> /// Se llama una sola vez, al principio cuando se ejecuta el ejemplo. /// Escribir aquí todo el código de inicialización: cargar modelos, texturas, estructuras de optimización, todo /// procesamiento que podemos pre calcular para nuestro juego. /// Borrar el codigo ejemplo no utilizado. /// </summary> public override void Init() { //Device de DirectX para crear primitivas. var d3dDevice = D3DDevice.Instance.Device; timestamp = DateTime.Now; //Utilizando esta propiedad puedo activar el update/render a intervalos constantes. FixedTickEnable = true; //Se puede configurar el tiempo en estas propiedades TimeBetweenUpdates y TimeBetweenRenders, por defecto esta puedo en 1F / FPS_60 es a lo minimo que deberia correr el TP. //De no estar a gusto como se ejecuta el metodo Tick (el que maneja el GameLoop) el mismo es virtual con lo cual pueden sobrescribirlo. //Esconder cursor focusWindows = d3dDevice.CreationParameters.FocusWindow; mousePosition = focusWindows.PointToScreen(new Point(focusWindows.Width / 2, focusWindows.Height / 2)); //Cursor.Hide(); Sounds.SoundsManager.Instance().sound = DirectSound.DsDevice; Sounds.SoundsManager.Instance().mediaDir = MediaDir; //Burbujas D3DDevice.Instance.ParticlesEnabled = true; D3DDevice.Instance.EnableParticles(); Particulas.Init(MediaDir, 20); //Oceano Oceano.Init(TGCVector3.Up * nivelDelAgua * 0.8f, 100, 100, ShadersDir); //Settear jugador y camara FPSCamara = new FPSCamara(Camera, Input); Player = Player.Instance(); Player.SetInput(Input); Player.Init(FPSCamara); //Inicializar camara var cameraPosition = new TGCVector3(0, 100, -250); var lookAt = new TGCVector3(0, nivelDelAgua, 0); Camera.SetCamera(cameraPosition, lookAt); sonidoUnderwater = new TgcStaticSound(); sonidoUnderwater.loadSound(MediaDir + "Sounds\\mar.wav", DirectSound.DsDevice); effect = TGCShaders.Instance.LoadEffect(ShadersDir + "e_fog.fx"); efectoInterior = TGCShaders.Instance.LoadEffect(ShadersDir + "interior.fx"); //Iniciar HUD Hud.Init(MediaDir); Hud.ChangeStatus(Hud.Status.MainMenu); //Cargar enviroment oceano = new Fondo(MediaDir, ShadersDir); oceano.Init(); oceano.Camera = Camera; heightmap = new TgcSimpleTerrain(); heightmap.loadHeightmap(MediaDir + marBnwDir, marScaleXZ, marScaleY, new TGCVector3(0, marOffsetY, 0)); heightmap.loadTexture(MediaDir + marTexDir); //Cargar entidades var loader = new TgcSceneLoader(); var scene = loader.loadSceneFromFile(MediaDir + "yellow_fish-TgcScene.xml"); var mesh = scene.Meshes[0]; peces = new List <Fish>(); corales = new List <Coral>(); metales = new List <Metal>(); piedras = new List <Metal>(); int i = 0; while (i < 20) { Fish fish; string meshName = i.ToString(); fish = new Fish(mesh.clone(meshName)); fish = (Fish)setearMeshParaLista(fish, i); peces.Add(fish); fish.Effect(effect); fish.Technique("RenderScene"); i++; } scene = loader.loadSceneFromFile(MediaDir + "shark-TgcScene.xml"); mesh = scene.Meshes[0]; shark = new Shark(mesh); shark.Init(); sharkSound = new Tgc3dSound(MediaDir + "Sounds\\shark.wav", shark.GetMesh().Position, DirectSound.DsDevice); shark.setearSonido(sharkSound); shark.setearAlturaMaxima(nivelDelAgua - 19f); efectoDesaparecer = TGCShaders.Instance.LoadEffect(ShadersDir + "perlin.fx"); shark.setearEfectoPerlin(efectoDesaparecer); perlinTexture = TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + "Textures\\perlin.png"); shark.setearPerlin(perlinTexture); scene = loader.loadSceneFromFile(MediaDir + "coral-TgcScene.xml"); mesh = scene.Meshes[0]; i = 0; while (i < 25) { Coral coral; string meshName = i.ToString(); coral = new Coral(mesh.createMeshInstance(meshName)); coral = (Coral)setearMeshParaLista(coral, i * 4, -17); corales.Add(coral); coral.Effect(effect); coral.Technique("RenderScene"); i++; } scene = loader.loadSceneFromFile(MediaDir + "Oro-TgcScene.xml"); mesh = scene.Meshes[0]; i = 0; while (i < 15) { Metal oro; string meshName = i.ToString(); oro = new Metal(mesh.createMeshInstance(meshName)); oro = (Metal)setearMeshParaLista(oro, i * 8, -17); oro.Tipo = ElementoRecolectable.oro; metales.Add(oro); oro.Effect(effect); oro.Technique("RenderSceneLight"); i++; } scene = loader.loadSceneFromFile(MediaDir + "Hierro-TgcScene.xml"); mesh = scene.Meshes[0]; i = 0; while (i < 15) { Metal hierro; string meshName = i.ToString() + i.ToString(); hierro = new Metal(mesh.createMeshInstance(meshName)); hierro = (Metal)setearMeshParaLista(hierro, (i + 10) * 8, -17); hierro.Tipo = ElementoRecolectable.hierro; metales.Add(hierro); hierro.Effect(effect); hierro.Technique("RenderScene"); i++; } scene = loader.loadSceneFromFile(MediaDir + "Roca-TgcScene.xml"); mesh = scene.Meshes[0]; i = 0; while (i < 15) { Metal roca; string meshName = i.ToString() + i.ToString() + i.ToString(); roca = new Metal(mesh.createMeshInstance(meshName)); roca = (Metal)setearMeshParaLista(roca, (i + 10) * 8, -17); roca.Tipo = ElementoRecolectable.madera; roca.escalar(new TGCVector3(0.3f, 0.3f, 0.3f)); piedras.Add(roca); roca.Effect(effect); roca.Technique("RenderScene"); i++; } scene = loader.loadSceneFromFile(MediaDir + "ship-TgcScene.xml"); nave = Nave.Instance(); nave.Init(scene, nivelDelAgua); scene = loader.loadSceneFromFile(MediaDir + "EspadaDoble-TgcScene.xml"); mesh = scene.Meshes[0]; arma = new Arma(mesh); scene = loader.loadSceneFromFile(MediaDir + "Mesa-TgcScene.xml"); mesaNave = MesaNave.Instance(); mesaNave.Init(scene); mesaNave.Effect(efectoInterior); mesaNave.Technique("RenderScene"); scene = loader.loadSceneFromFile(MediaDir + "SogaEnrollada-TgcScene.xml"); mesh = scene.Meshes[0]; sogaInterior = SogaInterior.Instance(); sogaInterior.Init(mesh); sogaInterior.Effect(efectoInterior); sogaInterior.Technique("RenderScene"); scene = loader.loadSceneFromFile(MediaDir + "silla-TgcScene.xml"); sillaInterior = SillaInterior.Instance(); sillaInterior.Init(scene); sillaInterior.Effect(efectoInterior); sillaInterior.Technique("RenderScene"); scene = loader.loadSceneFromFile(MediaDir + "Timon-TgcScene.xml"); timonInterior = TimonInterior.Instance(); timonInterior.Init(scene); timonInterior.Effect(efectoInterior); timonInterior.Technique("RenderScene"); scene = loader.loadSceneFromFile(MediaDir + "LamparaTecho-TgcScene.xml"); lamparaNave = new LamparaNave(scene.Meshes[0]); lamparaNave.Effect(efectoInterior); lamparaNave.Technique("RenderScene"); //Cargar shaders fog = new TgcFog(); fog.Color = Color.FromArgb(30, 144, 255); fog.Density = 1; fog.EndDistance = 1000; fog.StartDistance = 1; fog.Enabled = true; effect.SetValue("screen_dx", d3dDevice.PresentationParameters.BackBufferWidth); effect.SetValue("screen_dy", d3dDevice.PresentationParameters.BackBufferHeight); //Fog + Lights effect.SetValue("nivelAgua", nivelDelAgua); interiorNave = InteriorNave.Instance(); interiorNave.Init(MediaDir); DirectSound.ListenerTracking = Player.Instance().mesh; //Mascara post process maskTexture = TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + "Textures\\mascara.png"); effect.SetValue("textura_mascara", maskTexture.D3dTexture); // seteamos los efectos aca porque son fijos oceano.Effect(effect); oceano.Technique("RenderScene"); heightmap.Effect = effect; heightmap.Technique = "RenderScene"; shark.Effect(effect); shark.Technique("RenderScene"); nave.Effect(effect); nave.Technique("RenderSceneLight"); effect.SetValue("ambientColor", Color.FromArgb(255, 255, 255).ToArgb()); effect.SetValue("diffuseColor", Color.FromArgb(255, 255, 255).ToArgb()); effect.SetValue("specularColor", Color.FromArgb(255, 255, 255).ToArgb()); efectoInterior.SetValue("ambientColor", Color.FromArgb(255, 255, 255).ToArgb()); efectoInterior.SetValue("diffuseColor", Color.FromArgb(255, 255, 255).ToArgb()); efectoInterior.SetValue("specularColor", Color.FromArgb(255, 255, 255).ToArgb()); // dibujo el full screen quad CustomVertex.PositionTextured[] vertices = { 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 fullScreenQuad = new VertexBuffer(typeof(CustomVertex.PositionTextured), 4, d3dDevice, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default); fullScreenQuad.SetData(vertices, 0, LockFlags.None); // dibujo render target depthStencil = d3dDevice.CreateDepthStencilSurface(d3dDevice.PresentationParameters.BackBufferWidth, d3dDevice.PresentationParameters.BackBufferHeight, DepthFormat.D24S8, MultiSampleType.None, 0, true); renderTarget = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth, d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default); // inicializo los FB que uso para el Bloom coralesBrillantes = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth, d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default); FBHorizontalBool = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth, d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default); FBVerticalBloom = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth, d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default); }
public void Init() { var loader = new TgcSceneLoader(); Items = new List <Recolectable>(); Piezas = new List <Pieza>(); Objetos = new List <Colisionable>(); MeshARenderizar = new List <TgcMesh>(); meshFogatas = new List <TgcMesh>(); IluminacionEscenario = new List <Fogata>(); //Instancia de skybox skyBox = new TgcSkyBox(); skyBox.Center = TGCVector3.Empty; skyBox.Size = new TGCVector3(9000, 9000, 9000); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Up, MediaDir + "cielo.jpg"); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Down, MediaDir + "cielo.jpg"); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Left, MediaDir + "cielo.jpg"); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Right, MediaDir + "cielo.jpg"); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Front, MediaDir + "cielo.jpg"); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Back, MediaDir + "cielo.jpg"); skyBox.SkyEpsilon = 25f; skyBox.Init(); //Instancio la vegetacion var scene = loader.loadSceneFromFile(MediaDir + @"Pino-TgcScene.xml"); var PinoOriginal = scene.Meshes[0]; List <TGCVector3> posicionesArboles = new List <TGCVector3>(); posicionesArboles.Add(new TGCVector3(1, 1, 1)); posicionesArboles.Add(new TGCVector3(-3442, 1, -2736)); posicionesArboles.Add(new TGCVector3(-3689, 1, -3039)); posicionesArboles.Add(new TGCVector3(-3799, 1, -2719)); posicionesArboles.Add(new TGCVector3(-3417, 1, -2480)); posicionesArboles.Add(new TGCVector3(-2917, 1, -2433)); posicionesArboles.Add(new TGCVector3(-3668, 1, -2025)); posicionesArboles.Add(new TGCVector3(-3362, 1, -2009)); posicionesArboles.Add(new TGCVector3(-3451, 1, -3786)); posicionesArboles.Add(new TGCVector3(-4037, 1, -2329)); posicionesArboles.Add(new TGCVector3(-2885, 1, -1826)); posicionesArboles.Add(new TGCVector3(-4123, 1, -1581)); posicionesArboles.Add(new TGCVector3(-3289, 1, -909)); posicionesArboles.Add(new TGCVector3(-4261, 1, -435)); posicionesArboles.Add(new TGCVector3(-2883, 1, -655)); posicionesArboles.Add(new TGCVector3(-3352, 1, -1761)); posicionesArboles.Add(new TGCVector3(-3244, 1, -2394)); posicionesArboles.Add(new TGCVector3(-3978, 1, -2572)); posicionesArboles.Add(new TGCVector3(-3517, 1, -1982)); posicionesArboles.Add(new TGCVector3(-3118, 1, -1524)); posicionesArboles.Add(new TGCVector3(-3349, 1, -980)); posicionesArboles.Add(new TGCVector3(-4110, 1, -407)); posicionesArboles.Add(new TGCVector3(-3304, 1, -1774)); posicionesArboles.Add(new TGCVector3(-3139, 1, -1269)); posicionesArboles.Add(new TGCVector3(-2140, 1, -562)); posicionesArboles.Add(new TGCVector3(-4094, 1, -145)); posicionesArboles.Add(new TGCVector3(-3103, 1, -1337)); posicionesArboles.Add(new TGCVector3(-2896, 1, -1087)); posicionesArboles.Add(new TGCVector3(-2529, 1, 10)); posicionesArboles.Add(new TGCVector3(-3917, 1, 772)); posicionesArboles.Add(new TGCVector3(746, 1, 157)); posicionesArboles.Add(new TGCVector3(951, 1, 637)); posicionesArboles.Add(new TGCVector3(1361, 1, 404)); posicionesArboles.Add(new TGCVector3(1361, 1, 440)); posicionesArboles.Add(new TGCVector3(-3877, 1, -678)); posicionesArboles.Add(new TGCVector3(-3997, 1, -1079)); posicionesArboles.Add(new TGCVector3(-3996, 1, -1617)); posicionesArboles.Add(new TGCVector3(-3701, 1, -1505)); posicionesArboles.Add(new TGCVector3(-3761, 1, -1069)); posicionesArboles.Add(new TGCVector3(-3968, 1, -1952)); posicionesArboles.Add(new TGCVector3(-3550, 1, -1562)); posicionesArboles.Add(new TGCVector3(-3557, 1, -1192)); posicionesArboles.Add(new TGCVector3(-3938, 1, -1048)); posicionesArboles.Add(new TGCVector3(-3148, 1, -268)); posicionesArboles.Add(new TGCVector3(-4120, 1, 433)); posicionesArboles.Add(new TGCVector3(-3136, 1, -135)); posicionesArboles.Add(new TGCVector3(-2793, 1, -476)); var indiceArbolDirectorio = (new Random()).Next(posicionesArboles.Count, posicionesArboles.Count + 100); arbolesMesh = new List <TgcMesh>(); Colisionable Arbol; for (var i = 0; i < posicionesArboles.Count; i++) { var Instance = PinoOriginal.createMeshInstance("Pino" + i); Arbol = new SinEfecto(Instance); Arbol.mesh.Move(0, 0, 0); Arbol.mesh.Scale = new TGCVector3(0.05f * i, 0.05f * i, 0.05f * i); Arbol.mesh.Move(posicionesArboles[i]); Arbol.mesh.Transform = TGCMatrix.Translation(posicionesArboles[i]); Objetos.Add(Arbol); MeshARenderizar.Add(Arbol.mesh); arbolesMesh.Add(Arbol.mesh); } for (var i = posicionesArboles.Count; i < posicionesArboles.Count + 100; i++) { var Instance = PinoOriginal.createMeshInstance("Pino" + i); if (i == indiceArbolDirectorio) { Arbol = new ArbolDirectorio(MediaDir); } else { Arbol = new SinEfecto(Instance); } Arbol.mesh.Move(0, 0, 0); Arbol.mesh.Scale = new TGCVector3(0.01f * i, 0.01f * i, 0.01f * i); Arbol.mesh.Move(new TGCVector3(((float)Math.Pow(i, Math.PI) % 2066) + 98, 1, ((float)Math.Pow(i, Math.E) % 3136) - 1339)); Arbol.mesh.Transform = TGCMatrix.Translation(new TGCVector3(((float)Math.Pow(i, Math.PI) % 2066) + 98, 1, ((float)Math.Pow(i, Math.E) % 3136) - 1339)); Objetos.Add(Arbol); MeshARenderizar.Add(Arbol.mesh); arbolesMesh.Add(Arbol.mesh); } foreach (var mesh in arbolesMesh) { mesh.AlphaBlendEnable = true; } //Instancio el terreno (Heigthmap) terreno = new TgcSimpleTerrain(); var pathTextura = MediaDir + "Textures\\mapa1.jpg"; var pathHeighmap = MediaDir + "mapa1.jpg"; currentScaleXZ = 100f; currentScaleY = 3f; terreno.loadHeightmap(pathHeighmap, currentScaleXZ, currentScaleY, new TGCVector3(0, -30, 0)); terreno.loadTexture(pathTextura); //Instancio el piso var pisoTexture = TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + "Textures\\water2.jpg"); Plano = new TgcPlane(new TGCVector3(-tamanioMapa / 2, 0, -tamanioMapa / 2), new TGCVector3(tamanioMapa, 0, tamanioMapa), TgcPlane.Orientations.XZplane, pisoTexture, 50f, 50f); MeshPlano = Plano.toMesh("MeshPlano"); Objetos.Add(new SinEfecto(MeshPlano)); MeshARenderizar.Add(MeshPlano); piezaAsociadaLago = new Pieza(2, "Pieza 2", MediaDir + "\\2D\\windows\\windows_2.png", null); pistaAsociadaLago = new Pista(null, MediaDir + "\\2D\\pista_hacha.png", null); //Instancio la Cabania var sceneCabania = loader.loadSceneFromFile(MediaDir + @"cabania-TgcScene.xml"); foreach (var Mesh in sceneCabania.Meshes) { Mesh.Move(-500, 20, 500); Mesh.Scale = new TGCVector3(4.5f, 4.5f, 4.5f); Mesh.Transform = TGCMatrix.Scaling(Mesh.Scale); Objetos.Add(new SinEfecto(Mesh)); MeshARenderizar.Add(Mesh); } cabaniaBoundingBox = new TgcBoundingAxisAlignBox(new TGCVector3(-500, 20, 500), new TGCVector3(0, 1001, 1080)); var sceneBridge = loader.loadSceneFromFile(MediaDir + @"Bridge-TgcScene.xml"); foreach (var Mesh in sceneBridge.Meshes) { Mesh.Move(-2561, 12, 159); Mesh.Scale = new TGCVector3(4.5f, .75f, 1.35f); Mesh.Transform = TGCMatrix.Scaling(Mesh.Scale); Objetos.Add(new SinEfecto(Mesh)); MeshARenderizar.Add(Mesh); } var sceneCanoa = loader.loadSceneFromFile(MediaDir + @"Canoa-TgcScene.xml"); foreach (var Mesh in sceneCanoa.Meshes) { Mesh.Move(-482, 20, -3110); Mesh.Scale = new TGCVector3(1.5f, 1.5f, 1.5f); Mesh.Transform = TGCMatrix.Scaling(Mesh.Scale); Objetos.Add(new SinEfecto(Mesh)); MeshARenderizar.Add(Mesh); } //Cabania es lugar seguro if (TgcCollisionUtils.testAABBAABB(personaje.mesh.BoundingBox, cabaniaBoundingBox)) { personaje.tiempoDesprotegido = 0; } }
public override void Init() { MyMediaDir = MediaDir; MyShaderDir = ShadersDir + "WorkshopShaders\\"; //Crear loader var loader = new TgcSceneLoader(); // ------------------------------------------------------------ // Creo el Heightmap para el terreno: var PosTerrain = new Vector3(0, 0, 0); currentHeightmap = MyMediaDir + "Heighmaps\\Heightmap2.jpg"; currentScaleXZ = 100f; currentScaleY = 2f; currentTexture = MyMediaDir + "Heighmaps\\TerrainTexture3.jpg"; terrain = new TgcSimpleTerrain(); terrain.loadHeightmap(currentHeightmap, currentScaleXZ, currentScaleY, PosTerrain); terrain.loadTexture(currentTexture); // ------------------------------------------------------------ // Crear SkyBox: skyBox = new TgcSkyBox(); skyBox.Center = new Vector3(0, 0, 0); skyBox.Size = new Vector3(8000, 8000, 8000); var texturesPath = MediaDir + "Texturas\\Quake\\SkyBox1\\"; skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Up, texturesPath + "phobos_up.jpg"); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Down, texturesPath + "phobos_dn.jpg"); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Left, texturesPath + "phobos_lf.jpg"); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Right, texturesPath + "phobos_rt.jpg"); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Front, texturesPath + "phobos_bk.jpg"); skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Back, texturesPath + "phobos_ft.jpg"); skyBox.SkyEpsilon = 50f; skyBox.InitSkyBox(); // ------------------------------------------------------------ //Cargar los mesh: scene = loader.loadSceneFromFile(MediaDir + "MeshCreator\\Meshes\\Vehiculos\\TanqueFuturistaRuedas\\TanqueFuturistaRuedas-TgcScene.xml"); mesh = scene.Meshes[0]; sceneX = loader.loadSceneFromFile(MediaDir + "ModelosTgc\\Sphere\\Sphere-TgcScene.xml"); meshX = sceneX.Meshes[0]; scene2 = loader.loadSceneFromFile(MediaDir + "MeshCreator\\Meshes\\Vegetacion\\Palmera\\Palmera-TgcScene.xml"); palmera = scene2.Meshes[0]; scene3 = loader.loadSceneFromFile(MediaDir + "MeshCreator\\Meshes\\Vehiculos\\AvionCaza\\AvionCaza-TgcScene.xml"); avion = scene3.Meshes[0]; mesh.Scale = new Vector3(0.5f, 0.5f, 0.5f); mesh.Position = new Vector3(0f, 0f, 0f); mesh.AutoTransformEnable = false; var size = mesh.BoundingBox.calculateSize(); largo_tanque = Math.Abs(size.Z); alto_tanque = Math.Abs(size.Y) * mesh.Scale.Y; avion.Scale = new Vector3(1f, 1f, 1f); avion.Position = new Vector3(3000f, 550f, 0f); avion.AutoTransformEnable = false; dir_avion = new Vector3(0, 0, 1); size = palmera.BoundingBox.calculateSize(); var alto_palmera = Math.Abs(size.Y); int i; bosque = new List <TgcMesh>(); float[] r = { 1900f, 2100f, 2300f, 1800f }; for (i = 0; i < 4; i++) { for (var j = 0; j < 15; j++) { var instance = palmera.createMeshInstance(palmera.Name + i); instance.Scale = new Vector3(0.5f, 1.5f, 0.5f); var x = r[i] * (float)Math.Cos(Geometry.DegreeToRadian(180 + 10.0f * j)); var z = r[i] * (float)Math.Sin(Geometry.DegreeToRadian(180 + 10.0f * j)); instance.Position = new Vector3(x, CalcularAltura(x, z) /*+ alto_palmera / 2 * instance.Scale.Y*/, z); bosque.Add(instance); } } // Arreglo las normales del tanque /*int[] adj = new int[mesh.D3dMesh.NumberFaces * 3]; * mesh.D3dMesh.GenerateAdjacency(0, adj); * mesh.D3dMesh.ComputeNormals(adj); */ // Arreglo las normales de la esfera { var adj = new int[meshX.D3dMesh.NumberFaces * 3]; meshX.D3dMesh.GenerateAdjacency(0, adj); meshX.D3dMesh.ComputeNormals(adj); } //Cargar Shader personalizado effect = TgcShaders.loadEffect(ShadersDir + "WorkshopShaders\\EnvMap.fx"); // le asigno el efecto a la malla mesh.Effect = effect; meshX.Effect = effect; vel_tanque = 10; //Centrar camara rotacional respecto a este mesh CamaraRot = new TgcRotationalCamera(mesh.BoundingBox.calculateBoxCenter(), mesh.BoundingBox.calculateBoxRadius() * 2); CamaraRot.CameraDistance = 300; CamaraRot.RotationSpeed = 1.5f; Camara = CamaraRot; kx = kc = 0.5f; Modifiers.addFloat("Reflexion", 0, 1, kx); Modifiers.addFloat("Refraccion", 0, 1, kc); Modifiers.addBoolean("Fresnel", "fresnel", true); }