当前位置: 首页>>代码示例>>C#>>正文


C# IndexBuffer.Lock方法代码示例

本文整理汇总了C#中IndexBuffer.Lock方法的典型用法代码示例。如果您正苦于以下问题:C# IndexBuffer.Lock方法的具体用法?C# IndexBuffer.Lock怎么用?C# IndexBuffer.Lock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IndexBuffer的用法示例。


在下文中一共展示了IndexBuffer.Lock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateIndexBuffer

        public static void CreateIndexBuffer(Device gDevice, int width, int height, out IndexBuffer iBuffer)
        {
            // create buffer
            iBuffer = new IndexBuffer(typeof(int), (width - 1) * (height - 1) * 6, gDevice, Usage.WriteOnly, Pool.Managed);
            int[] indices = (int[])iBuffer.Lock(0, LockFlags.None);
            
            // fill buffer
            int bufIdx = 0;
            for (int y = 0; y < height - 1; y++)
            {
                for (int x = 0; x < width - 1; x++)
                {
                    // fill quad (2xtri)
                    int pos = (y * width) + x;
                    indices[bufIdx++] = pos;
                    indices[bufIdx++] = pos + width;
                    indices[bufIdx++] = pos + 1;

                    indices[bufIdx++] = pos + 1;
                    indices[bufIdx++] = pos + width;
                    indices[bufIdx++] = pos + 1 + width;
                }
            }
            iBuffer.Unlock();
        }
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:25,代码来源:PlaneHelper.cs

示例2: FromScene

        public static Model FromScene(Scene scene, Device device)
        {
            VertexDeclaration vertexDeclaration = new VertexDeclaration(device,
                VertexPositionNormalTexture.VertexElements);
            Model result = new Model(scene, device, vertexDeclaration);
            foreach (Mesh mesh in scene.Meshes)
            {
                VertexBuffer vertexBuffer = new VertexBuffer(device,
                    mesh.Positions.Count * VertexPositionNormalTexture.SizeInBytes,
                    Usage.WriteOnly, VertexFormat.None, Pool.Default);
                DataStream vertexDataStream = vertexBuffer.Lock(0,
                    mesh.Positions.Count * VertexPositionNormalTexture.SizeInBytes,
                    LockFlags.None);
                VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[mesh.Positions.Count];
                for (int i = 0; i < vertices.Length; ++i)
                    vertices[i] = new VertexPositionNormalTexture(mesh.Positions[i], (mesh.Normals.Count > i) ? mesh.Normals[i] : Vector3D.Zero, Point2D.Zero);
                vertexDataStream.WriteRange(vertices);
                vertexBuffer.Unlock();

                IndexBuffer indexBuffer = new IndexBuffer(device, mesh.Indices.Count * sizeof(int),
                    Usage.WriteOnly, Pool.Default, false);
                DataStream indexDataStream = indexBuffer.Lock(0, mesh.Indices.Count * sizeof(int), LockFlags.None);
                indexDataStream.WriteRange(mesh.Indices.ToArray());
                indexBuffer.Unlock();

                ModelMesh modelMesh = new ModelMesh(mesh, device, vertexBuffer,
                    mesh.Positions.Count, indexBuffer, mesh.PrimitiveCount,
                    Matrix3D.Identity, mesh.Material);
                result.Meshes.Add(modelMesh);
            }
            return result;
        }
开发者ID:bondehagen,项目名称:meshellator,代码行数:32,代码来源:ModelConverter.cs

