Esempio n. 1
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;
        }
Esempio n. 2
0
        public void update(float dt, C_Hoja[] hojas, C_Earth the_earth, C_Earth the_earth2, C_Water water, TgcSkyBox skyBox)
        {
            time += dt;
            TgcD3dInput d3dInput = GuiController.Instance.D3dInput;

            //gravedad (si no estoy en contacto con algo, caer)
            if (glued == null)
            {
                playMove.Y -= 30f * dt;
            }
            else
            {
                playMove.Y = 0;
            }
            //si estoy en el suelo y BARRA ESPACIADORA => Saltar
            if (move_able & d3dInput.keyDown(Key.Space) && (glued != null))
            {
                playMove.Y = 30f;
                sound_b.render();
            }
            //M => Bolquear movimiento
            if (d3dInput.keyDown(Key.M))
            {
                move_able = !move_able;
            }

            //calcular movimiento hacia adelante y costado
            float moveForward = 0f;
            float moveLateral = 0f;

            if (move_able & d3dInput.keyDown(Key.W))
            {
                moveForward = 1f;
            }
            if (move_able & d3dInput.keyDown(Key.S))
            {
                moveForward = -1f;
            }
            if (move_able & d3dInput.keyDown(Key.A))
            {
                moveLateral = 1f;
            }
            if (move_able & d3dInput.keyDown(Key.D))
            {
                moveLateral = -1f;
            }

            //rotar camara
            rotation = 0;
            if (d3dInput.keyDown(Key.Q))
            {
                rotation = 1;
            }
            if (d3dInput.keyDown(Key.E))
            {
                rotation = -1;
            }

            //calcular vectores de movimiento, basado en camara
            playMove.X = playMove.Z = 0f;
            if (moveLateral != 0 | moveForward != 0)
            {
                Vector3 camDir = GuiController.Instance.CurrentCamera.getLookAt() - GuiController.Instance.CurrentCamera.getPosition();
                camDir.Y = 0;
                Vector3 moveDir = Vector3.Normalize(camDir);
                playMove.X = moveDir.X * moveForward - moveDir.Z * moveLateral;
                playMove.Z = moveDir.Z * moveForward + moveDir.X * moveLateral;
                //"normalizar" para tener velocidad maxima
                float modXZ = (float)Math.Sqrt(playMove.X * playMove.X + playMove.Z * playMove.Z);
                playMove.X = playMove.X * 75f / modXZ;
                playMove.Z = playMove.Z * 75f / modXZ;
            }

            //si esta en contacto con una hoja, moverse con ella
            if (glued != null)
            {
                if (glued.id == 'h')
                {
                    C_Hoja h = (C_Hoja)glued;
                    playMove += h.vel;
                }
            }
            Vector3 old_pos = pos;

            pos += playMove * dt;
            mesh.BoundingBox.move(playMove * dt);

            bool collide = false;

            TgcCollisionUtils.BoxBoxResult result;

            //si choca contra una cara del skybox, frenarla
            foreach (TgcMesh face in skyBox.Faces)
            {
                result = TgcCollisionUtils.classifyBoxBox(mesh.BoundingBox, face.BoundingBox);
                if (result == TgcCollisionUtils.BoxBoxResult.Adentro || result == TgcCollisionUtils.BoxBoxResult.Atravesando)
                {
                    collide = true;
                    break;
                }
            }
            if (collide)
            {
                Vector3 dif = old_pos - pos;
                dif.Y = 0f;
                pos  += dif;
                mesh.BoundingBox.move(dif);
            }


            //cuando esta muriendo, si deja de estar en contacto con agua (la termino de atravesar) resetear
            if (dieing)
            {
                result = TgcCollisionUtils.classifyBoxBox(mesh.BoundingBox, water.BoundingBox());
                if (result == TgcCollisionUtils.BoxBoxResult.Atravesando)
                {
                    sound_c.render();
                }
                if (result != TgcCollisionUtils.BoxBoxResult.Adentro && result != TgcCollisionUtils.BoxBoxResult.Atravesando)
                {
                    reset(the_earth);
                }
                return;
            }


            //chequear si sihue en contacto con el objeto con el que estaba en contacto
            if (glued != null)
            {
                result = TgcCollisionUtils.BoxBoxResult.Afuera;
                if (glued.id == 'e')
                {
                    C_Earth e = (C_Earth)glued;
                    result = TgcCollisionUtils.classifyBoxBox(mesh.BoundingBox, e.BoundingBox());
                }
                else if (glued.id == 'h')
                {
                    C_Hoja h = (C_Hoja)glued;
                    result = TgcCollisionUtils.classifyBoxBox(mesh.BoundingBox, h.BoundingBox());
                }
                else if (glued.id == 'w')
                {
                    C_Water w = (C_Water)glued;
                    result = TgcCollisionUtils.classifyBoxBox(mesh.BoundingBox, w.BoundingBox());
                }

                if (result == TgcCollisionUtils.BoxBoxResult.Encerrando || result == TgcCollisionUtils.BoxBoxResult.Adentro || result == TgcCollisionUtils.BoxBoxResult.Atravesando)
                {
                    return;
                }
                glued = null;
            }

            //colisionar con hojas
            foreach (C_Hoja x in hojas)
            {
                result = TgcCollisionUtils.classifyBoxBox(mesh.BoundingBox, x.BoundingBox());
                if (result == TgcCollisionUtils.BoxBoxResult.Adentro || result == TgcCollisionUtils.BoxBoxResult.Atravesando)
                {
                    glued = x;
                    return;
                }
            }
            //colisionar con la tierra
            result = TgcCollisionUtils.classifyBoxBox(mesh.BoundingBox, the_earth.BoundingBox());
            if (result == TgcCollisionUtils.BoxBoxResult.Adentro || result == TgcCollisionUtils.BoxBoxResult.Atravesando)
            {
                glued = the_earth;
                return;
            }
            //colisionar con la otra tierra
            result = TgcCollisionUtils.classifyBoxBox(mesh.BoundingBox, the_earth2.BoundingBox());
            if (result == TgcCollisionUtils.BoxBoxResult.Adentro || result == TgcCollisionUtils.BoxBoxResult.Atravesando)
            {
                glued = the_earth2;
                return;
            }
            //colisionar con agua
            result = TgcCollisionUtils.classifyBoxBox(mesh.BoundingBox, water.BoundingBox());
            if (result == TgcCollisionUtils.BoxBoxResult.Adentro || result == TgcCollisionUtils.BoxBoxResult.Atravesando)
            {
                dieing = true;
            }
            return;
        }