예제 #1
0
        private void InitializeMeshes()
        {
            TgcTexture tiles, lava, stones, water;

            tiles  = TgcTexture.createTexture(MediaDir + "Textures/tiles.jpg");
            lava   = TgcTexture.createTexture(MediaDir + "Textures/lava.jpg");
            stones = TgcTexture.createTexture(MediaDir + "Textures/stones.bmp");
            water  = TgcTexture.createTexture(MediaDir + "Textures/water.bmp");

            TGCSphere baseSphere = new TGCSphere(1f, Color.White, TGCVector3.Empty);

            baseSphere.setTexture(lava);
            baseSphere.updateValues();
            sphereOne = baseSphere.toMesh("sphereOne");
            meshes.Add(sphereOne);
            baseSphere.setTexture(stones);
            sphereTwo = baseSphere.toMesh("sphereTwo");
            meshes.Add(sphereTwo);
            baseSphere.setTexture(water);
            sphereThree = baseSphere.toMesh("sphereThree");
            meshes.Add(sphereThree);

            TgcSceneLoader loader = new TgcSceneLoader();
            var            scene  = loader.loadSceneFromFile(MediaDir + "Robot2-TgcScene.xml");

            robot           = scene.Meshes[0];
            robot.Transform = TGCMatrix.Scaling(0.1f, 0.1f, 0.1f) * TGCMatrix.RotationY(FastMath.PI) * TGCMatrix.Translation(TGCVector3.Up * 40f);
            meshes.Add(robot);

            TgcPlane tgcPlane = new TgcPlane(TGCVector3.Empty, TGCVector3.One * 100f, TgcPlane.Orientations.XZplane, tiles, 10f, 10f);

            plane = tgcPlane.toMesh("plane");
            meshes.Add(plane);
        }
예제 #2
0
        public override void Init()
        {
            var device = D3DDevice.Instance.Device;

            // Creo una textura, genero sus mipmaps
            texture = TgcTexture.createTexture(MediaDir + "Textures//perlin1.png");
            texture.D3dTexture.GenerateMipSubLevels();

            // Creo un vertex buffer, en este caso un full screen quad
            CustomVertex.PositionTextured[] vertices =
            {
                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)
            };
            fullScreenQuad = new VertexBuffer(typeof(CustomVertex.PositionTextured), 4, device, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default);
            fullScreenQuad.SetData(vertices, 0, LockFlags.None);

            // Cargo mi efecto, que contiene mis tecnicas (shaders)
            effect          = TGCShaders.Instance.LoadEffect(ShadersDir + "Example.fx");
            hotReloadEffect = new HotReloadEffect(effect, ShadersDir + "Example.fx", 0.5f);

            time = 0f;

            // Da igual la camara, nuestros vertices no se van
            // a multiplicar por ninguna matriz
            var cameraPosition = TGCVector3.Empty;
            var lookAt         = TGCVector3.Empty;

            Camera.SetCamera(cameraPosition, lookAt);

            FixedTickEnable    = true;
            TimeBetweenUpdates = 1f / 40f;
        }
예제 #3
0
        public override void Init()
        {
            //Modifiers para variar parametros de la pared
            originModifier      = AddVertex3f("origin", new TGCVector3(-100, -100, -100), new TGCVector3(100, 100, 100), TGCVector3.Empty);
            dimensionModifier   = AddVertex3f("dimension", new TGCVector3(-100, -100, -100), new TGCVector3(1000, 1000, 100), new TGCVector3(100, 100, 100));
            orientationModifier = AddInterval("orientation", new[] { "XY", "XZ", "YZ" }, 0);
            tilingModifier      = AddVertex2f("tiling", TGCVector2.Zero, new TGCVector2(10, 10), TGCVector2.One);
            autoAdjustModifier  = AddBoolean("autoAdjust", "autoAdjust", false);

            //Modifier de textura
            var texturePath = MediaDir + "Texturas\\Quake\\TexturePack2\\brick1_1.jpg";

            currentTexture  = TgcTexture.createTexture(D3DDevice.Instance.Device, texturePath);
            textureModifier = AddTexture("texture", currentTexture.FilePath);

            //Crear pared
            plane = new TgcPlane();
            plane.setTexture(currentTexture);

            //Actualizar segun valores cargados
            updateTGCPlane();

            //Ajustar camara segun tamano de la pared
            Camara = new TgcRotationalCamera(plane.BoundingBox.calculateBoxCenter(), plane.BoundingBox.calculateBoxRadius() * 2, Input);
        }
예제 #4
0
        /// <summary>
        /// Actualiza los parámetros de la caja en base a lo cargado por el usuario
        /// </summary>
        private void updateBox()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            //Cambiar textura
            string texturePath = (string)GuiController.Instance.Modifiers["texture"];

            if (texturePath != currentTexture)
            {
                currentTexture = texturePath;
                box.setTexture(TgcTexture.createTexture(d3dDevice, currentTexture));
            }

            //Tamaño, posición y color
            box.Size     = (Vector3)GuiController.Instance.Modifiers["size"];
            box.Position = (Vector3)GuiController.Instance.Modifiers["position"];
            box.Color    = (Color)GuiController.Instance.Modifiers["color"];

            //Rotación, converitr a radianes
            Vector3 rotaion = (Vector3)GuiController.Instance.Modifiers["rotation"];

            box.Rotation = new Vector3(Geometry.DegreeToRadian(rotaion.X), Geometry.DegreeToRadian(rotaion.Y), Geometry.DegreeToRadian(rotaion.Z));

            //Offset y Tiling de textura
            box.UVOffset = (Vector2)GuiController.Instance.Modifiers["offset"];
            box.UVTiling = (Vector2)GuiController.Instance.Modifiers["tiling"];

            //Actualizar valores en la caja.
            box.updateValues();
        }
