Example #1
0
        internal void Init()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            score    = 0; //lleva el score del jugador
            capturas = 0;
            WINNER   = false;


            killMultiTracker   = 0;
            KILL_DELAY         = 0;
            SPAWN_TIME_COUNTER = 0f;
            time = 0;

            // creo meshes de modelo para clonar y asi optimizar
            TgcSceneLoader loader2 = new TgcSceneLoader();
            TgcScene       scene   = loader2.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir + "ModelosTgc\\Robot\\Robot-TgcScene.xml");

            this.ModeloRobot = scene.Meshes[0];
            TgcScene scene2 = loader2.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir + "MeshCreator\\Meshes\\Vehiculos\\StarWars-Speeder\\StarWars-Speeder-TgcScene.xml");

            this.ModeloNave = scene2.Meshes[0];
            TgcScene scene3 = loader2.loadSceneFromFile(GuiController.Instance.AlumnoEjemplosMediaDir + "Los_Borbotones\\Meshes\\proyectiles\\EnergyBall-TgcScene.xml");

            this.ModeloProyectil = scene3.Meshes[0];

            //Cargar textura de CubeMap para Environment Map
            cubeMap = TextureLoader.FromCubeFile(d3dDevice, GuiController.Instance.AlumnoEjemplosMediaDir + "Los_Borbotones\\Shaders\\CubemapRobot.dds");

            //Cargar Shader de DynamicLights
            envMap           = TgcShaders.loadEffect(GuiController.Instance.ExamplesMediaDir + "Shaders\\EnvironmentMap.fx");
            envMap.Technique = "SimpleEnvironmentMapTechnique";

            skeletalEnvMap = TgcShaders.loadEffect(GuiController.Instance.AlumnoEjemplosMediaDir + "Los_Borbotones\\Shaders\\" + "SkeletalEnvMap.fx");

            //Creo skybox
            skyBox        = new CustomSkyBox();
            skyBox.Center = new Vector3(0, 0, 0);
            float farplane = CustomFpsCamera.FAR_PLANE;

            skyBox.Size = new Vector3(farplane, farplane, farplane);

            string texturesPath = GuiController.Instance.ExamplesMediaDir + "Texturas\\Quake\\SkyBox1\\";

            skyBox.setFaceTexture(CustomSkyBox.SkyFaces.Up, texturesPath + "phobos_up.jpg");
            skyBox.setFaceTexture(CustomSkyBox.SkyFaces.Down, texturesPath + "phobos_dn.jpg");
            skyBox.setFaceTexture(CustomSkyBox.SkyFaces.Left, texturesPath + "phobos_lf.jpg");
            skyBox.setFaceTexture(CustomSkyBox.SkyFaces.Right, texturesPath + "phobos_rt.jpg");
            skyBox.setFaceTexture(CustomSkyBox.SkyFaces.Front, texturesPath + "phobos_bk.jpg");
            skyBox.setFaceTexture(CustomSkyBox.SkyFaces.Back, texturesPath + "phobos_ft.jpg");
            skyBox.updateValues();

            //Creacion del terreno
            currentHeightmap = GuiController.Instance.AlumnoEjemplosMediaDir + "Los_Borbotones\\Mapas\\" + "experimento-editando4_3.jpg";
            //Seteo de la resolucion del jpg de heightmap para la interpolacion de altura, como es cuadrado se usa una sola variable
            heightmapResolution = 800;
            textureResolution   = 1600;

            Vector3 posInicial = new Vector3(0, 0, 0);

            currentTexture = GuiController.Instance.AlumnoEjemplosMediaDir + "Los_Borbotones\\Mapas\\" + "grunge.jpg";
            terrain        = new CustomTerrain();
            terrain.loadHeightmap(currentHeightmap, currentScaleXZ, currentScaleY, posInicial, cantidadFilasColumnas);
            terrain.loadTexture(currentTexture);
            terrain.Effect    = TgcShaders.loadEffect(GuiController.Instance.AlumnoEjemplosMediaDir + "Los_Borbotones\\Shaders\\RenderTerrain.fx");
            terrain.Technique = "RenderTerrain";

            //Creacion del shader de viento
            windShader = TgcShaders.loadEffect(GuiController.Instance.AlumnoEjemplosMediaDir + "Los_Borbotones\\Shaders\\WindTree.fx");

            //Creacion de la Vegetacion
            this.vegetation = new List <TgcMesh>();
            TgcSceneLoader loader = new TgcSceneLoader();

            Vegetation = loader.loadSceneFromFile(GuiController.Instance.AlumnoEjemplosMediaDir + "Los_Borbotones\\Mapas\\100x8 v4-TgcScene.xml");

            vegetation = Vegetation.Meshes;
            int i;

            for (i = 1; i < vegetation.Count; i++)
            {
                float  randScaleXZ = (float)random.Next(85, 115) / 100;
                float  randScaleY  = (float)random.Next(70, 130) / 100;
                Matrix scale       = Matrix.Scaling(new Vector3(0.06f * randScaleXZ, 0.4f * randScaleY, 0.06f * randScaleXZ));

                vegetation[i].setColor(Color.Purple);
                vegetation[i].Effect    = windShader;
                vegetation[i].Technique = "WindTree";
                vegetation[i].Scale     = new Vector3(randScaleXZ, randScaleY, randScaleXZ);
                Vector3 center = vegetation[i].BoundingBox.calculateBoxCenter();
                float   y;
                interpoledHeight(center.X, center.Z, out y);
                center.Y = y;
                Matrix trans = Matrix.Translation(center + new Vector3(-4f, 0, 0));
                vegetation[i].BoundingBox.transform(scale * trans);
            }

            //Creacion de la Arbustos
            this.arbustos = new List <TgcMesh>();
            TgcSceneLoader loader6 = new TgcSceneLoader();

            Arbustos = loader6.loadSceneFromFile(GuiController.Instance.AlumnoEjemplosMediaDir + "Los_Borbotones\\Mapas\\Arbustos-TgcScene.xml");

            arbustos = Arbustos.Meshes;

            for (i = 1; i < arbustos.Count; i++)
            {
                float randScaleXZ = (float)random.Next(90, 110) / 100;
                float randScaleY  = (float)random.Next(75, 125) / 100;

                arbustos[i].Effect    = windShader;
                arbustos[i].Technique = "WindTree";
                arbustos[i].setColor(Color.DarkOrange);
                arbustos[i].Scale = new Vector3(randScaleXZ, randScaleY, randScaleXZ);
            }

            //Creacion de la Tesoros
            this.tesoros = new List <TgcMesh>();
            TgcSceneLoader loader5 = new TgcSceneLoader();

            Tesoros = loader5.loadSceneFromFile(GuiController.Instance.AlumnoEjemplosMediaDir + "Los_Borbotones\\Mapas\\Tesoros-TgcScene.xml");

            tesoros        = Tesoros.Meshes;
            pointerTexture = TgcTexture.createTexture(GuiController.Instance.AlumnoEjemplosMediaDir + "Los_Borbotones\\Sprites\\TreasurePointer.png");
            initPointer();
            int k;

            for (k = 1; k < tesoros.Count; k++)
            {
                TgcSprite pointer = new TgcSprite();
                pointer.Texture = pointerTexture;
                pointer.Scaling = pointerScaling;
                pointers.Add(pointer);
            }

            //Creacion de barriles
            this.meshesBarril = new List <TgcMesh>();
            TgcSceneLoader loader4 = new TgcSceneLoader();

            Barriles = loader4.loadSceneFromFile(GuiController.Instance.AlumnoEjemplosMediaDir + "Los_Borbotones\\Mapas\\Barriles2-TgcScene.xml");
            Barriles.setMeshesEnabled(true);
            meshesBarril = Barriles.Meshes;
            int j;

            //Matrix scale = Matrix.Scaling(new Vector3(0.06f, 0.4f, 0.06f));
            for (j = 1; j < meshesBarril.Count; j++)
            {
                Barril barril = new Barril();

                meshesBarril[j].Scale = new Vector3(0.3f, 0.3f, 0.3f);
                barril.mesh           = meshesBarril[j];
                barril.Init();
                barriles.Add(barril);
                //vegetation[i].setColor(Color.SkyBlue);
                //Vector3 center = vegetation[i].BoundingBox.calculateBoxCenter();
                //float y;
                //interpoledHeight(center.X, center.Z, out y);
                //center.Y = y;
                //Matrix trans = Matrix.Translation(center + new Vector3(-4f, 0, 0));
                //vegetation[i].BoundingBox.transform(scale * trans);
            }

            //inicializamos al player
            player1.Init();

            enemies     = new List <Enemy>();
            proyectiles = new List <Proyectil>();

            ScreenWidth  = GuiController.Instance.D3dDevice.Viewport.Width;
            ScreenHeight = GuiController.Instance.D3dDevice.Viewport.Height;



            obstaculos = new List <TgcMesh>();
            obstaculos.AddRange(vegetation);
            obstaculos.AddRange(meshesBarril);
            obstaculos.AddRange(arbustos);

            quadTree = new Quadtree();
            quadTree.create(obstaculos, Vegetation.BoundingBox);
            quadTree.createDebugQuadtreeMeshes();

            //seteamos niebla
            //d3dDevice.RenderState.FogTableMode = FogMode.Linear;
            d3dDevice.RenderState.FogTableMode  = FogMode.Exp2;
            d3dDevice.RenderState.FogVertexMode = FogMode.None;
            d3dDevice.RenderState.FogColor      = Color.MediumPurple;
            //d3dDevice.RenderState.FogStart = 3000f;
            //d3dDevice.RenderState.FogEnd = farplane;
            d3dDevice.RenderState.FogDensity = 0.00006f;
            d3dDevice.RenderState.FogEnable  = true;

            initPastos();

            int   secuense = 0;
            int   part     = 0;
            Pasto pasto    = new Pasto();

            foreach (Vector3 pastoCoord in pastosCoords)
            {
                pasto.crearPasto(d3dDevice, secuense, pastoCoord);
                if (part == 5)
                {
                    pastos.Add(pasto);
                    pasto = new Pasto();
                }
                secuense++;
                part++;
                if (secuense > 2)
                {
                    secuense = 0;
                }
                if (part > 5)
                {
                    part = 0;
                }
            }
        }
        internal void Init()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            score = 0; //lleva el score del jugador
            capturas = 0;
            WINNER = false;

            killMultiTracker = 0;
            KILL_DELAY = 0;
            SPAWN_TIME_COUNTER = 0f;
            time = 0;

            // creo meshes de modelo para clonar y asi optimizar
            TgcSceneLoader loader2 = new TgcSceneLoader();
            TgcScene scene = loader2.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir + "ModelosTgc\\Robot\\Robot-TgcScene.xml");
            this.ModeloRobot = scene.Meshes[0];
            TgcScene scene2 = loader2.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir + "MeshCreator\\Meshes\\Vehiculos\\StarWars-Speeder\\StarWars-Speeder-TgcScene.xml");
            this.ModeloNave = scene2.Meshes[0];
            TgcScene scene3 = loader2.loadSceneFromFile(GuiController.Instance.AlumnoEjemplosMediaDir + "Los_Borbotones\\Meshes\\proyectiles\\EnergyBall-TgcScene.xml");
            this.ModeloProyectil = scene3.Meshes[0];

            //Cargar textura de CubeMap para Environment Map
            cubeMap = TextureLoader.FromCubeFile(d3dDevice, GuiController.Instance.AlumnoEjemplosMediaDir + "Los_Borbotones\\Shaders\\CubemapRobot.dds");

            //Cargar Shader de DynamicLights
            envMap = TgcShaders.loadEffect(GuiController.Instance.ExamplesMediaDir + "Shaders\\EnvironmentMap.fx");
            envMap.Technique = "SimpleEnvironmentMapTechnique";

            skeletalEnvMap = TgcShaders.loadEffect(GuiController.Instance.AlumnoEjemplosMediaDir + "Los_Borbotones\\Shaders\\" + "SkeletalEnvMap.fx");

            //Creo skybox
            skyBox = new CustomSkyBox();
            skyBox.Center = new Vector3(0, 0, 0);
            float farplane = CustomFpsCamera.FAR_PLANE;
            skyBox.Size = new Vector3(farplane, farplane, farplane);

            string texturesPath = GuiController.Instance.ExamplesMediaDir + "Texturas\\Quake\\SkyBox1\\";

            skyBox.setFaceTexture(CustomSkyBox.SkyFaces.Up, texturesPath + "phobos_up.jpg");
            skyBox.setFaceTexture(CustomSkyBox.SkyFaces.Down, texturesPath + "phobos_dn.jpg");
            skyBox.setFaceTexture(CustomSkyBox.SkyFaces.Left, texturesPath + "phobos_lf.jpg");
            skyBox.setFaceTexture(CustomSkyBox.SkyFaces.Right, texturesPath + "phobos_rt.jpg");
            skyBox.setFaceTexture(CustomSkyBox.SkyFaces.Front, texturesPath + "phobos_bk.jpg");
            skyBox.setFaceTexture(CustomSkyBox.SkyFaces.Back, texturesPath + "phobos_ft.jpg");
            skyBox.updateValues();

            //Creacion del terreno
            currentHeightmap = GuiController.Instance.AlumnoEjemplosMediaDir + "Los_Borbotones\\Mapas\\" + "experimento-editando4_3.jpg";
            //Seteo de la resolucion del jpg de heightmap para la interpolacion de altura, como es cuadrado se usa una sola variable
            heightmapResolution = 800;
            textureResolution = 1600;

            Vector3 posInicial = new Vector3(0, 0, 0);
            currentTexture = GuiController.Instance.AlumnoEjemplosMediaDir + "Los_Borbotones\\Mapas\\" + "grunge.jpg";
            terrain = new CustomTerrain();
            terrain.loadHeightmap(currentHeightmap, currentScaleXZ, currentScaleY, posInicial, cantidadFilasColumnas);
            terrain.loadTexture(currentTexture);
            terrain.Effect = TgcShaders.loadEffect(GuiController.Instance.AlumnoEjemplosMediaDir + "Los_Borbotones\\Shaders\\RenderTerrain.fx");
            terrain.Technique = "RenderTerrain";

            //Creacion del shader de viento
            windShader = TgcShaders.loadEffect(GuiController.Instance.AlumnoEjemplosMediaDir + "Los_Borbotones\\Shaders\\WindTree.fx");

            //Creacion de la Vegetacion
            this.vegetation = new List<TgcMesh>();
            TgcSceneLoader loader = new TgcSceneLoader();
            Vegetation = loader.loadSceneFromFile(GuiController.Instance.AlumnoEjemplosMediaDir + "Los_Borbotones\\Mapas\\100x8 v4-TgcScene.xml");

            vegetation = Vegetation.Meshes;
            int i;
            for (i = 1; i < vegetation.Count; i++)
            {
                float randScaleXZ = (float)random.Next(85, 115) / 100;
                float randScaleY = (float)random.Next(70, 130) / 100;
                Matrix scale = Matrix.Scaling(new Vector3(0.06f * randScaleXZ, 0.4f * randScaleY, 0.06f * randScaleXZ));

                vegetation[i].setColor(Color.Purple);
                vegetation[i].Effect = windShader;
                vegetation[i].Technique = "WindTree";
                vegetation[i].Scale = new Vector3(randScaleXZ, randScaleY, randScaleXZ);
                Vector3 center = vegetation[i].BoundingBox.calculateBoxCenter();
                float y;
                interpoledHeight(center.X, center.Z, out y);
                center.Y = y;
                Matrix trans = Matrix.Translation(center + new Vector3(-4f, 0, 0));
                vegetation[i].BoundingBox.transform(scale * trans);
            }

            //Creacion de la Arbustos
            this.arbustos = new List<TgcMesh>();
            TgcSceneLoader loader6 = new TgcSceneLoader();
            Arbustos = loader6.loadSceneFromFile(GuiController.Instance.AlumnoEjemplosMediaDir + "Los_Borbotones\\Mapas\\Arbustos-TgcScene.xml");

            arbustos = Arbustos.Meshes;

            for (i = 1; i < arbustos.Count; i++)
            {
                float randScaleXZ = (float)random.Next(90, 110) / 100;
                float randScaleY = (float)random.Next(75, 125) / 100;

                arbustos[i].Effect = windShader;
                arbustos[i].Technique = "WindTree";
                arbustos[i].setColor(Color.DarkOrange);
                arbustos[i].Scale = new Vector3(randScaleXZ, randScaleY, randScaleXZ);
            }

            //Creacion de la Tesoros
            this.tesoros = new List<TgcMesh>();
            TgcSceneLoader loader5 = new TgcSceneLoader();
            Tesoros = loader5.loadSceneFromFile(GuiController.Instance.AlumnoEjemplosMediaDir + "Los_Borbotones\\Mapas\\Tesoros-TgcScene.xml");

            tesoros = Tesoros.Meshes;
            pointerTexture = TgcTexture.createTexture(GuiController.Instance.AlumnoEjemplosMediaDir + "Los_Borbotones\\Sprites\\TreasurePointer.png");
            initPointer();
            int k;
            for (k = 1; k < tesoros.Count; k++)
            {
                TgcSprite pointer = new TgcSprite();
                pointer.Texture = pointerTexture;
                pointer.Scaling = pointerScaling;
                pointers.Add(pointer);
            }

                //Creacion de barriles
                this.meshesBarril = new List<TgcMesh>();
            TgcSceneLoader loader4 = new TgcSceneLoader();
            Barriles = loader4.loadSceneFromFile(GuiController.Instance.AlumnoEjemplosMediaDir + "Los_Borbotones\\Mapas\\Barriles2-TgcScene.xml");
            Barriles.setMeshesEnabled(true);
            meshesBarril = Barriles.Meshes;
            int j;
            //Matrix scale = Matrix.Scaling(new Vector3(0.06f, 0.4f, 0.06f));
            for (j = 1; j < meshesBarril.Count; j++)
            {
                Barril barril = new Barril();

                meshesBarril[j].Scale = new Vector3(0.3f, 0.3f, 0.3f);
                barril.mesh = meshesBarril[j];
                barril.Init();
                barriles.Add(barril);
                //vegetation[i].setColor(Color.SkyBlue);
                //Vector3 center = vegetation[i].BoundingBox.calculateBoxCenter();
                //float y;
                //interpoledHeight(center.X, center.Z, out y);
                //center.Y = y;
                //Matrix trans = Matrix.Translation(center + new Vector3(-4f, 0, 0));
                //vegetation[i].BoundingBox.transform(scale * trans);
            }

            //inicializamos al player
            player1.Init();

            enemies = new List<Enemy>();
            proyectiles = new List<Proyectil>();

            ScreenWidth = GuiController.Instance.D3dDevice.Viewport.Width;
            ScreenHeight = GuiController.Instance.D3dDevice.Viewport.Height;

            obstaculos = new List<TgcMesh>();
            obstaculos.AddRange(vegetation);
            obstaculos.AddRange(meshesBarril);
            obstaculos.AddRange(arbustos);

            quadTree = new Quadtree();
            quadTree.create(obstaculos, Vegetation.BoundingBox);
            quadTree.createDebugQuadtreeMeshes();

            //seteamos niebla
            //d3dDevice.RenderState.FogTableMode = FogMode.Linear;
            d3dDevice.RenderState.FogTableMode = FogMode.Exp2;
            d3dDevice.RenderState.FogVertexMode = FogMode.None;
            d3dDevice.RenderState.FogColor = Color.MediumPurple;
            //d3dDevice.RenderState.FogStart = 3000f;
            //d3dDevice.RenderState.FogEnd = farplane;
            d3dDevice.RenderState.FogDensity = 0.00006f;
            d3dDevice.RenderState.FogEnable = true;

            initPastos();

            int secuense = 0;
            int part = 0;
            Pasto pasto = new Pasto();
            foreach (Vector3 pastoCoord in pastosCoords)
            {
                pasto.crearPasto(d3dDevice, secuense, pastoCoord);
                if (part == 5)
                {
                    pastos.Add(pasto);
                    pasto = new Pasto();
                }
                secuense++;
                part++;
                if (secuense > 2) secuense = 0;
                if (part > 5) part = 0;
            }
        }