Пример #1
0
        public override void init()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

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

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

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

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

            //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 + "phobos_bk.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Back, texturesPath + "phobos_ft.jpg");



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

            GuiController.Instance.FpsCamera.Enable = true;
        }
Пример #2
0
        public override void init()
        {
            Microsoft.DirectX.Direct3D.Device d3dDevice = GuiController.Instance.D3dDevice;

            setConfigVars();

            //Cargar escenario específico para este ejemplo
            TgcSceneLoader loader = new TgcSceneLoader();

            escenario = loader.loadSceneFromFile(GuiController.Instance.ExamplesDir + "\\Collision\\SphereCollision\\PatioDeJuegos\\PatioDeJuegos-TgcScene.xml");

            //Configurar camara en Tercer Persona
            camara        = new Camara();
            camara.Enable = true;

            camara.TargetDisplacement = new Vector3(0, 100, 0);

            movimientoController = new MovimientoController(camara);

            camara.setCamera(movimientoController.getPersonaje().Position, 100, -400);

            //Almacenar volumenes de colision del escenario
            objetosColisionables.Clear();
            foreach (TgcMesh mesh in escenario.Meshes)
            {
                objetosColisionables.Add(mesh.BoundingBox);
            }

            movimientoController.setObjetosColisionables(objetosColisionables);

            //Crear SkyBox
            skyBox        = new TgcSkyBox();
            skyBox.Center = new Vector3(0, 0, 0);
            skyBox.Size   = new Vector3(10000, 10000, 10000);
            string texturesPath = GuiController.Instance.ExamplesMediaDir + "Texturas\\Quake\\SkyBox3\\";

            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Up, texturesPath + "Up.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Down, texturesPath + "Down.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Left, texturesPath + "Left.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Right, texturesPath + "Right.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Front, texturesPath + "Back.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Back, texturesPath + "Front.jpg");
            skyBox.updateValues();


            //Modifier para ver BoundingBox
            GuiController.Instance.Modifiers.addBoolean("showBoundingBox", "Bouding Box", verLasEsferas);

            //Modifiers para desplazamiento del personaje
            GuiController.Instance.Modifiers.addFloat("VelocidadCaminar", 0, 100, 5);
            GuiController.Instance.Modifiers.addFloat("VelocidadRotacion", 1f, 360f, 150f);
            GuiController.Instance.Modifiers.addBoolean("HabilitarGravedad", "Habilitar Gravedad", true);
            GuiController.Instance.Modifiers.addVertex3f("Gravedad", new Vector3(-50, -50, -50), new Vector3(50, 50, 50), new Vector3(0, -10, 0));
            GuiController.Instance.Modifiers.addFloat("SlideFactor", 1f, 2f, 1.3f);

            GuiController.Instance.UserVars.addVar("Movement");
        }
Пример #3
0
 public PirateSkyBox()
 {
     skyBox        = new TgcSkyBox();
     skyBox.Center = new Vector3(0, 2000, 0);
     skyBox.Size   = new Vector3(10000, 5000, 10000);
     cargarTexturas();
     estaLloviendo     = false;
     skyBox.SkyEpsilon = 9f; //para que no se noten las aristas del box
     skyBox.updateValues();
 }
Пример #4
0
        public void update(Vector3 Center)
        {
            if (Center != skyBox.Center)
            {
                skyBox.Center = Center;
                skyBox.updateValues();
            }

            bool llueve = (Boolean)GuiController.Instance.Modifiers["lluvia"];

            if (llueve && !estaLloviendo)  //se largó
            {
                cargarTexturasNublado();
                estaLloviendo = true;
            }
            if (!llueve && estaLloviendo)  //paró
            {
                cargarTexturas();
                skyBox.updateValues();
                estaLloviendo = false;
            }
        }
Пример #5
0
        public void skyboxTormentoso(TgcSkyBox skyBox)
        {
            string texturesPath = GuiController.Instance.AlumnoEjemplosMediaDir + "grave\\";

            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Up, texturesPath + "grave_top.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Down, texturesPath + "grave_top.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Left, texturesPath + "grave_left.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Right, texturesPath + "grave_right.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Front, texturesPath + "grave_front.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Back, texturesPath + "grave_back.jpg");
            skyBox.SkyEpsilon = 50f;
            skyBox.updateValues();
        }
Пример #6
0
        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);
        }
Пример #7
0
        public Escenario()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            skyBox        = new TgcSkyBox();
            skyBox.Center = new Vector3(0, -20, 0);
            skyBox.Size   = new Vector3(50, 100, 50);
            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();
        }
Пример #8
0
        public override void init()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            //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();


            //Cargar escenario de Isla
            TgcSceneLoader loader = new TgcSceneLoader();
            TgcScene       scene  = loader.loadSceneFromFile(GuiController.Instance.ExamplesDir + "Optimizacion\\Isla\\Isla-TgcScene.xml");

            //Separar el Terreno del resto de los objetos
            List <TgcMesh> list1 = new List <TgcMesh>();

            scene.separeteMeshList(new string[] { "Terreno" }, out list1, out objetosIsla);
            terreno = list1[0];

            //Crear grilla
            grilla = new GrillaRegular();
            grilla.create(objetosIsla, scene.BoundingBox);
            grilla.createDebugMeshes();


            //Camara en 1ra persona
            GuiController.Instance.FpsCamera.Enable = true;
            GuiController.Instance.FpsCamera.setCamera(new Vector3(1500, 800, 0), new Vector3(0, 0, -1));
            GuiController.Instance.FpsCamera.MovementSpeed = 500f;
            GuiController.Instance.FpsCamera.JumpSpeed     = 500f;

            GuiController.Instance.Modifiers.addBoolean("showGrid", "Show Grid", false);
            GuiController.Instance.Modifiers.addBoolean("showTerrain", "Show Terrain", true);
        }
