Ejemplo n.º 1
0
        public void CrearRuta()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;
            // Cargo la ruta
            int totalVertices = cant_ptos_ruta * 3;

            //Crear vertexBuffer
            vb = new VertexBuffer(typeof(CustomVertex.PositionTextured), totalVertices, d3dDevice, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default);

            //Cargar vertices
            int dataIdx = 0;

            CustomVertex.PositionTextured[] data = new CustomVertex.PositionTextured[totalVertices];

            float r0 = R + 16;
            float r1 = R - 16;
            float Kr = 0.5f;

            for (int i = 0; i < cant_ptos_ruta; ++i)
            {
                float   an = 2.0f * (float)Math.PI * (float)i / (float)cant_ptos_ruta;
                Vector3 p0 = new Vector3(r0 * (float)Math.Sin(an), 0, r0 * (float)Math.Cos(an));
                Vector3 p1 = new Vector3(r1 * (float)Math.Sin(an), 0, r1 * (float)Math.Cos(an));
                data[dataIdx++] = new CustomVertex.PositionTextured(p0, 1, i * Kr);
                data[dataIdx++] = new CustomVertex.PositionTextured(p1, 0, i * Kr);
            }
            vb.SetData(data, 0, LockFlags.None);

            // Cargo la textura del piso
            textura_piso = Texture.FromBitmap(d3dDevice, (Bitmap)Bitmap.FromFile(MyMediaDir + "f1\\piso3.png"), Usage.None, Pool.Managed);
        }
Ejemplo n.º 2
0
        public static void Cargar()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            // Cargo el shader que tiene los efectos de postprocesado
            Shader = TgcShaders.loadEffect(GuiController.Instance.AlumnoEjemplosMediaDir + "RenderGroup\\shaders\\postProcess.fx");

            // Creo el quad que va a ocupar toda la pantalla
            CustomVertex.PositionTextured[] screenQuadVertices = 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)
                    };

            ScreenQuad = new VertexBuffer(typeof(CustomVertex.PositionTextured),
                    4, GuiController.Instance.D3dDevice, Usage.Dynamic | Usage.WriteOnly,
                        CustomVertex.PositionTextured.Format, Pool.Default);
            ScreenQuad.SetData(screenQuadVertices, 0, LockFlags.None);

            // Creamos un render targer sobre el cual se va a dibujar la pantalla
            RenderTargetPostprocesado = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth
                    , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget,
                        Format.X8R8G8B8, Pool.Default);

            #region VALORES DE INTERPOLACION
                intVaivenOscurecer = new InterpoladorVaiven();
                intVaivenOscurecer.Min = 1;
                intVaivenOscurecer.Max = 15;
                intVaivenOscurecer.Speed = 40f;
                intVaivenOscurecer.reset();
            #endregion
        }
Ejemplo n.º 3
0
        public static void Cargar()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            // Cargo el shader que tiene los efectos de postprocesado
            Shader = Utiles.CargarShaderConTechnique("postprocesado.fx");

            // Creo el quad que va a ocupar toda la pantalla
            CustomVertex.PositionTextured[] screenQuadVertices = 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)
            };

            ScreenQuad = new VertexBuffer(typeof(CustomVertex.PositionTextured),
                                          4, GuiController.Instance.D3dDevice, Usage.Dynamic | Usage.WriteOnly,
                                          CustomVertex.PositionTextured.Format, Pool.Default);
            ScreenQuad.SetData(screenQuadVertices, 0, LockFlags.None);

            // Creamos un render targer sobre el cual se va a dibujar la pantalla
            RenderTargetPostprocesado = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth
                                                    , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget,
                                                    Format.X8R8G8B8, Pool.Default);

            Trabajando = false;
        }
Ejemplo n.º 4
0
        static public void LoadResources(float width, float length)
        {
            dx = width * 0.5f;
            dy = length;

            billboardVerts    = new CustomVertex.PositionTextured[4];
            billboardVerts[0] = new CustomVertex.PositionTextured(dx, 0, 0, 1, 1);
            billboardVerts[1] = new CustomVertex.PositionTextured(dx, length, 0, 1, 0);
            billboardVerts[2] = new CustomVertex.PositionTextured(-dx, 0, 0, 0, 1);
            billboardVerts[3] = new CustomVertex.PositionTextured(-dx, length, 0, 0, 0);

            vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionTextured), billboardVerts.Length, MdxRender.Device,
                                            Usage.WriteOnly, CustomVertex.PositionTextured.Format, Microsoft.DirectX.Direct3D.Pool.Default);
            OnVertexBufferUpdate(vertexBuffer, null);

            Assembly assm = Assembly.GetExecutingAssembly();
            Stream   ddsFile;

            billboardTextures = new Texture[10];

            ddsFile = assm.GetManifestResourceStream("Interfaces.Resources.ctf.dds");
            billboardTextures[(int)BillboardType.CTF_Flag] = TextureLoader.FromStream(MdxRender.Device, ddsFile);
            ddsFile.Close();

            ddsFile = assm.GetManifestResourceStream("Interfaces.Resources.ctf_vehicle.dds");
            billboardTextures[(int)BillboardType.CTF_Vehicle] = TextureLoader.FromStream(MdxRender.Device, ddsFile);
            ddsFile.Close();

            ddsFile = assm.GetManifestResourceStream("Interfaces.Resources.oddball.dds");
            billboardTextures[(int)BillboardType.Oddball] = TextureLoader.FromStream(MdxRender.Device, ddsFile);
            ddsFile.Close();

            ddsFile = assm.GetManifestResourceStream("Interfaces.Resources.race.dds");
            billboardTextures[(int)BillboardType.Race_Track] = TextureLoader.FromStream(MdxRender.Device, ddsFile);
            ddsFile.Close();

            ddsFile = assm.GetManifestResourceStream("Interfaces.Resources.race_vehicle.dds");
            billboardTextures[(int)BillboardType.Race_Vehicle] = TextureLoader.FromStream(MdxRender.Device, ddsFile);
            ddsFile.Close();

            ddsFile = assm.GetManifestResourceStream("Interfaces.Resources.vegas_bank.dds");
            billboardTextures[(int)BillboardType.Vegas_Bank] = TextureLoader.FromStream(MdxRender.Device, ddsFile);
            ddsFile.Close();

            ddsFile = assm.GetManifestResourceStream("Interfaces.Resources.teleporter_enter.dds");
            billboardTextures[(int)BillboardType.Teleport_From] = TextureLoader.FromStream(MdxRender.Device, ddsFile);
            ddsFile.Close();

            ddsFile = assm.GetManifestResourceStream("Interfaces.Resources.teleporter_exit.dds");
            billboardTextures[(int)BillboardType.Teleport_To] = TextureLoader.FromStream(MdxRender.Device, ddsFile);
            ddsFile.Close();

            ddsFile = assm.GetManifestResourceStream("Interfaces.Resources.koh.dds");
            billboardTextures[(int)BillboardType.KOH] = TextureLoader.FromStream(MdxRender.Device, ddsFile);
            ddsFile.Close();

            ddsFile = assm.GetManifestResourceStream("Interfaces.Resources.sound_scenery.dds");
            billboardTextures[(int)BillboardType.Sound_Scenery] = TextureLoader.FromStream(MdxRender.Device, ddsFile);
            ddsFile.Close();
        }
Ejemplo n.º 5
0
        private double FaceVariance(short v1, short v2, short v3)
        {
            double MaxVar = 0;

            if (Math.Abs(v1 - v2) == 1 || Math.Abs(v3 - v2) == 1)
            {
                MaxVar = 0;                 // minimal face, no variance
            }
            else
            {
                // find vertice in middle of hypothenuse
                short mid_hyp_indice = MidHypVerticeIndice(v1, v3);
                // find real elevation in middle of hypothenuse
                CustomVertex.PositionTextured vh = this._elevatedVertices[mid_hyp_indice];
                Vector3 v    = MathEngine.CartesianToSpherical(vh.X, vh.Y, vh.Z);
                double  real = v.X - this._layerRadius;
                // find extrapolated elevation in middle hyp.
                float xe = (this._elevatedVertices[v1].X + this._elevatedVertices[v3].X) / 2;
                float ye = (this._elevatedVertices[v1].Y + this._elevatedVertices[v3].Y) / 2;
                float ze = (this._elevatedVertices[v1].Z + this._elevatedVertices[v3].Z) / 2;
                v = MathEngine.CartesianToSpherical(xe, ye, ze);
                double extrapolated = v.X - this._layerRadius;
                // variance Note: could be done w/out MathEngine by computing raw cartesian distance
                MaxVar = real - extrapolated;
                // recurse for potential childs until unit face
                MaxVar = Math.Max(MaxVar, FaceVariance(v2, mid_hyp_indice, v1));
                MaxVar = Math.Max(MaxVar, FaceVariance(v3, mid_hyp_indice, v2));
            }
            return(MaxVar);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Convierte el terreno en un TgcMesh
        /// </summary>
        /// <param name="meshName">Nombre de la malla que se va a crear</param>
        public TgcMesh toMesh(string meshName)
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            //Obtener matriz para transformar vertices
            if (autoTransformEnable)
            {
                this.transform = Matrix.Scaling(scale) * Matrix.RotationYawPitchRoll(rotation.Y, rotation.X, rotation.Z) * Matrix.Translation(translation);
            }

            //Crear Mesh con DiffuseMap
            Mesh d3dMesh = new Mesh(vertices.Length / 3, vertices.Length, MeshFlags.Managed, TgcSceneLoader.TgcSceneLoader.DiffuseMapVertexElements, d3dDevice);

            //Cargar VertexBuffer
            using (VertexBuffer vb = d3dMesh.VertexBuffer)
            {
                GraphicsStream data = vb.Lock(0, 0, LockFlags.None);
                for (int j = 0; j < vertices.Length; j++)
                {
                    TgcSceneLoader.TgcSceneLoader.DiffuseMapVertex v = new TgcSceneLoader.TgcSceneLoader.DiffuseMapVertex();
                    CustomVertex.PositionTextured vLand = vertices[j];

                    //vertices
                    v.Position = Vector3.TransformCoordinate(vLand.Position, this.transform);

                    //normals
                    v.Normal = Vector3.Empty;

                    //texture coordinates diffuseMap
                    v.Tu = vLand.Tu;
                    v.Tv = vLand.Tv;

                    data.Write(v);
                }
                vb.Unlock();
            }

            //Cargar IndexBuffer en forma plana
            using (IndexBuffer ib = d3dMesh.IndexBuffer)
            {
                short[] indices = new short[vertices.Length];
                for (int j = 0; j < indices.Length; j++)
                {
                    indices[j] = (short)j;
                }
                ib.SetData(indices, 0, LockFlags.None);
            }

            //Calcular normales
            d3dMesh.ComputeNormals();

            //Malla de TGC
            TgcMesh tgcMesh = new TgcMesh(d3dMesh, meshName, TgcMesh.MeshRenderType.DIFFUSE_MAP);

            tgcMesh.DiffuseMaps = new TgcTexture[] { texture };
            tgcMesh.Materials   = new Material[] { TgcD3dDevice.DEFAULT_MATERIAL };
            tgcMesh.createBoundingBox();
            tgcMesh.Enabled = true;
            return(tgcMesh);
        }
Ejemplo n.º 7
0
        public override void init()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            //Activamos el renderizado customizado. De esta forma el framework nos delega control total sobre como dibujar en pantalla
            //La responsabilidad cae toda de nuestro lado
            GuiController.Instance.CustomRenderEnabled = true;


            //Se crean 2 triangulos (o Quad) con las dimensiones de la pantalla con sus posiciones ya transformadas
            // x = -1 es el extremo izquiedo de la pantalla, x = 1 es el extremo derecho
            // Lo mismo para la Y con arriba y abajo
            // la Z en 1 simpre
            CustomVertex.PositionTextured[] screenQuadVertices = 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
            screenQuadVB = new VertexBuffer(typeof(CustomVertex.PositionTextured),
                    4, d3dDevice, Usage.Dynamic | Usage.WriteOnly,
                        CustomVertex.PositionTextured.Format, Pool.Default);
            screenQuadVB.SetData(screenQuadVertices, 0, LockFlags.None);

            //Creamos un Render Targer sobre el cual se va a dibujar la pantalla
            renderTarget2D = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth
                    , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget,
                        Format.X8R8G8B8, Pool.Default);


            //Cargar shader con efectos de Post-Procesado
            effect = TgcShaders.loadEffect(GuiController.Instance.ExamplesMediaDir + "Shaders\\PostProcess.fx");

            //Configurar Technique dentro del shader
            effect.Technique = "OscurecerTechnique";

            //Interpolador para efecto de variar la intensidad de la textura de alarma
            intVaivenOscurecer = new InterpoladorVaiven();
            intVaivenOscurecer.Min = 0;
            intVaivenOscurecer.Max = 1;
            intVaivenOscurecer.Speed = 0.4f;
            intVaivenOscurecer.reset();


            //Cargamos un escenario
            TgcSceneLoader loader = new TgcSceneLoader();
            TgcScene scene = loader.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir + "MeshCreator\\Scenes\\Deposito\\Deposito-TgcScene.xml");
            meshes = scene.Meshes;


            //Camara en primera personas
            GuiController.Instance.FpsCamera.Enable = true;
            GuiController.Instance.FpsCamera.setCamera(new Vector3(-182.3816f, 82.3252f, -811.9061f), new Vector3(-182.0957f, 82.3147f, -810.9479f));
            

            //Modifier para activar/desactivar efecto de oscurecer
            GuiController.Instance.Modifiers.addBoolean("activar_efecto", "Activar efecto", true);
        }
Ejemplo n.º 8
0
        private void CreateSquarePolygon()      //사각형 그리기
        {
            //삼각형의 다각형을 표시하기 위한 정점 버퍼를 작성
            //this._vertexBuffer = new VertexBuffer(typeof(CustomVertex.TransformedColored),3, this._device, Usage.None, CustomVertex.TransformedColored.Format, Pool.Managed);
            //TransformedColored => PositionColored (3D 상에서 아직 포인트가 없기 때문에?)
            this._vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionTextured), 4, this._device, Usage.None, CustomVertex.PositionTextured.Format, Pool.Managed);

            //3점의 정보를 보관하기 위한 메모리를 확보
            //TransformedColored => PositionColored , 3,thi -> 4,thi
            //CustomVertex.PositionColored[] vertices = new CustomVertex.PositionColored[3];        //3각형
            //4점의 정보를 보관하기 위한 메모리를 확보
            CustomVertex.PositionTextured[] vertices = new CustomVertex.PositionTextured[4];    //사각형

            ////정점 데이터의설정
            //(X 3D 공간상위치X, Y, Z, 정점의 색)
            vertices[0] = new CustomVertex.PositionTextured(
                -4.0f, 4.0f, 0.0f, 0.0f, 0.0f);
            vertices[1] = new CustomVertex.PositionTextured(
                4.0f, 4.0f, 0.0f, 1.0f, 0.0f);
            vertices[2] = new CustomVertex.PositionTextured(
                -4.0f, -4.0f, 0.0f, 0.0f, 1.0f);
            vertices[3] = new CustomVertex.PositionTextured(
                4.0f, -4.0f, 0.0f, 1.0f, 1.0f);



            //텍스쳐 작성
            this._texture = TextureLoader.FromFile(this._device, "OneSizeAllPae.jpg");
        }