示例3: InitRangeImage

        private void InitRangeImage()
        {
            if (m_RangeImage == null)
                return;

            m_Device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, (float)Width / Height, 0.001f, 10.0f * m_RangeImage.MaximumRange + 1.0f);

            m_VertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionNormalColored), m_RangeImage.Width * m_RangeImage.Height, m_Device, Usage.WriteOnly, CustomVertex.PositionNormalColored.Format, Pool.Managed);

            Vector3[] Points = m_RangeImage.ConvertToPoints(float.MaxValue);

            //create a writer and open the file
            TextWriter tw = new StreamWriter("ladarOutput.txt");

            float MinHeight = float.MaxValue;
            float MaxHeight = float.MinValue;
            //TextWriter tw = new StreamWriter("c:\\Users\\tog000\\Desktop\\spheres.txt");
            for (int i = 0; i < Points.Length; i++)
            {
                //CODIGO MIO
                //Points[i].Z = (float)Math.Pow(Points[i].Z,2) / 2;
                //tw.WriteLine(Points[i].X*200);
                //tw.WriteLine(Points[i].Y * 200);
                //tw.WriteLine(Points[i].Z * 200);
                if (Points[i].Y < MinHeight)
                    MinHeight = Points[i].Y;
                if (Points[i].Y > MaxHeight)
                    MaxHeight = Points[i].Y;

                //Write coordinates
                tw.WriteLine(Points[i].X);
                tw.WriteLine(Points[i].Y);
                tw.WriteLine(Points[i].Z);
            }

            //Close stream
            tw.Close();

            CustomVertex.PositionNormalColored[] Vertices = (CustomVertex.PositionNormalColored[])m_VertexBuffer.Lock(0, LockFlags.None);
            for (int i = 0; i < m_RangeImage.Height; i++)
            {
                for (int j = 0; j < m_RangeImage.Width; j++)
                {
                    Vertices[I(i, j)].Position = Points[I(i, j)];

                    Vector3 Normal = new Vector3(0, 0, 0);

                    if (i > 0 && j > 0)
                        Normal += CalculateNormal(Points, I(i, j), I(i, j - 1), I(i - 1, j));
                    if (i > 0 && j < m_RangeImage.Width - 1)
                        Normal += CalculateNormal(Points, I(i, j), I(i - 1, j), I(i, j + 1));
                    if (i < m_RangeImage.Height - 1 && j < m_RangeImage.Width - 1)
                        Normal += CalculateNormal(Points, I(i, j), I(i, j + 1), I(i + 1, j));
                    if (i < m_RangeImage.Height - 1 && j > 0)
                        Normal += CalculateNormal(Points, I(i, j), I(i + 1, j), I(i, j - 1));

                    Normal.Normalize();

                    Vertices[I(i, j)].Normal = Normal;

                    if (m_DrawStyle == DrawStyle.TrianglesColorByDistance)
                    {
                        Vertices[I(i, j)].Color = HSVtoRGB(m_RangeImage[i, j] / m_RangeImage.MaximumRange * (float)Math.PI * 2.0f, 1, 1).ToArgb();
                    }
                    else if (m_DrawStyle == DrawStyle.TrianglesColorByHeight)
                    {
                        float h = Points[I(i, j)].Y;
                        h -= MinHeight;
                        h /= (MaxHeight - MinHeight);
                        h *= (float)Math.PI * 2.0f;
                        Vertices[I(i, j)].Color = HSVtoRGB(h, 1, 1).ToArgb();
                    }

                    /*
                    int Red = (int)((Normal.X + 1.0) * 127.0f);
                    int Green = (int)((Normal.Y + 1.0) * 127.0f);
                    int Blue = (int)((Normal.Z + 1.0) * 127.0f);

                    Vertices[I(i, j)].Color = Color.FromArgb(Red, Green, Blue).ToArgb();
                    */
                }
            }
            m_VertexBuffer.Unlock();

            m_IndexBuffer = new IndexBuffer(typeof(int), (m_RangeImage.Width - 1) * (m_RangeImage.Height - 1) * 6, m_Device, Usage.WriteOnly, Pool.Managed);
            int[] Indices = (int[])m_IndexBuffer.Lock(0, LockFlags.None);
            int k = 0;
            for (int i = 0; i < m_RangeImage.Height - 1; i++)
            {
                for (int j = 0; j < m_RangeImage.Width - 1; j++)
                {
                    /*
                    float MinD;
                    float MaxD;

                    MinD = Math.Min(m_RangeImage[i, j], Math.Min(m_RangeImage[i, j + 1], m_RangeImage[i + 1, j]));
                    MaxD = Math.Max(m_RangeImage[i, j], Math.Max(m_RangeImage[i, j + 1], m_RangeImage[i + 1, j]));

                    if ((MaxD - MinD) < 1000)
                    */
//.........这里部分代码省略.........
开发者ID:anareboucas,项目名称:nanook,代码行数:101,代码来源:RangeImageViewer.cs

示例4: Main

        static void Main()
        {
            var form = new RenderForm("SlimDX - MiniTri Direct3D9 Sample");
            //var device = new Device(new Direct3D(), 0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters()
            //{
            //    BackBufferWidth = form.ClientSize.Width,
            //    BackBufferHeight = form.ClientSize.Height
            //});
            Core.CreateDevice(form);
            C3Sprite sprite = null;
            if (DnFile.OpenDnpFile("c3.dnp"))
            {
                C3DObj obj = new C3DObj();
                obj.Create( "c3/mesh/002137040.c3" );

                DnFile.CloseDnpFile("c3.dnp");
                C3Texture texture = new C3Texture( "c3/texture/001000000.dds" );
                sprite = new C3Sprite(texture);

            }

            var vertices = new VertexBuffer(Core.Device, 4 * 16, Usage.WriteOnly, VertexFormat.None, Pool.Managed);
            vertices.Lock(0, 0, LockFlags.None).WriteRange(new[] {
                //new Vertex() { Color = Color.Red.ToArgb(), Position = new Vector4(100.0f, 100.0f, 0.5f, 1.0f) },
                //new Vertex() { Color = Color.Blue.ToArgb(), Position = new Vector4(550.0f, 100.0f, 0.5f, 1.0f) },
                //new Vertex() { Color = Color.Green.ToArgb(), Position = new Vector4(350.0f, 500.0f, 0.5f, 1.0f) },
                ////new Vertex() { Color = Color.Blue.ToArgb(), Position = new Vector4(550.0f, 100.0f, 0.5f, 1.0f) },
                //new Vertex() { Color = Color.Green.ToArgb(), Position = new Vector4(450.0f, 500.0f, 0.5f, 1.0f) },
                //new Vertex() { Color = Color.Green.ToArgb(), Position = new Vector4(350.0f, 300.0f, 0.5f, 1.0f) }
                new Vertex() { Color = Color.Red.ToArgb(), Position = new Vector3(0.0f, 0.0f, 0.0f) },
                new Vertex() { Color = Color.Blue.ToArgb(), Position = new Vector3(0.5f, 1.0f, 0.0f) },
                new Vertex() { Color = Color.Red.ToArgb(), Position = new Vector3(1.0f, 0.0f, 0.0f) },
                new Vertex() { Color = Color.Red.ToArgb(), Position = new Vector3(0.5f, 0.5f, 1.0f) },

            });
            vertices.Unlock();

            IndexBuffer indexs = new IndexBuffer(Core.Device, 6 * sizeof(ushort), Usage.WriteOnly, Pool.Managed, true);
            indexs.Lock(0, 0, LockFlags.None).WriteRange<ushort>(new ushort[] { 0, 1, 2, 1, 3, 2 });
            indexs.Unlock();

                var vertexElems = new[] {
                        new VertexElement(0, 0, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Position, 0),
                        new VertexElement(0, 12, DeclarationType.Color, DeclarationMethod.Default, DeclarationUsage.Color, 0),
                                VertexElement.VertexDeclarationEnd
                };

                var vertexDecl = new VertexDeclaration(Core.Device, vertexElems);
              Mesh teapot = Mesh.CreateTeapot(Core.Device);

                Camera cam = new Camera();
                //cam.BuildView();
                //cam.BuildProjection(form.ClientSize.Width, form.ClientSize.Height);

                Core.Device.SetRenderState(RenderState.Lighting, false);//很重要 默认是开启光照的
                //Core.Device.SetRenderState(RenderState.FillMode, FillMode.Solid);

            MessagePump.Run(form, () =>
            {
                //device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
                //Matrix mat = new Matrix();

                //Core.Device.SetTransform(TransformState.World, mat);
               // Core.Device.SetTransform(TransformState.World, Matrix.Identity);
                Core.ClearBuffer(true, true, new Color4(0, 0, 0));
                Core.Begin3D();

                sprite.Draw(0,0);
                //Core.Device.SetStreamSource(0, vertices, 0, 16);
                //Core.Device.VertexDeclaration = vertexDecl;
                //Core.Device.Indices = indexs;
                ////device.DrawPrimitives(PrimitiveType.TriangleList, 0, 2);
                //Core.Device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 4, 0, 2);

                //teapot.DrawSubset(0);
                Core.End3D();
                Core.Filp();
            });

            foreach (var item in ObjectTable.Objects)
                item.Dispose();
        }
开发者ID:shaoleibo,项目名称:DnFile,代码行数:82,代码来源:Program.cs

示例5: loadUnmanagedResources

        protected unsafe override void loadUnmanagedResources()
        {
            Viewport vp = renderSys.Viewport;

            Size blmSize = new Size(vp.Width / 2, vp.Height / 2);
            Size scrnSize = new Size(vp.Width, vp.Height);

            blurredRt1 = factory.CreateRenderTarget(blmSize.Width, blmSize.Height, ImagePixelFormat.A8R8G8B8);
            blurredRt2 = factory.CreateRenderTarget(blmSize.Width, blmSize.Height, ImagePixelFormat.A8R8G8B8);
            colorBuffer = factory.CreateRenderTarget(scrnSize.Width, scrnSize.Height, ImagePixelFormat.A8R8G8B8);
            nrmDepthBuffer = factory.CreateRenderTarget(scrnSize.Width, scrnSize.Height, ImagePixelFormat.A8R8G8B8);
            edgeResultBuffer = factory.CreateRenderTarget(scrnSize.Width, scrnSize.Height, ImagePixelFormat.A8R8G8B8);

            #region 计算参数

            guassFilter = new GuassBlurFilter(SampleCount, BlurAmount, blmSize.Width, blmSize.Height);
            #endregion


            #region 建立屏幕quad
            quad = factory.CreateVertexBuffer(4, vtxDecl, BufferUsage.Static);

            float adj = -0.5f;

            RectVertex* vdst = (RectVertex*)quad.Lock(0, 0, LockMode.None);
            vdst[0].Position = new Vector4(adj, adj, 0, 1);
            vdst[0].TexCoord = new Vector2(0, 0);
            vdst[1].Position = new Vector4(scrnSize.Width + adj, adj, 0, 1);
            vdst[1].TexCoord = new Vector2(1, 0);
            vdst[2].Position = new Vector4(adj, scrnSize.Height + adj, 0, 1);
            vdst[2].TexCoord = new Vector2(0, 1);
            vdst[3].Position = new Vector4(scrnSize.Width + adj, scrnSize.Height + adj, 0, 1);
            vdst[3].TexCoord = new Vector2(1, 1);
            quad.Unlock();
            #endregion

            #region 建立小quad

            smallQuad = factory.CreateVertexBuffer(4, vtxDecl, BufferUsage.Static);
            vdst = (RectVertex*)smallQuad.Lock(0, 0, LockMode.None);
            vdst[0].Position = new Vector4(adj, adj, 0, 1);
            vdst[0].TexCoord = new Vector2(0, 0);
            vdst[1].Position = new Vector4(blmSize.Width + adj, adj, 0, 1);
            vdst[1].TexCoord = new Vector2(1, 0);
            vdst[2].Position = new Vector4(adj, blmSize.Height + adj, 0, 1);
            vdst[2].TexCoord = new Vector2(0, 1);
            vdst[3].Position = new Vector4(blmSize.Width + adj, blmSize.Height + adj, 0, 1);
            vdst[3].TexCoord = new Vector2(1, 1);
            smallQuad.Unlock();

            #endregion

            indexBuffer = factory.CreateIndexBuffer(IndexBufferType.Bit32, 6, BufferUsage.Static);
            int* idst = (int*)indexBuffer.Lock(0, 0, LockMode.None);

            idst[0] = 3;
            idst[1] = 1;
            idst[2] = 0;
            idst[3] = 2;
            idst[4] = 3;
            idst[5] = 0;
            indexBuffer.Unlock();

            quadOp = new GeomentryData();
            quadOp.BaseIndexStart = 0;
            quadOp.BaseVertex = 0;
            quadOp.IndexBuffer = indexBuffer;
            quadOp.PrimCount = 2;
            quadOp.PrimitiveType = RenderPrimitiveType.TriangleList;
            quadOp.VertexBuffer = quad;
            quadOp.VertexCount = 4;
            quadOp.VertexDeclaration = vtxDecl;
            quadOp.VertexSize = RectVertex.Size;

            smallQuadOp = new GeomentryData();
            smallQuadOp.BaseIndexStart = 0;
            smallQuadOp.BaseVertex = 0;
            smallQuadOp.IndexBuffer = indexBuffer;
            smallQuadOp.PrimCount = 2;
            smallQuadOp.PrimitiveType = RenderPrimitiveType.TriangleList;
            smallQuadOp.VertexBuffer = smallQuad;
            smallQuadOp.VertexCount = 4;
            smallQuadOp.VertexDeclaration = vtxDecl;
            smallQuadOp.VertexSize = RectVertex.Size;
        }
开发者ID:yuri410,项目名称:lrvbsvnicg,代码行数:85,代码来源:PostRenderer.cs

示例6: Init

        /// <summary>
        /// Inits the Device
        /// </summary>
        /// <returns>True if it succeeded else false</returns>
        public bool Init()
        {
            if (!_Device.Disposed)
            {
                this.Text = CSettings.GetFullVersionText();
                Matrix translate = Matrix.Translation(new Vector3(-CSettings.iRenderW / 2, CSettings.iRenderH / 2, 0));
                Matrix projection = Matrix.OrthoOffCenterLH(-CSettings.iRenderW / 2, CSettings.iRenderW / 2, -CSettings.iRenderH / 2, CSettings.iRenderH / 2, CSettings.zNear, CSettings.zFar);
                _VertexBuffer = new VertexBuffer(_Device, CSettings.iVertexBufferElements * (4 * Marshal.SizeOf(typeof(TexturedColoredVertex))), Usage.WriteOnly | Usage.Dynamic, VertexFormat.Position | VertexFormat.Texture1 | VertexFormat.Diffuse, Pool.Default);

                if (_Device.SetStreamSource(0, _VertexBuffer, 0, Marshal.SizeOf(typeof(TexturedColoredVertex))).IsFailure)
                    CLog.LogError("Failed to set stream source");
                _Device.VertexDeclaration = TexturedColoredVertex.GetDeclaration(_Device);
                if(_Device.SetTransform(TransformState.Projection, projection).IsFailure)
                    CLog.LogError("Failed to set orthogonal matrix");
                if(_Device.SetTransform(TransformState.World, translate).IsFailure)
                    CLog.LogError("Failed to set translation matrix");
                if(_Device.SetRenderState(RenderState.CullMode, Cull.None).IsFailure)
                    CLog.LogError("Failed to set cull mode");
                if(_Device.SetRenderState(RenderState.AlphaBlendEnable, true).IsFailure)
                    CLog.LogError("Failed to enable alpha blending");
                if(_Device.SetRenderState(RenderState.Lighting, false).IsFailure)
                    CLog.LogError("Failed to disable lighting");
                if(_Device.SetRenderState(RenderState.DestinationBlend, Blend.InverseSourceAlpha).IsFailure)
                    CLog.LogError("Failed to set destination blend");
                if(_Device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha).IsFailure)
                    CLog.LogError("Failed to set source blend");
                if (_PresentParameters.Multisample != MultisampleType.None)
                {
                    if(_Device.SetRenderState(RenderState.MultisampleAntialias, true).IsFailure)
                        CLog.LogError("Failed to set antialiasing");
                }
                if(_Device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Linear).IsFailure)
                    CLog.LogError("Failed to set min filter");
                if(_Device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Linear).IsFailure)
                    CLog.LogError("Failed to set mag filter");
                if(_Device.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Linear).IsFailure)
                    CLog.LogError("Failed to set mip filter");
                if(_Device.SetSamplerState(0, SamplerState.AddressU, TextureAddress.Clamp).IsFailure)
                    CLog.LogError("Failed to set clamping on u");
                if(_Device.SetSamplerState(0, SamplerState.AddressV, TextureAddress.Clamp).IsFailure)
                    CLog.LogError("Failed to set claming on v");
                if(_Device.SetTextureStageState(0, TextureStage.AlphaArg1, TextureArgument.Texture).IsFailure)
                    CLog.LogError("Failed to set alpha argument 1");
                if(_Device.SetTextureStageState(0, TextureStage.AlphaArg2, TextureArgument.Diffuse).IsFailure)
                    CLog.LogError("Failed to set alpha argument 2");
                if(_Device.SetTextureStageState(0, TextureStage.AlphaOperation, TextureOperation.Modulate).IsFailure)
                    CLog.LogError("Failed to set alpha operation");

                Int16[] indices = new Int16[6];
                indices[0] = 0;
                indices[1] = 1;
                indices[2] = 2;
                indices[3] = 0;
                indices[4] = 2;
                indices[5] = 3;

                _IndexBuffer = new IndexBuffer(_Device, 6 * sizeof(Int16), Usage.WriteOnly, Pool.Managed, true);

                DataStream stream = _IndexBuffer.Lock(0, 0, LockFlags.None);
                stream.WriteRange(indices);
                _IndexBuffer.Unlock();
                _Device.Indices = _IndexBuffer;

                //This creates a new white texture and adds it to the texture pool
                //This texture is used for the DrawRect method
                Bitmap blankMap = new Bitmap(1, 1);
                Graphics g = Graphics.FromImage(blankMap);
                g.Clear(Color.White);
                g.Dispose();
                _BlankTexture = AddTexture(blankMap);

                blankMap.Dispose();
                return true;
            }
            else
                return false;
        }