Пример #9
0
        private void crearSkyBoxNoche()
        {
            // Crear SkyBox:
            skyBox        = new TgcSkyBox();
            skyBox.Center = new Vector3(0, 0, 0);
            skyBox.Size   = new Vector3(LIMITEX_SBOX, LIMITEY_SBOX, LIMITEZ_SBOX);

            /*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.Front, texturesPath + "lostatseaday_lf.jpg");
             * skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Back, texturesPath + "lostatseaday_bk.jpg");
             * skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Right, texturesPath + "lostatseaday_rt.jpg");
             * skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Left, texturesPath + "lostatseaday_ft.jpg");*/

            //string texturesPath = GuiController.Instance.ExamplesMediaDir + "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.Front, texturesPath + "lun4_lf.jpg");
            //skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Back, texturesPath + "lun4_bk.jpg");
            //skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Right, texturesPath + "lun4_rt.jpg");
            //skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Left, texturesPath + "lun4_ft.jpg");

            /*string texturesPath = GuiController.Instance.AlumnoEjemplosMediaDir + "Dunedains\\Texturas\\";
             * skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Up, texturesPath + "nublado.jpg");
             * skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Down, texturesPath + "lostatseaday_dn.jpg");
             * skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Front, texturesPath + "noche.jpg");
             * skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Back, texturesPath + "nublado.jpg");
             * skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Right, texturesPath + "nublado.jpg");
             * skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Left, texturesPath + "nublado.jpg");*/

            string texturesPath = GuiController.Instance.AlumnoEjemplosMediaDir + "Dunedains\\Texturas\\Skybox\\";

            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Up, texturesPath + "dune3_up.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Down, texturesPath + "dune3_dn.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Front, texturesPath + "dune3_ft.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Back, texturesPath + "dune3_bk.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Right, texturesPath + "dune3_rt.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Left, texturesPath + "dune3_lt.jpg");

            skyBox.SkyEpsilon = 50f;
            skyBox.updateValues();
        }
Пример #10
0
        private void crearSkyBoxDia()
        {
            // Crear SkyBox:
            skyBox        = new TgcSkyBox();
            skyBox.Center = new Vector3(0, 0, 0);
            skyBox.Size   = new Vector3(LIMITEX_SBOX, LIMITEY_SBOX, LIMITEZ_SBOX);

            string texturesPath = GuiController.Instance.AlumnoEjemplosMediaDir + "Dunedains\\Texturas\\Skybox\\";

            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Up, texturesPath + "dune2_up.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Down, texturesPath + "dune2_dn.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Front, texturesPath + "dune2_ft.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Back, texturesPath + "dune2_bk.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Right, texturesPath + "dune2_rt.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Left, texturesPath + "dune2_lt.jpg");

            skyBox.SkyEpsilon = 50f;
            skyBox.updateValues();
        }