Ejemplo n.º 9
0
        private void FillVB(object sender, EventArgs e)
        {
            lock (sender)
            {
                CustomVertex.PositionTextured[] verts = new CustomVertex.PositionTextured[4];

                if (!Centered)
                {
                    verts[0] = new CustomVertex.PositionTextured(0.0f, -Height, 0.0f, 0.0f, 1.0f);
                    //Top left // 0 0 // 0 1 // 0 0
                    verts[1] = new CustomVertex.PositionTextured(0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
                    //Bottom left // 1 0 // 0 0 // 0 1
                    verts[2] = new CustomVertex.PositionTextured(Width, 0.0f, 0.0f, 1.0f, 0.0f);
                    //Bottom right // 1 1 // 1 0 // 1 1
                    verts[3] = new CustomVertex.PositionTextured(Width, -Height, 0.0f, 1.0f, 1.0f);
                    //Top right  // 0 0 // 1 1 // 1 0
                }
                else
                {
                    verts[0] = new CustomVertex.PositionTextured(-(Width / 2), -(Height / 2), 0.0f, 0.0f, 1.0f);
                    //Top left // 0 0 // 0 1 // 0 0
                    verts[1] = new CustomVertex.PositionTextured(-(Width / 2), (Height / 2), 0.0f, 0.0f, 0.0f);
                    //Bottom left // 1 0 // 0 0 // 0 1
                    verts[2] = new CustomVertex.PositionTextured((Width / 2), (Height / 2), 0.0f, 1.0f, 0.0f);
                    //Bottom right // 1 1 // 1 0 // 1 1
                    verts[3] = new CustomVertex.PositionTextured((Width / 2), -(Height / 2), 0.0f, 1.0f, 1.0f);
                    //Top right  // 0 0 // 1 1 // 1 0
                }
                ((VertexBuffer)sender).SetData(verts, 0, LockFlags.None);
            }
        }
Ejemplo n.º 10
0
        public void _UpdateValues()
        {
            //TODO:Calcular los 4 corners de la pared, segun el tipo de orientacion
            Vector3 bLeft  = new Vector3(-_Size.X / 2, -_Size.Y / 2, 0);
            Vector3 bRight = new Vector3(_Size.X / 2, -_Size.Y / 2, 0);
            Vector3 tLeft  = new Vector3(-_Size.X / 2, _Size.Y / 2, 0);
            Vector3 tRight = new Vector3(_Size.X / 2, _Size.Y / 2, 0);

            //Primer triangulo
            _Vertices[0] = new CustomVertex.PositionTextured(bLeft, UVOffset.X, UVOffset.Y + Tile.Y);
            _Vertices[1] = new CustomVertex.PositionTextured(tLeft, UVOffset.X, UVOffset.Y);
            _Vertices[2] = new CustomVertex.PositionTextured(tRight, UVOffset.X + Tile.X, UVOffset.Y);
            //Segundo triangulo
            _Vertices[3] = new CustomVertex.PositionTextured(bLeft, UVOffset.X, UVOffset.Y + Tile.Y);
            _Vertices[4] = new CustomVertex.PositionTextured(tRight, UVOffset.X + Tile.X, UVOffset.Y);
            _Vertices[5] = new CustomVertex.PositionTextured(bRight, UVOffset.X + Tile.X, UVOffset.Y + Tile.Y);

            //Transformar todos los puntos

            Matrix t = _RotationMatrix * Matrix.Translation(_Position);

            for (int i = 0; i < _Vertices.Length; i++)
            {
                _Vertices[i].Position = Vector3.TransformCoordinate(_Vertices[i].Position, t);
            }
        }
Ejemplo n.º 11
0
        public static void Cargar()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            // Cargo el shader que tiene los efectos de postprocesado
            Shader = TgcShaders.loadEffect(GuiController.Instance.AlumnoEjemplosMediaDir + "RenderGroup\\shaders\\postProcess.fx");


            // Creo el quad que va a ocupar toda la pantalla
            CustomVertex.PositionTextured[] screenQuadVertices = 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)
            };

            ScreenQuad = new VertexBuffer(typeof(CustomVertex.PositionTextured),
                                          4, GuiController.Instance.D3dDevice, Usage.Dynamic | Usage.WriteOnly,
                                          CustomVertex.PositionTextured.Format, Pool.Default);
            ScreenQuad.SetData(screenQuadVertices, 0, LockFlags.None);

            // Creamos un render targer sobre el cual se va a dibujar la pantalla
            RenderTargetPostprocesado = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth
                                                    , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget,
                                                    Format.X8R8G8B8, Pool.Default);

            #region VALORES DE INTERPOLACION
            intVaivenOscurecer       = new InterpoladorVaiven();
            intVaivenOscurecer.Min   = 1;
            intVaivenOscurecer.Max   = 15;
            intVaivenOscurecer.Speed = 40f;
            intVaivenOscurecer.reset();
            #endregion
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Convierte la pared en un TgcMesh
        /// </summary>
        /// <param name="meshName">Nombre de la malla que se va a crear</param>
        public TgcMesh toMesh(string meshName)
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            //Crear Mesh
            Mesh d3dMesh = new Mesh(vertices.Length / 3, vertices.Length, MeshFlags.Managed, TgcSceneLoader.TgcSceneLoader.DiffuseMapVertexElements, d3dDevice);

            //Cargar VertexBuffer
            using (VertexBuffer vb = d3dMesh.VertexBuffer)
            {
                GraphicsStream data       = vb.Lock(0, 0, LockFlags.None);
                Vector3        ceroNormal = new Vector3(0, 0, 0);
                int            whiteColor = Color.White.ToArgb();
                for (int j = 0; j < vertices.Length; j++)
                {
                    TgcSceneLoader.TgcSceneLoader.DiffuseMapVertex v = new TgcSceneLoader.TgcSceneLoader.DiffuseMapVertex();
                    CustomVertex.PositionTextured vWall = vertices[j];

                    //vertices
                    v.Position = vWall.Position;

                    //normals
                    v.Normal = ceroNormal;

                    //texture coordinates diffuseMap
                    v.Tu = vWall.Tu;
                    v.Tv = vWall.Tv;

                    //color
                    v.Color = whiteColor;

                    data.Write(v);
                }
                vb.Unlock();
            }

            //Cargar IndexBuffer en forma plana
            using (IndexBuffer ib = d3dMesh.IndexBuffer)
            {
                short[] indices = new short[vertices.Length];
                for (int j = 0; j < indices.Length; j++)
                {
                    indices[j] = (short)j;
                }
                ib.SetData(indices, 0, LockFlags.None);
            }

            //Calcular normales
            d3dMesh.ComputeNormals();

            //Malla de TGC
            TgcMesh tgcMesh = new TgcMesh(d3dMesh, meshName, TgcMesh.MeshRenderType.DIFFUSE_MAP);

            tgcMesh.DiffuseMaps = new TgcTexture[] { texture };
            tgcMesh.Materials   = new Material[] { TgcD3dDevice.DEFAULT_MATERIAL };
            tgcMesh.createBoundingBox();
            tgcMesh.Enabled = true;
            return(tgcMesh);
        }
Ejemplo n.º 13
0
        public void Create(float pscaleX, float pscaleY, float pscaleZ, Vector3 center)
        {
            scaleX = pscaleX;
            scaleY = pscaleY;
            scaleZ = pscaleZ;

            this.center = center;

            //Dispose de VertexBuffer anterior, si habia
            if (vbPlane != null && !vbPlane.Disposed)
            {
                vbPlane.Dispose();
            }

            //Crear vertexBuffer
            totalVertices = 2 * 3 * ((int)scaleX + 1) * ((int)scaleZ + 1);
            //totalVertices *= (int)ki * (int)kj;
            vbPlane = new VertexBuffer(typeof(CustomVertex.PositionTextured), totalVertices,
                                       D3DDevice.Instance.Device,
                                       Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default);

            //Cargar vertices
            var   dataIdx = 0;
            var   data    = new CustomVertex.PositionTextured[totalVertices];
            float width   = (int)scaleX;
            float length  = (int)scaleZ;

            for (var i = 0; i < width - 1; i++)
            {
                for (var j = 0; j < length - 1; j++)
                {
                    //Vertices
                    var v1 = new Vector3(center.X + i, center.Y * scaleY, center.Z + j);
                    var v2 = new Vector3(center.X + i, center.Y * scaleY, center.Z + (j + 1));
                    var v3 = new Vector3(center.X + (i + 1), center.Y * scaleY, center.Z + j);
                    var v4 = new Vector3(center.X + (i + 1), center.Y * scaleY, center.Z + (j + 1));

                    //Coordendas de textura
                    var t1 = new Vector2(i / width, j / length);
                    var t2 = new Vector2(i / width, (j + 1) / length);
                    var t3 = new Vector2((i + 1) / width, j / length);
                    var t4 = new Vector2((i + 1) / width, (j + 1) / length);

                    //Cargar triangulo 1
                    data[dataIdx]     = new CustomVertex.PositionTextured(v1, t1.X, t1.Y);
                    data[dataIdx + 1] = new CustomVertex.PositionTextured(v2, t2.X, t2.Y);
                    data[dataIdx + 2] = new CustomVertex.PositionTextured(v4, t4.X, t4.Y);

                    //Cargar triangulo 2
                    data[dataIdx + 3] = new CustomVertex.PositionTextured(v1, t1.X, t1.Y);
                    data[dataIdx + 4] = new CustomVertex.PositionTextured(v4, t4.X, t4.Y);
                    data[dataIdx + 5] = new CustomVertex.PositionTextured(v3, t3.X, t3.Y);

                    dataIdx += 6;
                }
            }

            vbPlane.SetData(data, 0, LockFlags.None);
        }
Ejemplo n.º 14
0
        public override void Init()
        {
            time = 0;

            Device d3dDevice = D3DDevice.Instance.Device;

            //Cargamos un escenario
            TgcSceneLoader loader = new TgcSceneLoader();
            TgcScene       scene  = loader.loadSceneFromFile(MediaDir + "MeshCreator\\Scenes\\Deposito\\Deposito-TgcScene.xml");

            meshes = scene.Meshes;

            //Cargar Shader personalizado
            string compilationErrors;

            effect = Effect.FromFile(d3dDevice, ShadersDir + "WorkshopShaders\\FullQuad.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
            Camara = new TgcFpsCamera(new TGCVector3(-182.3816f, 82.3252f, -811.9061f), 100, 10, 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);

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

            distorcionadorModifier = AddEnum("distorcionador", typeof(Distorciones), Distorciones.Pincushion);
            gridModifier           = AddBoolean("grid", "mostrar grilla", false);
            kuModifier             = AddFloat("Ku", 0, 1, 0.1f);
            kvModifier             = AddFloat("Kv", 0, 1, 0.1f);

            ocScaleInModifier = AddFloat("oc_scale_in", 0.1f, 4, 2.5f);
            ocScaleModifier   = AddFloat("oc_scale", 0.01f, 1f, 0.35f);
        }
Ejemplo n.º 15
0
        public override void init()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            //Activamos el renderizado customizado. De esta forma el framework nos delega control total sobre como dibujar en pantalla
            //La responsabilidad cae toda de nuestro lado
            GuiController.Instance.CustomRenderEnabled = true;


            //Se crean 2 triangulos (o Quad) con las dimensiones de la pantalla con sus posiciones ya transformadas
            // x = -1 es el extremo izquiedo de la pantalla, x = 1 es el extremo derecho
            // Lo mismo para la Y con arriba y abajo
            // la Z en 1 simpre
            CustomVertex.PositionTextured[] screenQuadVertices = 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
            screenQuadVB = new VertexBuffer(typeof(CustomVertex.PositionTextured),
                                            4, d3dDevice, Usage.Dynamic | Usage.WriteOnly,
                                            CustomVertex.PositionTextured.Format, Pool.Default);
            screenQuadVB.SetData(screenQuadVertices, 0, LockFlags.None);

            //Creamos un Render Targer sobre el cual se va a dibujar la pantalla
            renderTarget2D = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth
                                         , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget,
                                         Format.X8R8G8B8, Pool.Default);


            //Cargar shader con efectos de Post-Procesado
            effect = TgcShaders.loadEffect(GuiController.Instance.ExamplesMediaDir + "Shaders\\PostProcess.fx");

            //Configurar Technique dentro del shader
            effect.Technique = "OndasTechnique";


            //Cargamos un escenario
            TgcSceneLoader loader = new TgcSceneLoader();
            TgcScene       scene  = loader.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir + "MeshCreator\\Scenes\\Deposito\\Deposito-TgcScene.xml");

            meshes = scene.Meshes;


            //Camara en primera personas
            GuiController.Instance.FpsCamera.Enable = true;
            GuiController.Instance.FpsCamera.setCamera(new Vector3(-182.3816f, 82.3252f, -811.9061f), new Vector3(-182.0957f, 82.3147f, -810.9479f));


            //Modifier para variar tamaño de ondas
            GuiController.Instance.Modifiers.addBoolean("activar_efecto", "Activar efecto", true);
            GuiController.Instance.Modifiers.addFloat("wave_length", 0, 300, 200);
            GuiController.Instance.Modifiers.addFloat("wave_size", 0.01f, 1, 0.01f);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Actualiza la caja en base a los valores configurados
        /// </summary>
        public void updateValues()
        {
            //Crear grilla de 4x4 caras rectangulares
            bool triangleSide1 = true;
            int  vIndex        = 0;

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    //Los 4 vertices que forman la cara
                    EditableVertex tl = editableVertices[i * 5 + j];
                    EditableVertex tr = editableVertices[i * 5 + j + 1];
                    EditableVertex bl = editableVertices[(i + 1) * 5 + j];
                    EditableVertex br = editableVertices[(i + 1) * 5 + j + 1];

                    if (triangleSide1)
                    {
                        //Sentido 1
                        //Primer triangulo: tl - br - bl
                        vertices[vIndex]     = new CustomVertex.PositionTextured(tl.Pos, uvOffset.X + uvTiling.X * tl.UV.X, uvOffset.Y + uvTiling.Y * tl.UV.Y);
                        vertices[vIndex + 1] = new CustomVertex.PositionTextured(br.Pos, uvOffset.X + uvTiling.X * br.UV.X, uvOffset.Y + uvTiling.Y * br.UV.Y);
                        vertices[vIndex + 2] = new CustomVertex.PositionTextured(bl.Pos, uvOffset.X + uvTiling.X * bl.UV.X, uvOffset.Y + uvTiling.Y * bl.UV.Y);

                        //Segundo triangulo: tl - tr - br
                        vertices[vIndex + 3] = new CustomVertex.PositionTextured(tl.Pos, uvOffset.X + uvTiling.X * tl.UV.X, uvOffset.Y + uvTiling.Y * tl.UV.Y);
                        vertices[vIndex + 4] = new CustomVertex.PositionTextured(tr.Pos, uvOffset.X + uvTiling.X * tr.UV.X, uvOffset.Y + uvTiling.Y * tr.UV.Y);
                        vertices[vIndex + 5] = new CustomVertex.PositionTextured(br.Pos, uvOffset.X + uvTiling.X * br.UV.X, uvOffset.Y + uvTiling.Y * br.UV.Y);
                    }
                    else
                    {
                        //Sentido 2
                        //bl - tl - tr
                        vertices[vIndex]     = new CustomVertex.PositionTextured(bl.Pos, uvOffset.X + uvTiling.X * bl.UV.X, uvOffset.Y + uvTiling.Y * bl.UV.Y);
                        vertices[vIndex + 1] = new CustomVertex.PositionTextured(tl.Pos, uvOffset.X + uvTiling.X * tl.UV.X, uvOffset.Y + uvTiling.Y * tl.UV.Y);
                        vertices[vIndex + 2] = new CustomVertex.PositionTextured(tr.Pos, uvOffset.X + uvTiling.X * tr.UV.X, uvOffset.Y + uvTiling.Y * tr.UV.Y);

                        //bl - tr - br
                        vertices[vIndex + 3] = new CustomVertex.PositionTextured(bl.Pos, uvOffset.X + uvTiling.X * bl.UV.X, uvOffset.Y + uvTiling.Y * bl.UV.Y);
                        vertices[vIndex + 4] = new CustomVertex.PositionTextured(tr.Pos, uvOffset.X + uvTiling.X * tr.UV.X, uvOffset.Y + uvTiling.Y * tr.UV.Y);
                        vertices[vIndex + 5] = new CustomVertex.PositionTextured(br.Pos, uvOffset.X + uvTiling.X * br.UV.X, uvOffset.Y + uvTiling.Y * br.UV.Y);
                    }
                    vIndex += 6;

                    //Invertir proximo sentido (salvo el ultimo de la fila)
                    if (j != 3)
                    {
                        triangleSide1 = !triangleSide1;
                    }
                }
            }

            vertexBuffer.SetData(vertices, 0, LockFlags.None);
            updateBoundingBox();
        }
Ejemplo n.º 17
0
        public override void Init()
        {
            Device d3dDevice = D3DDevice.Instance.Device;

            //Cargamos un escenario

            TgcSceneLoader loader = new TgcSceneLoader();
            TgcScene       scene  = loader.loadSceneFromFile(MediaDir + "\\MeshCreator\\Meshes\\Esqueletos\\EsqueletoHumano3\\Esqueleto3-TgcScene.xml");

            mesh = scene.Meshes[0];

            //Cargar Shader personalizado
            string compilationErrors;

            effect = Effect.FromFile(d3dDevice, ShadersDir + "WorkshopShaders\\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
            Camara = new TgcFpsCamera(new TGCVector3(50, 30, 50), 100, 10, 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);
            effect.SetValue("g_RenderTarget", g_pRenderTarget);

            // Blur Factor
            g_pBlurFactor = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth, d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default);
            effect.SetValue("g_BlurFactor", g_pBlurFactor);

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

            activarEfectoModifier = AddBoolean("activar_efecto", "Activar efecto", true);
            focusPlaneModifier    = AddFloat("focus_plane", 1, 300, 10);
            blurFactorModifier    = AddFloat("blur_factor", 0.1f, 5f, 0.5f);
        }
