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


C# VertexBuffer.Allocate方法代码示例

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


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

示例1: Build

        protected override void Build()
        {
            vb = new VertexBuffer<Vector3>(Vector3.Descriptor);

            vb.Allocate(8);
            ib = new IndexBuffer<ushort>();
            ib.Allocate(4 * 6);

            vb[0] = new Vector3(-0.5f, -0.5f, -0.5f);
            vb[1] = new Vector3(0.5f, -0.5f, -0.5f);
            vb[2] = new Vector3(0.5f, 0.5f, -0.5f);
            vb[3] = new Vector3(-0.5f, 0.5f, -0.5f);

            vb[4] = new Vector3(-0.5f, -0.5f, 0.5f);
            vb[5] = new Vector3(0.5f, -0.5f, 0.5f);
            vb[6] = new Vector3(0.5f, 0.5f, 0.5f);
            vb[7] = new Vector3(-0.5f, 0.5f, 0.5f);

            ib[0] = 0;
            ib[1] = 1;
            ib[2] = 2;
            ib[3] = 3;

            ib[4] = 4;
            ib[5] = 0;
            ib[6] = 3;
            ib[7] = 7;

            ib[8] = 5;
            ib[9] = 4;
            ib[10] = 7;
            ib[11] = 6;

            ib[12] = 1;
            ib[13] = 5;
            ib[14] = 6;
            ib[15] = 2;

            ib[16] = 6;
            ib[17] = 7;
            ib[18] = 3;
            ib[19] = 2;

            ib[20] = 0;
            ib[21] = 4;
            ib[22] = 5;
            ib[23] = 1;

            vb.BufferData(VboUsage.GL_STATIC_DRAW);
            ib.BufferData(VboUsage.GL_STATIC_DRAW);
            // Client data is no longer needed. Free it!
            vb.FreeClientData();
            ib.FreeClientData();
        }
开发者ID:r-bel,项目名称:glorg2,代码行数:54,代码来源:Box.cs

示例2: Build

        public override Model Build()
        {
            Model ret = new Model();

            VertexBuffer<VertexPositionTexCoordNormal> vb = new VertexBuffer<VertexPositionTexCoordNormal>(VertexPositionTexCoordNormal.Descriptor);
            //IndexBuffer<uint> ib = new IndexBuffer<uint>();

            float ang_inc = (float)(2 * Math.PI) / sides;
            int vsides = sides / 2 - 2;
            float ang = 0;
            vb.Allocate(sides * (sides / 2 - 2) + 2);
            int index = 0;
            for (int i = 0; i < sides; i++, ang += ang_inc)
            {
                float cs = (float)Math.Cos(ang);
                float ss = (float)Math.Sin(ang);

                float sang_inc = (float)Math.PI / vsides;
                float sang = -((float)Math.PI / 2) + sang_inc;
                for (int j = 0; j < vsides; j++, sang += sang_inc, ++index)
                {
                    float vcs = (float)Math.Cos(sang);
                    float vss = (float)Math.Sin(sang);
                    Vector3 pos = new Vector3(
                        cs * radius * vcs,
                        vss * radius,
                        ss * radius * vss);
                    vb[index] = new VertexPositionTexCoordNormal()
                    {
                        Position = pos,
                        TexCoord = new Vector2(),
                        Normal = new Vector3(cs * vcs, vss, ss * vss)
                    };
                }
                vb[index] = new VertexPositionTexCoordNormal()
                {
                    Position = new Vector3(0, -radius, 0),
                    Normal = new Vector3(0, -1, 0)
                };
                vb[index + 1] = new VertexPositionTexCoordNormal()
                {
                    Position = new Vector3(0, radius, 0),
                    Normal = new Vector3(0, radius, 0)
                };
            }
            ret.VertexBuffer = vb;
            vb.BufferData(Glorg2.Graphics.OpenGL.VboUsage.GL_STATIC_DRAW);
            return ret;
        }
开发者ID:r-bel,项目名称:glorg2,代码行数:49,代码来源:SphereBuilder.cs