예제 #5
0
        public void init(string text)
        {
            TgcBox box = new TgcBox();

            box.setExtremes(new Vector3(0, 0, 0), new Vector3(400, 2, 1000));
            box.Color = Color.Blue;
            box.updateValues();
            TgcMesh temp = box.toMesh("water");

            TgcSceneLoader loader = new TgcSceneLoader();

            //Configurar MeshFactory customizado
            loader.MeshFactory = new ShadedMeshFactory();
            mesh             = (ShadedMesh)loader.MeshFactory.createNewMesh(temp.D3dMesh, "water", TgcMesh.MeshRenderType.VERTEX_COLOR);
            mesh.BoundingBox = box.BoundingBox;
            mesh.loadEffect("Shaders//water.fx", "Basic");
            mesh.AutoUpdateBoundingBox = false;

            TgcTexture t_temp = TgcTexture.createTexture(GuiController.Instance.D3dDevice, GuiController.Instance.AlumnoEjemplosMediaDir + "RenderizameLaBanera\\waterbump.dds");//"perlin_noise.jpg");//"waterbump.dds");

            noise       = t_temp.D3dTexture;
            t_temp      = TgcTexture.createTexture(GuiController.Instance.D3dDevice, GuiController.Instance.AlumnoEjemplosMediaDir + "RenderizameLaBanera\\" + text);
            riverBottom = t_temp.D3dTexture;

            mesh.Effect.SetValue("xNoiseTex", noise);
            mesh.Effect.SetValue("xRiverBottom", riverBottom);

            Surface renderTarget = GuiController.Instance.D3dDevice.GetRenderTarget(0);

            riverReflex = new Texture(GuiController.Instance.D3dDevice, renderTarget.Description.Width, renderTarget.Description.Height, 1, Usage.RenderTarget, renderTarget.Description.Format, Pool.Default);
        }
예제 #6
0
        /// <summary>
        ///     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
            var d3dDevice = D3DDevice.Instance.Device;

            //Piso la camara que viene por defecto con la que yo quiero usar.
            //Configurar centro al que se mira y distancia desde la que se mira
            Camara = new TgcRotationalCamera(new Vector3(), 50f, Input);

            //Textura de la carperta Media
            var pathTexturaCaja = MediaDir + Game.Default.TexturaCaja;

            //Cargamos una textura
            var texture = TgcTexture.createTexture(pathTexturaCaja);

            //Creamos una caja 3D ubicada en (0, 0, 0), dimensiones (5, 10, 5) y la textura como color.
            var center = new Vector3(0, 0, 0);
            var size   = new Vector3(5, 10, 5);

            Box = TgcBox.fromSize(center, size, texture);

            //Cargo el unico mesh que tiene la escena
            Mesh = new TgcSceneLoader().loadSceneFromFile(MediaDir + "LogoTGC-TgcScene.xml").Meshes[0];
            //Escalo el mesh que es muy grande
            Mesh.Scale = new Vector3(0.5f, 0.5f, 0.5f);
        }
예제 #7
0
            public static void cargar()
            {
                SpriteDrawer = new Drawer2D();

                //AnimatedSprite = new TgcAnimatedSprite(Utiles.getDirExtras("Explosion.png"), new Size(64, 64), 16, 10);
                //AnimatedSprite.Position = new Vector2(GuiController.Instance.Panel3d.Width - 32*2, 0);
                //Crear Sprite
                sprite         = new TgcSprite();
                sprite.Texture = TgcTexture.createTexture(Utiles.getDirExtras("calabera1.jpg"));

                //Ubicarlo centrado en la pantalla
                Size screenSize  = GuiController.Instance.Panel3d.Size;
                Size textureSize = sprite.Texture.Size;

                sprite.Position = new Vector2(GuiController.Instance.Panel3d.Width - 34 * 2, 0);
                sprite.Scaling  = new Vector2(0.1f, 0.1f);

                Puntos2d          = new TgcText2d();
                Puntos2d.Text     = puntos.ToString();
                Puntos2d.Color    = Color.Yellow;
                Puntos2d.Align    = TgcText2d.TextAlign.RIGHT;
                Puntos2d.Position = new Point(GuiController.Instance.Panel3d.Width - 32, 0);
                Puntos2d.Size     = new Size(30, 20);
                Puntos2d.changeFont(new System.Drawing.Font("Sans-serif ", 15, FontStyle.Bold));
            }