Пример #11
0
        public override void init()
        {
            Microsoft.DirectX.Direct3D.Device d3dDevice = GuiController.Instance.D3dDevice;


            //Cargar escenario específico para este ejemplo
            TgcSceneLoader loader = new TgcSceneLoader();

            escenario = loader.loadSceneFromFile(GuiController.Instance.ExamplesDir + "\\Collision\\SphereCollision\\PatioDeJuegos\\PatioDeJuegos-TgcScene.xml");


            //Cargar personaje con animaciones
            TgcSkeletalLoader skeletalLoader = new TgcSkeletalLoader();

            personaje = skeletalLoader.loadMeshAndAnimationsFromFile(
                GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\Robot\\" + "Robot-TgcSkeletalMesh.xml",
                GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\Robot\\",
                new string[] {
                GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\Robot\\" + "Caminando-TgcSkeletalAnim.xml",
                GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\Robot\\" + "Parado-TgcSkeletalAnim.xml",
            });

            //Le cambiamos la textura para diferenciarlo un poco
            personaje.changeDiffuseMaps(new TgcTexture[] { TgcTexture.createTexture(d3dDevice, GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\Robot\\Textures\\" + "uvwGreen.jpg") });

            //Configurar animacion inicial
            personaje.playAnimation("Parado", true);
            //Escalarlo porque es muy grande
            personaje.Position = new Vector3(0, 500, -100);
            //Rotarlo 180° porque esta mirando para el otro lado
            personaje.rotateY(Geometry.DegreeToRadian(180f));


            //BoundingSphere que va a usar el personaje
            personaje.AutoUpdateBoundingBox = false;
            characterSphere = new TgcBoundingSphere(personaje.BoundingBox.calculateBoxCenter(), personaje.BoundingBox.calculateBoxRadius());


            //Almacenar volumenes de colision del escenario
            objetosColisionables.Clear();
            foreach (TgcMesh mesh in escenario.Meshes)
            {
                objetosColisionables.Add(mesh.BoundingBox);
            }


            //Crear linea para mostrar la direccion del movimiento del personaje
            directionArrow           = new TgcArrow();
            directionArrow.BodyColor = Color.Red;
            directionArrow.HeadColor = Color.Green;
            directionArrow.Thickness = 1;
            directionArrow.HeadSize  = new Vector2(10, 20);

            //Crear manejador de colisiones
            collisionManager = new SphereCollisionManager();
            collisionManager.GravityEnabled = true;


            //Configurar camara en Tercer Persona
            GuiController.Instance.ThirdPersonCamera.Enable = true;
            GuiController.Instance.ThirdPersonCamera.setCamera(personaje.Position, 100, -400);
            GuiController.Instance.ThirdPersonCamera.TargetDisplacement = new Vector3(0, 100, 0);

            //Crear SkyBox
            skyBox        = new TgcSkyBox();
            skyBox.Center = new Vector3(0, 0, 0);
            skyBox.Size   = new Vector3(10000, 10000, 10000);
            string texturesPath = GuiController.Instance.ExamplesMediaDir + "Texturas\\Quake\\SkyBox3\\";

            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Up, texturesPath + "Up.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Down, texturesPath + "Down.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Left, texturesPath + "Left.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Right, texturesPath + "Right.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Front, texturesPath + "Back.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Back, texturesPath + "Front.jpg");
            skyBox.updateValues();


            //Modifier para ver BoundingBox
            GuiController.Instance.Modifiers.addBoolean("showBoundingBox", "Bouding Box", true);

            //Modifiers para desplazamiento del personaje
            GuiController.Instance.Modifiers.addFloat("VelocidadCaminar", 0, 100, 16);
            GuiController.Instance.Modifiers.addFloat("VelocidadRotacion", 1f, 360f, 150f);
            GuiController.Instance.Modifiers.addBoolean("HabilitarGravedad", "Habilitar Gravedad", true);
            GuiController.Instance.Modifiers.addVertex3f("Gravedad", new Vector3(-50, -50, -50), new Vector3(50, 50, 50), new Vector3(0, -10, 0));
            GuiController.Instance.Modifiers.addFloat("SlideFactor", 1f, 2f, 1.3f);

            GuiController.Instance.UserVars.addVar("Movement");
        }
Пример #12
0
        public PlayScene()
        {
            string mediaDir         = GuiController.Instance.AlumnoEjemplosMediaDir;
            string examplesMediaDir = GuiController.Instance.ExamplesMediaDir;

            TgcTexture pisoTexture = TgcTexture.createTexture(GuiController.Instance.D3dDevice,
                                                              mediaDir + "CEGA\\Textures\\Grass.jpg");

            suelo = TgcBox.fromSize(new Vector3(1300, 0, 1300), new Vector3(2800, 0, 2800), pisoTexture);


            heightMap = new SimpleTerrain();

            heightMap.loadHeightmap(GuiController.Instance.AlumnoEjemplosMediaDir + "CEGA\\Heightmap\\" + "hmap4.jpg", 26, 0.4f, new Vector3(52, 0, 48));
            heightMap.loadTexture(GuiController.Instance.AlumnoEjemplosMediaDir + "CEGA\\Textures\\" + "Pasto2.jpg");


            treeWindEffect = TgcShaders.loadEffect(
                GuiController.Instance.AlumnoEjemplosMediaDir + "CEGA\\Shaders\\TreeWind.fx");

            TgcSceneLoader loader       = new TgcSceneLoader();
            TgcScene       scene        = loader.loadSceneFromFile(mediaDir + "CEGA\\Pino-TgcScene.xml");
            TgcMesh        pinoOriginal = scene.Meshes[0];

            scene = loader.loadSceneFromFile(mediaDir + "CEGA\\BarrilPolvora-TgcScene.xml");
            TgcMesh barrilOriginal = scene.Meshes[0];

            scene         = loader.loadSceneFromFile(mediaDir + "CEGA\\Pasto3-TgcScene.xml");
            pastoOriginal = scene.Meshes[0];

            //Crear varias instancias del modelo original, pero sin volver a cargar el modelo entero cada vez, hace 23*23 = 529 pinos
            int rows = 22;
            int cols = 22;

            Random RandomPlayScene = new Random(10);

            int offset = RandomPlayScene.Next(100);

            otrosObjetos = new List <TgcMesh>();

            for (int i = 1; i <= rows; i++)
            {
                for (int j = 1; j <= cols; j++)
                {
                    //Randomeo el proximo offset, de esta forma nunca vamos a tener 2 escenarios iguales, si queremos evitar que se superpongan cosas hay que fijarse acá.
                    //Si les parece que quedan muy concentrados en el origen podemos separarlo en 2 For (o en 4) para que no se peguen tanto cuando i=1 y j=1.

                    offset = RandomPlayScene.Next(50, 150);
                    scale  = RandomPlayScene.Next(10, 30);

                    //Me fijo que quede dentro de los limites del mapa

                    if (i * offset > 2600 || j * offset > 2600)
                    {
                        offset = RandomPlayScene.Next(10, 100);
                    }

                    //Crear instancia de modelo
                    //  Barriles
                    if (i == 21)
                    {
                        TgcMesh BarrilInstance = barrilOriginal.createMeshInstance(barrilOriginal.Name + i + j);
                        BarrilInstance.move(j * offset, 0, i * offset);
                        BarrilInstance.AlphaBlendEnable = true;
                        BarrilInstance.Scale            = new Vector3(0.09f, 0.09f, 0.09f);

                        // gana algunos fps
                        BarrilInstance.AutoTransformEnable = false;
                        BarrilInstance.Transform           =
                            Matrix.Scaling(BarrilInstance.Scale) *
                            Matrix.Translation(BarrilInstance.Position);

                        BarrilInstance.UserProperties = new Dictionary <string, string>();
                        BarrilInstance.UserProperties["colisionable"] = "";

                        otrosObjetos.Add(BarrilInstance);
                    }

                    //  Pinos
                    //

                    TgcMesh instance = pinoOriginal.createMeshInstance(pinoOriginal.Name + i + "_" + j);

                    instance.AlphaBlendEnable = true;
                    instance.Position         = new Vector3(i * offset, 0, j * offset);
                    instance.Scale            = new Vector3(0.05f * (scale), 0.05f * (scale), 0.05f * (scale));

                    // gana algunos fps
                    instance.AutoTransformEnable = false;
                    instance.Transform           =
                        Matrix.Scaling(instance.Scale) *
                        Matrix.Translation(instance.Position);

                    instance.UserProperties = new Dictionary <string, string>();
                    instance.UserProperties["colisionable"] = "";

                    //Modifico el BB del arbol para que sea solo el tronco
                    instance.AutoUpdateBoundingBox = false;
                    instance.BoundingBox.scaleTranslate(instance.Position, new Vector3(0.0012f * instance.BoundingBox.calculateSize().X, 0.0016f * instance.BoundingBox.calculateSize().Y, 0.0012f * instance.BoundingBox.calculateSize().Z));
                    //Effecto de Viento (Shader);
                    instance.Effect    = treeWindEffect;
                    instance.Technique = "SimpleWindTree";
                    //Agrego a la coleccion
                    otrosObjetos.Add(instance);

                    //  Bancos de Pasto

                    if (j == 20)
                    {
                        generarBancoPasto(otrosObjetos, new Vector3(j * offset, 0, i * offset), RandomPlayScene);
                    }
                }
            }

            //Sky Box

            string texturesPath = mediaDir + "CEGA\\Skyboxes\\SkyBox4\\";

            //Creo el SkyBox
            skyBox        = new TgcSkyBox();
            skyBox.Center = new Vector3(1300, 250, 1300);
            skyBox.Size   = new Vector3(4000, 1500, 4000);

            //Cargo las texturas de las caras, (algunas no tienen "down" así que uso TOP, por que igual no se debería ver en nuestro caso)
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Up, texturesPath + "top.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Down, texturesPath + "top.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Left, texturesPath + "left.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Right, texturesPath + "right.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Front, texturesPath + "front.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Back, texturesPath + "back.jpg");

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

            sound_WindLong = new TgcStaticSound();
            sound_WindLong.loadSound(mediaDir + @"CEGA\Sound\viento_largo.wav", -2000);

            sound_WindMedium = new TgcStaticSound();
            sound_WindMedium.loadSound(mediaDir + @"CEGA\Sound\viento_medio.wav", -2000);

            sound_WindLeaves = new TgcStaticSound();
            sound_WindLeaves.loadSound(examplesMediaDir + @"\Sound\viento en arbustos.wav", -2000);

            sound_music = new TgcStaticSound();
            sound_music.loadSound(mediaDir + @"CEGA\Sound\rabbia.wav", -2000);
            sound_music.play(true);

            //Crear Grilla
            grilla = new GrillaRegular();
            grilla.create(otrosObjetos, heightMap.BoundingBox);
            grilla.createDebugMeshes();
        }
Пример #13
0
        public override void init()
        {
            Microsoft.DirectX.Direct3D.Device d3dDevice = GuiController.Instance.D3dDevice;


            //Cargar escenario específico para este ejemplo. Este escenario tiene dos layers: objetos normales y objetos con colisión a nivel de triángulo.
            //La colisión a nivel de triángulos es costosa. Solo debe utilizarse para objetos puntuales (como el piso). Y es recomendable dividirlo en varios
            //meshes (y no hacer un único piso que ocupe todo el escenario)
            TgcSceneLoader loader = new TgcSceneLoader();

            escenario = loader.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir + "\\MeshCreator\\Scenes\\Mountains\\Mountains-TgcScene.xml");


            //Cargar personaje con animaciones
            TgcSkeletalLoader skeletalLoader = new TgcSkeletalLoader();

            personaje = skeletalLoader.loadMeshAndAnimationsFromFile(
                GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\BasicHuman\\" + "BasicHuman-TgcSkeletalMesh.xml",
                new string[] {
                GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\BasicHuman\\Animations\\" + "Walk-TgcSkeletalAnim.xml",
                GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\BasicHuman\\Animations\\" + "StandBy-TgcSkeletalAnim.xml",
                GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\BasicHuman\\Animations\\" + "Jump-TgcSkeletalAnim.xml"
            });

            //Configurar animacion inicial
            personaje.playAnimation("StandBy", true);
            //Escalarlo porque es muy grande
            personaje.Position = new Vector3(0, 1000, -150);
            //Rotarlo 180° porque esta mirando para el otro lado
            personaje.rotateY(Geometry.DegreeToRadian(180f));


            //BoundingSphere que va a usar el personaje
            personaje.AutoUpdateBoundingBox = false;
            characterElipsoid = new TgcElipsoid(personaje.BoundingBox.calculateBoxCenter() + new Vector3(0, 0, 0), new Vector3(12, 28, 12));
            jumping           = false;

            //Almacenar volumenes de colision del escenario
            objetosColisionables.Clear();
            foreach (TgcMesh mesh in escenario.Meshes)
            {
                //Los objetos del layer "TriangleCollision" son colisiones a nivel de triangulo
                if (mesh.Layer == "TriangleCollision")
                {
                    objetosColisionables.Add(TriangleMeshCollider.fromMesh(mesh));
                }
                //El resto de los objetos son colisiones de BoundingBox. Las colisiones a nivel de triangulo son muy costosas asi que deben utilizarse solo
                //donde es extremadamente necesario (por ejemplo en el piso). El resto se simplifica con un BoundingBox
                else
                {
                    objetosColisionables.Add(BoundingBoxCollider.fromBoundingBox(mesh.BoundingBox));
                }
            }

            //Crear manejador de colisiones
            collisionManager = new ElipsoidCollisionManager();
            collisionManager.GravityEnabled = true;



            //Crear linea para mostrar la direccion del movimiento del personaje
            directionArrow           = new TgcArrow();
            directionArrow.BodyColor = Color.Red;
            directionArrow.HeadColor = Color.Green;
            directionArrow.Thickness = 0.4f;
            directionArrow.HeadSize  = new Vector2(5, 10);

            //Linea para normal de colision
            collisionNormalArrow           = new TgcArrow();
            collisionNormalArrow.BodyColor = Color.Blue;
            collisionNormalArrow.HeadColor = Color.Yellow;
            collisionNormalArrow.Thickness = 0.4f;
            collisionNormalArrow.HeadSize  = new Vector2(2, 5);

            //Caja para marcar punto de colision
            collisionPoint = TgcBox.fromSize(new Vector3(4, 4, 4), Color.Red);

            //Configurar camara en Tercer Persona
            GuiController.Instance.ThirdPersonCamera.Enable = true;
            GuiController.Instance.ThirdPersonCamera.setCamera(personaje.Position, 20, -120);
            GuiController.Instance.ThirdPersonCamera.TargetDisplacement = new Vector3(0, 45, 0);

            //Crear SkyBox
            skyBox        = new TgcSkyBox();
            skyBox.Center = new Vector3(0, 0, 0);
            skyBox.Size   = new Vector3(10000, 10000, 10000);
            string texturesPath = GuiController.Instance.ExamplesMediaDir + "Texturas\\Quake\\SkyBox3\\";

            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Up, texturesPath + "Up.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Down, texturesPath + "Down.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Left, texturesPath + "Left.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Right, texturesPath + "Right.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Front, texturesPath + "Back.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Back, texturesPath + "Front.jpg");
            skyBox.updateValues();


            //Modifier para ver BoundingBox
            GuiController.Instance.Modifiers.addBoolean("Collisions", "Collisions", true);
            GuiController.Instance.Modifiers.addBoolean("showBoundingBox", "Bouding Box", true);

            //Modifiers para desplazamiento del personaje
            GuiController.Instance.Modifiers.addFloat("VelocidadCaminar", 0, 20, 2);
            GuiController.Instance.Modifiers.addFloat("VelocidadRotacion", 1f, 360f, 150f);
            GuiController.Instance.Modifiers.addBoolean("HabilitarGravedad", "Habilitar Gravedad", true);
            GuiController.Instance.Modifiers.addVertex3f("Gravedad", new Vector3(-50, -50, -50), new Vector3(50, 50, 50), new Vector3(0, -4, 0));
            GuiController.Instance.Modifiers.addFloat("SlideFactor", 0f, 2f, 1f);
            GuiController.Instance.Modifiers.addFloat("Pendiente", 0f, 1f, 0.72f);
            GuiController.Instance.Modifiers.addFloat("VelocidadSalto", 0f, 50f, 10f);
            GuiController.Instance.Modifiers.addFloat("TiempoSalto", 0f, 2f, 0.5f);


            GuiController.Instance.UserVars.addVar("Movement");
        }
Пример #14
0
        /// <summary>
        /// Método que se llama una sola vez,  al principio cuando se ejecuta el ejemplo.
        /// Escribir aquí todo el código de inicialización: cargar modelos, texturas, modifiers, uservars, etc.
        /// Borrar todo lo que no haga falta
        /// </summary>
        public override void init()
        {
            //Device de DirectX para crear primitivas
            Device d3dDevice = GuiController.Instance.D3dDevice;

            //Creacion del Skybox
            skyBox        = new TgcSkyBox();
            skyBox.Center = new Vector3(0, 0, 0);
            skyBox.Size   = new Vector3(1000, 1000, 1000);
            //Configurar las texturas para cada una de las 6 caras
            string texturesPath = GuiController.Instance.AlumnoEjemplosMediaDir + "RenderizameLaBanera\\SkyBox1\\lostatseaday_";

            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Up, texturesPath + "up.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Down, texturesPath + "dn.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Right, texturesPath + "rt.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Left, texturesPath + "lf.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.Back, texturesPath + "ft.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Front, texturesPath + "bk.jpg");
            skyBox.updateValues();


            //Creacion e iniciaizacion de hojas
            C_Hoja.init();
            hojas = new C_Hoja[3];
            for (int i = 0; i < 3; i++)
            {
                hojas[i] = new C_Hoja();
                hojas[i].reset();
            }

            //Sonido
            sound_a = new soundAmbience();
            sound_a.init();

            //Creacion e inicializacion de bloques de tierra
            earth  = new C_Earth();
            earth2 = new C_Earth();
            earth.init(300, 5, 1000);
            earth2.init(300, 5, 1000);
            earth.reset(-350, 0, 0);
            earth2.reset(350, 0, 0);

            //Agua
            water = new C_Water();
            water.init("sand2.jpg");
            water.reset();

            //Bola
            ball = new C_Ball();
            ball.init();
            ball.reset(earth);

            //Crear Textura de Enviromental Map
            g_pCubeMap = new CubeTexture(d3dDevice, 256, 1, Usage.RenderTarget,
                                         d3dDevice.GetRenderTarget(0).Description.Format, Pool.Default);


            GuiController.Instance.UserVars.addVar("posX");
            GuiController.Instance.UserVars.addVar("posY");
            GuiController.Instance.UserVars.addVar("posZ");
            GuiController.Instance.UserVars.addVar("Dying");

            GuiController.Instance.Modifiers.addFloat("xKBallBooble", 0.01f, 0.2f, 0.015f);
            GuiController.Instance.Modifiers.addFloat("xWaveLength", 0f, 2f, 1f);
            GuiController.Instance.Modifiers.addFloat("xWaveHeight", 0f, 1f, 0.3f);
            GuiController.Instance.Modifiers.addFloat("xWindForce", 0f, 1f, 0.04f);


            GuiController.Instance.Modifiers.addVertex3f("LightDir", new Vector3(-1f, -1f, -1f), new Vector3(1f, 1f, 1f), new Vector3(1f, 1f, 0f));
            GuiController.Instance.Modifiers.addBoolean("drawBoxes", "draw Bounding Boxes", false);


            ///////////////CONFIGURAR CAMARA ROTACIONAL//////////////////
            GuiController.Instance.ThirdPersonCamera.Enable = true;
            GuiController.Instance.ThirdPersonCamera.setCamera(ball.pos, 100, 200);
            //GuiController.Instance.ThirdPersonCamera.EnableSpringSystem = false;
        }
Пример #15
0
        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);
        }