Ejemplo n.º 18
0
        public CustomVertex.PositionTextured[] actualizarFlash()
        {
            float   autoWidth;
            float   autoHeight;
            Vector3 origen = new Vector3(0, 0, 0);

            origen.Y          -= muzzleFlash.Size.Y / 2;
            origen.X          -= muzzleFlash.Size.X / 2;
            muzzleFlash.Origin = origen;

            //Calcular los 4 corners de la pared
            Vector3 bLeft, tLeft, bRight, tRight;

            bLeft  = muzzleFlash.Origin;
            tLeft  = new Vector3(muzzleFlash.Origin.X + muzzleFlash.Size.X, muzzleFlash.Origin.Y, muzzleFlash.Origin.Z);
            bRight = new Vector3(muzzleFlash.Origin.X, muzzleFlash.Origin.Y + muzzleFlash.Size.Y, muzzleFlash.Origin.Z);
            tRight = new Vector3(muzzleFlash.Origin.X + muzzleFlash.Size.X, muzzleFlash.Origin.Y + muzzleFlash.Size.Y, muzzleFlash.Origin.Z);

            autoWidth  = (muzzleFlash.Size.Y / muzzleFlash.Texture.Width);
            autoHeight = (muzzleFlash.Size.X / muzzleFlash.Texture.Height);

            //Auto ajustar UV
            if (muzzleFlash.AutoAdjustUv)
            {
                muzzleFlash.UTile = autoHeight;
                muzzleFlash.VTile = autoWidth;
            }
            float offsetU = muzzleFlash.UVOffset.X;
            float offsetV = muzzleFlash.UVOffset.Y;

            CustomVertex.PositionTextured[] vertices = new CustomVertex.PositionTextured[6];
            //Primer triangulo
            vertices[0] = new CustomVertex.PositionTextured(bLeft, offsetU + muzzleFlash.UTile, offsetV + muzzleFlash.VTile);
            vertices[1] = new CustomVertex.PositionTextured(tLeft, offsetU, offsetV + muzzleFlash.VTile);
            vertices[2] = new CustomVertex.PositionTextured(tRight, offsetU, offsetV);

            //Segundo triangulo
            vertices[3] = new CustomVertex.PositionTextured(bLeft, offsetU + muzzleFlash.UTile, offsetV + muzzleFlash.VTile);
            vertices[4] = new CustomVertex.PositionTextured(tRight, offsetU, offsetV);
            vertices[5] = new CustomVertex.PositionTextured(bRight, offsetU + muzzleFlash.UTile, offsetV);

            //Transformar triangulos
            vertices[0].Position = Vector3.TransformCoordinate(vertices[0].Position, calcularOrientacion(BLoffset));
            vertices[1].Position = Vector3.TransformCoordinate(vertices[1].Position, calcularOrientacion(TLoffset));
            vertices[2].Position = Vector3.TransformCoordinate(vertices[2].Position, calcularOrientacion(TRoffset));
            vertices[3].Position = Vector3.TransformCoordinate(vertices[3].Position, calcularOrientacion(BLoffset));
            vertices[4].Position = Vector3.TransformCoordinate(vertices[4].Position, calcularOrientacion(TRoffset));
            vertices[5].Position = Vector3.TransformCoordinate(vertices[5].Position, calcularOrientacion(BRoffset));

            //BoundingBox
            muzzleFlash.BoundingBox.setExtremes(bLeft, tRight);

            return(vertices);
        }
Ejemplo n.º 19
0
        public override void Init(Device device)
        {
            this.device = device;

            texQuad    = new CustomVertex.PositionTextured[4];
            texQuad[0] = new CustomVertex.PositionTextured(new Vector3(), 0, 0);
            texQuad[1] = new CustomVertex.PositionTextured(new Vector3(), 1, 0);
            texQuad[2] = new CustomVertex.PositionTextured(new Vector3(), 0, 1);
            texQuad[3] = new CustomVertex.PositionTextured(new Vector3(), 1, 1);

            tex = TextureLoader.FromFile(device, (string)HashTableSettings.Instance["Base.Path"] + @"Media/AtomSelection.png");
        }
Ejemplo n.º 20
0
        public override void Init(Device device)
        {
            this.device = device;

            texQuad    = new CustomVertex.PositionTextured[4];
            texQuad[0] = new CustomVertex.PositionTextured(new Vector3(), 0, 0);
            texQuad[1] = new CustomVertex.PositionTextured(new Vector3(), 1, 0);
            texQuad[2] = new CustomVertex.PositionTextured(new Vector3(), 0, 1);
            texQuad[3] = new CustomVertex.PositionTextured(new Vector3(), 1, 1);

            texture = ChemSymbolTextures.Instance[atom.Atom.Symbol];
        }
Ejemplo n.º 21
0
        public PostProcesadoManager(EjemploAlumno ejemAlumno)
        {
            ejemploAlumno = ejemAlumno;
            GuiController.Instance.CustomRenderEnabled = true;
            Device d3dDevice = GuiController.Instance.D3dDevice;

            //Activamos el renderizado customizado. De esta forma el framework nos delega control total sobre como dibujar en pantalla
            //La responsabilidad cae toda de nuestro lado
            GuiController.Instance.CustomRenderEnabled = true;

            //Se crean 2 triangulos (o Quad) con las dimensiones de la pantalla con sus posiciones ya transformadas
            // x = -1 es el extremo izquiedo de la pantalla, x = 1 es el extremo derecho
            // Lo mismo para la Y con arriba y abajo
            // la Z en 1 simpre
            CustomVertex.PositionTextured[] screenQuadVertices = 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
            screenQuadVB = new VertexBuffer(typeof(CustomVertex.PositionTextured),
                    4, d3dDevice, Usage.Dynamic | Usage.WriteOnly,
                        CustomVertex.PositionTextured.Format, Pool.Default);
            screenQuadVB.SetData(screenQuadVertices, 0, LockFlags.None);

            // stencil
            g_pDepthStencil = d3dDevice.CreateDepthStencilSurface(d3dDevice.PresentationParameters.BackBufferWidth,
                                                                         d3dDevice.PresentationParameters.BackBufferHeight,
                                                                         DepthFormat.D24S8,
                                                                         MultiSampleType.None,
                                                                         0,
                                                                         true);

            //Creamos un Render Targer sobre el cual se va a dibujar la pantalla
            renderTarget2D = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth
                    , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget,
                        Format.X8R8G8B8, Pool.Default);

            effect = TgcShaders.loadEffect(GuiController.Instance.AlumnoEjemplosDir + "SRC\\Renderman\\Efectos\\PostProcesado\\PocaVidaRestante.fx");

            //Cargar textura que se va a dibujar arriba de la escena del Render Target
            alarmTexture = TgcTexture.createTexture(GuiController.Instance.D3dDevice, GuiController.Instance.AlumnoEjemplosMediaDir + "\\RenderMan\\texturas\\efecto_alarma.png");

            //Interpolador para efecto de variar la intensidad de la textura de alarma
            intVaivenAlarm = new InterpoladorVaiven();
            intVaivenAlarm.Min = 0;
            intVaivenAlarm.Max = 1;
            intVaivenAlarm.Speed = 5;
            intVaivenAlarm.reset();
        }
Ejemplo n.º 22
0
        public CustomVertex.PositionTextured[] actualizarFlash()
        {
            float autoWidth;
            float autoHeight;
            Vector3 origen = new Vector3(0, 0, 0);
            origen.Y -= muzzleFlash.Size.Y / 2;
            origen.X -= muzzleFlash.Size.X / 2;
            muzzleFlash.Origin = origen;

            //Calcular los 4 corners de la pared
            Vector3 bLeft, tLeft, bRight, tRight;
            bLeft = muzzleFlash.Origin;
            tLeft = new Vector3(muzzleFlash.Origin.X + muzzleFlash.Size.X, muzzleFlash.Origin.Y, muzzleFlash.Origin.Z);
            bRight = new Vector3(muzzleFlash.Origin.X, muzzleFlash.Origin.Y + muzzleFlash.Size.Y, muzzleFlash.Origin.Z);
            tRight = new Vector3(muzzleFlash.Origin.X + muzzleFlash.Size.X, muzzleFlash.Origin.Y + muzzleFlash.Size.Y, muzzleFlash.Origin.Z);

            autoWidth = (muzzleFlash.Size.Y / muzzleFlash.Texture.Width);
            autoHeight = (muzzleFlash.Size.X / muzzleFlash.Texture.Height);

            //Auto ajustar UV
            if (muzzleFlash.AutoAdjustUv)
            {
                muzzleFlash.UTile = autoHeight;
                muzzleFlash.VTile = autoWidth;
            }
            float offsetU = muzzleFlash.UVOffset.X;
            float offsetV = muzzleFlash.UVOffset.Y;

            CustomVertex.PositionTextured[] vertices = new CustomVertex.PositionTextured[6];
            //Primer triangulo
            vertices[0] = new CustomVertex.PositionTextured(bLeft, offsetU + muzzleFlash.UTile, offsetV + muzzleFlash.VTile);
            vertices[1] = new CustomVertex.PositionTextured(tLeft, offsetU, offsetV + muzzleFlash.VTile);
            vertices[2] = new CustomVertex.PositionTextured(tRight, offsetU, offsetV);

            //Segundo triangulo
            vertices[3] = new CustomVertex.PositionTextured(bLeft, offsetU + muzzleFlash.UTile, offsetV + muzzleFlash.VTile);
            vertices[4] = new CustomVertex.PositionTextured(tRight, offsetU, offsetV);
            vertices[5] = new CustomVertex.PositionTextured(bRight, offsetU + muzzleFlash.UTile, offsetV);

            //Transformar triangulos
            vertices[0].Position = Vector3.TransformCoordinate(vertices[0].Position, calcularOrientacion(BLoffset));
            vertices[1].Position = Vector3.TransformCoordinate(vertices[1].Position, calcularOrientacion(TLoffset));
            vertices[2].Position = Vector3.TransformCoordinate(vertices[2].Position, calcularOrientacion(TRoffset));
            vertices[3].Position = Vector3.TransformCoordinate(vertices[3].Position, calcularOrientacion(BLoffset));
            vertices[4].Position = Vector3.TransformCoordinate(vertices[4].Position, calcularOrientacion(TRoffset));
            vertices[5].Position = Vector3.TransformCoordinate(vertices[5].Position, calcularOrientacion(BRoffset));

            //BoundingBox
            muzzleFlash.BoundingBox.setExtremes(bLeft, tRight);

            return vertices;
        }
        public PreviewManager()
        {
            float w = 5;
            float h = 5;

            m_debugTextureVertices    = new CustomVertex.PositionTextured[6];
            m_debugTextureVertices[0] = new CustomVertex.PositionTextured(-w, -h, 1.0f, 0f, 0f);
            m_debugTextureVertices[1] = new CustomVertex.PositionTextured(-w, h, 1.0f, 0f, 1.0f);
            m_debugTextureVertices[2] = new CustomVertex.PositionTextured(w, h, 1.0f, 1.0f, 1.0f);
            m_debugTextureVertices[3] = new CustomVertex.PositionTextured(w, h, 1.0f, 1.0f, 1.0f);
            m_debugTextureVertices[4] = new CustomVertex.PositionTextured(w, -h, 1.0f, 1.0f, 0f);
            m_debugTextureVertices[5] = new CustomVertex.PositionTextured(-w, -h, 1.0f, 0f, 0f);
        }
Ejemplo n.º 24
0
        private void SetupPostProcessing()
        {
            GuiController.Instance.CustomRenderEnabled = true;

            Device d3dDevice = GuiController.Instance.D3dDevice;

            // Define un quad que cubre toda la pantalla, para hacer post-procesamiento
            CustomVertex.PositionTextured[] screenVertices = 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)
            };

            vbPostProcessMesh = new VertexBuffer(
                typeof(CustomVertex.PositionTextured), 4, d3dDevice, Usage.Dynamic | Usage.WriteOnly,
                CustomVertex.PositionTextured.Format, Pool.Default);

            vbPostProcessMesh.SetData(screenVertices, 0, LockFlags.None);

            // Textura donde se renderea la escena en el paso 1.
            preTargetTexture = new Texture(
                d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth,
                d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget,
                Format.X8R8G8B8, Pool.Default);

            // Depth stencil usado en el pre-rendering. No tiene multisampling.
            preDepthStencil = d3dDevice.CreateDepthStencilSurface(
                d3dDevice.PresentationParameters.BackBufferWidth, d3dDevice.PresentationParameters.BackBufferHeight,
                DepthFormat.D24S8, MultiSampleType.None, 0, true);

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

            PostProcessing = new PostProcessEffects();
            PostProcessing.LensDistortion = false;
            PostProcessing.LensRadius     = 0.3f;

            GuiController.Instance.Modifiers.addFloat(CHROMATIC_ABERRANCE_FACTOR_MOD,
                                                      0.0f, 6.0f, 1.0f);

            GuiController.Instance.Modifiers.addFloat(BLUE_TINT_FACTOR_MOD,
                                                      0.0f, 6.0f, 1.0f);

            GuiController.Instance.Modifiers.addFloat(LENS_DISTORTION_K_MOD,
                                                      -4.0f, 4.0f, 2.0f);

            GuiController.Instance.Modifiers.addFloat(LENS_DISTORTION_KCUBE_MOD,
                                                      -4.0f, 4.0f, 2.0f);
        }
Ejemplo n.º 25
0
        public static HeightmapModel CreateHeightMapMesh(Device d3dDevice, string path, float scaleXZ, float scaleY)
        {
            //parsear bitmap y cargar matriz de alturas
            var heightmap = LoadHeightMap(path);

            //Crear vertexBuffer
            var totalVertices = 2 * 3 * (heightmap.GetLength(0) - 1) * (heightmap.GetLength(1) - 1);
            var vbTerrain     = new VertexBuffer(typeof(CustomVertex.PositionTextured), totalVertices, d3dDevice, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default);

            //Crear array temporal de vertices
            var dataIdx = 0;
            var data    = new CustomVertex.PositionTextured[totalVertices];

            //Iterar sobre toda la matriz del Heightmap y crear los triangulos necesarios para el terreno
            for (var i = 0; i < heightmap.GetLength(0) - 1; i++)
            {
                for (var j = 0; j < heightmap.GetLength(1) - 1; j++)
                {
                    //Crear los cuatro vertices que conforman este cuadrante, aplicando la escala correspondiente
                    var v1 = new TGCVector3(i * scaleXZ, heightmap[i, j] * scaleY, j * scaleXZ);
                    var v2 = new TGCVector3(i * scaleXZ, heightmap[i, j + 1] * scaleY, (j + 1) * scaleXZ);
                    var v3 = new TGCVector3((i + 1) * scaleXZ, heightmap[i + 1, j] * scaleY, j * scaleXZ);
                    var v4 = new TGCVector3((i + 1) * scaleXZ, heightmap[i + 1, j + 1] * scaleY, (j + 1) * scaleXZ);

                    //Crear las coordenadas de textura para los cuatro vertices del cuadrante
                    var t1 = new TGCVector2(i / (float)heightmap.GetLength(0), j / (float)heightmap.GetLength(1));
                    var t2 = new TGCVector2(i / (float)heightmap.GetLength(0), (j + 1) / (float)heightmap.GetLength(1));
                    var t3 = new TGCVector2((i + 1) / (float)heightmap.GetLength(0), j / (float)heightmap.GetLength(1));
                    var t4 = new TGCVector2((i + 1) / (float)heightmap.GetLength(0), (j + 1) / (float)heightmap.GetLength(1));

                    //Cargar triangulo 1
                    data[dataIdx]     = new CustomVertex.PositionTextured(v1, t1.X, t1.Y);
                    data[dataIdx + 1] = new CustomVertex.PositionTextured(v2, t2.X, t2.Y);
                    data[dataIdx + 2] = new CustomVertex.PositionTextured(v4, t4.X, t4.Y);

                    //Cargar triangulo 2
                    data[dataIdx + 3] = new CustomVertex.PositionTextured(v1, t1.X, t1.Y);
                    data[dataIdx + 4] = new CustomVertex.PositionTextured(v4, t4.X, t4.Y);
                    data[dataIdx + 5] = new CustomVertex.PositionTextured(v3, t3.X, t3.Y);

                    dataIdx += 6;
                }
            }

            //Llenar todo el VertexBuffer con el array temporal
            vbTerrain.SetData(data, 0, LockFlags.None);

            return(new HeightmapModel {
                Terrain = vbTerrain, TotalVertex = totalVertices, HeightmapData = heightmap
            });
        }
Ejemplo n.º 26
0
        private void InitDevice()
        {
            PresentParameters pp = new PresentParameters();

            pp.Windowed   = true;
            pp.SwapEffect = SwapEffect.Discard;
            device        = new Device(0, DeviceType.Hardware, this, CreateFlags.HardwareVertexProcessing, pp);
            device.Transform.Projection = Matrix.PerspectiveFovLH(3.14f / 4, device.Viewport.Width / device.Viewport.Height, 1f, 1000f);
            device.Transform.View       = Matrix.LookAtLH(new Vector3(0, 0, 20), new Vector3(), new Vector3(0, 1, 0));
            device.RenderState.Lighting = false;
            vertex[0] = new CustomVertex.PositionTextured(new Vector3(0, 0, 0), 0, 0);
            vertex[1] = new CustomVertex.PositionTextured(new Vector3(5, 0, 0), 0, 1);
            vertex[2] = new CustomVertex.PositionTextured(new Vector3(0, 5, 0), -1, 1);
            texture   = new Texture(device, new Bitmap("C:\\Users\\Jaisal Shah\\source\\repos\\Prac3\\images\\bg.png"), 0, Pool.Managed);
        }
Ejemplo n.º 27
0
 private void GenerateDXMeshes()
 {
     DirectXSections = new List <CustomVertex.PositionTextured[]>();
     for (int i = 0; i < LODModels.Count; i++)
     {
         LODModelStruct l = LODModels[i];
         CustomVertex.PositionTextured[] list = new CustomVertex.PositionTextured[l.IndexBuffer.Indexes.Count];
         for (int j = 0; j < l.IndexBuffer.Indexes.Count; j++)
         {
             int idx = l.IndexBuffer.Indexes[j];
             GPUSkinVertexStruct v = l.VertexBufferGPUSkin.Vertices[idx];
             list[j] = new CustomVertex.PositionTextured(v.Position, HalfToFloat(v.U), HalfToFloat(v.V));
         }
         DirectXSections.Add(list);
     }
 }