예제 #8
0
        public override void Init()
        {
            //Device de DirectX para crear primitivas.
            var d3dDevice = D3DDevice.Instance.Device;

            this.initVector();

            this.center = new TGCVector3(0, 0, 0);

            this.setEffects();

            var lava = TgcTexture.createTexture(d3dDevice, MediaDir + "lava.jpg");

            this.createText(d3dDevice.Viewport.Width, d3dDevice.Viewport.Height);
            this.createSphereMesh(lava);

            this.scale = new TGCVector3(20, 20, 20);

            var cameraPosition = new TGCVector3(0, 0, 125);
            //Quiero que la camara mire hacia el origen (0,0,0).
            var lookAt = TGCVector3.Empty;

            //Configuro donde esta la posicion de la camara y hacia donde mira.
            Camara.SetCamera(cameraPosition, lookAt);
            //Internamente el framework construye la matriz de view con estos dos vectores.
            //Luego en nuestro juego tendremos que crear una cámara que cambie la matriz de view con variables como movimientos o animaciones de escenas.
        }
예제 #9
0
        public override void Init()
        {
            var sphere = MediaDir + "ModelosTgc\\Sphere\\Sphere-TgcScene.xml";

            var loader = new TgcSceneLoader();

            //Cargar modelos para el sol, la tierra y la luna. Son esfereas a las cuales le cambiamos la textura
            sun = loader.loadSceneFromFile(sphere).Meshes[0];
            sun.changeDiffuseMaps(new[]
            {
                TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + "SistemaSolar\\SunTexture.jpg")
            });

            earth = loader.loadSceneFromFile(sphere).Meshes[0];
            earth.changeDiffuseMaps(new[]
            {
                TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + "SistemaSolar\\EarthTexture.jpg")
            });

            moon = loader.loadSceneFromFile(sphere).Meshes[0];
            moon.changeDiffuseMaps(new[]
            {
                TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + "SistemaSolar\\MoonTexture.jpg")
            });

            BackgroundColor = Color.Black;

            //Camara en primera persona
            Camera = new TgcRotationalCamera(new TGCVector3(0f, 200f, 1000f), 500f, Input);
        }
예제 #10
0
        public VideoScene(string directory, string format, float fps, int total_frames)
        {
            FPS         = fps;
            TotalFrames = total_frames;

            current_frame = 0;
            time          = 0.0f;

            frames = new TgcTexture[TotalFrames];

            for (int i = 1; i <= TotalFrames; i++)
            {
                frames[i - 1] = TgcTexture.createTexture(directory + @"\" + i.ToString("D4") + "." + format);
            }

            sprite         = new TgcSprite();
            sprite.Texture = frames[current_frame];

            Size screenSize  = GuiController.Instance.Panel3d.Size;
            Size textureSize = sprite.Texture.Size;

            sprite.Scaling = new Vector2(
                (float)screenSize.Width / textureSize.Width,
                (float)screenSize.Height / textureSize.Height);

            sprite.Position = new Vector2(
                FastMath.Max(screenSize.Width / 2 - textureSize.Width * sprite.Scaling.X / 2, 0),
                FastMath.Max(screenSize.Height / 2 - textureSize.Height * sprite.Scaling.Y / 2, 0));

            sound = new TgcStaticSound();
            sound.loadSound(directory + @"\sound.wav");

            Playing = false;
        }
예제 #11
0
        private Jugador CrearJugador(string pathRecursos)
        {
            string nombreTextura = Settings.Default.textureTeam2;

            //Cargar personaje con animaciones
            TgcSkeletalMesh personaje = new TgcSkeletalLoader().loadMeshAndAnimationsFromFile(
                pathRecursos + Settings.Default.meshFolderPlayer + Settings.Default.meshFilePlayer,
                pathRecursos + Settings.Default.meshFolderPlayer,
                new string[] {
                pathRecursos + Settings.Default.meshFolderPlayer + Settings.Default.animationWalkFilePlayer,
                pathRecursos + Settings.Default.meshFolderPlayer + Settings.Default.animationRunFilePlayer,
                pathRecursos + Settings.Default.meshFolderPlayer + Settings.Default.animationStopFilePlayer,
            }
                );

            //Le cambiamos la textura
            personaje.changeDiffuseMaps(new TgcTexture[] {
                TgcTexture.createTexture(pathRecursos + Settings.Default.meshFolderPlayer + nombreTextura)
            });

            //Configurar animacion inicial
            personaje.playAnimation(Settings.Default.animationStopPlayer, true);
            personaje.Position = new Vector3(0, 0, 0);

            //Lo Escalo porque es muy grande
            personaje.Scale = new Vector3(0.75f, 0.75f, 0.75f);

            //Recalculo las normales para evitar problemas con la luz
            personaje.computeNormals();

            return(new Jugador(personaje, new JugadorIAStrategy(), null));
        }
예제 #12
0
        public override void init()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;


            TgcSceneLoader loader = new TgcSceneLoader();
            TgcScene       scene  = loader.loadSceneFromFile(
                GuiController.Instance.ExamplesMediaDir + "ModelosTgc\\Box\\" + "Box-TgcScene.xml",
                GuiController.Instance.ExamplesMediaDir + "ModelosTgc\\Box\\");

            mesh       = scene.Meshes[0];
            mesh.Scale = new Vector3(0.25f, 0.25f, 0.25f);


            GuiController.Instance.FpsCamera.Enable = true;
            GuiController.Instance.FpsCamera.setCamera(new Vector3(7.9711f, 11.7f, -32.5475f), new Vector3(7.972f, 11.4178f, -31.5475f));


            GuiController.Instance.Modifiers.addVertex3f("origin", new Vector3(-100, -100, -100), new Vector3(100, 100, 100), new Vector3(0, 0, 0));
            GuiController.Instance.Modifiers.addVertex3f("dimension", new Vector3(-100, -100, -100), new Vector3(1000, 1000, 100), new Vector3(10, 10, 10));
            GuiController.Instance.Modifiers.addInterval("orientation", new string[] { "XY", "XZ", "YZ" }, 0);
            GuiController.Instance.Modifiers.addVertex2f("tiling", new Vector2(0, 0), new Vector2(10, 10), new Vector2(1, 1));

            string texturePath = GuiController.Instance.ExamplesMediaDir + "Texturas\\Quake\\TexturePack2\\brick1_1.jpg";

            currentTexture = TgcTexture.createTexture(d3dDevice, texturePath);
            GuiController.Instance.Modifiers.addTexture("texture", currentTexture.FilePath);



            updateWall();
        }