Пример #16
0
        public override void init()
        {
            GuiController.Instance.CustomRenderEnabled = true;

            Device d3dDevice = GuiController.Instance.D3dDevice;

            MyMediaDir  = GuiController.Instance.ExamplesDir + "Shaders\\WorkshopShaders\\Media\\";
            MyShaderDir = GuiController.Instance.ExamplesDir + "Shaders\\WorkshopShaders\\Shaders\\";

            //Cargamos un escenario
            TgcSceneLoader loader = new TgcSceneLoader();

            TgcScene scene = loader.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir + "MeshCreator\\Scenes\\Selva\\Selva-TgcScene.xml");

            meshes = scene.Meshes;
            TgcScene scene2 = loader.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir + "MeshCreator\\Meshes\\Vegetacion\\Pasto\\Pasto-TgcScene.xml");

            pasto = scene2.Meshes[0];
            TgcScene scene3 = loader.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir + "MeshCreator\\Meshes\\Vegetacion\\ArbolSelvatico\\ArbolSelvatico-TgcScene.xml");

            arbol       = scene3.Meshes[0];
            arbol.Scale = new Vector3(1, 3, 1);
            TgcScene scene4 = loader.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir + "MeshCreator\\Meshes\\Vegetacion\\Arbusto2\\Arbusto2-TgcScene.xml");

            arbusto = scene4.Meshes[0];

            //Cargar terreno: cargar heightmap y textura de color
            terrain = new TgcSimpleTerrain();
            terrain.loadHeightmap(MyMediaDir + "Heighmaps\\" + "TerrainTexture2.jpg",
                                  20, 0.3f, new Vector3(0, -115, 0));
            terrain.loadTexture(MyMediaDir + "Heighmaps\\" + "grass.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\\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.updateValues();



            //Cargar Shader personalizado
            string compilationErrors;

            effect = Effect.FromFile(GuiController.Instance.D3dDevice,
                                     GuiController.Instance.ExamplesDir + "Shaders\\WorkshopShaders\\Shaders\\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 personas
            GuiController.Instance.FpsCamera.Enable = true;
            GuiController.Instance.FpsCamera.setCamera(new Vector3(-944.1269f, 50, -1033.307f), new Vector3(-943.6573f, 50.8481f, -1033.533f));
            GuiController.Instance.FpsCamera.MovementSpeed *= 2;
            GuiController.Instance.FpsCamera.JumpSpeed      = 600f;
            GuiController.Instance.FpsCamera.RotationSpeed *= 4;

            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);

            GuiController.Instance.Modifiers.addBoolean("activar_glow", "Activar Glow", true);
            GuiController.Instance.Modifiers.addBoolean("pantalla_completa", "Pant.completa", true);
            GuiController.Instance.Modifiers.addEnum("tm_izq", typeof(ToneMapping), ToneMapping.MiddleGray);
            GuiController.Instance.Modifiers.addEnum("tm_der", typeof(ToneMapping), ToneMapping.Nada);
            GuiController.Instance.Modifiers.addInterval("adaptacion_pupila", new object[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f }, 2);
        }
