예제 #1
0
        public override void Init()
        {
            time = 0f;
            var d3dDevice   = D3DDevice.Instance.Device;
            var MyShaderDir = ShadersDir + "WorkshopShaders\\";

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

            // parallax oclussion
            scene = loader.loadSceneFromFile(MediaDir + "ModelosTgc\\Piso\\Piso-Custom-TgcScene.xml");

            g_pBaseTexture = TextureLoader.FromFile(d3dDevice, MediaDir + "Texturas\\wood.bmp");
            g_pHeightmap   = TextureLoader.FromFile(d3dDevice, MediaDir + "Texturas\\NM_four_height.tga");

            g_pBaseTexture2 = TextureLoader.FromFile(d3dDevice, MediaDir + "Texturas\\stones.bmp");
            g_pHeightmap2   = TextureLoader.FromFile(d3dDevice, MediaDir + "Texturas\\NM_height_stones.tga");

            g_pBaseTexture3 = TextureLoader.FromFile(d3dDevice, MediaDir + "Texturas\\rocks.jpg");
            g_pHeightmap3   = TextureLoader.FromFile(d3dDevice, MediaDir + "Texturas\\NM_height_rocks.tga");

            mesh = scene.Meshes[0];
            var adj = new int[mesh.D3dMesh.NumberFaces * 3];

            mesh.D3dMesh.GenerateAdjacency(0, adj);
            mesh.D3dMesh.ComputeNormals(adj);

            //Cargar Shader
            string compilationErrors;

            effect = Effect.FromFile(d3dDevice, MyShaderDir + "Parallax.fx", null, null, ShaderFlags.None, null,
                                     out compilationErrors);
            if (effect == null)
            {
                throw new Exception("Error al cargar shader. Errores: " + compilationErrors);
            }

            Modifiers.addVertex3f("LightDir", new Vector3(-1, -1, -1), new Vector3(1, 1, 1), new Vector3(0, -1, 0));
            Modifiers.addFloat("minSample", 1f, 10f, 10f);
            Modifiers.addFloat("maxSample", 11f, 50f, 50f);
            Modifiers.addFloat("HeightMapScale", 0.001f, 0.5f, 0.1f);

            //Centrar camara rotacional respecto a este mesh
            var rotCamera = new TgcRotationalCamera(mesh.BoundingBox.calculateBoxCenter(),
                                                    mesh.BoundingBox.calculateBoxRadius() * 2, Input);

            rotCamera.CameraCenter   = rotCamera.CameraCenter + new Vector3(0, 20f, 0);
            rotCamera.CameraDistance = 75;
            rotCamera.RotationSpeed  = 50f;
            Camara = rotCamera;

            pom         = false;
            phong       = true;
            nro_textura = 0;
        }
예제 #2
0
        private void LoadShaders()
        {
            var d3dDevice = D3DDevice.Instance.Device;

            //Cargar Shader personalizado
            string compilationErrors;

            effect = Effect.FromFile(d3dDevice, ShadersDir + "\\PostProcess.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 = "PostProcess";

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

            effect.SetValue("g_RenderTarget", g_pRenderTarget);

            // Resolucion de pantalla
            effect.SetValue("screen_dx", d3dDevice.PresentationParameters.BackBufferWidth);
            effect.SetValue("screen_dy", d3dDevice.PresentationParameters.BackBufferHeight);

            var texturaCasco = TgcTexture.createTexture(MediaDir + "Level1\\Textures\\mask.png");

            effect.SetValue("texCasco", texturaCasco.D3dTexture);

            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)
            };
            //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);
        }