예제 #13
0
        public override void Init()
        {
            //Crear Sprite
            sprite         = new TgcSprite();
            sprite.Texture = TgcTexture.createTexture(MediaDir + "\\Texturas\\LogoTGC.png");

            //Ubicarlo centrado en la pantalla
            var textureSize = sprite.Texture.Size;

            sprite.Position = new Vector2(FastMath.Max(D3DDevice.Instance.Width / 2 - textureSize.Width / 2, 0),
                                          FastMath.Max(D3DDevice.Instance.Height / 2 - textureSize.Height / 2, 0));

            //Modifiers para variar parametros del sprite
            Modifiers.addVertex2f("position", new Vector2(0, 0),
                                  new Vector2(D3DDevice.Instance.Width, D3DDevice.Instance.Height), sprite.Position);
            Modifiers.addVertex2f("scaling", new Vector2(0, 0), new Vector2(4, 4), sprite.Scaling);
            Modifiers.addFloat("rotation", 0, 360, 0);

            //Creamos un Box3D para que se vea como el Sprite es en 2D y se dibuja siempre arriba de la escena 3D
            box = TgcBox.fromSize(new Vector3(10, 10, 10), TgcTexture.createTexture(MediaDir + "\\Texturas\\pasto.jpg"));

            //Hacer que la camara se centre en el box3D
            Camara = new TgcRotationalCamera(box.BoundingBox.calculateBoxCenter(),
                                             box.BoundingBox.calculateBoxRadius() * 2);
        }
        public override void Init()
        {
            //Crear Sprite animado
            animatedSprite = new TgcAnimatedSprite(MediaDir + "\\Texturas\\Sprites\\Explosion.png", //Textura de 256x256
                                                   new Size(64, 64),                                //Tamaño de un frame (64x64px en este caso)
                                                   16,                                              //Cantidad de frames, (son 16 de 64x64px)
                                                   10                                               //Velocidad de animacion, en cuadros x segundo
                                                   );

            //Ubicarlo centrado en la pantalla
            var textureSize = animatedSprite.Sprite.Texture.Size;

            animatedSprite.Position = new Vector2(D3DDevice.Instance.Width / 2 - textureSize.Width / 2,
                                                  D3DDevice.Instance.Height / 2 - textureSize.Height / 2);

            //Modifiers para variar parametros del sprite
            Modifiers.addFloat("frameRate", 1, 30, 10);
            Modifiers.addVertex2f("position", new Vector2(0, 0),
                                  new Vector2(D3DDevice.Instance.Width, D3DDevice.Instance.Height), animatedSprite.Position);
            Modifiers.addVertex2f("scaling", new Vector2(0, 0), new Vector2(4, 4), animatedSprite.Scaling);
            Modifiers.addFloat("rotation", 0, 360, 0);

            //Creamos un Box3D para que se vea como el Sprite es en 2D y se dibuja siempre arriba de la escena 3D
            box = TgcBox.fromSize(new Vector3(10, 10, 10), TgcTexture.createTexture(MediaDir + "\\Texturas\\pasto.jpg"));

            //Hacer que la camara se centre en el box3D
            Camara = new TgcRotationalCamera(box.BoundingBox.calculateBoxCenter(),
                                             box.BoundingBox.calculateBoxRadius() * 2);
        }
        public void Init(string MediaDir)
        {
            paredes = new List <TGCBox>();
            var diffuseMap = TgcTexture.createTexture(MediaDir + "Textures//Lisas.bmp");

            // todo: usar planos para piso y techo?
            piso           = TGCBox.fromExtremes(new TGCVector3(-100, -1, -100), new TGCVector3(100, 0, 100), diffuseMap);
            piso.Transform = TGCMatrix.Translation(piso.Position);

            techo           = TGCBox.fromExtremes(new TGCVector3(-100, 100, -100), new TGCVector3(100, 101, 100), diffuseMap);
            techo.Transform = TGCMatrix.Translation(techo.Position);

            var paredSur = TGCBox.fromExtremes(new TGCVector3(-100, 0, -110), new TGCVector3(100, 100, -100), diffuseMap);

            paredSur.Transform = TGCMatrix.Translation(paredSur.Position);

            var paredNorte = TGCBox.fromExtremes(new TGCVector3(-100, 0, 100), new TGCVector3(100, 100, 110), diffuseMap);

            paredNorte.Transform = TGCMatrix.Translation(paredNorte.Position);

            var paredOeste = TGCBox.fromExtremes(new TGCVector3(-110, 0, -100), new TGCVector3(-100, 100, 100), diffuseMap);

            paredOeste.Transform = TGCMatrix.Translation(paredOeste.Position);

            var paredEste = TGCBox.fromExtremes(new TGCVector3(100, 0, -100), new TGCVector3(110, 100, 100), diffuseMap);

            paredEste.Transform = TGCMatrix.Translation(paredEste.Position);

            paredes.Add(paredSur);
            paredes.Add(paredNorte);
            paredes.Add(paredEste);
            paredes.Add(paredOeste);
        }
