Beispiel #1
0
 /// <summary>
 /// Crea una caja con el centro y tamaño especificado
 /// </summary>
 /// <param name="center">Centro de la caja</param>
 /// <param name="size">Tamaño de la caja</param>
 /// <returns>Caja creada</returns>
 public static TgcBox fromSize(Vector3 center, Vector3 size)
 {
     TgcBox box = new TgcBox();
     box.setPositionSize(center, size);
     box.updateValues();
     return box;
 }
        public EscenarioManager()
        {
            EscenarioManager.Instance = this;

            sonido = SoundManager.getInstance();
            arboles = new List<TgcMesh>();
            pasto = new List<TgcMesh>();
            barriles = new List<Barril>();
            loader = new TgcSceneLoader();

            casillasPorEje = 50;
            divisionesPiso = new Vector3[2500];
            _random = new Random();

            piso = new TgcBox();
            piso.UVTiling = new Vector2(300, 300);
            pisoSize = (int) tamanio;
            piso.setPositionSize(new Vector3(0, 0, 0), new Vector3(pisoSize*2, 0, pisoSize*2));
            piso.updateValues();

            piso.setTexture(TgcTexture.createTexture(GuiController.Instance.D3dDevice, GuiController.Instance.AlumnoEjemplosMediaDir + "\\RenderMan\\texturas\\nieve.png"));

            generarSkyBox();

            colisionables = new List<TgcBoundingCylinder>();

            limites = new TgcBoundingBox(new Vector3(-tamanio, 0, -tamanio), new Vector3(tamanio, 5000, tamanio));

            GuiController.Instance.Modifiers.addInt("Viento en X", 0, 30, 5);
            GuiController.Instance.Modifiers.addInt("Viento en Z", 0, 30, 5);
        }
Beispiel #3
0
        /// <summary>
        /// Crea una caja con el centro y tamaño especificado
        /// </summary>
        /// <param name="center">Centro de la caja</param>
        /// <param name="size">Tamaño de la caja</param>
        /// <returns>Caja creada</returns>
        public static TgcBox fromSize(Vector3 center, Vector3 size)
        {
            TgcBox box = new TgcBox();

            box.setPositionSize(center, size);
            box.updateValues();
            return(box);
        }
Beispiel #4
0
        /// <summary>
        /// Crea una caja en base al punto minimo y maximo, con el color especificado
        /// </summary>
        /// <param name="pMin">Punto mínimo</param>
        /// <param name="pMax">Punto máximo</param>
        /// <param name="color">Color de la caja</param>
        /// <returns>Caja creada</returns>
        public static TgcBox fromExtremes(Vector3 pMin, Vector3 pMax, Color color)
        {
            TgcBox box = TgcBox.fromExtremes(pMin, pMax);

            box.color = color;
            box.updateValues();
            return(box);
        }
        public Wall(Vector3 position, Vector3 size){
            TgcTexture textura = TgcTexture.createTexture(TEXTURE_PATH);
            box = TgcBox.fromSize(position+new Vector3(0, size.Y/2,0), size, textura);

            box.UVTiling = new Vector2(size.X / textura.Width*3, size.Y / textura.Height*3);
            box.updateValues();

            this.position = position;
            radius = box.BoundingBox.calculateBoxRadius();

        }
Beispiel #6
0
        /// <summary>
        /// Crear un nuevo TgcBox igual a este
        /// </summary>
        /// <returns>Box clonado</returns>
        public TgcBox clone()
        {
            TgcBox cloneBox = new TgcBox();

            cloneBox.setPositionSize(this.translation, this.size);
            cloneBox.color = this.color;
            if (this.texture != null)
            {
                cloneBox.setTexture(this.texture.clone());
            }
            cloneBox.autoTransformEnable = this.autoTransformEnable;
            cloneBox.transform           = this.transform;
            cloneBox.rotation            = this.rotation;
            cloneBox.alphaBlendEnable    = this.alphaBlendEnable;
            cloneBox.uvOffset            = this.uvOffset;
            cloneBox.uvTiling            = this.uvTiling;

            cloneBox.updateValues();
            return(cloneBox);
        }
Beispiel #7
0
        public Humo(Vector3 position)
        {
            a = 255f;
            box1 = new TgcBox();
            box1.UVTiling = new Vector2(1, 1);
            box1.setPositionSize(position, new Vector3(200, 0, 200));
            box1.setTexture(getTexture());
            box1.AlphaBlendEnable = true;
            box1.updateValues();

            box2 = new TgcBox();
            box2.UVTiling = new Vector2(1, 1);
            box2.setPositionSize(position, new Vector3(200, 0, 200));
            box2.setTexture(getTexture());
            box2.AlphaBlendEnable = true;
            box2.updateValues();

            box3 = new TgcBox();
            box3.UVTiling = new Vector2(1, 1);
            box3.setPositionSize(position, new Vector3(200, 0, 200));
            box3.setTexture(getTexture());
            box3.AlphaBlendEnable = true;
            box3.updateValues();
        }