예제 #3
0
        public override void Init()
        {
            var d3dDevice = D3DDevice.Instance.Device;

            MyShaderDir = ShadersDir + "WorkshopShaders\\";

            circuito = new F1Circuit(MediaDir);

            //Cargar terreno: cargar heightmap y textura de color
            terrain = new TgcSimpleTerrain();
            terrain.loadHeightmap(MediaDir + "Heighmaps\\" + "TerrainTexture2.jpg",
                                  20, 0.1f, new TGCVector3(0, -125, 0));
            terrain.loadTexture(MediaDir + "Heighmaps\\" + "TerrainTexture2.jpg");

            //Crear SkyBox
            skyBox        = new TgcSkyBox();
            skyBox.Center = new TGCVector3(0, 500, 0);
            skyBox.Size   = new TGCVector3(10000, 10000, 10000);
            var texturesPath = MediaDir + "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.Init();

            var loader = new TgcSceneLoader();
            var scene  = loader.loadSceneFromFile(MediaDir + "MeshCreator\\Meshes\\Vehiculos\\Auto\\Auto-TgcScene.xml");

            car = scene.Meshes[0];

            //Cargar Shader personalizado
            string compilationErrors;

            effect = Effect.FromFile(D3DDevice.Instance.Device, 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
            Camara.SetCamera(new TGCVector3(315.451f, 40, -464.28490f), new TGCVector3(315.451f, 40, -465.28490f));

            reset_pos();

            // para capturar el mouse
            var focusWindows = D3DDevice.Instance.Device.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);
            g_pDepthStencilOld = d3dDevice.DepthStencilSurface;
            // 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(-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);
        }
예제 #4
0
        public override void Init()
        {
            var d3dDevice = D3DDevice.Instance.Device;

            MyShaderDir = ShadersDir + "WorkshopShaders\\";

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

            //TgcScene scene = loader.loadSceneFromFile(this.MediaDir + "MeshCreator\\Scenes\\Deposito\\Deposito-TgcScene.xml");
            var scene = loader.loadSceneFromFile(MediaDir + "MeshCreator\\Scenes\\Selva\\Selva-TgcScene.xml");

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

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

            arbol = scene3.Meshes[0];
            var scene4 = loader.loadSceneFromFile(MediaDir + "MeshCreator\\Meshes\\Vegetacion\\Arbusto2\\Arbusto2-TgcScene.xml");

            arbusto = scene4.Meshes[0];

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

            for (var t = 0; t < 25; ++t)
            {
                enemigos.Add(skeletalLoader.loadMeshAndAnimationsFromFile(
                                 MediaDir + "SkeletalAnimations\\BasicHuman\\" + "CombineSoldier-TgcSkeletalMesh.xml",
                                 MediaDir + "SkeletalAnimations\\BasicHuman\\",
                                 new[]
                {
                    MediaDir + "SkeletalAnimations\\BasicHuman\\Animations\\" + "StandBy-TgcSkeletalAnim.xml",
                    MediaDir + "SkeletalAnimations\\BasicHuman\\Animations\\" + "Run-TgcSkeletalAnim.xml"
                }));

                //Configurar animacion inicial
                enemigos[t].playAnimation("StandBy", true);
                enemigos[t].Position  = new TGCVector3(-rnd.Next(0, 1500) - 250, 0, -rnd.Next(0, 1500) - 250);
                enemigos[t].Scale     = new TGCVector3(2f, 2f, 2f);
                enemigos[t].Transform = TGCMatrix.Scaling(enemigos[t].Scale) * TGCMatrix.Translation(enemigos[t].Position);
                //enemigos[t].UpdateMeshTransform();
                bot_status[t] = 0;
            }

            //Cargar Shader personalizado
            string compilationErrors;

            effect = Effect.FromFile(D3DDevice.Instance.Device, MyShaderDir + "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 persona
            Camera = new TgcFpsCamera(new TGCVector3(-1000, 250, -1000), 1000f, 600f, Input);

            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_pGlowMap = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth, d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget,
                                     Format.X8R8G8B8, Pool.Default);

            g_pRenderTarget4 = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth / 4, d3dDevice.PresentationParameters.BackBufferHeight / 4, 1, Usage.RenderTarget,
                                           Format.X8R8G8B8, Pool.Default);

            g_pRenderTarget4Aux = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth / 4, d3dDevice.PresentationParameters.BackBufferHeight / 4, 1, Usage.RenderTarget,
                                              Format.X8R8G8B8, 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(-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);

            activarEfectoModifier = AddBoolean("activar_efecto", "Activar efecto", true);

            timer_firing = new float[100];
            pos_bala     = new TGCVector3[100];
            dir_bala     = new TGCVector3[100];

            for (var i = 0; i < cant_balas; ++i)
            {
                timer_firing[i] = i / (float)cant_balas * total_timer_firing;
            }
        }