예제 #16
0
        public override void init()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            //Crear Sprite animado
            animatedSprite = new TgcAnimatedSprite(
                GuiController.Instance.ExamplesMediaDir + "\\Texturas\\Sprites\\Explosion.png", //Textura de 256x256
                new Size(64, 64),                                                               //Tamaño de un frame (64x64px en este caso)
                16,                                                                             //Cantidad de frames, (son 16 de 64x64px)
                10                                                                              //Velocidad de animacion, en cuadros x segundo
                );

            //Ubicarlo centrado en la pantalla
            Size screenSize  = GuiController.Instance.Panel3d.Size;
            Size textureSize = animatedSprite.Sprite.Texture.Size;

            animatedSprite.Position = new Vector2(screenSize.Width / 2 - textureSize.Width / 2, screenSize.Height / 2 - textureSize.Height / 2);

            //Modifiers para variar parametros del sprite
            GuiController.Instance.Modifiers.addFloat("frameRate", 1, 30, 10);
            GuiController.Instance.Modifiers.addVertex2f("position", new Vector2(0, 0), new Vector2(screenSize.Width, screenSize.Height), animatedSprite.Position);
            GuiController.Instance.Modifiers.addVertex2f("scaling", new Vector2(0, 0), new Vector2(4, 4), animatedSprite.Scaling);
            GuiController.Instance.Modifiers.addFloat("rotation", 0, 360, 0);


            //Creamos un Box3D para que se vea como el Sprite es en 2D y se dibuja siempre arriba de la escena 3D
            box = TgcBox.fromSize(new Vector3(10, 10, 10), TgcTexture.createTexture(GuiController.Instance.ExamplesMediaDir + "\\Texturas\\pasto.jpg"));

            //Hacer que la camara se centre en el box3D
            GuiController.Instance.RotCamera.targetObject(box.BoundingBox);
        }
예제 #17
0
        public override void init()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            d3dDevice.RenderState.AlphaFunction    = Compare.Greater;
            d3dDevice.RenderState.BlendOperation   = BlendOperation.Add;
            d3dDevice.RenderState.AlphaBlendEnable = true;
            d3dDevice.RenderState.AlphaTestEnable  = true;
            d3dDevice.RenderState.SourceBlend      = Blend.SourceAlpha;
            d3dDevice.RenderState.DestinationBlend = Blend.InvSourceAlpha;

            TgcTexture texture = TgcTexture.createTexture(d3dDevice, GuiController.Instance.ExamplesMediaDir + "ModelosTgc\\BoxAlpha\\Textures\\pruebaAlpha.png");

            mesh1 = new TgcPlaneWall(new Vector3(0, 0, 0), new Vector3(100, 100, 0), TgcPlaneWall.Orientations.XYplane, texture);
            mesh1.AutoAdjustUv = false;
            mesh1.UTile        = 1;
            mesh1.VTile        = 1;
            mesh1.updateValues();

            mesh2 = new TgcPlaneWall(new Vector3(0, 0, 100), new Vector3(100, 100, 0), TgcPlaneWall.Orientations.XYplane, texture);
            mesh2.AutoAdjustUv = false;
            mesh2.UTile        = 1;
            mesh2.VTile        = 1;
            mesh2.updateValues();


            GuiController.Instance.FpsCamera.Enable = true;

            GuiController.Instance.Modifiers.addBoolean("invertRender", "Invert Render", false);
        }
예제 #18
0
        private void InitGogleViewEffectResources()
        {
            gogleViewEffect = TGCShaders.Instance.LoadEffect(ShadersDir + "Varios.fx");

            gogleViewTexture = TgcTexture.createTexture(MediaDir + "gogleView.png").D3dTexture;
            gogleViewEffect.SetValue("gogleViewTexture", gogleViewTexture);
        }