示例3: InitializeGraphics

        public virtual void InitializeGraphics()
        {
            if (heightmap == null && string.IsNullOrEmpty(Heightmap))
                return;

            if (heightmap == null)
                owner.Resources.Load(Heightmap, out heightmap);

            //if (heightmap.Width != heightmap.Height)
                //throw new NotSupportedException("Must be rectangular heightmap");
            int num_vertices = (heightmap.Width) * (heightmap.Height);
            if (vb != null)
                DoDispose();

            vb = new VertexBuffer<VertexPositionTexCoordNormal>(VertexPositionTexCoordNormal.Descriptor);
            vb.Allocate(num_vertices);

            if (mat_name != null)
                owner.Resources.Load(mat_name, out mat);

            size = CellSize * heightmap.Width;
            float s2 = size / 2;

            int vi = 0;
            float xx = 0;
            float yy = -s2;
            Vector3[,] norms = new Vector3[heightmap.Height, heightmap.Width];
            for (int i = 0; i < heightmap.Height; i++)
            {
                for (int j = 0; j < heightmap.Width; j++)
                {
                    Vector3 n = new Vector3();
                    n.x = (heightmap[i - 1, j] - heightmap[i + 1, j]) * Height;
                    n.y = (heightmap[i, j - 1] - heightmap[i, j + 1]) * Height;
                    n.z = 2.0f / (heightmap.Width + 1) / CellSize + 2.0f / (heightmap.Height + 1) / CellSize;
                    norms[i, j] = n.Normalize();
                }
            }

            for (int i = 0; i < heightmap.Height; i++)
            {
                xx = -s2;
                for (int j = 0; j < heightmap.Width; j++, vi++)
                {
                    vb[vi] = new VertexPositionTexCoordNormal()
                    {
                        Position = new Vector3(xx, heightmap[i, j] * Height, yy),
                        Normal = norms[i, j]
                    };
                    xx += CellSize;
                }
                yy += CellSize;
            }

            float offset = s2 / 2;

            int x_count = heightmap.Width / 2;
            int y_count = heightmap.Height / 2;

            var new_size = new Vector3(s2, size / 8, s2);
            blocks = new TerrainBlock[4];
            blocks[0] = new TerrainBlock(0, 0, x_count, y_count, new BoundingBox()
            {
                Size = new_size,
                Position = new Vector3(-offset, 0, offset)
            }, 0, this);
            blocks[1] = new TerrainBlock(x_count-1, 0, x_count, y_count, new BoundingBox()
            {
                Size = new_size,
                Position = new Vector3(offset, 0, offset)
            }, 0, this);

            blocks[2] = new TerrainBlock(x_count-1, y_count-1, x_count, y_count, new BoundingBox()
            {
                Size = new_size,
                Position = new Vector3(offset, 0, -offset)
            }, 0, this);
            blocks[3] = new TerrainBlock(0, y_count-1, x_count, y_count, new BoundingBox()
            {
                Size = new_size,
                Position = new Vector3(-offset, 0, -offset)
            }, 0, this);

            vb.BufferData(VboUsage.GL_STATIC_DRAW);
            vb.FreeClientData();
            init_finished = true;
        }
开发者ID:r-bel,项目名称:glorg2,代码行数:87,代码来源:Terrain.cs

示例4: InitializeGraphics

        public void InitializeGraphics()
        {
            if (vb != null)
                vb.Dispose();

            if (mat == null)
            {
                Glorg2.Resource.MaterialImporter imp = new Glorg2.Resource.MaterialImporter();
                using(var stream = System.IO.File.OpenRead(".\\shaders\\Grid.mxl"))
                {
                    mat = imp.Import<StdMaterial>(stream, "grid", null);
                }
            }
            vb = new VertexBuffer<WireframeVertex>(WireframeVertex.Description);

            vb.Allocate(Columns * 2 + Rows * 2 + 4);
            float tot_w = Size * Columns;
            float tot_h = Size * Rows;
            float fi = -tot_w / 2;
            int i;
            for (i = 0; i <= Columns; i++, fi += Size)
            {
                Vector4 color;
                if(Major == 0 || (i % Major) == 0)
                    color = MajorColor;
                else
                    color = MinorColor;
                vb[i * 2]     = new WireframeVertex() { Position = new Vector3(fi, 0, -tot_h / 2), Color = color };
                vb[i * 2 + 1] = new WireframeVertex() { Position = new Vector3(fi, 0,  tot_h / 2), Color = color };
            }
            int start = i * 2;
            fi = -tot_h / 2;
            for (int j = 0; j <= Rows; j++, fi += Size)
            {
                Vector4 color;
                if (Major == 0 || (j % Major) == 0)
                    color = MajorColor;
                else
                    color = MinorColor;
                vb[start + j * 2]     = new WireframeVertex() { Position = new Vector3(-tot_h / 2, 0, fi), Color = color };
                vb[start + j * 2 + 1] = new WireframeVertex() { Position = new Vector3( tot_h / 2, 0, fi), Color = color };
            }
            vb.BufferData(VboUsage.GL_STATIC_DRAW);
            vb.FreeClientData();
        }
开发者ID:r-bel,项目名称:glorg2,代码行数:45,代码来源:Wireframe.cs

示例5: InitializeGraphics

        public void InitializeGraphics()
        {
            if(mat == null)
                owner.Resources.Load("shaders\\Grid", out mat);
            if (vb == null)
            {
                vb = new VertexBuffer<VertexPositionColor>(VertexPositionColor.Descriptor);
                vb.Allocate(8);
            }
            if (ib == null)
            {
                ib = new IndexBuffer<uint>();
                ib.Allocate(24);
                ib[0] = 0;
                ib[1] = 1;
                ib[2] = 1;
                ib[3] = 2;
                ib[4] = 2;
                ib[5] = 3;
                ib[6] = 3;
                ib[7] = 0;

                ib[8] = 4;
                ib[9] = 5;
                ib[10] = 5;
                ib[11] = 6;
                ib[12] = 6;
                ib[13] = 7;
                ib[14] = 4;

                ib[15] = 0;
                ib[16] = 4;

                ib[17] = 1;
                ib[18] = 5;

                ib[19] = 2;
                ib[20] = 6;

                ib[21] = 3;
                ib[22] = 7;
                ib.BufferData(VboUsage.GL_STATIC_DRAW);
            }

            if (points != null)
            {
                for (int i = 0; i < 8; i++)
                {
                    vb[i] = new VertexPositionColor() { Position = points[i], Color = Colors.Yellow };
                }
            }

            vb.BufferData(VboUsage.GL_DYNAMIC_DRAW);
        }
开发者ID:r-bel,项目名称:glorg2,代码行数:54,代码来源:Camera.cs


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