Ejemplo n.º 28
0
        /// <summary>
        /// Set the data for the background's vertex buffer
        /// </summary>
        private void BackgroundVertexCreated(object sender, EventArgs e)
        {
            VertexBuffer vb = (VertexBuffer)sender;

            CustomVertex.PositionTextured[] v = new CustomVertex.PositionTextured[4];
            v[0].SetPosition(new Vector3(-1000.0f, 0.0f, 0.0f));
            v[1].SetPosition(new Vector3(-1000.0f, 1000.0f, 0.0f));
            v[2].SetPosition(new Vector3(1000.0f, 0.0f, 0.0f));
            v[3].SetPosition(new Vector3(1000.0f, 1000.0f, 0.0f));
            v[0].Tu = 0.0f; v[0].Tv = 147 / 256.0f;
            v[1].Tu = 0.0f; v[1].Tv = 0.0f;
            v[2].Tu = 1.0f; v[2].Tv = 147 / 256.0f;
            v[3].Tu = 1.0f; v[3].Tv = 0.0f;

            vb.SetData(v, 0, 0);
        }
Ejemplo n.º 29
0
        private void HighlightIntersectedFace(IntersectInformation ii)
        {
            short[] intersectedIndices = new short[3];
            short[] indices            = (short[])scannerMesh.LockIndexBuffer(typeof(short), LockFlags.ReadOnly, scannerMesh.NumberFaces * 3);
            Array.Copy(indices, ii.FaceIndex * 3, intersectedIndices, 0, 3);
            scannerMesh.UnlockIndexBuffer();

            CustomVertex.PositionTextured[] tempIntersectedVertices = new CustomVertex.PositionTextured[3];
            CustomVertex.PositionTextured[] meshVertices            = (CustomVertex.PositionTextured[])scannerMesh.LockVertexBuffer(typeof(CustomVertex.PositionTextured), LockFlags.ReadOnly, scannerMesh.NumberVertices);
            tempIntersectedVertices[0] = meshVertices[intersectedIndices[0]];
            tempIntersectedVertices[1] = meshVertices[intersectedIndices[1]];
            tempIntersectedVertices[2] = meshVertices[intersectedIndices[2]];
            scannerMesh.UnlockVertexBuffer();

            this.intersectedVertices = tempIntersectedVertices;
        }
Ejemplo n.º 30
0
        public PromDecal(float radius, TagFileName BitmapTFN)
        {
            dx = radius * 0.5f;
            dy = radius * 0.5f;

            decalTextureIndex = MdxRender.SM.m_TextureManager.RegisterTexture(BitmapTFN);
            decalVerts        = new CustomVertex.PositionTextured[4];
            decalVerts[0]     = new CustomVertex.PositionTextured(dx, -dy, 0, 1, 1);
            decalVerts[1]     = new CustomVertex.PositionTextured(dx, dy, 0, 1, 0);
            decalVerts[2]     = new CustomVertex.PositionTextured(-dx, -dy, 0, 0, 1);
            decalVerts[3]     = new CustomVertex.PositionTextured(-dx, dy, 0, 0, 0);

            m_VertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionTextured), decalVerts.Length, MdxRender.Dev,
                                              Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default);
            m_VertexBuffer.Created += new EventHandler(OnVertexBufferUpdate);
            OnVertexBufferUpdate(m_VertexBuffer, null);
        }
Ejemplo n.º 31
0
        void CreateVertices(Rectangle rect)
        {
            vertices = new CustomVertex.PositionTextured[4];

            const float z = 0.5f;

            vertices[0] = new CustomVertex.PositionTextured(0, 0, z, 0.0f, 0.0f);
            vertices[1] = new CustomVertex.PositionTextured(rect.Width, 0, z, 1.0f, 0.0f);
            vertices[2] = new CustomVertex.PositionTextured(0, rect.Height, z, 0.0f, 1.0f);
            vertices[3] = new CustomVertex.PositionTextured(rect.Width, rect.Height, z, 1.0f, 1.0f);

            for (int i = 0; i < 4; i++)
            {
                vertices[i].X -= 0.5f;
                vertices[i].Y -= 0.5f;
            }
        }
Ejemplo n.º 32
0
        void CreateVertices(Rectangle rect)
        {
            vertices = new CustomVertex.PositionTextured[4];

            const float z = 0.5f;

            vertices[0] = new CustomVertex.PositionTextured(rect.Left, rect.Bottom, z, 0.0f, 1.0f);
            vertices[1] = new CustomVertex.PositionTextured(rect.Left, rect.Top, z, 0.0f, 0.0f);
            vertices[2] = new CustomVertex.PositionTextured(rect.Right, rect.Bottom, z, 1.0f, 1.0f);
            vertices[3] = new CustomVertex.PositionTextured(rect.Right, rect.Top, z, 1.0f, 0.0f);

            for (int i = 0; i < 4; i++)
            {
                vertices[i].X -= 0.5f;
                vertices[i].Y -= 0.5f;
            }
        }
Ejemplo n.º 33
0
        public Billboard(float width, float length, int TextureIndex)
        {
            dx = width * 0.5f;
            dy = length;

            billboardTextureIndex = TextureIndex;
            billboardVerts        = new CustomVertex.PositionTextured[4];
            billboardVerts[0]     = new CustomVertex.PositionTextured(dx, 0, 0, 1, 1);
            billboardVerts[1]     = new CustomVertex.PositionTextured(dx, length, 0, 1, 0);
            billboardVerts[2]     = new CustomVertex.PositionTextured(-dx, 0, 0, 0, 1);
            billboardVerts[3]     = new CustomVertex.PositionTextured(-dx, length, 0, 0, 0);

            m_VertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionTextured), billboardVerts.Length, MdxRender.Dev,
                                              Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default);
            m_VertexBuffer.Created += new EventHandler(OnVertexBufferUpdate);
            OnVertexBufferUpdate(m_VertexBuffer, null);
        }
Ejemplo n.º 34
0
        public override void Init()
        {
            g.input         = Input;
            g.cameraSprites = new CameraSprites();
            g.cameraSprites.initMenu();
            Camara = new Camera.Camera();
            new Map();
            new Shadow();


            //copy paste de distorciones.cs, ni idea
            Device d3dDevice = D3DDevice.Instance.Device;

            depthStencil = d3dDevice.CreateDepthStencilSurface(d3dDevice.PresentationParameters.BackBufferWidth,
                                                               d3dDevice.PresentationParameters.BackBufferHeight, DepthFormat.D24S8, MultiSampleType.None, 0, true);

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

            postProcess = Effect.FromFile(d3dDevice,
                                          ShadersDir + "postProcess.fx", null, null,
                                          ShaderFlags.PreferFlowControl, null, out string compilationErrors);
            if (postProcess == null)
            {
                throw new Exception("Error al cargar shader. Errores: " + compilationErrors);
            }

            postProcess.SetValue("renderTarget", renderTarget);
            postProcess.SetValue("screen_dx", d3dDevice.PresentationParameters.BackBufferWidth);
            postProcess.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)
            };
            vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionTextured), 4,
                                            d3dDevice, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default);
            vertexBuffer.SetData(vertices, 0, LockFlags.None);
        }
Ejemplo n.º 35
0
        /// <summary>
        /// Crear quad
        /// </summary>
        public TgcScreenQuad()
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;

            //Se crean 2 triangulos (o Quad) con las dimensiones de la pantalla con sus posiciones ya transformadas
            // x = -1 es el extremo izquiedo de la pantalla, x = 1 es el extremo derecho
            // Lo mismo para la Y con arriba y abajo
            // la Z en 1 simpre
            CustomVertex.PositionTextured[] screenQuadVertices = 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
            screenQuadVB = new VertexBuffer(typeof(CustomVertex.PositionTextured),
                    4, d3dDevice, Usage.Dynamic | Usage.WriteOnly,
                        CustomVertex.PositionTextured.Format, Pool.Default);
            screenQuadVB.SetData(screenQuadVertices, 0, LockFlags.None);
        }
Ejemplo n.º 36
0
 public static void CreateVertexBufferInside(Device gDevice, int width, int height, Vector2 area, out VertexBuffer vBuffer)
 {
     // create buffer
     vBuffer = new VertexBuffer(typeof(CustomVertex.PositionTextured), (width - 2) * (height - 2), gDevice,
                                Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Managed);
     CustomVertex.PositionTextured[] verts = (CustomVertex.PositionTextured[])vBuffer.Lock(0, LockFlags.None);
     
     // fill buffer
     Vector2 scale = new Vector2(area.X / (width - 1), area.Y / (height - 1));
     Vector2 texScale = new Vector2(1f / (width - 1), 1f / (height - 1));
     float halfPixel = texScale.X / 2;
     texScale = new Vector2((1 - texScale.X) / (width - 1), (1 - texScale.Y) / (height - 1));
     int vIdx = 0;
     for (int y = 1; y < height - 1; y++)
     {
         for (int x = 1; x < width - 1; x++)
         {
             verts[vIdx++] = new CustomVertex.PositionTextured(x * scale.X, 0, y * scale.Y, (x * texScale.X) + halfPixel, (y * texScale.Y) + halfPixel);
         }
     }
     vBuffer.Unlock();
 }
Ejemplo n.º 37
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 mesh
            TgcSceneLoader loader = new TgcSceneLoader();
            mesh = loader.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir + "ModelosTgc\\Teapot\\Teapot-TgcScene.xml").Meshes[0];

            //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";
            mesh.Effect = effect;
            //Camara
            GuiController.Instance.RotCamera.Enable = true;
            GuiController.Instance.RotCamera.CameraCenter = new Vector3(0, 0, 0);
            GuiController.Instance.RotCamera.CameraDistance = 150;

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

            antMatWorldView  = Matrix.Identity;



        }
Ejemplo n.º 38
0
		// Read star catalog and build vertex list
		private void LoadStars()
		{
            string DecSep = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
			sphereRadius = drawArgs.WorldCamera.WorldRadius * 20;
			refWidth = drawArgs.device.Viewport.Width;
			StarCount = 0;
			FlareCount = 0;
			int idxRAhms = 2;		// Catalog field indices
			int idxDEdms = 3;
			int idxVmag = 4;
			int idxBV = 5;
			string line;
			int isData = 0;

			// Count stars and flares
			TextReader tr = File.OpenText(Path.Combine(pluginPath, catalogFileName));
			while ((line = tr.ReadLine()) != null) 
			{
				if(line.Length < 3) continue;
				if(line.Substring(0, 1) == "#") continue;
				if(isData == 0 && line.IndexOf("RA") != -1) // Field names here
				{
					// Find out fields indices
					string[] fieldData = line.Split(';');
					for(int i = 0; i < fieldData.Length; i++) 
					{
						if(fieldData[i] == "RAhms") idxRAhms = i;
						if(fieldData[i] == "DEdms") idxDEdms = i;
						if(fieldData[i] == "Vmag") idxVmag = i;
						if(fieldData[i] == "B-V") idxBV = i;
					}
				}
				if(isData == 1) // Star data here
				{
					StarCount++; // just counting now...
					// Data in ';' separated values
					string[] starData = line.Split(';');
					string Vmag = starData[idxVmag];	// Aparent magnitude	" 4.78"
					// check magnitude -1.5 - 10 for flares
					double VM = Convert.ToDouble(Vmag.Replace(".", DecSep));
					if(VM < FlareMag) FlareCount++;
				}
				if(line.Substring(0, 3) == "---") isData = 1;
			}
			tr.Close();
			
			// Create vertex buffer for stars
			int idx = 0;
			StarListVB = new VertexBuffer( typeof(CustomVertex.PositionColored),
				StarCount, drawArgs.device,
				Usage.Points | Usage.WriteOnly,
				CustomVertex.PositionColored.Format,
				Pool.Managed );
			CustomVertex.PositionColored[] verts = new CustomVertex.PositionColored[StarCount];
			
			// Create mesh for flares
			int vertIndex=0;
			CustomVertex.PositionTextured pnt;
			Vector3 v;
			int numVertices = 4 * FlareCount;
			int numFaces	= 2 * FlareCount;
			FlareMesh = new Mesh(numFaces, numVertices, MeshFlags.Managed, CustomVertex.PositionTextured.Format, drawArgs.device);
			// Get the original mesh's vertex buffer.
			int [] ranks = new int[1];
			ranks[0] = FlareMesh.NumberVertices;
			System.Array arr = FlareMesh.VertexBuffer.Lock(0,typeof(CustomVertex.PositionTextured),LockFlags.None,ranks);
			
			// Now process star data and build vertex list and flare mesh
			double longitude = 0;
			double latitude = 0;
			double maxVdec = 0;
			double maxBVdec = -99;
			double minBVdec = 99;
			isData = 0;
			tr = File.OpenText(Path.Combine(pluginPath, catalogFileName));
            while ((line = tr.ReadLine()) != null) 
			{
				if(line.Length < 3) continue;
				if(line.Substring(0, 1) == "#") continue;
				if(isData == 1) // Star data here
				{
					// Data in ';' separated values
					string[] starData = line.Split(';');
					string RAhms = starData[idxRAhms];	// Right Asc in H, min, sec 	"00 01 35.85"
					string DEdms = starData[idxDEdms];	// Declinaison Degre min sec	"-77 03 55.1"
					string Vmag = starData[idxVmag];	// Aparent magnitude	" 4.78"
					string BV = starData[idxBV];		// B-V spectral color	" 1.254"
					// compute RAhms into longitude
					double RAh = Convert.ToDouble(RAhms.Substring(0, 2));
					double RAm = Convert.ToDouble(RAhms.Substring(3, 2));
					double RAs = Convert.ToDouble(RAhms.Substring(6, 5).Replace(".", DecSep)); 
					longitude = (RAh * 15) + (RAm * .25) + (RAs * 0.0041666) - 180;
					// compute DEdms into latitude
					string DEsign = DEdms.Substring(0, 1);
					double DEd = Convert.ToDouble(DEdms.Substring(1, 2));
					double DEm = Convert.ToDouble(DEdms.Substring(4, 2));
					double DEs = Convert.ToDouble(DEdms.Substring(7, 4).Replace(".", DecSep)); 
					latitude = DEd + (DEm / 60) + (DEs / 3600);
					if(DEsign == "-") latitude *= -1;
					// compute aparent magnitude -1.5 - 10 to grayscale 0 - 255
					double VM = Convert.ToDouble(Vmag.Replace(".", DecSep));
					double Vdec = 255 - ((VM + 1.5) * 255 / 10);
					if(Vdec > maxVdec) maxVdec = Vdec;
					Vdec += 20; // boost luminosity
					if(Vdec > 255) Vdec = 255;
					// convert B-V  -0.5 - 4 for rgb color select
					double BVdec = 0;
					try {BVdec = Convert.ToDouble(BV.Replace(".", DecSep));}
					catch {BVdec = 0;}
					if(BVdec > maxBVdec) maxBVdec = BVdec;
					if(BVdec < minBVdec) minBVdec = BVdec;
					
					// Place vertex for point star
					v = MathEngine.SphericalToCartesian( latitude, longitude, sphereRadius);			
					verts[idx].Position = new Vector3( v.X, v.Y, v.Z );
					// color based on B-V
					verts[idx].Color = Color.FromArgb(255, (int)Vdec, (int)Vdec, (int)Vdec).ToArgb(); // gray scale default
					if(BVdec < 4)   verts[idx].Color = Color.FromArgb(255, (int)(235*Vdec/255), (int)(96*Vdec/255), (int)(10*Vdec/255)).ToArgb(); // redish
					if(BVdec < 1.5) verts[idx].Color = Color.FromArgb(255, (int)(246*Vdec/255), (int)(185*Vdec/255), (int)(20*Vdec/255)).ToArgb(); // orange
					if(BVdec < 1)   verts[idx].Color = Color.FromArgb(255, (int)(255*Vdec/255), (int)(251*Vdec/255), (int)(68*Vdec/255)).ToArgb(); // yellow
					if(BVdec < .5)  verts[idx].Color = Color.FromArgb(255, (int)(255*Vdec/255), (int)(255*Vdec/255), (int)(255*Vdec/255)).ToArgb(); // white
					if(BVdec < 0)   verts[idx].Color = Color.FromArgb(255, (int)(162*Vdec/255), (int)(195*Vdec/255), (int)(237*Vdec/255)).ToArgb(); // light blue

					// Next vertex
					idx++;

					// if flare add 4 vertex to mesh
					if(VM < FlareMag) 
					{
						double flareFactor = sphereRadius * 5 / drawArgs.device.Viewport.Width;
						double l = (VM + 1.5) / (FlareMag + 1.5) * flareFactor;	// Size of half flare texture in meter
						// Calculate perp1 and perp2 so they form a plane perpendicular to the star vector and crossing earth center
						Vector3 perp1 = Vector3.Cross( v, new Vector3(1,1,1) );
						Vector3 perp2 = Vector3.Cross( perp1, v );
						perp1.Normalize();
						perp2.Normalize();
						perp1.Scale((float)l);
						perp2.Scale((float)l);
						Vector3 v1;

						//v = MathEngine.SphericalToCartesian( latitude + l, longitude - l, sphereRadius);			
						v1 = v + perp1 - perp2;
						pnt = new CustomVertex.PositionTextured();
						pnt.Position = new Vector3( v1.X, v1.Y, v1.Z );
						pnt.Tu = 0;
						pnt.Tv = 0;
						arr.SetValue(pnt,vertIndex++);
						//v = MathEngine.SphericalToCartesian( latitude + l, longitude + l, sphereRadius);			
						v1 = v + perp1 + perp2;
						pnt = new CustomVertex.PositionTextured();
						pnt.Position = new Vector3( v1.X, v1.Y, v1.Z );
						pnt.Tu = 1;
						pnt.Tv = 0;
						arr.SetValue(pnt,vertIndex++);
						//v = MathEngine.SphericalToCartesian( latitude - l, longitude - l, sphereRadius);			
						v1 = v - perp1 - perp2;
						pnt = new CustomVertex.PositionTextured();
						pnt.Position = new Vector3( v1.X, v1.Y, v1.Z );
						pnt.Tu = 0;
						pnt.Tv = 1;
						arr.SetValue(pnt,vertIndex++);
						//v = MathEngine.SphericalToCartesian( latitude - l, longitude + l, sphereRadius);			
						v1 = v - perp1 + perp2;
						pnt = new CustomVertex.PositionTextured();
						pnt.Position = new Vector3( v1.X, v1.Y, v1.Z );
						pnt.Tu = 1;
						pnt.Tv = 1;
						arr.SetValue(pnt,vertIndex++);
					}
					

				}
				if(line.Substring(0, 3) == "---") isData = 1;
			}
			tr.Close();
			//MessageBox.Show("FlareCount : " + FlareCount.ToString(), "Info", MessageBoxButtons.OK, MessageBoxIcon.Error );


			// Set vertex buffer for stars
			StarListVB.SetData( verts, 0, LockFlags.None );

			// Set flare mesh indices
			FlareMesh.VertexBuffer.Unlock();
			ranks[0] = numFaces * 3;
			arr = FlareMesh.LockIndexBuffer(typeof(short),LockFlags.None,ranks);
			vertIndex = 0;
			for(int flare = 0; flare < FlareCount; flare++)
			{
				short v1 = (short)(flare * 4);
				arr.SetValue(v1, vertIndex++);
				arr.SetValue((short)(v1 + 1), vertIndex++);
				arr.SetValue((short)(v1 + 2),vertIndex++);
				arr.SetValue((short)(v1 + 1), vertIndex++);
				arr.SetValue((short)(v1 + 3), vertIndex++);
				arr.SetValue((short)(v1 + 2),vertIndex++);
			}
			FlareMesh.IndexBuffer.SetData(arr,0,LockFlags.None);
            FlareMesh.UnlockIndexBuffer();
        }