Пример #17
0
        public override void init()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            MyMediaDir  = GuiController.Instance.ExamplesDir + "Shaders\\WorkshopShaders\\Media\\";
            MyShaderDir = GuiController.Instance.ExamplesDir + "Shaders\\WorkshopShaders\\Shaders\\";

            //Crear loader
            TgcSceneLoader loader = new TgcSceneLoader();

            // ------------------------------------------------------------
            // Creo el Heightmap para el terreno:
            Vector3 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);
            string texturesPath = GuiController.Instance.ExamplesMediaDir + "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.updateValues();

            // ------------------------------------------------------------
            //Cargar los mesh:
            scene = loader.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir
                                             + "MeshCreator\\Meshes\\Vehiculos\\TanqueFuturistaRuedas\\TanqueFuturistaRuedas-TgcScene.xml");
            mesh = scene.Meshes[0];

            sceneX = loader.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir
                                              + "ModelosTgc\\Sphere\\Sphere-TgcScene.xml");
            meshX = sceneX.Meshes[0];



            scene2 = loader.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir
                                              + "MeshCreator\\Meshes\\Vegetacion\\Palmera\\Palmera-TgcScene.xml");
            palmera = scene2.Meshes[0];

            scene3 = loader.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir
                                              + "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;
            Vector3 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();
            float 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 (int j = 0; j < 15; j++)
                {
                    TgcMesh instance = palmera.createMeshInstance(palmera.Name + i);
                    instance.Scale = new Vector3(0.5f, 1.5f, 0.5f);
                    float x = r[i] * (float)Math.Cos(Geometry.DegreeToRadian(180 + 10.0f * j));
                    float 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);
                }
            }

            GuiController.Instance.RotCamera.CameraDistance = 300;
            GuiController.Instance.RotCamera.RotationSpeed  = 1.5f;

            // 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
            {
                int[] adj = new int[meshX.D3dMesh.NumberFaces * 3];
                meshX.D3dMesh.GenerateAdjacency(0, adj);
                meshX.D3dMesh.ComputeNormals(adj);
            }


            //Cargar Shader personalizado
            effect = TgcShaders.loadEffect(GuiController.Instance.ExamplesDir + "Shaders\\WorkshopShaders\\Shaders\\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
            GuiController.Instance.RotCamera.targetObject(mesh.BoundingBox);

            kx = kc = 0.5f;
            GuiController.Instance.Modifiers.addFloat("Reflexion", 0, 1, kx);
            GuiController.Instance.Modifiers.addFloat("Refraccion", 0, 1, kc);
            GuiController.Instance.Modifiers.addBoolean("Fresnel", "fresnel", true);
        }