예제 #19
0
        public override void init()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            //Crear Sprite
            sprite         = new TgcSprite();
            sprite.Texture = TgcTexture.createTexture(GuiController.Instance.ExamplesMediaDir + "\\Texturas\\LogoTGC.png");

            //Ubicarlo centrado en la pantalla
            Size screenSize  = GuiController.Instance.Panel3d.Size;
            Size textureSize = sprite.Texture.Size;

            sprite.Position = new Vector2(FastMath.Max(screenSize.Width / 2 - textureSize.Width / 2, 0), FastMath.Max(screenSize.Height / 2 - textureSize.Height / 2, 0));


            //Modifiers para variar parametros del sprite
            GuiController.Instance.Modifiers.addVertex2f("position", new Vector2(0, 0), new Vector2(screenSize.Width, screenSize.Height), sprite.Position);
            GuiController.Instance.Modifiers.addVertex2f("scaling", new Vector2(0, 0), new Vector2(4, 4), sprite.Scaling);
            GuiController.Instance.Modifiers.addFloat("rotation", 0, 360, 0);



            //Creamos un Box3D para que se vea como el Sprite es en 2D y se dibuja siempre arriba de la escena 3D
            box = TgcBox.fromSize(new Vector3(10, 10, 10), TgcTexture.createTexture(GuiController.Instance.ExamplesMediaDir + "\\Texturas\\pasto.jpg"));

            //Hacer que la camara se centre en el box3D
            GuiController.Instance.RotCamera.targetObject(box.BoundingBox);
        }
예제 #20
0
 public void init(string mediaDir, string shaderDir, TgcCamera camara)
 {
     inicio = new Boton("INICIO", 0f, 0.8f, () => AdministradorDeEscenarios.getSingleton().agregarEscenario(new nivelF1(), camara));
     //inicio = new Boton("INICIO", 0f, 0.8f, () => AdministradorDeEscenarios.getSingleton().agregarEscenario(new nivelPDP(), camara));
     sprite  = new Sprite(D3DDevice.Instance.Device);
     trustMe = TgcTexture.createTexture(D3DDevice.Instance.Device, mediaDir + "imgMenu.png");
 }
        /// <summary>
        /// Crear un nuevo Sprite animado
        /// </summary>
        /// <param name="texturePath">path de la textura animada</param>
        /// <param name="frameSize">tamaño de un tile de la animacion</param>
        /// <param name="totalFrames">cantidad de frames que tiene la animacion</param>
        /// <param name="frameRate">velocidad en cuadros por segundo</param>
        public TgcAnimatedSprite(string texturePath, Size frameSize, int totalFrames, float frameRate)
        {
            this.enabled      = true;
            this.currentFrame = 0;
            this.frameSize    = frameSize;
            this.totalFrames  = totalFrames;
            this.currentTime  = 0;
            this.playing      = true;

            //Crear textura
            Device     d3dDevice = GuiController.Instance.D3dDevice;
            TgcTexture texture   = TgcTexture.createTexture(d3dDevice, texturePath);

            //Sprite
            sprite         = new TgcSprite();
            sprite.Texture = texture;

            //Calcular valores de frames de la textura
            textureWidth    = texture.Width;
            textureHeight   = texture.Height;
            framesPerColumn = (int)textureWidth / frameSize.Width;
            framesPerRow    = (int)textureHeight / frameSize.Height;
            int realTotalFrames = framesPerRow * framesPerColumn;

            if (realTotalFrames > totalFrames)
            {
                throw new Exception("Error en AnimatedSprite. No coinciden la cantidad de frames y el tamaño de la textura: " + totalFrames);
            }

            setFrameRate(frameRate);
        }
예제 #22
0
        public override void Init()
        {
            D3DDevice.Instance.Device.RenderState.AlphaFunction    = Compare.Greater;
            D3DDevice.Instance.Device.RenderState.BlendOperation   = BlendOperation.Add;
            D3DDevice.Instance.Device.RenderState.SourceBlend      = Blend.SourceAlpha;
            D3DDevice.Instance.Device.RenderState.DestinationBlend = Blend.InvSourceAlpha;

            var texture = TgcTexture.createTexture(D3DDevice.Instance.Device,
                                                   MediaDir + "ModelosTgc\\BoxAlpha\\Textures\\pruebaAlpha.png");

            mesh1 = new TgcPlaneWall(new Vector3(0, 0, -50), new Vector3(50, 50, 50), TgcPlaneWall.Orientations.XYplane,
                                     texture);
            mesh1.AutoAdjustUv = false;
            mesh1.UTile        = 1;
            mesh1.VTile        = 1;
            mesh1.updateValues();

            mesh2 = new TgcPlaneWall(new Vector3(0, 0, 50), new Vector3(50, 50, 50), TgcPlaneWall.Orientations.XYplane,
                                     texture);
            mesh2.AutoAdjustUv = false;
            mesh2.UTile        = 1;
            mesh2.VTile        = 1;
            mesh2.updateValues();

            Camara = new TgcFpsCamera(new Vector3(50.0f, 50.0f, 150.0f));

            Modifiers.addBoolean("invertRender", "Invert Render", false);
        }
        /// <summary>
        /// Crear un emisor de particulas
        /// </summary>
        /// <param name="texturePath">textura a utilizar</param>
        /// <param name="particlesCount">cantidad maxima de particlas a generar</param>
        public ParticleEmitter(string texturePath, int particlesCount)
        {
            Device device = GuiController.Instance.D3dDevice;

            //valores default
            enabled            = true;
            playing            = true;
            random             = new Random(0);
            creationFrecuency  = 1.0f;
            particleTimeToLive = 5.0f;
            minSizeParticle    = 0.25f;
            maxSizeParticle    = 0.5f;
            dispersion         = 100;
            speed = new Vector3(1, 1, 1);
            particleVertexArray = new Particle.ParticleVertex[1];
            vertexDeclaration   = new VertexDeclaration(device, Particle.ParticleVertexElements);
            position            = new Vector3(0, 0, 0);

            this.particlesCount = particlesCount;
            this.particles      = new Particle[particlesCount];

            this.particlesAlive = new ColaDeParticulas(particlesCount);
            this.particlesDead  = new Stack <Particle>(particlesCount);

            //Creo todas las particulas. Inicialmente estan todas muertas.
            for (int i = 0; i < particlesCount; i++)
            {
                this.particles[i] = new Particle();
                this.particlesDead.Push(this.particles[i]);
            }

            //Cargo la textura que tendra cada particula
            this.texture = TgcTexture.createTexture(device, texturePath);
        }