开发者ID:Klafhor,项目名称:Vocaluxe,代码行数:81,代码来源:CDirect3D.cs

示例7: SetUpBuffers

        private void SetUpBuffers()
        {
            indices.Clear();
            int indexOffset = 0;

            for (int i = 0; i < particles.Count; i++)
            {
                if (particles[i].LifeBar > 0)
                {
                    vertexOffset += 4;
                }
            }
            if (vertexOffset > 0)
            {

                if (vb!=null) vb.Dispose();
                vb = new VertexBuffer(device, VertexPositionNormalColor.SizeInBytes * vertexOffset, Usage.None, VertexPositionNormalColor.Format, Pool.Default);
                vertexOffset = 0;
                using (DataStream stream = vb.Lock(0, 0, LockFlags.None))
                {
                    for (int i = 0; i < particles.Count; i++)
                    {
                        if (particles[i].LifeBar > 0)
                        {

                            float angle = (float)Math.PI / 3.0f;

                            Matrix billBoard = Matrix.Translation(-particles[i].Position) * CreateTransform(particles[i].Velocity) * Matrix.Translation(particles[i].Position);
                            Vector3 v1 = Vector3.TransformCoordinate(
                                new Vector3(
                                    particles[i].Position.X,
                                    particles[i].Position.Y + particleSize * 2.0f,
                                    particles[i].Position.Z),
                                billBoard);
                            Vector3 v2 = Vector3.TransformCoordinate(
                                new Vector3(
                                    particles[i].Position.X + particleSize * (float)Math.Sin(angle),
                                    particles[i].Position.Y - particleSize * (float)Math.Cos(angle),
                                    particles[i].Position.Z),
                                billBoard);
                            Vector3 v3 = Vector3.TransformCoordinate(
                                new Vector3(
                                    particles[i].Position.X - particleSize * (float)Math.Sin(angle) * (float)Math.Sin(angle / 2.0f),
                                    particles[i].Position.Y - particleSize * (float)Math.Cos(angle),
                                    particles[i].Position.Z + particleSize * (float)Math.Sin(angle) * (float)Math.Cos(angle / 2.0f)),
                                billBoard);
                            Vector3 v4 = Vector3.TransformCoordinate(
                                new Vector3(
                                    particles[i].Position.X - particleSize * (float)Math.Sin(angle) * (float)Math.Sin(angle / 2.0f),
                                    particles[i].Position.Y - particleSize * (float)Math.Cos(angle),
                                    particles[i].Position.Z - particleSize * (float)Math.Sin(angle) * (float)Math.Cos(angle / 2.0f)),
                                billBoard);


                            Vector4 v11 = new Vector4(v1 * positionScaleParam, 1.0f);
                            VertexPositionNormalColor vertex1 = new VertexPositionNormalColor(v1, Vector3.TransformNormal(new Vector3(0, 1, 0), billBoard), (int)particles[i].ColorARGB);
                            stream.Write(vertex1);

                            Vector4 v22 = new Vector4(v2 * positionScaleParam, 1.0f);
                            VertexPositionNormalColor vertex2 = new VertexPositionNormalColor(v2, Vector3.TransformNormal(v2 - particles[i].Position, billBoard), (int)particles[i].ColorARGB);
                            stream.Write(vertex2);

                            Vector4 v33 = new Vector4(v3 * positionScaleParam, 1.0f);
                            VertexPositionNormalColor vertex3 = new VertexPositionNormalColor(v3, Vector3.TransformNormal(v3 - particles[i].Position, billBoard), (int)particles[i].ColorARGB);
                            stream.Write(vertex3);

                            Vector4 v44 = new Vector4(v4 * positionScaleParam, 1.0f);
                            VertexPositionNormalColor vertex4 = new VertexPositionNormalColor(v4, Vector3.TransformNormal(v4 - particles[i].Position, billBoard), (int)particles[i].ColorARGB);
                            stream.Write(vertex4);

                            indices.AddRange(new int[] { vertexOffset, vertexOffset + 1, vertexOffset + 2, vertexOffset, vertexOffset + 2, vertexOffset + 3, vertexOffset, vertexOffset + 1, vertexOffset + 3, vertexOffset + 1, vertexOffset + 2, vertexOffset + 3, });

                            vertexOffset += 4;
                            indexOffset += 12;

                        }
                    }
                    vb.Unlock();
                }
            }


            if (vertexOffset > 0)
            {
                if (ib!=null) ib.Dispose(); 
                ib = new IndexBuffer(device, sizeof(int) * indices.Count, Usage.None, Pool.Default, false);
                using (DataStream stream = ib.Lock(0, 0, LockFlags.None))
                {
                    for (int i = 0; i < indices.Count; i++)
                    {
                        stream.Write(indices[i]);
                    }
                    ib.Unlock();
                }
            }

        }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:97,代码来源:ParticleSystem3D.cs