Пример #18
0
        public void CrearEscenario()
        {
            //Modifier para variables de shader
            //GuiController.Instance.Modifiers.addVertex3f("LightPosition", new Vector3(-1000, -1000, -1000), new Vector3(1000, 1000, 1000), new Vector3(0, 400, 0));
            GuiController.Instance.Modifiers.addColor("AmbientColor", Color.White);
            GuiController.Instance.Modifiers.addColor("DiffuseColor", Color.Orange);
            GuiController.Instance.Modifiers.addColor("SpecularColor", Color.Red);
            GuiController.Instance.Modifiers.addFloat("SpecularPower", 1, 1000, 1000);
            //GuiController.Instance.Modifiers.addVertex3f("MeshPos", new Vector3(-1000, -1000, -1000), new Vector3(1000, 1000, 1000), new Vector3(0, 0, 0));

            sonido              = new Sonido();
            sonido2             = new Sonido();
            sonido.currentFile  = "Alarma.wav";
            sonido2.currentFile = "Helicoptero_2.wav";

            sonido.init();
            sonido2.init();

            camera = new CamaraTerceraPersona();



            //Cargar pilar egipcio
            TgcSceneLoader loader = new TgcSceneLoader();

            //Configurar MeshFactory customizado
            loader.MeshFactory = new CustomMeshShaderFactory();


            //****************************************************
            //Escenario Principal
            //****************************************************
            TgcSceneLoader loader10 = new TgcSceneLoader();

            //Configurar MeshFactory customizado
            loader10.MeshFactory = new CustomMeshShaderFactory();
            terreno = loader10.loadSceneFromFile(GuiController.Instance.AlumnoEjemplosMediaDir + "Blizarro\\Meshes\\PuebloJapones\\PuebloJaponesv9X-TgcScene.xml");
            //Separar el Terreno del resto de los objetos
            List <TgcMesh> list1 = new List <TgcMesh>();

            separeteMeshList(new string[] { "cesped" }, out list1, out objetosIsla);
            terrenoMesh = list1;
            //terreno.separeteMeshList
            //Crear Quadtree
            quadtree = new Quadtree();
            quadtree.create(objetosIsla, terreno.BoundingBox);
            quadtree.createDebugQuadtreeMeshes();

            //Crear caja para indicar ubicacion de la luz
            //lightBox = TgcBox.fromSize(new Vector3(50, 50, 50), Color.Yellow);


            foreach (TgcMeshShader mesh in terreno.Meshes)
            {
                //Cargar Shader de PhonhShading
                string compilationErrors;
                mesh.Effect = Effect.FromFile(d3dDevice, GuiController.Instance.AlumnoEjemplosMediaDir + "Blizarro\\Shaders\\PhongShading.fx", null, null, ShaderFlags.None, null, out compilationErrors);
                if (mesh.Effect == null)
                {
                    throw new Exception("Error al cargar shader. Errores: " + compilationErrors);
                }
                //Configurar Technique
                mesh.Effect.Technique = "DefaultTechnique";


                mesh.Effect.SetValue("fvAmbient", ColorValue.FromColor(Color.White));
                mesh.Effect.SetValue("fvDiffuse", ColorValue.FromColor(Color.Black));
                mesh.Effect.SetValue("fvSpecular", ColorValue.FromColor(Color.Black));
                mesh.Effect.SetValue("fSpecularPower", (float)GuiController.Instance.Modifiers["SpecularPower"]);
            }

            //Modifier para habilitar o deshabilitar FrustumCulling
            GuiController.Instance.Modifiers.addBoolean("culling", "Frustum culling", true);

            //UserVar para contar la cantidad de meshes que se renderizan
            GuiController.Instance.UserVars.addVar("Meshes renderizadas");

            //UserVar para contar la cantidad de meshes que se renderizan
            GuiController.Instance.UserVars.addVar("Soldados");

            //Carga fuertes enemigos



            d3dDevice.RenderState.AlphaBlendEnable = false;



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


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

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

            //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 + "phobos_bk.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Back, texturesPath + "phobos_ft.jpg");

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

            // Cargo niebla

            /* GuiController.Instance.Fog.Enabled = true;
             * GuiController.Instance.Fog.StartDistance = 5;
             * GuiController.Instance.Fog.EndDistance = 8000;
             * GuiController.Instance.Fog.Density = 0.1f;
             * GuiController.Instance.Fog.updateValues();
             */
            GuiController.Instance.Modifiers.addBoolean("showQuadtree", "Show Quadtree", false);
            GuiController.Instance.Modifiers.addBoolean("showTerrain", "Show Terrain", true);
            //GuiController.Instance.Modifiers.addBoolean("showBoundingBox", "Bouding Box", false);
        }