Ejemplo n.º 39
0
        /// <summary>
        /// Crea la malla de un terreno en base a un Heightmap
        /// </summary>
        /// <param name="heightmapPath">Imagen de Heightmap</param>
        /// <param name="scaleXZ">Escala para los ejes X y Z</param>
        /// <param name="scaleY">Escala para el eje Y</param>
        /// <param name="center">Centro de la malla del terreno</param>
        public void loadHeightmap(string heightmapPath, float scaleXZ, float scaleY, Vector3 center)
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;
            this.center = center;

            //Dispose de VertexBuffer anterior, si habia
            if (vbTerrain != null && !vbTerrain.Disposed)
            {
                vbTerrain.Dispose();
            }

            //cargar heightmap
            heightmapData = loadHeightMap(d3dDevice, heightmapPath);
            float width = (float)heightmapData.GetLength(0);
            float length = (float)heightmapData.GetLength(1);

            //Crear vertexBuffer
            totalVertices = 2 * 3 * (heightmapData.GetLength(0) - 1) * (heightmapData.GetLength(1) - 1);
            vbTerrain = new VertexBuffer(typeof(CustomVertex.PositionTextured), totalVertices, d3dDevice, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default);

            //Cargar vertices
            int dataIdx = 0;
            CustomVertex.PositionTextured[] data = new CustomVertex.PositionTextured[totalVertices];

            center.X = center.X * scaleXZ - (width / 2) * scaleXZ;
            center.Y = center.Y * scaleY;
            center.Z = center.Z * scaleXZ - (length / 2) * scaleXZ;

            for (int i = 0; i < width - 1; i++)
            {
                for (int j = 0; j < length - 1; j++)
                {
                    //Vertices
                    Vector3 v1 = new Vector3(center.X + i * scaleXZ, center.Y + heightmapData[i, j] * scaleY, center.Z + j * scaleXZ);
                    Vector3 v2 = new Vector3(center.X + i * scaleXZ, center.Y + heightmapData[i, j + 1] * scaleY, center.Z + (j + 1) * scaleXZ);
                    Vector3 v3 = new Vector3(center.X + (i + 1) * scaleXZ, center.Y + heightmapData[i + 1, j] * scaleY, center.Z + j * scaleXZ);
                    Vector3 v4 = new Vector3(center.X + (i + 1) * scaleXZ, center.Y + heightmapData[i + 1, j + 1] * scaleY, center.Z + (j + 1) * scaleXZ);

                    //Coordendas de textura
                    Vector2 t1 = new Vector2(i / width, j / length);
                    Vector2 t2 = new Vector2(i / width, (j + 1) / length);
                    Vector2 t3 = new Vector2((i + 1) / width, j / length);
                    Vector2 t4 = new Vector2((i + 1) / width, (j + 1) / length);

                    //Cargar triangulo 1
                    data[dataIdx] = new CustomVertex.PositionTextured(v1, t1.X, t1.Y);
                    data[dataIdx + 1] = new CustomVertex.PositionTextured(v2, t2.X, t2.Y);
                    data[dataIdx + 2] = new CustomVertex.PositionTextured(v4, t4.X, t4.Y);

                    //Cargar triangulo 2
                    data[dataIdx + 3] = new CustomVertex.PositionTextured(v1, t1.X, t1.Y);
                    data[dataIdx + 4] = new CustomVertex.PositionTextured(v4, t4.X, t4.Y);
                    data[dataIdx + 5] = new CustomVertex.PositionTextured(v3, t3.X, t3.Y);

                    dataIdx += 6;
                }
            }

            vbTerrain.SetData(data, 0, LockFlags.None);
        }
Ejemplo n.º 40
0
        /// <summary>
        /// Actualiza la caja en base a los valores configurados
        /// </summary>
        public void updateValues()
        {
            //Crear grilla de 4x4 caras rectangulares
            bool triangleSide1 = true;
            int vIndex = 0;
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    //Los 4 vertices que forman la cara
                    EditableVertex tl = editableVertices[i * 5 + j];
                    EditableVertex tr = editableVertices[i * 5 + j + 1];
                    EditableVertex bl = editableVertices[(i + 1) * 5 + j];
                    EditableVertex br = editableVertices[(i + 1) * 5 + j + 1];

                    if (triangleSide1)
                    {
                        //Sentido 1
                        //Primer triangulo: tl - br - bl
                        vertices[vIndex] = new CustomVertex.PositionTextured(tl.Pos, uvOffset.X + uvTiling.X * tl.UV.X, uvOffset.Y + uvTiling.Y * tl.UV.Y);
                        vertices[vIndex + 1] = new CustomVertex.PositionTextured(br.Pos, uvOffset.X + uvTiling.X * br.UV.X, uvOffset.Y + uvTiling.Y * br.UV.Y);
                        vertices[vIndex + 2] = new CustomVertex.PositionTextured(bl.Pos, uvOffset.X + uvTiling.X * bl.UV.X, uvOffset.Y + uvTiling.Y * bl.UV.Y);

                        //Segundo triangulo: tl - tr - br
                        vertices[vIndex + 3] = new CustomVertex.PositionTextured(tl.Pos, uvOffset.X + uvTiling.X * tl.UV.X, uvOffset.Y + uvTiling.Y * tl.UV.Y);
                        vertices[vIndex + 4] = new CustomVertex.PositionTextured(tr.Pos, uvOffset.X + uvTiling.X * tr.UV.X, uvOffset.Y + uvTiling.Y * tr.UV.Y);
                        vertices[vIndex + 5] = new CustomVertex.PositionTextured(br.Pos, uvOffset.X + uvTiling.X * br.UV.X, uvOffset.Y + uvTiling.Y * br.UV.Y);
                    }
                    else
                    {
                        //Sentido 2
                        //bl - tl - tr
                        vertices[vIndex] = new CustomVertex.PositionTextured(bl.Pos, uvOffset.X + uvTiling.X * bl.UV.X, uvOffset.Y + uvTiling.Y * bl.UV.Y);
                        vertices[vIndex + 1] = new CustomVertex.PositionTextured(tl.Pos, uvOffset.X + uvTiling.X * tl.UV.X, uvOffset.Y + uvTiling.Y * tl.UV.Y);
                        vertices[vIndex + 2] = new CustomVertex.PositionTextured(tr.Pos, uvOffset.X + uvTiling.X * tr.UV.X, uvOffset.Y + uvTiling.Y * tr.UV.Y);

                        //bl - tr - br
                        vertices[vIndex + 3] = new CustomVertex.PositionTextured(bl.Pos, uvOffset.X + uvTiling.X * bl.UV.X, uvOffset.Y + uvTiling.Y * bl.UV.Y);
                        vertices[vIndex + 4] = new CustomVertex.PositionTextured(tr.Pos, uvOffset.X + uvTiling.X * tr.UV.X, uvOffset.Y + uvTiling.Y * tr.UV.Y);
                        vertices[vIndex + 5] = new CustomVertex.PositionTextured(br.Pos, uvOffset.X + uvTiling.X * br.UV.X, uvOffset.Y + uvTiling.Y * br.UV.Y);
                    }
                    vIndex += 6;

                    //Invertir proximo sentido (salvo el ultimo de la fila)
                    if (j != 3)
                    {
                        triangleSide1 = !triangleSide1;
                    }
                }
            }

            vertexBuffer.SetData(vertices, 0, LockFlags.None);
            updateBoundingBox();
        }
Ejemplo n.º 41
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();

            //Cargar mesh
            scene = loader.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir
                        + "ModelosTgc\\Teapot\\Teapot-TgcScene.xml");

            mesh = scene.Meshes[0];
            mesh.Scale = new Vector3(1f, 1f, 1f);
            mesh.Position = new Vector3(-100f, -5f, 0f);

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

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

            // le asigno el efecto a la malla
            mesh.Effect = effect;
            mesh.Technique = "DefaultTechnique";

            // Creo las instancias de malla
            instances = new List<TgcMesh>();
            for (int i = -5; i < 5; i++)
                for (int j = -5; j < 5; j++)
                {
                    TgcMesh instance = mesh.createMeshInstance(mesh.Name + i);
                    instance.move(i * 50, (i + j) * 5, j * 50);
                    instances.Add(instance);
                }

            GuiController.Instance.Modifiers.addVertex3f("LightPosition", new Vector3(-100, -100, -100), new Vector3(100, 100, 100), new Vector3(0, 40, 0));
            GuiController.Instance.Modifiers.addFloat("Ambient", 0, 1, 0.5f);
            GuiController.Instance.Modifiers.addFloat("Diffuse", 0, 1, 0.6f);
            GuiController.Instance.Modifiers.addFloat("Specular", 0, 1, 0.5f);
            GuiController.Instance.Modifiers.addFloat("SpecularPower", 1, 100, 16);

            GuiController.Instance.RotCamera.setCamera(new Vector3(20, 20, 0), 200);
            GuiController.Instance.RotCamera.CameraDistance = 300;
            GuiController.Instance.RotCamera.RotationSpeed = 1.5f;

            // Creo un depthbuffer sin multisampling, para que sea compatible con el render to texture

            // Nota:
            // El render to Texture no es compatible con el multisampling en dx9
            // Por otra parte la mayor parte de las placas de ultima generacion no soportan
            // mutisampling para texturas de punto flotante con lo cual
            // hay que suponer con generalidad que no se puede usar multisampling y render to texture

            // Para resolverlo hay que crear un depth buffer que no tenga multisampling,
            // (de lo contrario falla el zbuffer y se producen artifacts tipicos de que no tiene zbuffer)

            // Si uno quisiera usar el multisampling, la tecnica habitual es usar un RenderTarget
            // en lugar de una textura.
            // Por ejemplo en c++:
            //
            // Render Target formato color buffer con multisampling
            //
            //  g_pd3dDevice->CreateRenderTarget(Ancho,Alto,
            //          D3DFMT_A8R8G8B8, D3DMULTISAMPLE_2_SAMPLES, 0,
            //          FALSE, &g_pRenderTarget, NULL);
            //
            // Luego, ese RenderTarget NO ES una textura, y nosotros necesitamos acceder a esos
            // pixeles, ahi lo que se hace es COPIAR del rendertartet a una textura,
            // para poder trabajar con esos datos en el contexto del Pixel shader:
            //
            // Eso se hace con la funcion StretchRect:
            // copia de rendertarget ---> sceneSurface (que es la superficie asociada a una textura)
            // g_pd3dDevice->StretchRect(g_pRenderTarget, NULL, g_pSceneSurface, NULL, D3DTEXF_NONE);
            //
            // Esta tecnica se llama downsampling
            // Y tiene el costo adicional de la transferencia de memoria entre el rendertarget y la
            // textura, pero que no traspasa los limites de la GPU. (es decir es muy performante)
            // no es lo mismo que lockear una textura para acceder desde la CPU, que tiene el problema
            // de transferencia via AGP.

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

            // inicializo el mapa de normales
            g_pNormals = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth
                    , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget,
                        Format.A16B16G16R16F, Pool.Default);

            effect.SetValue("g_Normals", g_pNormals);

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

            //Se crean 2 triangulos con las dimensiones de la pantalla con sus posiciones ya transformadas
            // x = -1 es el extremo izquiedo de la pantalla, x=1 es el extremo derecho
            // Lo mismo para la Y con arriba y abajo
            // la Z en 1 simpre
            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);

            efecto_blur = false;
        }
Ejemplo n.º 42
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\\Deposito\\Deposito-TgcScene.xml");
            meshes = scene.Meshes;

            //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(-182.3816f, 82.3252f, -811.9061f), new Vector3(-182.0957f, 82.3147f, -810.9479f));

            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_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[]
            {
                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_efecto", "Activar efecto", true);
            GuiController.Instance.Modifiers.addBoolean("separable", "Separable Blur", true);
            GuiController.Instance.Modifiers.addInt("cant_pasadas", 1, 10, 1);
        }
Ejemplo n.º 43
0
        public override void init()
        {
            instance = this;

            pantallas.Add(new PantallaInicio());
            pantallas.Add(new PantallaFinalizacion(0));
            pantallas.Add(new PantallaFinalizacion(1));

            pantalla = pantallas[0];

            //Aumentamos el alcance del Frustum
            setDistanciaFrustum(200000f);

            //Paths de meshes de distintos vehículos
            string pathAutoMario = GuiController.Instance.AlumnoEjemplosMediaDir + "LosBorbotones\\Autos\\autoMario\\autoMario-TgcScene.xml";
            string pathAutoLuigi = GuiController.Instance.AlumnoEjemplosMediaDir + "LosBorbotones\\Autos\\autoLuigi\\autoLuigi-TgcScene.xml";

            // Creo los vehículos
            Auto autoMario = new Auto(pathAutoMario, "Mario", new Vector3(0, 0, 0), 2000, 90, 400, 47, new Vector3(2.4f, 2.4f, 2.4f), new Vector3(0,0,0));
            Auto autoLuigi = new Auto(pathAutoLuigi, "Luigi", new Vector3(0, 0, 0), 3000, 80, 500, 40, new Vector3(3f, 3f, 3f), new Vector3(0, 0, 0));
            this.autos.Add(autoMario);
            this.autos.Add(autoLuigi);

            TgcSceneLoader loader = new TgcSceneLoader();

            //Crea los arboles
            string pathArbol = GuiController.Instance.AlumnoEjemplosMediaDir + "\\LosBorbotones\\ambientacion\\arbol\\arbol-TgcScene.xml"; ;
            int cantidadDeArboles = 8;
            for (int i = 0; i < cantidadDeArboles;i++ )
                this.arboles.Add(loader.loadSceneFromFile(pathArbol));

            //Crea el circuito
            this.niveles.Add( new Nivel(1) );
            this.niveles.Add(new Nivel(2));

            /// EFECTO BLUR ///
            Device d3dDevice = GuiController.Instance.D3dDevice;

            //Activamos el renderizado customizado. De esta forma el framework nos delega control total sobre como dibujar en pantalla
            //La responsabilidad cae toda de nuestro lado
            GuiController.Instance.CustomRenderEnabled = true;

            //Se crean 2 triangulos (o Quad) con las dimensiones de la pantalla con sus posiciones ya transformadas
            // x = -1 es el extremo izquiedo de la pantalla, x = 1 es el extremo derecho
            // Lo mismo para la Y con arriba y abajo
            // la Z en 1 simpre
            CustomVertex.PositionTextured[] screenQuadVertices = 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
            screenQuadVB = new VertexBuffer(typeof(CustomVertex.PositionTextured),
                    4, d3dDevice, Usage.Dynamic | Usage.WriteOnly,
                        CustomVertex.PositionTextured.Format, Pool.Default);
            screenQuadVB.SetData(screenQuadVertices, 0, LockFlags.None);

            //Creamos un Render Targer sobre el cual se va a dibujar la pantalla
            renderTarget2D = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth
                    , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget,
                        Format.X8R8G8B8, Pool.Default);

            //Cargar shader con efectos de Post-Procesado
            string compilationErrors;
            effect = Effect.FromFile(GuiController.Instance.D3dDevice,
                GuiController.Instance.ExamplesMediaDir + "Shaders\\PostProcess.fx",
                null, null, ShaderFlags.None, null, out compilationErrors);
            if (effect == null)
            {
                throw new Exception("Error al cargar shader. Errores: " + compilationErrors);
            }
            //Configurar Technique dentro del shader
            effect.Technique = "BlurTechnique";
            /// FIN EFECTO BLUR ///

            //MODIFIERS
            GuiController.Instance.Modifiers.addVertex2f("AlturaCamara", new Vector2(50, 200), new Vector2(800, 2000), new Vector2(200, 600));
            GuiController.Instance.Modifiers.addVertex2f("PosicionFlechaDebug", new Vector2(-5000, -5000), new Vector2(5000, 5000), new Vector2(0, 0));
        }