예제 #24
0
        public override void Init()
        {
            var loader        = new TgcSceneLoader();
            var sceneOriginal = loader.loadSceneFromFile(MediaDir + "ModelosTgc\\Box\\" +
                                                         "Box-TgcScene.xml");
            var meshOriginal = sceneOriginal.Meshes[0];

            var meshInstance1 = new TgcMesh(meshOriginal.Name + "-1", meshOriginal,
                                            new Vector3(50, 0, 0), meshOriginal.Rotation, meshOriginal.Scale);

            meshInstance1.Enabled = true;

            var meshInstance2 = new TgcMesh(meshOriginal.Name + "-2", meshOriginal,
                                            new Vector3(100, 0, 0), meshOriginal.Rotation, meshOriginal.Scale);

            meshInstance2.Enabled = true;

            meshes = new List <TgcMesh>();
            meshes.Add(meshOriginal);
            meshes.Add(meshInstance1);
            meshes.Add(meshInstance2);

            var texture = TgcTexture.createTexture(D3DDevice.Instance.Device,
                                                   MediaDir + "ModelosTgc\\Piso\\Textures\\piso2.jpg");

            meshOriginal.changeDiffuseMaps(new[] { texture });

            Camara = new TgcFpsCamera();
        }
예제 #25
0
        public static void ChangeTextureColor(TgcMesh mesh, string newColor)
        {
            TgcTexture[] diffuseMaps = mesh.DiffuseMaps;

            string newTexturePath = "";
            int    index          = 0;

            foreach (TgcTexture texture in diffuseMaps)
            {
                if (texture.FileName.Contains("Car Material"))
                {
                    newTexturePath = texture.FilePath;
                    break;
                }
                index++;
            }

            string oldColor = newTexturePath.Split('\\')[5].Split(' ')[2].Split('.')[0];

            newTexturePath = newTexturePath.Replace(oldColor, newColor);

            var textureAux = TgcTexture.createTexture(D3DDevice.Instance.Device, newTexturePath.Split('\\')[5], newTexturePath);

            mesh.addDiffuseMap(textureAux);
            mesh.deleteDiffuseMap(index, diffuseMaps.Length - 1);
        }
예제 #26
0
        public void initializeSol()
        {
            Device         d3dDevice = GuiController.Instance.D3dDevice;
            string         sphere    = GuiController.Instance.ExamplesMediaDir + "ModelosTgc\\Sphere\\Sphere-TgcScene.xml";
            TgcSceneLoader loader    = new TgcSceneLoader();



            //Cargar modelos para el sol, la tierra y la luna. Son esfereas a las cuales le cambiamos la textura
            sol = loader.loadSceneFromFile(sphere).Meshes[0];
            sol.changeDiffuseMaps(new TgcTexture[] { TgcTexture.createTexture(d3dDevice, GuiController.Instance.AlumnoEjemplosMediaDir + "Textures\\environment\\sol1.jpg") });

            //Deshabilitamos el manejo automático de Transformaciones de TgcMesh, para poder manipularlas en forma customizada
            sun.AutoTransformEnable = false;

            //Posición del sol
            //NO logro ubicarlo arriba de todo.
            sol.Position = new Vector3(990, 500, 1500);

            //Modifiers de la luz
            GuiController.Instance.Modifiers.addBoolean("lightEnable", "lightEnable", true);
            GuiController.Instance.Modifiers.addVertex3f("lightPos", new Vector3(-200, -100, -200), new Vector3(200, 200, 300), new Vector3(60, 35, 250));
            GuiController.Instance.Modifiers.addColor("lightColor", Color.White);
            GuiController.Instance.Modifiers.addFloat("lightIntensity", 0, 150, 20);
            GuiController.Instance.Modifiers.addFloat("lightAttenuation", 0.1f, 2, 0.3f);
            GuiController.Instance.Modifiers.addFloat("specularEx", 0, 20, 9f);

            //Modifiers de material
            GuiController.Instance.Modifiers.addColor("mEmissive", Color.Black);
            GuiController.Instance.Modifiers.addColor("mAmbient", Color.White);
            GuiController.Instance.Modifiers.addColor("mDiffuse", Color.White);
            GuiController.Instance.Modifiers.addColor("mSpecular", Color.White);
        }