示例8: setCollisionBox

        // Default 값
        public void setCollisionBox()
        {
            if (null != m_CollisionBox)
            {
                m_CollisionBox.Dispose();
            }

            m_CollisionBox = new VertexBuffer(typeof(CustomVertex.PositionColored), 8,
                m_device, 0, CustomVertex.PositionColored.Format, Pool.Default);

            CustomVertex.PositionColored[] posColoredVerts = new CustomVertex.PositionColored[8];

            for (int i = 0; i < posColoredVerts.Length; ++i )
            {
                posColoredVerts[i].Position = new Vector3(0, 0, 0);
                posColoredVerts[i].Color = System.Drawing.Color.Black.ToArgb();
            }

            GraphicsStream gstm = m_CollisionBox.Lock(0, 0, LockFlags.None);
            gstm.Write(posColoredVerts);
            m_CollisionBox.Unlock();

            // indexedBuffer
            m_IndexBuffer = new IndexBuffer(m_device, 12 * 2 * 2, Usage.WriteOnly, Pool.Managed, true);

            GraphicsStream idstm = m_IndexBuffer.Lock(0, 0, LockFlags.None);
            idstm.Write(m_IndexedBufferOrder);
            m_IndexBuffer.Unlock();
        }
开发者ID:NHNNEXT,项目名称:2014-01-HUDIGAME-skyLab,代码行数:30,代码来源:GameObject.cs