Ejemplo n.º 44
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);
        }
        private void OnVertexBufferCreate(object sender, EventArgs e)
        {
            VertexBuffer buffer = (VertexBuffer)sender;
            CustomVertex.PositionTextured[] verts = new CustomVertex.PositionTextured[numVerts];
            // 1st facet ---------------------------------------------------------
            //triangle 1
            verts[0] = new CustomVertex.PositionTextured(0, 0, 0, 0, 0);
            verts[1] = new CustomVertex.PositionTextured(90, 0, 0, 1, 0);
            verts[2] = new CustomVertex.PositionTextured(0, 90, 0, 0, 1);

            //triangle 2
            verts[3] = new CustomVertex.PositionTextured(0, 90, 0, 0, 1);
            verts[4] = new CustomVertex.PositionTextured(90, 0, 0, 1, 0);
            verts[5] = new CustomVertex.PositionTextured(90, 90, 0, 1, 1);

            // 2nd facet ---------------------------------------------------------
            //triangle 1
            verts[6] = new CustomVertex.PositionTextured(90, 0, 0, 0, 0);
            verts[7] = new CustomVertex.PositionTextured(90, 90, 0, 1, 0);
            verts[8] = new CustomVertex.PositionTextured(90, 0, 90, 0, 1);

            //triangle 2
            verts[9] = new CustomVertex.PositionTextured(90, 0, 90, 0, 1);
            verts[10] = new CustomVertex.PositionTextured(90, 90, 0, 1, 0);
            verts[11] = new CustomVertex.PositionTextured(90, 90, 90, 1, 1);

            // 3rd facet ---------------------------------------------------------
            //triangle 1
            verts[12] = new CustomVertex.PositionTextured(0, 0, 0, 0, 0);
            verts[13] = new CustomVertex.PositionTextured(90, 0, 0, 1, 0);
            verts[14] = new CustomVertex.PositionTextured(0, 0, 90, 0, 1);

            //triangle 2
            verts[15] = new CustomVertex.PositionTextured(0, 0, 90, 0, 1);
            verts[16] = new CustomVertex.PositionTextured(90, 0, 0, 1, 0);
            verts[17] = new CustomVertex.PositionTextured(90, 0, 90, 1, 1);

            // 4th facet ---------------------------------------------------------
            //triangle 1
            verts[18] = new CustomVertex.PositionTextured(0, 0, 0, 0, 0);
            verts[19] = new CustomVertex.PositionTextured(0, 90, 0, 1, 0);
            verts[20] = new CustomVertex.PositionTextured(0, 0, 90, 0, 1);

            //triangle 2
            verts[21] = new CustomVertex.PositionTextured(0, 0, 90, 0, 1);
            verts[22] = new CustomVertex.PositionTextured(0, 90, 0, 1, 0);
            verts[23] = new CustomVertex.PositionTextured(0, 90, 90, 1, 1);

            // 5th facet ---------------------------------------------------------
            //triangle 1
            verts[24] = new CustomVertex.PositionTextured(0, 0, 90, 0, 0);
            verts[25] = new CustomVertex.PositionTextured(90, 0, 90, 1, 0);
            verts[26] = new CustomVertex.PositionTextured(0, 90, 90, 0, 1);

            //triangle 2
            verts[27] = new CustomVertex.PositionTextured(0, 90, 90, 0, 1);
            verts[28] = new CustomVertex.PositionTextured(90, 0, 90, 1, 0);
            verts[29] = new CustomVertex.PositionTextured(90, 90, 90, 1, 1);

            // 6th facet ---------------------------------------------------------
            //triangle 1
            verts[30] = new CustomVertex.PositionTextured(0, 90, 0, 0, 0);
            verts[31] = new CustomVertex.PositionTextured(90, 90, 0, 1, 0);
            verts[32] = new CustomVertex.PositionTextured(0, 90, 90, 0, 1);

            //triangle 2
            verts[33] = new CustomVertex.PositionTextured(0, 90, 90, 0, 1);
            verts[34] = new CustomVertex.PositionTextured(90, 90, 0, 1, 0);
            verts[35] = new CustomVertex.PositionTextured(90, 90, 90, 1, 1);

            buffer.SetData(verts, 0, LockFlags.None);
        }
Ejemplo n.º 46
0
        /// <summary>
        /// Actualizar parámetros de la pared en base a los valores configurados
        /// </summary>
        public void updateValues()
        {
            float autoWidth;
            float autoHeight;

            //Calcular los 4 corners de la pared, segun el tipo de orientacion
            Vector3 bLeft, tLeft, bRight, tRight;
            if (orientation == Orientations.XYplane)
            {
                bLeft = origin;
                tLeft = new Vector3(origin.X + size.X, origin.Y, origin.Z);
                bRight = new Vector3(origin.X, origin.Y + size.Y, origin.Z);
                tRight = new Vector3(origin.X + size.X, origin.Y + size.Y, origin.Z);

                autoWidth = (size.X / texture.Width);
                autoHeight = (size.Y / texture.Height);
            }
            else if(orientation == Orientations.YZplane)
            {
                bLeft = origin;
                tLeft = new Vector3(origin.X, origin.Y, origin.Z + size.Z);
                bRight = new Vector3(origin.X, origin.Y + size.Y, origin.Z);
                tRight = new Vector3(origin.X, origin.Y + size.Y, origin.Z + size.Z);

                autoWidth = (size.Y / texture.Width);
                autoHeight = (size.Z / texture.Height);
            }
            else
            {
                bLeft = origin;
                tLeft = new Vector3(origin.X + size.X, origin.Y, origin.Z);
                bRight = new Vector3(origin.X, origin.Y, origin.Z + size.Z);
                tRight = new Vector3(origin.X + size.X, origin.Y, origin.Z + size.Z);

                autoWidth = (size.X / texture.Width);
                autoHeight = (size.Z / texture.Height);
            }

            //Auto ajustar UV
            if (autoAdjustUv)
            {
                this.uTile = autoHeight;
                this.vTile = autoWidth;
            }
            float offsetU = this.uvOffset.X;
            float offsetV = this.uvOffset.Y;

            //Primer triangulo
            vertices[0] = new CustomVertex.PositionTextured(bLeft, offsetU + uTile, offsetV + vTile);
            vertices[1] = new CustomVertex.PositionTextured(tLeft, offsetU, offsetV + vTile);
            vertices[2] = new CustomVertex.PositionTextured(tRight, offsetU, offsetV);

            //Segundo triangulo
            vertices[3] = new CustomVertex.PositionTextured(bLeft, offsetU + uTile, offsetV + vTile);
            vertices[4] = new CustomVertex.PositionTextured(tRight, offsetU, offsetV);
            vertices[5] = new CustomVertex.PositionTextured(bRight, offsetU + uTile, offsetV);

            /*Versión con triángulos para el otro sentido
            //Primer triangulo
            vertices[0] = new CustomVertex.PositionTextured(tLeft, 0 * this.uTile, 1 * this.vTile);
            vertices[1] = new CustomVertex.PositionTextured(bLeft, 1 * this.uTile, 1 * this.vTile);
            vertices[2] = new CustomVertex.PositionTextured(bRight, 1 * this.uTile, 0 * this.vTile);

            //Segundo triangulo
            vertices[3] = new CustomVertex.PositionTextured(bRight, 1 * this.uTile, 0 * this.vTile);
            vertices[4] = new CustomVertex.PositionTextured(tRight, 0 * this.uTile, 0 * this.vTile);
            vertices[5] = new CustomVertex.PositionTextured(tLeft, 0 * this.uTile, 1 * this.vTile);
            */

            //BoundingBox
            boundingBox.setExtremes(bLeft, tRight);
        }
Ejemplo n.º 47
0
        public override void Init(Device device)
        {
            this.device = device;

            texQuad = new CustomVertex.PositionTextured[4];
            texQuad[0] = new CustomVertex.PositionTextured(new Vector3(), 0, 0);
            texQuad[1] = new CustomVertex.PositionTextured(new Vector3(), 1, 0);
            texQuad[2] = new CustomVertex.PositionTextured(new Vector3(), 0, 1);
            texQuad[3] = new CustomVertex.PositionTextured(new Vector3(), 1, 1);

            tex = TextureLoader.FromFile(device, (string)HashTableSettings.Instance["Base.Path"] + @"Media/AtomSelection.png");
        }
Ejemplo n.º 48
0
        /// <summary>
        /// Crea y carga el VertexBuffer en base a una textura de Heightmap
        /// </summary>
        private void createHeightMapMesh(Device d3dDevice, string path, float scaleXZ, float scaleY)
        {
            //parsear bitmap y cargar matriz de alturas
            int[,] heightmap = loadHeightMap(d3dDevice, path);

            //Crear vertexBuffer
            totalVertices = 2 * 3 * (heightmap.GetLength(0) - 1) * (heightmap.GetLength(1) - 1);
            vbTerrain = new VertexBuffer(typeof(CustomVertex.PositionTextured), totalVertices, d3dDevice, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default);

            //Crear array temporal de vertices
            int dataIdx = 0;
            CustomVertex.PositionTextured[] data = new CustomVertex.PositionTextured[totalVertices];

            //Iterar sobre toda la matriz del Heightmap y crear los triangulos necesarios para el terreno
            for (int i = 0; i < heightmap.GetLength(0) - 1; i++)
            {
                for (int j = 0; j < heightmap.GetLength(1) - 1; j++)
                {
                    //Crear los cuatro vertices que conforman este cuadrante, aplicando la escala correspondiente
                    Vector3 v1 = new Vector3(i * scaleXZ, heightmap[i, j] * scaleY, j * scaleXZ);
                    Vector3 v2 = new Vector3(i * scaleXZ, heightmap[i, j + 1] * scaleY, (j + 1) * scaleXZ);
                    Vector3 v3 = new Vector3((i + 1) * scaleXZ, heightmap[i + 1, j] * scaleY, j * scaleXZ);
                    Vector3 v4 = new Vector3((i + 1) * scaleXZ, heightmap[i + 1, j + 1] * scaleY, (j + 1) * scaleXZ);

                    //Crear las coordenadas de textura para los cuatro vertices del cuadrante
                    Vector2 t1 = new Vector2(i / (float)heightmap.GetLength(0), j / (float)heightmap.GetLength(1));
                    Vector2 t2 = new Vector2(i / (float)heightmap.GetLength(0), (j + 1) / (float)heightmap.GetLength(1));
                    Vector2 t3 = new Vector2((i + 1) / (float)heightmap.GetLength(0), j / (float)heightmap.GetLength(1));
                    Vector2 t4 = new Vector2((i + 1) / (float)heightmap.GetLength(0), (j + 1) / (float)heightmap.GetLength(1));

                    //Cargar triangulo 1
                    data[dataIdx] = new CustomVertex.PositionTextured(v1, t1.X, t1.Y);
                    data[dataIdx + 1] = new CustomVertex.PositionTextured(v2, t2.X, t2.Y);
                    data[dataIdx + 2] = new CustomVertex.PositionTextured(v4, t4.X, t4.Y);

                    //Cargar triangulo 2
                    data[dataIdx + 3] = new CustomVertex.PositionTextured(v1, t1.X, t1.Y);
                    data[dataIdx + 4] = new CustomVertex.PositionTextured(v4, t4.X, t4.Y);
                    data[dataIdx + 5] = new CustomVertex.PositionTextured(v3, t3.X, t3.Y);

                    dataIdx += 6;
                }
            }

            //Llenar todo el VertexBuffer con el array temporal
            vbTerrain.SetData(data, 0, LockFlags.None);
        }
Ejemplo n.º 49
0
        public override void Init(Device device)
        {
            this.device = device;

            texQuad = new CustomVertex.PositionTextured[4];
            texQuad[0] = new CustomVertex.PositionTextured(new Vector3(), 0, 0);
            texQuad[1] = new CustomVertex.PositionTextured(new Vector3(), 1, 0);
            texQuad[2] = new CustomVertex.PositionTextured(new Vector3(), 0, 1);
            texQuad[3] = new CustomVertex.PositionTextured(new Vector3(), 1, 1);

            texture = ChemSymbolTextures.Instance[atom.Atom.Symbol];
        }
Ejemplo n.º 50
0
        public void loadHeightmap(string heightmapPath, float pscaleXZ, float pscaleY, Vector3 center)
        {
            scaleXZ = pscaleXZ;
            scaleY = pscaleY;

            Device d3dDevice = GuiController.Instance.D3dDevice;
            this.center = center;

            //Dispose de VertexBuffer anterior, si habia
            if (vbTerrain != null && !vbTerrain.Disposed)
            {
                vbTerrain.Dispose();
            }

            //cargar heightmap
            heightmapData = loadHeightMap(d3dDevice, heightmapPath);
            float width = (float)heightmapData.GetLength(0);
            float length = (float)heightmapData.GetLength(1);


            //Crear vertexBuffer
            totalVertices = 2 * 3 * (heightmapData.GetLength(0)+1 ) * (heightmapData.GetLength(1)+1 );
            totalVertices *= (int)ki * (int)kj;
            vbTerrain = new VertexBuffer(typeof(CustomVertex.PositionTextured), totalVertices, d3dDevice, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default);

            //Cargar vertices
            int dataIdx = 0;
            CustomVertex.PositionTextured[] data = new CustomVertex.PositionTextured[totalVertices];

            center.X = center.X * scaleXZ - (width / 2) * scaleXZ;
            center.Y = center.Y * scaleY;
            center.Z = center.Z * scaleXZ - (length / 2) * scaleXZ;

            if (torus)
            {
                float di = width * ki;
                float dj = length* kj;

                for (int i = 0; i < width*ki; i++)
                {
                    for (int j = 0; j < length*kj; j++)
                    {
                        int ri = i % (int)width;
                        int rj = j % (int)length;
                        int ri1 = (i + 1)  % (int)width;
                        int rj1 = (j + 1)  % (int)length;


                        Vector3 v1, v2, v3, v4;
                        {
                            float r = radio_2 + heightmapData[ri, rj] * scaleY;
                            float s = 2f * (float)Math.PI * j / dj;
                            float t = -(float)Math.PI * i / di;
                            float x = (float)Math.Cos(s) * (radio_1 + r * (float)Math.Cos(t));
                            float z = (float)Math.Sin(s) * (radio_1 + r * (float)Math.Cos(t));
                            float y = r * (float)Math.Sin(t);
                            v1 = new Vector3(x, y, z);
                        }   
                        {
                            float r = radio_2 + heightmapData[ri, rj1] * scaleY;
                            float s = 2f * (float)Math.PI * (j + 1) / dj;
                            float t = -(float)Math.PI * i / di;
                            float x = (float)Math.Cos(s) * (radio_1 + r * (float)Math.Cos(t));
                            float z = (float)Math.Sin(s) * (radio_1 + r * (float)Math.Cos(t));
                            float y = r * (float)Math.Sin(t);
                            v2 = new Vector3(x, y, z);
                        }
                        {
                            float r = radio_2 + heightmapData[ri1, rj] * scaleY;
                            float s = 2f * (float)Math.PI * j / dj;
                            float t = -(float)Math.PI * (i + 1) / di;
                            float x = (float)Math.Cos(s) * (radio_1 + r * (float)Math.Cos(t));
                            float z = (float)Math.Sin(s) * (radio_1 + r * (float)Math.Cos(t));
                            float y = r * (float)Math.Sin(t);
                            v3 = new Vector3(x, y, z);
                        }
                        {
                            float r = radio_2 + heightmapData[ri1, rj1] * scaleY;
                            float s = 2f * (float)Math.PI * (j + 1) / dj;
                            float t = -(float)Math.PI * (i + 1) / di;
                            float x = (float)Math.Cos(s) * (radio_1 + r * (float)Math.Cos(t));
                            float z = (float)Math.Sin(s) * (radio_1 + r * (float)Math.Cos(t));
                            float y = r * (float)Math.Sin(t);
                            v4 = new Vector3(x, y, z);
                        }

                        //Coordendas de textura
                        Vector2 t1 = new Vector2(ftex * i / width, ftex * j / length);
                        Vector2 t2 = new Vector2(ftex * i / width, ftex * (j + 1) / length);
                        Vector2 t3 = new Vector2(ftex * (i + 1) / width, ftex * j / length);
                        Vector2 t4 = new Vector2(ftex * (i + 1) / width, ftex * (j + 1) / length);

                        //Cargar triangulo 1
                        data[dataIdx] = new CustomVertex.PositionTextured(v1, t1.X, t1.Y);
                        data[dataIdx + 1] = new CustomVertex.PositionTextured(v2, t2.X, t2.Y);
                        data[dataIdx + 2] = new CustomVertex.PositionTextured(v4, t4.X, t4.Y);

                        //Cargar triangulo 2
                        data[dataIdx + 3] = new CustomVertex.PositionTextured(v1, t1.X, t1.Y);
                        data[dataIdx + 4] = new CustomVertex.PositionTextured(v4, t4.X, t4.Y);
                        data[dataIdx + 5] = new CustomVertex.PositionTextured(v3, t3.X, t3.Y);

                        dataIdx += 6;
                    }
                }
            }
            else
            {
                for (int i = 0; i < width - 1; i++)
                {
                    for (int j = 0; j < length - 1; j++)
                    {
                        //Vertices
                        Vector3 v1 = new Vector3(center.X + i * scaleXZ, center.Y + heightmapData[i, j] * scaleY, center.Z + j * scaleXZ);
                        Vector3 v2 = new Vector3(center.X + i * scaleXZ, center.Y + heightmapData[i, j + 1] * scaleY, center.Z + (j + 1) * scaleXZ);
                        Vector3 v3 = new Vector3(center.X + (i + 1) * scaleXZ, center.Y + heightmapData[i + 1, j] * scaleY, center.Z + j * scaleXZ);
                        Vector3 v4 = new Vector3(center.X + (i + 1) * scaleXZ, center.Y + heightmapData[i + 1, j + 1] * scaleY, center.Z + (j + 1) * scaleXZ);

                        //Coordendas de textura
                        Vector2 t1 = new Vector2(ftex * i / width, ftex * j / length);
                        Vector2 t2 = new Vector2(ftex * i / width, ftex * (j + 1) / length);
                        Vector2 t3 = new Vector2(ftex * (i + 1) / width, ftex * j / length);
                        Vector2 t4 = new Vector2(ftex * (i + 1) / width, ftex * (j + 1) / length);

                        //Cargar triangulo 1
                        data[dataIdx] = new CustomVertex.PositionTextured(v1, t1.X, t1.Y);
                        data[dataIdx + 1] = new CustomVertex.PositionTextured(v2, t2.X, t2.Y);
                        data[dataIdx + 2] = new CustomVertex.PositionTextured(v4, t4.X, t4.Y);

                        //Cargar triangulo 2
                        data[dataIdx + 3] = new CustomVertex.PositionTextured(v1, t1.X, t1.Y);
                        data[dataIdx + 4] = new CustomVertex.PositionTextured(v4, t4.X, t4.Y);
                        data[dataIdx + 5] = new CustomVertex.PositionTextured(v3, t3.X, t3.Y);

                        dataIdx += 6;
                    }
                }
            }

            vbTerrain.SetData(data, 0, LockFlags.None);
        }