예제 #27
0
        public override void Init()
        {
            var sphere = MediaDir + "ModelosTgc\\Sphere\\Sphere-TgcScene.xml";

            var loader = new TgcSceneLoader();

            //Cargar modelos para el sol, la tierra y la luna. Son esfereas a las cuales le cambiamos la textura
            sun = loader.loadSceneFromFile(sphere).Meshes[0];
            sun.changeDiffuseMaps(new[]
            {
                TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + "SistemaSolar\\SunTexture.jpg")
            });

            earth = loader.loadSceneFromFile(sphere).Meshes[0];
            earth.changeDiffuseMaps(new[]
            {
                TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + "SistemaSolar\\EarthTexture.jpg")
            });

            moon = loader.loadSceneFromFile(sphere).Meshes[0];
            moon.changeDiffuseMaps(new[]
            {
                TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + "SistemaSolar\\MoonTexture.jpg")
            });

            //Deshabilitamos el manejo automático de Transformaciones de TgcMesh, para poder manipularlas en forma customizada
            sun.AutoTransformEnable   = false;
            earth.AutoTransformEnable = false;
            moon.AutoTransformEnable  = false;

            //Camara en primera persona
            Camara = new TgcFpsCamera(new Vector3(705.2938f, 305.347f, -888.1567f));
        }
예제 #28
0
        public override void init()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            //Cargamos una textura
            //Una textura es una imágen 2D que puede dibujarse arriba de un polígono 3D para darle color.
            //Es muy útil para generar efectos de relieves y superficies.
            //Puede ser cualquier imágen 2D (jpg, png, gif, etc.) y puede ser editada con cualquier editor
            //normal (photoshop, paint, descargada de goole images, etc).
            //El framework viene con un montón de texturas incluidas y organizadas en categorias (texturas de
            //madera, cemento, ladrillo, pasto, etc). Se encuentran en la carpeta del framework:
            //  TgcViewer\Examples\Media\MeshCreator\Textures
            //Podemos acceder al path de la carpeta "Media" utilizando la variable "GuiController.Instance.ExamplesMediaDir".
            //Esto evita que tengamos que hardcodear el path de instalación del framework.
            TgcTexture texture = TgcTexture.createTexture(GuiController.Instance.ExamplesMediaDir + "MeshCreator\\Textures\\Madera\\cajaMadera3.jpg");

            //Creamos una caja 3D ubicada en (0, -3, 0), dimensiones (5, 10, 5) y la textura como color.
            Vector3 center = new Vector3(0, -3, 0);
            Vector3 size   = new Vector3(5, 10, 5);

            box = TgcBox.fromSize(center, size, texture);


            GuiController.Instance.RotCamera.targetObject(box.BoundingBox);
        }
예제 #29
0
        /// <summary>
        ///     Iniciar cliente
        /// </summary>
        private void initClient()
        {
            //Crear piso
            var pisoTexture = TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + "Texturas\\Quake\\TexturePack2\\rock_wall.jpg");

            piso = TGCBox.fromSize(new TGCVector3(0, -60, 0), new TGCVector3(5000, 5, 5000), pisoTexture);
        }
예제 #30
0
        public void Init(string MediaDir)
        {
            //Creamos el mundo fisico por defecto.
            collisionConfiguration = new DefaultCollisionConfiguration();
            dispatcher             = new CollisionDispatcher(collisionConfiguration);
            GImpactCollisionAlgorithm.RegisterAlgorithm(dispatcher);
            constraintSolver      = new SequentialImpulseConstraintSolver();
            overlappingPairCache  = new DbvtBroadphase(); //AxisSweep3(new BsVector3(-5000f, -5000f, -5000f), new BsVector3(5000f, 5000f, 5000f), 8192);
            dynamicsWorld         = new DiscreteDynamicsWorld(dispatcher, overlappingPairCache, constraintSolver, collisionConfiguration);
            dynamicsWorld.Gravity = new TGCVector3(0, -100f, 0).ToBulletVector3();

            //Creamos el terreno
            var meshRigidBody = BulletRigidBodyFactory.Instance.CreateSurfaceFromHeighMap(triangleDataVB);

            dynamicsWorld.AddRigidBody(meshRigidBody);

            //Creamos la esfera del dragon
            dragonBall = BulletRigidBodyFactory.Instance.CreateBall(30f, 0.75f, new TGCVector3(100f, 500f, 100f));
            dragonBall.SetDamping(0.1f, 0.5f);
            dragonBall.Restitution = 1f;
            dragonBall.Friction    = 1;
            dynamicsWorld.AddRigidBody(dragonBall);
            var textureDragonBall = TgcTexture.createTexture(D3DDevice.Instance.Device, MediaDir + @"Texturas\dragonball.jpg");

            sphereMesh = new TGCSphere(1, textureDragonBall, TGCVector3.Empty);
            sphereMesh.updateValues();
            director = new TGCVector3(1, 0, 0);
        }