Пример #19
0
        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\\";

            //Cargar Shader personalizado
            string compilationErrors;

            effect = Effect.FromFile(GuiController.Instance.D3dDevice, MyShaderDir + "MotionBlur.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";

            // Cargo los modelos de edificios
            for (int i = 0; i < CANT_MODELOS; ++i)
            {
                edicios[i] = new TgcBox();
                edicios[i].setPositionSize(new Vector3(0, 0, 0), new Vector3(1, 1, 1));
                edicios[i].setTexture(TgcTexture.createTexture(MyMediaDir + "fachadas\\pared" + i + ".jpg"));
                edicios[i].AutoTransformEnable = false;
                edicios[i].Effect = effect;
                edicios[i].updateValues();
            }


            //Camara
            GuiController.Instance.FpsCamera.Enable = true;
            GuiController.Instance.BackgroundColor  = Color.Black;


            // 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);


            // velocidad del pixel
            g_pVel1 = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth
                                  , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget,
                                  Format.A16B16G16R16F, Pool.Default);
            g_pVel2 = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth
                                  , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget,
                                  Format.A16B16G16R16F, 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);

            // Creo la ruta circular
            CrearRuta();

            //Crear SkyBox
            skyBox        = new TgcSkyBox();
            skyBox.Center = new Vector3(0, -200, 0);
            skyBox.Size   = new Vector3(5000, 5000, 5000);
            string texturesPath = GuiController.Instance.ExamplesMediaDir + "Texturas\\Quake\\SkyBox4\\";

            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Up, texturesPath + "city_top.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Down, texturesPath + "city_down.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Left, texturesPath + "city_left.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Right, texturesPath + "city_right.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Front, texturesPath + "city_front.jpg");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Back, texturesPath + "city_back.jpg");
            skyBox.updateValues();

            TgcSceneLoader loader = new TgcSceneLoader();
            TgcScene       scene3 = loader.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir + "MeshCreator\\Meshes\\Vegetacion\\ArbolSelvatico\\ArbolSelvatico-TgcScene.xml");

            arbol       = scene3.Meshes[0];
            arbol.Scale = new Vector3(0.02f, 0.05f, 0.02f);


            GuiController.Instance.Modifiers.addBoolean("motion_blur", "Activar MB", true);
            GuiController.Instance.Modifiers.addBoolean("vel_map", "Mapa Velocidad", false);
            GuiController.Instance.Modifiers.addFloat("factor_blur", 0.01f, 0.5f, 0.05f);
            GuiController.Instance.Modifiers.addFloat("velocidad", 0.1f, 5f, 1.5f);
            GuiController.Instance.Modifiers.addBoolean("paused", "Pausar", false);
        }
Пример #20
0
        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);
        }