Ejemplo n.º 51
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\\Deposito\\Deposito-TgcScene.xml");
            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];
            TgcScene scene4 = loader.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir + "MeshCreator\\Meshes\\Vegetacion\\Arbusto2\\Arbusto2-TgcScene.xml");
            arbusto = scene4.Meshes[0];

            //Cargar personaje con animaciones
            TgcSkeletalLoader skeletalLoader = new TgcSkeletalLoader();
            Random rnd = new Random();
            for (int t = 0; t < 25; ++t)
            {
                enemigos.Add(skeletalLoader.loadMeshAndAnimationsFromFile(
                    GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\BasicHuman\\" + "CombineSoldier-TgcSkeletalMesh.xml",
                    GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\BasicHuman\\",
                    new string[] {
                    GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\BasicHuman\\Animations\\" + "StandBy-TgcSkeletalAnim.xml",
                    GuiController.Instance.ExamplesMediaDir + "SkeletalAnimations\\BasicHuman\\Animations\\" + "Run-TgcSkeletalAnim.xml",
                }));

                //Configurar animacion inicial
                enemigos[t].playAnimation("StandBy", true);
                enemigos[t].Position = new Vector3(-rnd.Next(0, 1500) - 250, 0, -rnd.Next(0, 1500) - 250);
                enemigos[t].Scale = new Vector3(2f, 2f, 2f);

                bot_status[t] = 0;

            }

            //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(-1000, 50, -1000), new Vector3(-1000, 50, -1001));
            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.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[]
            {
                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_efecto", "Activar efecto", true);

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

            for (int i = 0; i < cant_balas;++i )
            {
                timer_firing[i] = (float)i / (float)cant_balas * total_timer_firing;
            }
        }
Ejemplo n.º 52
0
            /// <summary>
            /// The create hill object.
            /// </summary>
            /// <param name="device">The device.</param>
            /// <param name="hillPoints">The hill points.</param>
            /// <returns></returns>
            /// <remarks></remarks>
            public static Mesh createHillObject(Device device, List<Vector3> hillPoints)
            {
                Mesh mesh;

                short[] arrayIndices = new short[(hillPoints.Count * 2 - 1) * 6];
                CustomVertex.PositionTextured[] arrayVertices = new CustomVertex.PositionTextured[hillPoints.Count * 2];
                AttributeRange attributeRange = new AttributeRange();

                // Create mesh with desired vertex format and desired size
                mesh = new Mesh(
                    arrayIndices.Length / 3,
                    arrayVertices.Length,
                    MeshFlags.SystemMemory,
                    CustomVertex.PositionTextured.Format,
                    device);

                // For each point in the height field calculate the x, y, z and
                // texture coordinates.
                for (int y = 0; y < hillPoints.Count; y++)
                {
                    CustomVertex.PositionTextured vertex = new CustomVertex.PositionTextured(
                        hillPoints[y].X, hillPoints[y].Y, hillPoints[y].Z, 0, 0);
                    arrayVertices[y * 2] = vertex;
                    vertex = new CustomVertex.PositionTextured(
                        hillPoints[y].X, hillPoints[y].Y, hillPoints[y].Z + hillHeight, 0, 0);
                    arrayVertices[y * 2 + 1] = vertex;
                }

                // Calculate the index buffer.
                for (int y = 0; y < hillPoints.Count; y++)
                {
                    int arrayIndex = (y * 2) * 6;
                    int vertexIndex = y * 2;

                    if (y != hillPoints.Count - 1)
                    {
                        arrayIndices[arrayIndex + 0] = (short)vertexIndex;
                        arrayIndices[arrayIndex + 1] = (short)(vertexIndex + 1);
                        arrayIndices[arrayIndex + 2] = (short)(vertexIndex + 2);
                        arrayIndices[arrayIndex + 3] = (short)(vertexIndex + 2);
                        arrayIndices[arrayIndex + 4] = (short)(vertexIndex + 1);
                        arrayIndices[arrayIndex + 5] = (short)(vertexIndex + 3);
                    }
                    else
                    {
                        arrayIndices[arrayIndex + 0] = (short)vertexIndex;
                        arrayIndices[arrayIndex + 1] = (short)(vertexIndex + 1);
                        arrayIndices[arrayIndex + 2] = 0;
                        arrayIndices[arrayIndex + 3] = 0;
                        arrayIndices[arrayIndex + 4] = (short)(vertexIndex + 1);
                        arrayIndices[arrayIndex + 5] = 1;
                    }
                }

                // There is only one attribute value for this mesh.
                // By specifying an attribute range the DrawSubset function
                // does not have to scan the entire mesh for all faces that are
                // are marked with a particular attribute id.
                attributeRange.AttributeId = 0;
                attributeRange.FaceStart = 0;
                attributeRange.FaceCount = arrayIndices.Length / 3;
                attributeRange.VertexStart = 0;
                attributeRange.VertexCount = arrayVertices.Length;

                mesh.VertexBuffer.SetData(arrayVertices, 0, LockFlags.None);
                mesh.IndexBuffer.SetData(arrayIndices, 0, LockFlags.None);
                mesh.SetAttributeTable(new[] { attributeRange });

                return mesh;
            }
Ejemplo n.º 53
0
        private void FillVB(object sender, EventArgs e)
        {
            lock (sender)
            {
                CustomVertex.PositionTextured[] verts = new CustomVertex.PositionTextured[4];

                if (!Centered)
                {
                    verts[0] = new CustomVertex.PositionTextured(0.0f, -Height, 0.0f, 0.0f, 1.0f);
                    //Top left // 0 0 // 0 1 // 0 0
                    verts[1] = new CustomVertex.PositionTextured(0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
                    //Bottom left // 1 0 // 0 0 // 0 1
                    verts[2] = new CustomVertex.PositionTextured(Width, 0.0f, 0.0f, 1.0f, 0.0f);
                    //Bottom right // 1 1 // 1 0 // 1 1
                    verts[3] = new CustomVertex.PositionTextured(Width, -Height, 0.0f, 1.0f, 1.0f);
                    //Top right  // 0 0 // 1 1 // 1 0
                }
                else
                {
                    verts[0] = new CustomVertex.PositionTextured(-(Width/2), -(Height/2), 0.0f, 0.0f, 1.0f);
                    //Top left // 0 0 // 0 1 // 0 0
                    verts[1] = new CustomVertex.PositionTextured(-(Width/2), (Height/2), 0.0f, 0.0f, 0.0f);
                    //Bottom left // 1 0 // 0 0 // 0 1
                    verts[2] = new CustomVertex.PositionTextured((Width/2), (Height/2), 0.0f, 1.0f, 0.0f);
                    //Bottom right // 1 1 // 1 0 // 1 1
                    verts[3] = new CustomVertex.PositionTextured((Width/2), -(Height/2), 0.0f, 1.0f, 1.0f);
                    //Top right  // 0 0 // 1 1 // 1 0
                }
                ((VertexBuffer) sender).SetData(verts, 0, LockFlags.None);
            }
        }
Ejemplo n.º 54
0
 private void GenerateDXMeshes()
 {
     DirectXSections = new List<CustomVertex.PositionTextured[]>();
     for (int i = 0; i < LODModels.Count; i++)
     { 
         LODModelStruct l = LODModels[i];
         CustomVertex.PositionTextured[] list = new CustomVertex.PositionTextured[l.IndexBuffer.Indexes.Count];
         for (int j = 0; j < l.IndexBuffer.Indexes.Count; j++)
         {
             int idx = l.IndexBuffer.Indexes[j];
             GPUSkinVertexStruct v =l.VertexBufferGPUSkin.Vertices[idx];
             list[j] = new CustomVertex.PositionTextured(v.Position, HalfToFloat(v.U), HalfToFloat(v.V));
         }
         DirectXSections.Add(list);
     }
 }
Ejemplo n.º 55
0
        public void draw(Vector3 cameraLocation, Vector3 cameraRotation, Device device)
        {
            Material initialMaterial = device.Material;

            if (particleList.Count > 0)
            {
                sortParticles(particleList, 0, particleList.Count - 1, cameraLocation);
            }

            device.RenderState.AlphaBlendEnable = true;
            device.RenderState.SourceBlend = Blend.SourceAlpha;
            device.RenderState.DestinationBlend = Blend.InvSourceAlpha;

            device.SetTexture(0, particleTexture);

            foreach (ParticleData particle in particleList)
            {
                device.Transform.World =
                    Matrix.RotationYawPitchRoll(cameraRotation.X, cameraRotation.Y, cameraRotation.Z) *
                    Matrix.Translation(particle.location);

                Material material = device.Material;
                Color diffuse = material.Diffuse;
                material.Diffuse = particle.modColor;
                material.Emissive = Color.White;
                device.Material = material;

                VertexBuffer buffer = new VertexBuffer(typeof(CustomVertex.PositionTextured), 4, device, 0, CustomVertex.PositionNormalTextured.Format, Pool.Default);
                CustomVertex.PositionTextured[] vertices = (CustomVertex.PositionTextured[])buffer.Lock(0, 0);

                float particleRadius = particle.size / 2;

                vertices[0] = new CustomVertex.PositionTextured(new Vector3(-particleRadius, -particleRadius, 0f), 0, 1); // bottom right
                vertices[1] = new CustomVertex.PositionTextured(new Vector3(-particleRadius, particleRadius, 0f), 0, 0); // top right
                vertices[2] = new CustomVertex.PositionTextured(new Vector3(particleRadius, -particleRadius, 0f), 1, 1); // bottom left
                vertices[3] = new CustomVertex.PositionTextured(new Vector3(particleRadius, particleRadius, 0), 1, 0); // top left

                buffer.Unlock();

                device.VertexFormat = CustomVertex.PositionTextured.Format;

                device.SetStreamSource(0, buffer, 0);
                device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);
            }

            device.RenderState.AlphaBlendEnable = false;
            device.Material = initialMaterial;
        }
Ejemplo n.º 56
0
            public void OnCreateVertexBuffer(object sender, EventArgs e)
            {
                CustomVertex.PositionTextured[] points = new CustomVertex.PositionTextured[4]
                {
                    new CustomVertex.PositionTextured(-3,0,-3,0,0),
                    new CustomVertex.PositionTextured(-3,0,3,0,1),
                    new CustomVertex.PositionTextured(3,0,3,1,1),
                    new CustomVertex.PositionTextured(3,0,-3,1,0),
                };

                CustomVertex.PositionTextured[] vertices = new CustomVertex.PositionTextured[6]
                {
                    points[0],
                    points[1],
                    points[2],
                    points[0],
                    points[2],
                    points[3],
                };

                VertexBuffer vb = (VertexBuffer)sender;
                vb.SetData((object)vertices, 0, LockFlags.None);
            }
