Ejemplo n.º 1
0
        public override void init()
        {
            //GuiController.Instance: acceso principal a todas las herramientas del Framework
            enemigos = new List<Barco>();
            terminoJuego = false;

            //Device de DirectX para crear primitivas
            Microsoft.DirectX.Direct3D.Device d3dDevice = GuiController.Instance.D3dDevice;

            //Activamos el renderizado customizado. De esta forma el framework nos delega control total sobre como dibujar en pantalla
            //La responsabilidad cae toda de nuestro lado
            GuiController.Instance.CustomRenderEnabled = true;
            g_pCubeMapAgua = TextureLoader.FromCubeFile(d3dDevice, GuiController.Instance.ExamplesMediaDir + "Shaders\\CubeMap.dds");
            //sol = TgcBox.fromSize(new Vector3(50, 50, 50), Color.LightYellow);

            //Cargo la escena completa que tendria que ser la del escenario con el cielo / la del agua
            //PROXIMAMENTE, ahora cargo otro escenario

            //Pruebo postprocess lluvia
            CustomVertex.PositionTextured[] screenQuadVertices = 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
            screenQuadVB = new VertexBuffer(typeof(CustomVertex.PositionTextured),
                    4, d3dDevice, Usage.Dynamic | Usage.WriteOnly,
                        CustomVertex.PositionTextured.Format, Pool.Default);
            screenQuadVB.SetData(screenQuadVertices, 0, LockFlags.None);

            //Creamos un Render Targer sobre el cual se va a dibujar la pantalla
            renderTarget2D = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth
                    , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget,
                        Format.X8R8G8B8, Pool.Default);

            //Cargar shader con efectos de Post-Procesado
            effectlluvia = TgcShaders.loadEffect(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\PostProcess.fx");

            //Configurar Technique dentro del shader
            effectlluvia.Technique = "AlarmaTechnique";

            //Cargar textura que se va a dibujar arriba de la escena del Render Target
            alarmTexture = TgcTexture.createTexture(d3dDevice, GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\rain.png");

            //Interpolador para efecto de variar la intensidad de la textura de alarma
            intVaivenAlarm = new InterpoladorVaiven();
            intVaivenAlarm.Min = 0;
            intVaivenAlarm.Max = 2;
            intVaivenAlarm.Speed = 10;
            intVaivenAlarm.reset();

            //Modifier para activar/desactivar efecto de alarma
            GuiController.Instance.Modifiers.addBoolean("activar_efecto", "Activar efecto", true);

            //termina post process

            //inicio//
            spriteFondo = new TgcSprite();
            spriteFondo.Texture = TgcTexture.createTexture(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\MenuPrincipal.jpg");

            Size screenSize = GuiController.Instance.Panel3d.Size;
            Size textureSize = spriteFondo.Texture.Size;
            spriteFondo.Scaling = new Vector2(1f, 0.8f);
            spriteFondo.Position = new Vector2(FastMath.Max(screenSize.Width / 2 - textureSize.Width / 2, 0), FastMath.Max(screenSize.Height / 2 - textureSize.Height / 2, 0));

            spriteLetras = new TgcSprite();
            spriteLetras.Texture = TgcTexture.createTexture(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\Texto.png");

            spriteInicio = new TgcSprite();
            spriteInicio.Texture = TgcTexture.createTexture(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\inicio.png");

            spriteLetras.Scaling = new Vector2(0.4f*1.65f, 0.3f*1.65f);
            Size textureSize2 = spriteLetras.Texture.Size;

            spriteInicio.Scaling = new Vector2(0.4f, 0.3f);
            Size textureSize3 = spriteInicio.Texture.Size;

            spriteTermino = new TgcSprite();
            spriteTermino.Texture = TgcTexture.createTexture(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\termino.png");
            //spriteTermino.Scaling = new Vector2(0.5f,0.5f);
            spriteTermino.Position = new Vector2(screenSize.Width / 4, screenSize.Height / 2);

            spriteLetras.Position = new Vector2(FastMath.Max(screenSize.Width / 2 - textureSize2.Width / 2, 0), FastMath.Max(screenSize.Height / 2 - textureSize2.Height / 2, 0));
            spriteLetras.Position = new Vector2(spriteLetras.Position.X + 110, spriteLetras.Position.Y);

            spriteInicio.Position = new Vector2(FastMath.Max(screenSize.Width / 2 - textureSize3.Width / 2, 0), FastMath.Max(screenSize.Height / 2 - textureSize3.Height / 2, 0));
            spriteInicio.Position = new Vector2(spriteInicio.Position.X + 210, spriteLetras.Position.Y+95);

            spriteMinimapa = new TgcSprite();
            spriteMinimapa.Texture = TgcTexture.createTexture(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\minimapa.png");

            spriteMinimapa.Scaling = new Vector2(0.2f, 0.2f);
            Size minimapSize = spriteMinimapa.Texture.Size;

            spriteMinimapa.Position = new Vector2(FastMath.Max(screenSize.Width  - 210, 0), FastMath.Max(screenSize.Height  - minimapSize.Height , 0));

            spriteBarcoPrincipal = new TgcSprite();
            spriteBarcoPrincipal.Texture = TgcTexture.createTexture(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\pointgreen.png");
            spriteBarcoPrincipal.Scaling = new Vector2(0.5f,0.5f);

            //inicio//

            //ui
            sprBarraVida = new TgcSprite();
            sprBarraVida.Texture = TgcTexture.createTexture(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\BarraVacia.png");
            Size textureSize4 = sprBarraVida.Texture.Size;

            sprBarraVida.Scaling = new Vector2(1f, 1f);
            sprBarraVida.Position = new Vector2(1, 1);

            sprVidaLLena = new TgcSprite();
            sprVidaLLena.Texture = TgcTexture.createTexture(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\vidallena.png");
            Size textureSize5 = sprVidaLLena.Texture.Size;
            sprVidaLLena.Scaling = new Vector2(1f, 1f);
            sprVidaLLena.Position = new Vector2(1, 15);

            //ui

            Bitmap b = (Bitmap)Bitmap.FromFile(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\wallhaven-276951.jpg"); //"water_water_0056_01_preview.jpg");
            b.RotateFlip(RotateFlipType.Rotate90FlipX);
            textura = Texture.FromBitmap(d3dDevice, b, Usage.None, Pool.Managed);

            b = (Bitmap)Bitmap.FromFile(GuiController.Instance.ExamplesMediaDir
                    + "Shaders\\BumpMapping_DiffuseMap.jpg");
            diffuseMapTexture = Texture.FromBitmap(d3dDevice, b, Usage.None, Pool.Managed);

            oceano = new SmartTerrain();
            //oceano.loadHeightmap(GuiController.Instance.ExamplesMediaDir + "Heighmaps\\" + "TerrainTexture1-256x256.jpg", 30.00f, 1.0f, new Vector3(0, 0, 0));
            oceano.loadPlainHeightmap(256, 256, 0, 50.0f, 1.0f, new Vector3(0, 0, 0));
            oceano.loadTexture(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\water_water_0056_01_preview.jpg");

            TgcSceneLoader loader = new TgcSceneLoader();
            //escena = loader.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir + "MeshCreator\\Scenes\\Isla\\Isla-TgcScene.xml");

            //Textura del skybox
            string texturesPath = GuiController.Instance.ExamplesMediaDir + "Texturas\\Quake\\SkyBox LostAtSeaDay\\";

            //Crear SkyBox
            skyBox = new TgcSkyBox();
            skyBox.Center = new Vector3(0, 0, 0);
            skyBox.Size = new Vector3(10000, 10000, 10000);

            //Configurar color
            //skyBox.Color = Color.OrangeRed;

            //Configurar las texturas para cada una de las 6 caras
            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");

            //Hay veces es necesario invertir las texturas Front y Back si se pasa de un sistema RightHanded a uno LeftHanded
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Front, texturesPath + "lostatseaday_bk.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Back, texturesPath + "lostatseaday_ft.jpg");

            //Actualizar todos los valores para crear el SkyBox
            skyBox.updateValues();

            //Cargo el mesh del/los barco/s -> porque se carga como escena y no cargo el mesh directamente?

            TgcScene scene2 = loader.loadSceneFromFile(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\Boteconcañon\\BoteConCanion-TgcScene.xml");
            mainMesh = scene2.Meshes[0];
            mainMesh.Position = new Vector3(-200f,0f, 200f);
            mainMesh.Scale = new Vector3(2f,2f,2f);
            TgcScene scene4 = loader.loadSceneFromFile(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\Boteconcañon\\BoteConCanion-TgcScene.xml");
            meshBot = scene4.Meshes[0];
            meshBot.Position = new Vector3(-200f,0f,200f);
            meshBot.Scale = new Vector3(1.8f, 1.8f, 1.8f);
            TgcScene scene3 = loader.loadSceneFromFile(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\Hacha\\Bala-TgcScene.xml");
            balaMesh1 = scene3.Meshes[0];

            TgcScene scene5 = loader.loadSceneFromFile(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\Hacha\\Hacha-TgcScene.xml");
             balaMesh2 = scene5.Meshes[0];

            barcoPrincipal = new BarcoPlayer(150, 50, VELOCIDAD_MOVIMIENTO, ACELERACION, VELOCIDAD_ROTACION, mainMesh, 0.06, loader,balaMesh2);

            //pongo enemigos
            int rows = 12;

            float offset = 3000;

            for (int i = 0; i < rows; i++)
            {

                    //Crear instancia de modelo
                    TgcMesh instance = meshBot.createMeshInstance(meshBot.Name + i + "_" );

                    //Desplazarlo
                    instance.move(offset * (FastMath.Cos((float)i * 0.523599f)),0,offset * FastMath.Sin((float)i * 0.523599f));
                    instance.Scale = new Vector3(1.5f, 1.5f, 1.5f);

                    var barcoenem = new BarcoBot(100, 10, 100, ACELERACION, 18, instance, 0.05, barcoPrincipal, loader,balaMesh1);

                    barcoenem.Mesh.Effect = TgcShaders.loadEffect(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\shader_bote.fx"); //efectosAguaIluminacion;
                    barcoenem.Mesh.Technique = GuiController.Instance.Shaders.getTgcMeshTechnique(barcoenem.Mesh.RenderType);//"EnvironmentMapTechnique";
                    barcoenem.BarcosEnemigos = new List<Barco>();
                    barcoenem.BarcosEnemigos.Add(barcoPrincipal);
                    enemigos.Add(barcoenem);

            }
            //TgcScene scene3 = loader.loadSceneFromFile(GuiController.Instance.ExamplesDir + "Shaders\\WorkshopShaders\\Media\\Piso\\Agua-TgcScene.xml");
            //agua = scene3.Meshes[0];
            //agua.Scale = new Vector3(25f, 1f, 25f);
            //agua.Position = new Vector3(0f, 0f, 0f);

            efectosAguaIluminacion = TgcShaders.loadEffect(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\shader_agua.fx");
            oceano.Effect = efectosAguaIluminacion;
            oceano.Technique = "RenderAgua";//"EnvironmentMapTechnique"; //"RenderAgua";
            oceano.AlphaBlendEnable = true;

            //barcoEnemigo = new BarcoBot(100, 35,100, ACELERACION, 18, meshBot, 0.05,barcoPrincipal,loader);
            barcoPrincipal.BarcosEnemigos = enemigos;

            // iluminacion en los barcos
            barcoPrincipal.Mesh.Effect = TgcShaders.loadEffect(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\shader_bote.fx");//GuiController.Instance.Shaders.TgcMeshPointLightShader;// efectosAguaIluminacion; //GuiController.Instance.Shaders.TgcMeshPointLightShader;// efectosAguaIluminacion;
            barcoPrincipal.Mesh.Technique = GuiController.Instance.Shaders.getTgcMeshTechnique(barcoPrincipal.Mesh.RenderType); //"EnvironmentMapTechnique";
            //barcoEnemigo.Mesh.Effect = GuiController.Instance.Shaders.TgcMeshPointLightShader; //efectosAguaIluminacion;
            //barcoEnemigo.Mesh.Technique = GuiController.Instance.Shaders.getTgcMeshTechnique(barcoEnemigo.Mesh.RenderType);//"EnvironmentMapTechnique";

            //Camara en tercera persona focuseada en el barco (canoa)

            //PARA DESARROLLO DEL ESCENARIO ES MEJOR MOVERSE CON ESTA CAMARA
            GuiController.Instance.FpsCamera.Enable = true;
            GuiController.Instance.FpsCamera.Velocity = new Vector3(0.0f,0.0f,0.0f);
            GuiController.Instance.FpsCamera.JumpSpeed = 0f;
            GuiController.Instance.FpsCamera.setCamera(new Vector3(0f,700f,-2300f), new Vector3(900f, 100f, -300f));
            GuiController.Instance.ThirdPersonCamera.rotateY(Geometry.DegreeToRadian(180));
            ////GuiController.Instance.Fog.Enabled = true;

            //GuiController.Instance.Modifiers.addFloat("reflection", 0, 1, 0.35f);

            //GuiController.Instance.Modifiers.addVertex3f("lightPos", new Vector3(-3000, 0, -3000), new Vector3(3000, 3000, 3000), new Vector3(-300, 1500, 3000));

            GuiController.Instance.Modifiers.addColor("lightColor", Color.LightYellow);
            //GuiController.Instance.Modifiers.addFloat("bumpiness", 0, 1, 1f);
            GuiController.Instance.Modifiers.addFloat("lightIntensity", 0, 500, 150);
            GuiController.Instance.Modifiers.addFloat("lightAttenuation", 0.1f, 2, 0.1f);
            GuiController.Instance.Modifiers.addFloat("specularEx", 0, 100, 20f);

            GuiController.Instance.Modifiers.addColor("mEmissive", Color.Black);
            GuiController.Instance.Modifiers.addColor("mAmbient", Color.White);
            GuiController.Instance.Modifiers.addColor("mDiffuse", Color.White);
            GuiController.Instance.Modifiers.addColor("mSpecular", Color.White);

            //Carpeta de archivos Media del alumno
            //string alumnoMediaFolder = GuiController.Instance.AlumnoEjemplosMediaDir;

            Mapa.oceano_mesh = oceano;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Método que se llama cuando termina la ejecución del ejemplo.
 /// Hacer dispose() de todos los objetos creados.
 /// </summary>
 public override void close()
 {
     //escena.disposeAll();
     GuiController.Instance.Modifiers.clear();
     mainMesh.dispose();
     meshBot.dispose();
     balaMesh1.dispose();
     balaMesh2.dispose();
     barcoEnemigo = null;
     barcoPrincipal = null;
     enemigos = null;
     g_pCubeMapAgua = null;
 }