示例9: RipTriangleStrip

        public void RipTriangleStrip(int baseVertexIndex, int startIndex, int primCount, ref IndexBuffer ib)
        {
            Queue.Push("Strip");
            if (ib == null)
            {
                Queue.Push("IB IS NULL");
                return;
            }

            if (vb == null)
            {
                Queue.Push("VB IS NULL");
                return;
            }

            BinaryReader IndexData = new BinaryReader(ib.Lock(0, 0, LockFlags.ReadOnly));
            BinaryReader VertexData = new BinaryReader(vb.Lock(0, 0, LockFlags.ReadOnly));
            vertex v;

            if (IndexData == null)
            {
                Queue.Push("Index Data is Null");
                return;
            }

            if (VertexData == null)
            {
                Queue.Push("VertexData is NULL");
                return;
            }

            IndexData.BaseStream.Seek(startIndex*sizeof(UInt16), SeekOrigin.Begin);
            int f = 0;
            string verts = "";
            for (int i = 0; i < primCount; i++)
            {
                UInt16 index = IndexData.ReadUInt16();
                UInt16 bVertex = (UInt16)baseVertexIndex;
                v = GetVertex((UInt16)(index+bVertex), ref VertexData);
                if (!VertContains(v))
                {
                    vertices.Add(v);
                    verts += "v " + v.x + " " + v.y + " " + v.z + "\r\n";
                }
                vmap[index + bVertex] = GetIndex(v);
            }

            if (!Directory.Exists(Interface.OutPutDir + "Output"))
                Directory.CreateDirectory(Interface.OutPutDir + "Output");

            if (!Directory.Exists(Interface.OutPutDir + "Output\\" + Interface.exe))
                Directory.CreateDirectory(Interface.OutPutDir + "Output\\" + Interface.exe);

            System.IO.File.WriteAllText(Interface.OutPutDir + "Output\\" + Interface.exe + "\\model" + mod_count + ".obj", verts);

            IndexData.BaseStream.Seek(startIndex*sizeof(UInt16), SeekOrigin.Begin);
            string faces = "";

            //build initial face
            //faces += "f " + vmap[IndexData.ReadUInt16() + (UInt16)baseVertexIndex] + " " + vmap[IndexData.ReadUInt16() + (UInt16)baseVertexIndex] +
            //" " + vmap[IndexData.ReadUInt16() + (UInt16)baseVertexIndex] + "\r\n";

            //IndexData.BaseStream.Seek(startIndex+1, SeekOrigin.Begin);

            for (int i = 0; i < primCount; i++)
            {
                IndexData.BaseStream.Seek((startIndex + i)*sizeof(UInt16), SeekOrigin.Begin);
                UInt16 bVertex = (UInt16)baseVertexIndex;

                UInt16 I = IndexData.ReadUInt16();
                UInt16 I1 = IndexData.ReadUInt16();
                UInt16 I2 = IndexData.ReadUInt16();
                faces+="f " + vmap[I+bVertex] + " " + vmap[I1 + bVertex] + " "
                            + vmap[I2 + bVertex] + "\r\n";
                f++;
            }
            System.IO.File.AppendAllText(Interface.OutPutDir + "Output\\" + Interface.exe + "\\model" + mod_count + ".obj", faces);
            mod_count++;
            vb.Unlock();
            ib.Unlock();
            vertices.Clear();
            vertices.Add(new vertex());
            vmap.Clear();
        }