Beispiel #8
0
        /// <summary>
        /// Crear un nuevo TgcBox igual a este
        /// </summary>
        /// <returns>Box clonado</returns>
        public TgcBox clone()
        {
            TgcBox cloneBox = new TgcBox();
            cloneBox.setPositionSize(this.translation, this.size);
            cloneBox.color = this.color;
            if (this.texture != null)
            {
                cloneBox.setTexture(this.texture.clone());
            }
            cloneBox.autoTransformEnable = this.autoTransformEnable;
            cloneBox.transform = this.transform;
            cloneBox.rotation = this.rotation;
            cloneBox.alphaBlendEnable = this.alphaBlendEnable;
            cloneBox.uvOffset = this.uvOffset;
            cloneBox.uvTiling = this.uvTiling;

            cloneBox.updateValues();
            return cloneBox;
        }
        public void inicializarTerreno()
        {
            //Crear SkyBox
            skyBox = new TgcSkyBox();
            skyBox.Center = new Vector3(0, 500, 0);
            skyBox.Size = new Vector3(20000, 20000, 20000);
            string texturesPath = GuiController.Instance.AlumnoEjemplosMediaDir;//GuiController.Instance.ExamplesMediaDir + "Texturas\\Quake\\SkyBox4\\";
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Up, texturesPath + "//FullMoon//up.png");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Down, texturesPath + "//FullMoon//down.png");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Left, texturesPath + "//FullMoon//right.png");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Right, texturesPath + "//FullMoon//left.png");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Front, texturesPath + "//FullMoon//front.png");
            skyBox.setFaceTexture(TgcSkyBox.SkyFaces.Back, texturesPath + "//FullMoon//back.png");
            skyBox.SkyEpsilon = 50f;
            skyBox.updateValues();

            TgcBox tb = TgcBox.fromSize(skyBox.Center, skyBox.Size);
            bbSkyBox = tb.BoundingBox.clone();

            //Crear piso
            TgcTexture pisoTexture = TgcTexture.createTexture(d3dDevice, GuiController.Instance.AlumnoEjemplosMediaDir + "\\pasto2.jpg");
            piso = TgcBox.fromSize(new Vector3(0, 0, 0), new Vector3(20000, 0, 20000), pisoTexture);
            piso.UVTiling = new Vector2(50, 50);
            piso.updateValues();

            //crear terreno
            terreno = new TgcSimpleTerrain();
            terreno.loadHeightmap(GuiController.Instance.ExamplesMediaDir + "Heighmaps\\Heightmap1.jpg", 350f, 1.6f,new Vector3(0f,0f,0f));
            terreno.loadTexture(GuiController.Instance.AlumnoEjemplosMediaDir + "\\pasto2.jpg");
        }