Пример #21
0
        public override void init()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            //Crear loader
            TgcSceneLoader loader = new TgcSceneLoader();


            // ------------------------------------------------------------
            // Creo el Heightmap para el terreno:
            terrain = new MySimpleTerrain();
            terrain.loadHeightmap(GuiController.Instance.ExamplesDir
                                  + "Shaders\\WorkshopShaders\\Media\\Heighmaps\\" + "Heightmap3.jpg", 100f, 1f, new Vector3(0, 0, 0));
            terrain.loadTexture(GuiController.Instance.ExamplesDir
                                + "Shaders\\WorkshopShaders\\Media\\Heighmaps\\" + "TerrainTexture3.jpg");

            // ------------------------------------------------------------
            // Crear SkyBox:
            skyBox        = new TgcSkyBox();
            skyBox.Center = new Vector3(0, 0, 0);
            skyBox.Size   = new Vector3(8000, 8000, 8000);
            string texturesPath = GuiController.Instance.ExamplesMediaDir + "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.updateValues();

            // ------------------------------------------------------------
            //Cargar los mesh:
            scene = loader.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir
                                             + "MeshCreator\\Meshes\\Vehiculos\\TanqueFuturistaRuedas\\TanqueFuturistaRuedas-TgcScene.xml");
            mesh = scene.Meshes[0];

            scene2 = loader.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir
                                              + "MeshCreator\\Meshes\\Vegetacion\\Palmera\\Palmera-TgcScene.xml");
            palmera = scene2.Meshes[0];

            scene3 = loader.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir
                                              + "MeshCreator\\Meshes\\Vehiculos\\Canoa\\Canoa-TgcScene.xml");
            canoa = scene3.Meshes[0];

            scene4 = loader.loadSceneFromFile(GuiController.Instance.ExamplesDir
                                              + "Shaders\\WorkshopShaders\\Media\\Piso\\Agua-TgcScene.xml");
            piso = scene4.Meshes[0];

            mesh.Scale               = new Vector3(0.5f, 0.5f, 0.5f);
            mesh.Position            = new Vector3(0f, 0f, 0f);
            mesh.AutoTransformEnable = false;
            Vector3 size = mesh.BoundingBox.calculateSize();

            largo_tanque              = Math.Abs(size.Z);
            alto_tanque               = Math.Abs(size.Y) * mesh.Scale.Y;
            vel_tanque                = 10;
            an_tanque                 = 0;
            canoa.Scale               = new Vector3(1f, 1f, 1f);
            canoa.Position            = new Vector3(3000f, 550f, 0f);
            canoa.AutoTransformEnable = false;
            dir_canoa                 = new Vector3(0, 0, 1);
            nivel_mar                 = 135f;
            piso.Scale                = new Vector3(25f, 1f, 25f);
            piso.Position             = new Vector3(0f, nivel_mar, 0f);

            size = palmera.BoundingBox.calculateSize();
            float alto_palmera = Math.Abs(size.Y);

            cant_palmeras = 0;
            int i;

            bosque = new List <TgcMesh>();
            float[] r = { 1850f, 2100f, 2300f, 1800f };
            for (i = 0; i < 4; i++)
            {
                for (int j = 0; j < 15; j++)
                {
                    TgcMesh instance = palmera.createMeshInstance(palmera.Name + i);
                    instance.Scale = new Vector3(0.5f, 1.5f, 0.5f);
                    float x = r[i] * (float)Math.Cos(Geometry.DegreeToRadian(100 + 10.0f * j));
                    float z = r[i] * (float)Math.Sin(Geometry.DegreeToRadian(100 + 10.0f * j));
                    instance.Position = new Vector3(x, terrain.CalcularAltura(x, z) /*+ alto_palmera / 2 * instance.Scale.Y*/, z);
                    bosque.Add(instance);
                    ++cant_palmeras;
                }
            }

            // segunda parte: la isla del medio
            // estas no entran en el env. map (porque se supone que el env. map esta lejos
            // del pto de vista del observador y estas palmeras estan en el medio del lago)
            float[] r2 = { 200f, 350f, 400f, 477f };
            for (i = 0; i < 4; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    TgcMesh instance = palmera.createMeshInstance(palmera.Name + i);
                    instance.Scale = new Vector3(0.5f, 1f + j / 5f * 0.33f, 0.5f);
                    float x = r2[i] * (float)Math.Cos(Geometry.DegreeToRadian(25.0f * j));
                    float z = r2[i] * (float)Math.Sin(Geometry.DegreeToRadian(25.0f * j));
                    instance.Position = new Vector3(x, terrain.CalcularAltura(x, z) /*+ alto_palmera / 2 * instance.Scale.Y*/, z);
                    bosque.Add(instance);
                }
            }

            GuiController.Instance.RotCamera.CameraDistance = 300;
            GuiController.Instance.RotCamera.RotationSpeed  = 1.5f;

            // Arreglo las normales del tanque

            /*int[] adj = new int[mesh.D3dMesh.NumberFaces * 3];
             * mesh.D3dMesh.GenerateAdjacency(0, adj);
             * mesh.D3dMesh.ComputeNormals(adj);
             */

            g_pCubeMapAgua = null;

            //Cargar Shader personalizado
            effect = TgcShaders.loadEffect(GuiController.Instance.ExamplesDir + "Shaders\\WorkshopShaders\\Shaders\\Demo.fx");

            // le asigno el efecto a las mallas
            mesh.Effect       = effect;
            mesh.Technique    = "RenderScene";
            piso.Effect       = effect;
            piso.Technique    = "RenderScene";
            palmera.Effect    = effect;
            palmera.Technique = "RenderScene";
            canoa.Effect      = effect;
            canoa.Technique   = "RenderScene";

            //--------------------------------------------------------------------------------------
            // Creo el shadowmap.
            // Format.R32F
            // Format.X8R8G8B8
            g_pShadowMap = new Texture(d3dDevice, SHADOWMAP_SIZE, SHADOWMAP_SIZE,
                                       1, Usage.RenderTarget, Format.R32F,
                                       Pool.Default);

            // tengo que crear un stencilbuffer para el shadowmap manualmente
            // para asegurarme que tenga la el mismo tamaño que el shadowmap, y que no tenga
            // multisample, etc etc.
            g_pDSShadow = d3dDevice.CreateDepthStencilSurface(SHADOWMAP_SIZE,
                                                              SHADOWMAP_SIZE,
                                                              DepthFormat.D24S8,
                                                              MultiSampleType.None,
                                                              0,
                                                              true);
            // por ultimo necesito una matriz de proyeccion para el shadowmap, ya
            // que voy a dibujar desde el pto de vista de la luz.
            // El angulo tiene que ser mayor a 45 para que la sombra no falle en los extremos del cono de luz
            // de hecho, un valor mayor a 90 todavia es mejor, porque hasta con 90 grados es muy dificil
            // lograr que los objetos del borde generen sombras
            Control panel3d     = GuiController.Instance.Panel3d;
            float   aspectRatio = (float)panel3d.Width / (float)panel3d.Height;

            g_mShadowProj = Matrix.PerspectiveFovLH(Geometry.DegreeToRadian(130.0f),
                                                    aspectRatio, near_plane, far_plane);
            d3dDevice.Transform.Projection =
                Matrix.PerspectiveFovLH(Geometry.DegreeToRadian(45.0f),
                                        aspectRatio, near_plane, far_plane);

            alfa_sol = 1.7f;
            //alfa_sol = 0;

            //--------------------------------------------------------------------------------------
            //Centrar camara rotacional respecto a este mesh
            camara_rot = false;
            GuiController.Instance.RotCamera.targetObject(mesh.BoundingBox);
            LookFrom = new Vector3(0, 400, 2000);
            LookAt   = new Vector3(0, 200, 0);


            // inicio unos segundos de preview
            timer_preview = 50;

            arrow           = new TgcArrow();
            arrow.Thickness = 1f;
            arrow.HeadSize  = new Vector2(2f, 2f);
            arrow.BodyColor = Color.Blue;

            ant_vista    = tipo_vista = 0;
            View1        = new Viewport();
            View1.X      = 0;
            View1.Y      = 0;
            View1.Width  = panel3d.Width;
            View1.Height = panel3d.Height / 2;
            View1.MinZ   = 0;
            View1.MaxZ   = 1;
            View2        = new Viewport();
            View2.X      = 0;
            View2.Y      = View1.Height;
            View2.Width  = panel3d.Width;
            View2.Height = panel3d.Height / 2;
            View2.MinZ   = 0;
            View2.MaxZ   = 1;

            ViewF = d3dDevice.Viewport;
        }