Ejemplo n.º 57
0
        public override void init()
        {
            //GuiController.Instance: acceso principal a todas las herramientas del Framework
            enemigos = new List<Barco>();
            terminoJuego = false;

            //Device de DirectX para crear primitivas
            Microsoft.DirectX.Direct3D.Device d3dDevice = GuiController.Instance.D3dDevice;

            //Activamos el renderizado customizado. De esta forma el framework nos delega control total sobre como dibujar en pantalla
            //La responsabilidad cae toda de nuestro lado
            GuiController.Instance.CustomRenderEnabled = true;
            g_pCubeMapAgua = TextureLoader.FromCubeFile(d3dDevice, GuiController.Instance.ExamplesMediaDir + "Shaders\\CubeMap.dds");
            //sol = TgcBox.fromSize(new Vector3(50, 50, 50), Color.LightYellow);

            //Cargo la escena completa que tendria que ser la del escenario con el cielo / la del agua
            //PROXIMAMENTE, ahora cargo otro escenario

            //Pruebo postprocess lluvia
            CustomVertex.PositionTextured[] screenQuadVertices = 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
            screenQuadVB = new VertexBuffer(typeof(CustomVertex.PositionTextured),
                    4, d3dDevice, Usage.Dynamic | Usage.WriteOnly,
                        CustomVertex.PositionTextured.Format, Pool.Default);
            screenQuadVB.SetData(screenQuadVertices, 0, LockFlags.None);

            //Creamos un Render Targer sobre el cual se va a dibujar la pantalla
            renderTarget2D = new Texture(d3dDevice, d3dDevice.PresentationParameters.BackBufferWidth
                    , d3dDevice.PresentationParameters.BackBufferHeight, 1, Usage.RenderTarget,
                        Format.X8R8G8B8, Pool.Default);

            //Cargar shader con efectos de Post-Procesado
            effectlluvia = TgcShaders.loadEffect(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\PostProcess.fx");

            //Configurar Technique dentro del shader
            effectlluvia.Technique = "AlarmaTechnique";

            //Cargar textura que se va a dibujar arriba de la escena del Render Target
            alarmTexture = TgcTexture.createTexture(d3dDevice, GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\rain.png");

            //Interpolador para efecto de variar la intensidad de la textura de alarma
            intVaivenAlarm = new InterpoladorVaiven();
            intVaivenAlarm.Min = 0;
            intVaivenAlarm.Max = 2;
            intVaivenAlarm.Speed = 10;
            intVaivenAlarm.reset();

            //Modifier para activar/desactivar efecto de alarma
            GuiController.Instance.Modifiers.addBoolean("activar_efecto", "Activar efecto", true);

            //termina post process

            //inicio//
            spriteFondo = new TgcSprite();
            spriteFondo.Texture = TgcTexture.createTexture(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\MenuPrincipal.jpg");

            Size screenSize = GuiController.Instance.Panel3d.Size;
            Size textureSize = spriteFondo.Texture.Size;
            spriteFondo.Scaling = new Vector2(1f, 0.8f);
            spriteFondo.Position = new Vector2(FastMath.Max(screenSize.Width / 2 - textureSize.Width / 2, 0), FastMath.Max(screenSize.Height / 2 - textureSize.Height / 2, 0));

            spriteLetras = new TgcSprite();
            spriteLetras.Texture = TgcTexture.createTexture(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\Texto.png");

            spriteInicio = new TgcSprite();
            spriteInicio.Texture = TgcTexture.createTexture(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\inicio.png");

            spriteLetras.Scaling = new Vector2(0.4f*1.65f, 0.3f*1.65f);
            Size textureSize2 = spriteLetras.Texture.Size;

            spriteInicio.Scaling = new Vector2(0.4f, 0.3f);
            Size textureSize3 = spriteInicio.Texture.Size;

            spriteTermino = new TgcSprite();
            spriteTermino.Texture = TgcTexture.createTexture(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\termino.png");
            //spriteTermino.Scaling = new Vector2(0.5f,0.5f);
            spriteTermino.Position = new Vector2(screenSize.Width / 4, screenSize.Height / 2);

            spriteLetras.Position = new Vector2(FastMath.Max(screenSize.Width / 2 - textureSize2.Width / 2, 0), FastMath.Max(screenSize.Height / 2 - textureSize2.Height / 2, 0));
            spriteLetras.Position = new Vector2(spriteLetras.Position.X + 110, spriteLetras.Position.Y);

            spriteInicio.Position = new Vector2(FastMath.Max(screenSize.Width / 2 - textureSize3.Width / 2, 0), FastMath.Max(screenSize.Height / 2 - textureSize3.Height / 2, 0));
            spriteInicio.Position = new Vector2(spriteInicio.Position.X + 210, spriteLetras.Position.Y+95);

            spriteMinimapa = new TgcSprite();
            spriteMinimapa.Texture = TgcTexture.createTexture(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\minimapa.png");

            spriteMinimapa.Scaling = new Vector2(0.2f, 0.2f);
            Size minimapSize = spriteMinimapa.Texture.Size;

            spriteMinimapa.Position = new Vector2(FastMath.Max(screenSize.Width  - 210, 0), FastMath.Max(screenSize.Height  - minimapSize.Height , 0));

            spriteBarcoPrincipal = new TgcSprite();
            spriteBarcoPrincipal.Texture = TgcTexture.createTexture(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\pointgreen.png");
            spriteBarcoPrincipal.Scaling = new Vector2(0.5f,0.5f);

            //inicio//

            //ui
            sprBarraVida = new TgcSprite();
            sprBarraVida.Texture = TgcTexture.createTexture(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\BarraVacia.png");
            Size textureSize4 = sprBarraVida.Texture.Size;

            sprBarraVida.Scaling = new Vector2(1f, 1f);
            sprBarraVida.Position = new Vector2(1, 1);

            sprVidaLLena = new TgcSprite();
            sprVidaLLena.Texture = TgcTexture.createTexture(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\vidallena.png");
            Size textureSize5 = sprVidaLLena.Texture.Size;
            sprVidaLLena.Scaling = new Vector2(1f, 1f);
            sprVidaLLena.Position = new Vector2(1, 15);

            //ui

            Bitmap b = (Bitmap)Bitmap.FromFile(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\wallhaven-276951.jpg"); //"water_water_0056_01_preview.jpg");
            b.RotateFlip(RotateFlipType.Rotate90FlipX);
            textura = Texture.FromBitmap(d3dDevice, b, Usage.None, Pool.Managed);

            b = (Bitmap)Bitmap.FromFile(GuiController.Instance.ExamplesMediaDir
                    + "Shaders\\BumpMapping_DiffuseMap.jpg");
            diffuseMapTexture = Texture.FromBitmap(d3dDevice, b, Usage.None, Pool.Managed);

            oceano = new SmartTerrain();
            //oceano.loadHeightmap(GuiController.Instance.ExamplesMediaDir + "Heighmaps\\" + "TerrainTexture1-256x256.jpg", 30.00f, 1.0f, new Vector3(0, 0, 0));
            oceano.loadPlainHeightmap(256, 256, 0, 50.0f, 1.0f, new Vector3(0, 0, 0));
            oceano.loadTexture(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\water_water_0056_01_preview.jpg");

            TgcSceneLoader loader = new TgcSceneLoader();
            //escena = loader.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir + "MeshCreator\\Scenes\\Isla\\Isla-TgcScene.xml");

            //Textura del skybox
            string texturesPath = GuiController.Instance.ExamplesMediaDir + "Texturas\\Quake\\SkyBox LostAtSeaDay\\";

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

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

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

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

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

            //Cargo el mesh del/los barco/s -> porque se carga como escena y no cargo el mesh directamente?

            TgcScene scene2 = loader.loadSceneFromFile(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\Boteconcañon\\BoteConCanion-TgcScene.xml");
            mainMesh = scene2.Meshes[0];
            mainMesh.Position = new Vector3(-200f,0f, 200f);
            mainMesh.Scale = new Vector3(2f,2f,2f);
            TgcScene scene4 = loader.loadSceneFromFile(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\Boteconcañon\\BoteConCanion-TgcScene.xml");
            meshBot = scene4.Meshes[0];
            meshBot.Position = new Vector3(-200f,0f,200f);
            meshBot.Scale = new Vector3(1.8f, 1.8f, 1.8f);
            TgcScene scene3 = loader.loadSceneFromFile(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\Hacha\\Bala-TgcScene.xml");
            balaMesh1 = scene3.Meshes[0];

            TgcScene scene5 = loader.loadSceneFromFile(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\Hacha\\Hacha-TgcScene.xml");
             balaMesh2 = scene5.Meshes[0];

            barcoPrincipal = new BarcoPlayer(150, 50, VELOCIDAD_MOVIMIENTO, ACELERACION, VELOCIDAD_ROTACION, mainMesh, 0.06, loader,balaMesh2);

            //pongo enemigos
            int rows = 12;

            float offset = 3000;

            for (int i = 0; i < rows; i++)
            {

                    //Crear instancia de modelo
                    TgcMesh instance = meshBot.createMeshInstance(meshBot.Name + i + "_" );

                    //Desplazarlo
                    instance.move(offset * (FastMath.Cos((float)i * 0.523599f)),0,offset * FastMath.Sin((float)i * 0.523599f));
                    instance.Scale = new Vector3(1.5f, 1.5f, 1.5f);

                    var barcoenem = new BarcoBot(100, 10, 100, ACELERACION, 18, instance, 0.05, barcoPrincipal, loader,balaMesh1);

                    barcoenem.Mesh.Effect = TgcShaders.loadEffect(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\shader_bote.fx"); //efectosAguaIluminacion;
                    barcoenem.Mesh.Technique = GuiController.Instance.Shaders.getTgcMeshTechnique(barcoenem.Mesh.RenderType);//"EnvironmentMapTechnique";
                    barcoenem.BarcosEnemigos = new List<Barco>();
                    barcoenem.BarcosEnemigos.Add(barcoPrincipal);
                    enemigos.Add(barcoenem);

            }
            //TgcScene scene3 = loader.loadSceneFromFile(GuiController.Instance.ExamplesDir + "Shaders\\WorkshopShaders\\Media\\Piso\\Agua-TgcScene.xml");
            //agua = scene3.Meshes[0];
            //agua.Scale = new Vector3(25f, 1f, 25f);
            //agua.Position = new Vector3(0f, 0f, 0f);

            efectosAguaIluminacion = TgcShaders.loadEffect(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\shader_agua.fx");
            oceano.Effect = efectosAguaIluminacion;
            oceano.Technique = "RenderAgua";//"EnvironmentMapTechnique"; //"RenderAgua";
            oceano.AlphaBlendEnable = true;

            //barcoEnemigo = new BarcoBot(100, 35,100, ACELERACION, 18, meshBot, 0.05,barcoPrincipal,loader);
            barcoPrincipal.BarcosEnemigos = enemigos;

            // iluminacion en los barcos
            barcoPrincipal.Mesh.Effect = TgcShaders.loadEffect(GuiController.Instance.AlumnoEjemplosMediaDir + "quicksort\\shader_bote.fx");//GuiController.Instance.Shaders.TgcMeshPointLightShader;// efectosAguaIluminacion; //GuiController.Instance.Shaders.TgcMeshPointLightShader;// efectosAguaIluminacion;
            barcoPrincipal.Mesh.Technique = GuiController.Instance.Shaders.getTgcMeshTechnique(barcoPrincipal.Mesh.RenderType); //"EnvironmentMapTechnique";
            //barcoEnemigo.Mesh.Effect = GuiController.Instance.Shaders.TgcMeshPointLightShader; //efectosAguaIluminacion;
            //barcoEnemigo.Mesh.Technique = GuiController.Instance.Shaders.getTgcMeshTechnique(barcoEnemigo.Mesh.RenderType);//"EnvironmentMapTechnique";

            //Camara en tercera persona focuseada en el barco (canoa)

            //PARA DESARROLLO DEL ESCENARIO ES MEJOR MOVERSE CON ESTA CAMARA
            GuiController.Instance.FpsCamera.Enable = true;
            GuiController.Instance.FpsCamera.Velocity = new Vector3(0.0f,0.0f,0.0f);
            GuiController.Instance.FpsCamera.JumpSpeed = 0f;
            GuiController.Instance.FpsCamera.setCamera(new Vector3(0f,700f,-2300f), new Vector3(900f, 100f, -300f));
            GuiController.Instance.ThirdPersonCamera.rotateY(Geometry.DegreeToRadian(180));
            ////GuiController.Instance.Fog.Enabled = true;

            //GuiController.Instance.Modifiers.addFloat("reflection", 0, 1, 0.35f);

            //GuiController.Instance.Modifiers.addVertex3f("lightPos", new Vector3(-3000, 0, -3000), new Vector3(3000, 3000, 3000), new Vector3(-300, 1500, 3000));

            GuiController.Instance.Modifiers.addColor("lightColor", Color.LightYellow);
            //GuiController.Instance.Modifiers.addFloat("bumpiness", 0, 1, 1f);
            GuiController.Instance.Modifiers.addFloat("lightIntensity", 0, 500, 150);
            GuiController.Instance.Modifiers.addFloat("lightAttenuation", 0.1f, 2, 0.1f);
            GuiController.Instance.Modifiers.addFloat("specularEx", 0, 100, 20f);

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

            //Carpeta de archivos Media del alumno
            //string alumnoMediaFolder = GuiController.Instance.AlumnoEjemplosMediaDir;

            Mapa.oceano_mesh = oceano;
        }
Ejemplo n.º 58
0
        /// <summary>
        /// Crea la malla de un terreno en base a un Heightmap
        /// </summary>
        /// <param name="heightmapPath">Imagen de Heightmap</param>
        /// <param name="scaleXZ">Escala para los ejes X y Z</param>
        /// <param name="scaleY">Escala para el eje Y</param>
        /// <param name="center">Centro de la malla del terreno</param>
        /// <param name="divisiones">Cantidad de filas y columnas en las que se va a dividir el terreno</param>
        public void loadHeightmap(string heightmapPath, float scaleXZ, float scaleY, Vector3 center, int divisiones)
        {
            Device d3dDevice = GuiController.Instance.D3dDevice;
            this.center = center;
            TgcBoundingBox box;
            vbTerrains = new List<VertexBuffer>();
            boundingBoxes = new List<TgcBoundingBox>();

            //Dispose de VertexBuffer anterior, si habia
            foreach (VertexBuffer vbTerrain in vbTerrains)
            {
                if (vbTerrain != null && !vbTerrain.Disposed)
                {
                    vbTerrain.Dispose();
                }
            }
            vbTerrains.Clear();

            //cargar heightmap
            heightmapData = loadHeightMap(d3dDevice, heightmapPath);
            float width = (float)heightmapData.GetLength(0);
            float length = (float)heightmapData.GetLength(1);

            //Crear vertexBuffer
            float nodeWidth = (width / divisiones);
            float nodeLength = (length / divisiones);

            for(int x=0; x < divisiones; x++)
            {
                for (int z = 0; z < divisiones; z++)
                {
                    VertexBuffer vbTerrain;

                    totalVertices = 2 * 3 * ((int)nodeWidth - 1) * ((int)nodeLength - 1);
                    vbTerrain = new VertexBuffer(typeof(CustomVertex.PositionTextured), totalVertices, d3dDevice, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default);

                    //Cargar vertices
                    int dataIdx = 0;
                    Vector3 pMin = Vector3.Empty;
                    Vector3 pMax = Vector3.Empty;
                    CustomVertex.PositionTextured[] data = new CustomVertex.PositionTextured[totalVertices];
                    Vector3 currentCenter;
                    currentCenter.X = center.X * scaleXZ - (width / 2) * scaleXZ;
                    currentCenter.Y = center.Y * scaleY;
                    currentCenter.Z = center.Z * scaleXZ - (length / 2) * scaleXZ;

                    for (int k = 0; k < (nodeWidth) - 1; k++)
                    {
                        for (int l = 0; l < (nodeLength) - 1; l++)
                        {
                            int i = k + (x*((int)nodeWidth -1));
                            int j = l + (z*((int)nodeLength -1));
                            //Vertices
                            Vector3 v1 = new Vector3(currentCenter.X + i * scaleXZ, currentCenter.Y + heightmapData[i, j] * scaleY, currentCenter.Z + j * scaleXZ);
                            Vector3 v2 = new Vector3(currentCenter.X + i * scaleXZ, currentCenter.Y + heightmapData[i, j + 1] * scaleY, currentCenter.Z + (j + 1) * scaleXZ);
                            Vector3 v3 = new Vector3(currentCenter.X + (i + 1) * scaleXZ, currentCenter.Y + heightmapData[i + 1, j] * scaleY, currentCenter.Z + j * scaleXZ);
                            Vector3 v4 = new Vector3(currentCenter.X + (i + 1) * scaleXZ, currentCenter.Y + heightmapData[i + 1, j + 1] * scaleY, currentCenter.Z + (j + 1) * scaleXZ);

                            //Coordendas de textura
                            Vector2 t1 = new Vector2(i / nodeWidth, j / nodeLength);
                            Vector2 t2 = new Vector2(i / nodeWidth, (j + 1) / nodeLength);
                            Vector2 t3 = new Vector2((i + 1) / nodeWidth, j / nodeLength);
                            Vector2 t4 = new Vector2((i + 1) / nodeWidth, (j + 1) / nodeLength);

                            //Cargar triangulo 1
                            data[dataIdx] = new CustomVertex.PositionTextured(v1, t1.X, t1.Y);
                            data[dataIdx + 1] = new CustomVertex.PositionTextured(v2, t2.X, t2.Y);
                            data[dataIdx + 2] = new CustomVertex.PositionTextured(v4, t4.X, t4.Y);

                            //Cargar triangulo 2
                            data[dataIdx + 3] = new CustomVertex.PositionTextured(v1, t1.X, t1.Y);
                            data[dataIdx + 4] = new CustomVertex.PositionTextured(v4, t4.X, t4.Y);
                            data[dataIdx + 5] = new CustomVertex.PositionTextured(v3, t3.X, t3.Y);

                            dataIdx += 6;

                            if(k == 0 && l==0){
                                pMin = v1;
                                pMin.Y = 0;
                            }
                            if (k == (nodeLength) - 2 && l == (nodeLength) - 2)
                            {
                                pMax = v4;
                                pMax.Y = 1500;
                            }
                        }
                    }

                    vbTerrain.SetData(data, 0, LockFlags.None);
                    vbTerrains.Add(vbTerrain);
                    //vbTerrain.Dispose();

                    box = new TgcBoundingBox(pMin, pMax);
                    box.setRenderColor(Color.Red);
                    boundingBoxes.Add(box);
                }
            }
        }
Ejemplo n.º 59
0
        public static CustomVertex.PositionTextured[] BuildPositionTextured(PointF bottomLeft,
            PointF topRight, int nX, int nY, PointF texture_bLeft, PointF texture_tRight)
        {
            if (nX < 2 || nY < 2)
            {
                throw new Exception("Cannot tesselate with nX or nY below 2");
            }
            float deltaX = (topRight.X - bottomLeft.X) / (float)(nX - 1);
            float deltaY = (topRight.Y - bottomLeft.Y) / (float)(nY - 1);
            float tdeltaX = (texture_tRight.X - texture_bLeft.X) / (float)(nX - 1);
            float tdeltaY = (texture_tRight.Y - texture_bLeft.Y) / (float)(nY - 1);
            float fx, fy;
            float tx, ty;

            CustomVertex.PositionTextured[] verts = new CustomVertex.PositionTextured[nX * nY];

            for (int y = 0; y < nY; y++)
            {
                if (y == nY - 1)
                {
                    fy = topRight.Y;
                    ty = texture_tRight.Y;
                }
                else
                {
                    fy = bottomLeft.Y + (float)y * deltaY;
                    ty = texture_bLeft.Y + (float)y * tdeltaY;
                }
                for (int x = 0; x < nX; x++)
                {
                    if (x == nX - 1)
                    {
                        fx = topRight.X;
                        tx = texture_tRight.Y;
                    }
                    else
                    {
                        fx = bottomLeft.X + (float)x * deltaX;
                        tx = texture_bLeft.X + (float)x * tdeltaX;
                    }
                    verts[y * nY + x].X = fx;
                    verts[y * nY + x].Y = fy;
                    verts[y * nY + x].Z = 0;
                    verts[y * nY + x].Tu = tx;
                    verts[y * nY + x].Tv = ty;
                }
            }
            return verts;
        }
Ejemplo n.º 60
0
        void fillPosTex(ref OBJGroup group)
        {
            List<CustomVertex.PositionTextured> verts = new List<CustomVertex.PositionTextured>();
              List<int> indicies = new List<int>();

              foreach (OBJFace f in group.faces)
              {
            int numVerts = f.vertIndices.Count;
            for (int i = 0; i < numVerts; i++)
            {
              CustomVertex.PositionTextured vert = new CustomVertex.PositionTextured(positions[f.vertIndices[i]], texCoords[f.texCoords[i] - 1].X, texCoords[f.texCoords[i] - 1].Y);
              verts.Add(vert);
              indicies.Add(indicies.Count);
            }
              }

              group.numVerts = verts.Count;
              group.numTris = indicies.Count / 3;
              group.vertexFormat = CustomVertex.PositionTextured.Format;
              group.vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionTextured), verts.Count, device, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default);
              group.vertexBuffer.SetData(verts.ToArray(), 0, LockFlags.None);
              group.indexBuffer = new IndexBuffer(typeof(int), indicies.Count * sizeof(int), device, Usage.WriteOnly, Pool.Default);
              group.indexBuffer.SetData(indicies.ToArray(), 0, LockFlags.None);
        }