开发者ID:emist,项目名称:D3DTextureLoggerClient,代码行数:84,代码来源:Main.cs

示例10: CreatePatchIndexBuffer

        public static void CreatePatchIndexBuffer(Device gDevice, int width, int height, out IndexBuffer iBuffer)
        {
            // create buffer
            iBuffer = new IndexBuffer(typeof(int), /*(((width - 1) * 4) + ((height - 1) * 4))*/(width - 1) * 4 * 6, gDevice, Usage.WriteOnly, Pool.Managed);
            int[] indices = (int[])iBuffer.Lock(0, LockFlags.None);

            // fill buffer
            int bufIdx = 0;
            for (int y = 0; y < (height - 1) * 2; y += 2)
            {
                // fill quad (2xtri)
                indices[bufIdx++] = y;
                indices[bufIdx++] = y + 2;
                indices[bufIdx++] = y + 1;

                indices[bufIdx++] = y + 1;
                indices[bufIdx++] = y + 2;
                indices[bufIdx++] = y + 3;
            }
            for (int y = 0; y < (height - 1) * 2; y += 2)
            {
                // fill quad (2xtri)
                indices[bufIdx++] = y;
                indices[bufIdx++] = y + 1;
                indices[bufIdx++] = y + 2;

                indices[bufIdx++] = y + 1;
                indices[bufIdx++] = y + 3;
                indices[bufIdx++] = y + 2;
            }
            /*for (int y = height * 2; y < (height - 1) * 4; y += 2)
            {
                // fill quad (2xtri)
                indices[bufIdx++] = y;
                indices[bufIdx++] = y + 2;
                indices[bufIdx++] = y + 1;

                indices[bufIdx++] = y + 1;
                indices[bufIdx++] = y + 2;
                indices[bufIdx++] = y + 3;
            }*/
            /*for (int x = height * 4; x < (height * 4) + ((width - 1) * 2); x+=2)
            {
                // fill quad (2xtri)
                indices[bufIdx++] = x;
                indices[bufIdx++] = x + width;
                indices[bufIdx++] = x + 1;

                indices[bufIdx++] = x + 1;
                indices[bufIdx++] = x + width;
                indices[bufIdx++] = x + 1 + width;
            }
            for (int x = (height * 4) + ((width - 1) * 2); x < (height * 4) + ((width - 1) * 4); x+=2)
            {
                // fill quad (2xtri)
                indices[bufIdx++] = x;
                indices[bufIdx++] = x + width;
                indices[bufIdx++] = x + 1;

                indices[bufIdx++] = x + 1;
                indices[bufIdx++] = x + width;
                indices[bufIdx++] = x + 1 + width;
            }*/
            iBuffer.Unlock();
        }
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:65,代码来源:PlaneHelper.cs