Beispiel #10
0
        public Game()
        {
            Fuentes.cargarFuentes();

            //sprites
            if (!inicializo)
            {
                mapita = new TgcSprite();
                mapita.Texture = TgcTexture.createTexture(GuiController.Instance.AlumnoEjemplosMediaDir + "\\sprites\\preview.png");
                motoSprite = new TgcSprite();
                motoSprite.Texture = TgcTexture.createTexture(GuiController.Instance.AlumnoEjemplosMediaDir + "\\sprites\\dirtbike.png");
                timer = new TgcSprite();
                timer.Texture = TgcTexture.createTexture(GuiController.Instance.AlumnoEjemplosMediaDir + "\\sprites\\gate.png");

                //Ubicarlo centrado en la pantalla
                screenSize = GuiController.Instance.Panel3d.Size;
                textureSize = mapita.Texture.Size;
                motoTextureSize = motoSprite.Texture.Size;
                mapita.Scaling = (new Vector2(0.7f, 0.7f));
                motoSprite.Scaling = (new Vector2(0.5f, 0.5f));

                mapita.Position = new Vector2(FastMath.Max(screenSize.Width / 2 - textureSize.Width * 0.7f / 2, 0), 16);

                motoSprite.Position = new Vector2(FastMath.Max(screenSize.Width / 2 - motoTextureSize.Width * 0.5f / 2 - textureSize.Width * 0.7f / 2, 0), 8);

                timer.Position = new Vector2(screenSize.Width - 250, screenSize.Height - 125);

                timer.Scaling = new Vector2(0.9f, 0.8f);
                posMotoInicial = motoSprite.Position;
                inicializo = true;
            }
            d3dDevice = GuiController.Instance.D3dDevice;

            d3dDevice.Transform.Projection =
                Matrix.PerspectiveFovLH(Geometry.DegreeToRadian(45.0f),
                TgcD3dDevice.aspectRatio, 1f, 5000000f);

            string texturesPath = GuiController.Instance.AlumnoEjemplosMediaDir + "skybox\\";
            TgcSceneLoader loader = new TgcSceneLoader();
            collisionManager = new ElipsoidCollisionManager();
            collisionManager.GravityEnabled = false;
            tiempoAcelerando = 0f;
            tiempoDescelerando = 0f;
            velIni = 0f;
            tocandoPiso = false;
            saltando = true;
            ultimoMov = new Vector3(0, 0, 0);

            //skybox
            inicializarSkybox(texturesPath);

            //checkpoints
            int posCP = -150;
            foreach (TgcBoundingBox bb in checkpoints)
            {
                bb.setExtremes(new Vector3(-200, -100, posCP), new Vector3(200, 1000, posCP - 10));
                posCP -= 1300;
            }

            //carga la ciudad
            scene = loader.loadSceneFromFile(GuiController.Instance.AlumnoEjemplosMediaDir + "pistaDesierto\\pistaDesierto2-TgcScene.xml");

            //cargo la moto
            motorcycle = loader.loadSceneFromFile(GuiController.Instance.AlumnoEjemplosMediaDir + "moto\\Moto2-TgcScene.xml").Meshes[0];
            motorcycle.move(-40, 100, -150);

            //cargo la piramide
            piramid = loader.loadSceneFromFile(GuiController.Instance.AlumnoEjemplosMediaDir + "piramide\\piramide-TgcScene.xml").Meshes[0];
            piramid.Scale = new Vector3(5, 5, 5);
            piramid.move(-265, -45, -13750);

            //cargo texto ganaste

            textGanaste = new TgcText2d();
            textGanaste2 = new TgcText2d();

            //Cargar Textos
            textGanaste.Text = "FELICIDADES, HAS GANADO";
            textGanaste2.Text = "APRETE Q PARA VOLVER AL MENU";
            textGanaste.Position = new Point(0, 50);
            textGanaste2.Position = new Point(0, 100);
            textGanaste.changeFont(new System.Drawing.Font("TimesNewRoman", 23, FontStyle.Bold | FontStyle.Bold));
            textGanaste2.changeFont(new System.Drawing.Font("TimesNewRoman", 23, FontStyle.Bold | FontStyle.Bold));

            textGanaste.Color = Color.White;
            textGanaste2.Color = Color.White;

            // Creo texto contador de tiempo
            textoContadorTiempo = new TgcText2d();
            textoContadorTiempo.Color = Color.Black;
            textoContadorTiempo.Align = TgcText2d.TextAlign.RIGHT;
            textoContadorTiempo.Position = new Point(630, 400); //(680, 400)
            textoContadorTiempo.Size = new Size(300, 100);
            textoContadorTiempo.changeFont(new System.Drawing.Font(Fuentes.fuente.Families[0], 25, FontStyle.Regular));

            // Creo texto mejor tiempo
            textoMejorTiempo = new TgcText2d();
            textoMejorTiempo.Color = Color.Black;
            textoMejorTiempo.Align = TgcText2d.TextAlign.RIGHT;
            textoMejorTiempo.Position = new Point(630, 430);  //(680, 430)
            textoMejorTiempo.Size = new Size(300, 100);
            textoMejorTiempo.changeFont(new System.Drawing.Font(Fuentes.fuente.Families[0], 25, FontStyle.Regular));

            //Texto para mostrar fps
            textFPS = new TgcText2d();
            textFPS.Position = new Point((screenSize.Width / (-2)), 0);
            textFPS.Text = "FPS: ";
            textFPS.Color = Color.Yellow;

            //camara
            GuiController.Instance.ThirdPersonCamera.Enable = true;
            GuiController.Instance.ThirdPersonCamera.setCamera(motorcycle.Position + new Vector3(0,0,-100), 10, 200);
            GuiController.Instance.ThirdPersonCamera.rotateY(-0.7f);

            //creo la bounding elipsoid

            motorcycle.Scale = new Vector3(0.5f, 0.5f, 0.5f);

            // motorcycle.AutoUpdateBoundingBox = false;
            characterElipsoid = new TgcElipsoid(motorcycle.BoundingBox.calculateBoxCenter() + new Vector3(0, 0, 0), new Vector3(23, 23, 23) * 0.5f);

            //cargo los colliders
            objetosColisionables.Clear();
            foreach (TgcMesh mesh in scene.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));
                }
            }

            //agrego Piramide Como objeto Colisionable
            objetosColisionables.Add(BoundingBoxCollider.fromBoundingBox(piramid.BoundingBox));

            //Cargo lineaInicio

            lineaInicio = new TgcBox();
            lineaInicio.Position = new Vector3(-7, 30, -50);
            lineaInicio.Size = new Vector3(200, 2000, 1);
            lineaInicio.updateValues();

            //Cargo lineaFin
            lineaFin = new TgcBox();
            lineaFin.Size = new Vector3(100, 1000, 1);
            lineaFin.Position = new Vector3(0, 15, -13250);
            lineaFin.Color = Color.White;
            lineaFin.updateValues();

            //La agrego como objeto colisionable
            objetosColisionables.Add(BoundingBoxCollider.fromBoundingBox(lineaInicio.BoundingBox));

            showBB = false;

            //iluminacion
            ojalaQueAnde = new ShadowMap(scene, motorcycle);

            //DEBUG
            //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);
            //TERMINA DEBUG
        }