예제 #5
0
        public override void Init()
        {
            var d3dDevice = D3DDevice.Instance.Device;

            MyShaderDir = ShadersDir;

            wav_files = Directory.GetFiles(MediaDir + "sound");

            //sound.Create(MediaDir + "sound\\smokeonthewater.wav");
            //sound.Create(MediaDir + "sound\\rolemu_-_neogauge.wav");        // super dificl
            //sound.Create(MediaDir + "sound\\rolem_-_Neoishiki.wav");            // buenisimo (dificil)
            //sound.Create(MediaDir + "sound\\Azureflux_-_06_-_Kinetic_Sands.wav");
            //sound.Create(MediaDir + "sound\\Azureflux_-_01_-_BOMB.wav");
            //sound.Create(MediaDir + "sound\\Azureflux_-_02_-_Waves.wav");       // muy bueno, facil
            //sound.Create(MediaDir + "sound\\Monplaisir_-_03_-_Level_0.wav");
            //sound.Create(MediaDir + "sound\\Monplaisir_-_04_-_Level_1.wav");           // monotono
            //sound.Create(MediaDir + "sound\\Monplaisir_-_05_-_Level_2.wav");           // monotono
            //sound.Create(MediaDir + "sound\\Monplaisir_-_06_-_Level_3.wav");
            //sound.Create(MediaDir + "sound\\Monplaisir_-_07_-_Level_4.wav");            // bueno
            //sound.Create(MediaDir + "sound\\tecno1.wav");                         // dificil
            //sound.Create(MediaDir + "sound\\ScoobyDooPaPa.wav");                         // interesante
            //sound.Create(MediaDir + "sound\\highway intro.wav");                // se va de escala
            //sound.Create(MediaDir + "sound\\Shook_Me_All_Night.wav");           // bajo volumen
            //sound.Create(MediaDir + "sound\\ACDC.wav");


            //Cargar Shader personalizado
            string compilationErrors;

            effect = Effect.FromFile(D3DDevice.Instance.Device, MyShaderDir + "shaders.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";


            // para capturar el mouse
            var focusWindows = D3DDevice.Instance.Device.CreationParameters.FocusWindow;

            mouseCenter   = focusWindows.PointToScreen(new Point(focusWindows.Width / 2, focusWindows.Height / 2));
            mouseCaptured = false;
            //Cursor.Hide();

            // stencil
            g_pDepthStencil = d3dDevice.CreateDepthStencilSurface(d3dDevice.PresentationParameters.BackBufferWidth,
                                                                  d3dDevice.PresentationParameters.BackBufferHeight,
                                                                  DepthFormat.D24S8, MultiSampleType.None, 0, true);
            g_pDepthStencilOld = d3dDevice.DepthStencilSurface;
            // 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(-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);

            time = 0;

            sprite = new Sprite(d3dDevice);
            // ajusto las letras para que se vean mas o menos igual en todas las resoluciones.
            float kx = (float)d3dDevice.PresentationParameters.BackBufferWidth / 1366.0f;
            float ky = (float)d3dDevice.PresentationParameters.BackBufferHeight / 768.0f;
            float k  = Math.Min(kx, ky);

            // Fonts
            font = new Microsoft.DirectX.Direct3D.Font(d3dDevice, (int)(24 * k), 0, FontWeight.Light, 0, false, CharacterSet.Default,
                                                       Precision.Default, FontQuality.Default, PitchAndFamily.DefaultPitch, "Lucida Console");
            font.PreloadGlyphs('0', '9');
            font.PreloadGlyphs('a', 'z');
            font.PreloadGlyphs('A', 'Z');

            s_font = new Microsoft.DirectX.Direct3D.Font(d3dDevice, (int)(18 * k), 0, FontWeight.Light, 0, false, CharacterSet.Default,
                                                         Precision.Default, FontQuality.Default, PitchAndFamily.DefaultPitch, "Lucida Console");
            s_font.PreloadGlyphs('0', '9');
            s_font.PreloadGlyphs('a', 'z');
            s_font.PreloadGlyphs('A', 'Z');

            c64_font = new Microsoft.DirectX.Direct3D.Font(d3dDevice, (int)(40 * k), (int)(30 * k), FontWeight.Light, 0, false, CharacterSet.Default,
                                                           Precision.Default, FontQuality.Default, PitchAndFamily.DefaultPitch, "System");
            c64_font.PreloadGlyphs('0', '9');
            c64_font.PreloadGlyphs('a', 'z');
            c64_font.PreloadGlyphs('A', 'Z');
        }