示例11: CellTexCreator

        public CellTexCreator(int Res)
        {
            texBanks = new System.Collections.Generic.List<TextureBank>();

            //Create basic vertex buffer that can be used for all cells which has positions and texture coordinates
            vBuffer = new VertexBuffer(typeof(CellVertex), 4225, DXMain.device, Usage.WriteOnly, CellVertex.Format, Pool.Managed);
            CellVertex[] CellData = (CellVertex[])vBuffer.Lock(0, LockFlags.None);

            float mult = (float)(Res / 64);
            for(int y=0;y<=64;y++) {
                for(int x=0;x<=64;x++) {
                    //Figure out which index to use
                    int i = y * 65 + x;

                    //Write values
                    CellData[i].x = ((float)x / 64.0f) * 2.0f - 1.0f;
                    CellData[i].y = ((float)y / 64.0f) * 2.0f - 1.0f;
                    CellData[i].z = 0.5f;
                    CellData[i].w = 1.0f;
                    CellData[i].u = (float)x / 16.0f;
                    CellData[i].v = (float)y / 16.0f;
                }
            }
            vBuffer.Unlock();

            //Create triangle strip index buffer
            //Size is 2r + 2rc + 2(r-1) where r is rows and c is colums (squares, not vertices)
            iBuffer = new IndexBuffer(typeof(Int16), 8446, DXMain.device, Usage.WriteOnly, Pool.Managed);
            Int16[] iBuf = (Int16[])iBuffer.Lock(0, LockFlags.None);
            int idx = 0;
            for(int y=0;y<64;y++) {
                //If this is is a continuation strip, we need to add two extra vertices to create degenerat triangles
                //and get us back to the left side
                if ( y > 0 ) {
                    iBuf[idx] = (Int16)(y * 65 + (63+1));
                    iBuf[idx + 1] = (Int16)(y * 65 + 0);
                    idx += 2;
                }

                //Start the row off with a vertex in the lower left corner of the square
                iBuf[idx] = (Int16)(y * 65 + 0);
                ++idx;

                for(int x=0;x<64;x++) {
                    //Add the top left and bottom right vertex of each square
                    iBuf[idx] = (Int16)((y+1) * 65 + x);
                    iBuf[idx + 1] = (Int16)(y * 65 + (x+1));

                    idx += 2;
                }

                //End the row with the top right vertex
                iBuf[idx] = (Int16)((y+1) * 65 + (63+1));
                ++idx;
            }

            iBuffer.Unlock();

            //Create the buffers that will contain different information during each render
            colorBuffer = new VertexBuffer(typeof(NormalColorVertex), 4225, DXMain.device, Usage.WriteOnly, NormalColorVertex.Format, Pool.Managed);

            ResetColorsAndNormals();

            RenderTargetTex=new Texture(DXMain.device, Res, Res, 0, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default);
            CompressedTex=new Texture(DXMain.device, Res, Res, 0, Usage.None, Format.Dxt1, Pool.SystemMemory);
            RenderTarget=RenderTargetTex.GetSurfaceLevel(0);
            effect=Effect.FromFile(DXMain.device, EffectPath, null, null, ShaderFlags.NotCloneable, null);

            m1h = effect.GetParameter(null, "transform");
            t1h = effect.GetParameter(null, "t1");
            t2h = effect.GetParameter(null, "t2");
            t3h = effect.GetParameter(null, "t3");
            t4h = effect.GetParameter(null, "t4");
        }
开发者ID:europop,项目名称:morrgraphext,代码行数:74,代码来源:DistantLandTextures.cs

示例12: BuildRemainder

        public IndexBuffer BuildRemainder(Device device)
        {
            if (UsedCount == indices.Length) { return null; }

            int numIndices = indices.Length - UsedCount;
            IndexBuffer result = null;
            try
            {
                result = new IndexBuffer(device, numIndices * 2, Usage.WriteOnly, Pool.Managed, true);

                try
                {
                    var str = result.Lock(0, 0, LockFlags.None);
                    int numTris = used.Length;
                    for (var i = 0; i < numTris; i++)
                    {
                        if (used[i]) { continue; }

                        int offset = i * 3;

                        str.Write(this.indices[offset]);
                        str.Write(this.indices[offset + 1]);
                        str.Write(this.indices[offset + 2]);
                    }
                }
                finally
                {
                    result.Unlock();
                }
                return result;
            }
            catch
            {
                if (result != null) { result.Dispose(); }
                throw;
            }
        }
开发者ID:nohbdy,项目名称:ffxivmodelviewer,代码行数:37,代码来源:Mesh.cs

示例13: ExtractSubset

        public IndexBuffer ExtractSubset(Device device, short[] triList)
        {
            int numTris = triList.Length;
            IndexBuffer result = null;
            try
            {
                result = new IndexBuffer(device, numTris * 6, Usage.WriteOnly, Pool.Managed, true);
                try
                {
                    var str = result.Lock(0, 0, LockFlags.None);
                    for (var i = 0; i < numTris; i++)
                    {
                        int triNum = triList[i];
                        int offset = triNum * 3;

                        str.Write(this.indices[offset]);
                        str.Write(this.indices[offset+1]);
                        str.Write(this.indices[offset+2]);

                        if (!used[triNum])
                        {
                            used[triNum] = true;
                            UsedCount += 3; // 3 indices used
                        }
                    }
                }
                finally
                {
                    result.Unlock();
                }
                return result;
            }
            catch
            {
                if (result != null) { result.Dispose(); }
                throw;
            }
        }
开发者ID:nohbdy,项目名称:ffxivmodelviewer,代码行数:38,代码来源:Mesh.cs

示例14: OnResetDevice

        /// <summary>
        /// This event-handler is a good place to create and initialize any 
        /// Direct3D related objects, which may become invalid during a 
        /// device reset.
        /// </summary>
        public void OnResetDevice(object sender, EventArgs e)
        {
            logMessageToFile("Reset device");

            Device device = (Device)sender;

            if (device == null) return;

            this.Invalidate();

            device.RenderState.FillMode = getFillMode();

            device.RenderState.ZBufferEnable = true;

            setupShaders();

            vertexBuffers.Clear();
            indexBuffers.Clear();

            //
            // Create a vertex buffer...
            //
            uint numPolygons = 0;
            uint numVertices = 0;
            for (int i = 0; i < models.Count; i++)
            {
                if (models[i] != null && models[i].numVertices > 0)
                {

                    numPolygons += models[i].numPolygons;
                    numVertices += models[i].numVertices;

                    vertexDeclaration = new VertexDeclaration(device, MadScience.Render.vertex.Elements);
                    VertexBuffer vertexBuffer = new VertexBuffer(typeof(MadScience.Render.vertex),
                                                     (int)models[i].numVertices, device,
                                                     Usage.Dynamic | Usage.WriteOnly,
                                                     MadScience.Render.vertex.FVF_Flags,
                                                     Pool.Default);

                    GraphicsStream gStream = vertexBuffer.Lock(0, 0, LockFlags.None);

                    // Now, copy the vertex data into the vertex buffer
                    gStream.Write(models[i].vertexData.ToArray());

                    vertexBuffer.Unlock();

                    vertexBuffers.Add(vertexBuffer);

                    //
                    // Create an index buffer to use with our indexed vertex buffer...
                    //

                    IndexBuffer indexBuffer = new IndexBuffer(typeof(int), (int)(models[i].faceData.Count * 2), device,
                                                   Usage.WriteOnly, Pool.Default);

                    gStream = indexBuffer.Lock(0, 0, LockFlags.None);

                    // Now, copy the indices data into the index buffer
                    gStream.Write(models[i].faceData.ToArray());

                    indexBuffer.Unlock();

                    indexBuffers.Add(indexBuffer);
                }
            }

            this.statusLabel.Text = "Model loaded. " + models.Count.ToString() + " part(s), total " + String.Format("{0:0} polygons, ", numPolygons) + String.Format("{0:0} vertices", numVertices);
        }
开发者ID:ellacharmed,项目名称:madscientistproductions,代码行数:73,代码来源:RenderWindow.cs

示例15: p1_Load


//.........这里部分代码省略.........
                                 if (num9 == 48)
                                 {
                                     list3.Add(Convert.ToUInt32(array[num - 1 & 3]));
                                     list3.Add(Convert.ToUInt32(array[num - 3 & 3]));
                                     list3.Add(Convert.ToUInt32(array[num - 2 & 3]));
                                 }
                             }
                         }
                         Color color = Color.FromArgb((int)this.lm.al[num13], (int)this.lm.al[num10], (int)this.lm.al[num11], (int)this.lm.al[num12]);
                         CustomVertex.PositionColoredTextured item2 = new CustomVertex.PositionColoredTextured(v, color.ToArgb(), (float)num6 / 16f / 256f, (float)num7 / 16f / 256f);
                         list.Add(item2);
                     }
                     cI2.ali = list3.ToArray();
                     cI2.texi = count + vifpli.texi;
                     cI2.vifi = k;
                     this.alci.Add(cI2);
                 }
             }
             goto IL_75D;
         }
         goto IL_75D;
     }
     if (this.alalci.Count != 0)
     {
         this.alci.Clear();
         this.alci.AddRange(this.alalci[0]);
     }
     if (list.Count == 0)
     {
         list.Add(default(CustomVertex.PositionColoredTextured));
     }
     this.vb = new VertexBuffer(this.device, (this.cntVerts = list.Count) * CustomVertex.PositionColoredTextured.Size, Usage.Points, CustomVertex.PositionColoredTextured.Format, Pool.Managed);
     this.alDeleter.Add(this.vb);
     DataStream dataStream = this.vb.Lock(0, 0, LockFlags.None);
     try
     {
         foreach (CustomVertex.PositionColoredTextured current5 in list)
         {
             dataStream.Write<CustomVertex.PositionColoredTextured>(current5);
         }
     }
     finally
     {
         this.vb.Unlock();
     }
     this.lCntVert.Text = this.cntVerts.ToString("#,##0");
     int num14 = 0;
     this.alib.Clear();
     int num15 = 0;
     foreach (Visf.CI[] current6 in this.alalci)
     {
         Visf.CI[] array2 = current6;
         for (int i = 0; i < array2.Length; i++)
         {
             Visf.CI cI3 = array2[i];
             if (cI3.ali.Length != 0)
             {
                 IndexBuffer indexBuffer = new IndexBuffer(this.device, 4 * cI3.ali.Length, Usage.None, Pool.Managed, false);
                 num14 += cI3.ali.Length;
                 this.alDeleter.Add(indexBuffer);
                 DataStream dataStream2 = indexBuffer.Lock(0, 0, LockFlags.None);
                 try
                 {
                     uint[] ali = cI3.ali;
                     for (int m = 0; m < ali.Length; m++)
                     {
开发者ID:Truthkey,项目名称:OpenKH,代码行数:67,代码来源:Visf.cs


注:本文中的IndexBuffer.Lock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。